Ejemplo n.º 1
0
/*
//
//  ISAM - build file cluster
//
*/
int tcob_build_vbidx(struct file_desc *f)
{ 
  int r=0, i=0, ifilehandle, iresult, imode;
  tcb_fileio_vbidx_handle *h;
  struct keydesc *wkeydesc;   

#ifdef DEBUG_FILEISAM_RTS8
     fprintf(stderr, "debug : tcob_build_vbidx 010.040 : f->filename=%s, f->flags.file_isvariable=%d;\n", f->filename, f->flags.file_isvariable);
#endif                                       
  
  h = (tcb_fileio_vbidx_handle *)f->dbp;

  if (f->flags.file_isvariable == 1) {
     imode = ISINOUT+ISVARLEN+ISEXCLLOCK;
     isreclen = f->reclen_min;
  }
  else {
     imode = ISINOUT+ISFIXLEN+ISEXCLLOCK;
  }

  wkeydesc = h->skeydesc;
  /* Define ISAM file - define primary key */  
  ifilehandle = isbuild(f->filename, f->reclen, wkeydesc, imode);
#ifdef DEBUG_FILEISAM_RTS8
  fprintf(stderr, "debug : tcob_build_vbidx 010.060 : f->filename=%s, f->reclen=%d, ifilehandle=%d;\n", f->filename, f->reclen, ifilehandle);
#endif                                       
  if (ifilehandle < 0) {
     r = tcob_eisam2ecob(0);
     return (r);        
  }

  /* Define ISAM file - define secondary keys */  
  for (i=1; i < f->nkeys; i++) {
     wkeydesc = h->skeydesc + i;
     iresult = isaddindex(ifilehandle, wkeydesc);
     if (iresult != 0) {
        r = tcob_eisam2ecob(0);
        iresult = isclose(ifilehandle);
        iserase (f->filename);
        return (r);        
     }
  }

  iresult = isclose(ifilehandle);
  if (iresult != 0) {
     r = tcob_eisam2ecob(0);
     iserase (f->filename);
     return (r);        
  }
  
  h->ifilehandle = ifilehandle;

#ifdef DEBUG_FILEISAM_RTS8
     fprintf(stderr, "debug : tcob_build_vbidx 010.080 : r=%d;\n", r);
#endif                                       

  RETURN_STATUS(r);        
}
Ejemplo n.º 2
0
int
main (int iArgc, char **ppcArgv)
{
	int	iResult,
		iLoop,
		iLoop2,
		iLoop3,
		iHandle;
	unsigned char
		cRecord [256];
	struct	keydesc
		sKeydesc;
	char	cLogfileName [100],
		cCommand [100];
	char	cFileName [] = "IsamTest";

	memset (&sKeydesc, 0, sizeof (sKeydesc));
	sKeydesc.k_flags = COMPRESS;
	sKeydesc.k_nparts = 1;
	sKeydesc.k_start = 0;
	sKeydesc.k_leng = 2;
	sKeydesc.k_type = CHARTYPE;

	if (iArgc == 1) {
		printf ("Usage:\n\t%s create\nOR\n\t%s <#iterations>\n", ppcArgv [0], ppcArgv [0]);
		exit (1);
	}

	if (iArgc > 1 && strcmp (ppcArgv [1], "create") == 0) {
		iserase (cFileName);
		iHandle = isbuild (cFileName, 255, &sKeydesc, ISINOUT+ISFIXLEN+ISEXCLLOCK);
		if (iHandle < 0) {
			printf ("Error creating database: %d\n", iserrno);
			exit (-1);
		}
		sKeydesc.k_flags |= ISDUPS;
	sKeydesc.k_start = 3;
	sKeydesc.k_leng = 4;
		for (sKeydesc.k_start = 1; sKeydesc.k_start < 2; sKeydesc.k_start++) {
			if (isaddindex (iHandle, &sKeydesc)) {
				printf ("Error %d adding index %d\n", iserrno, sKeydesc.k_start);
			}
		}
		isclose (iHandle);
		sprintf (cLogfileName, "RECOVER");
#ifdef	_WIN32
		sprintf (cCommand, "del /f /q %s", cLogfileName);
#else
		sprintf (cCommand, "rm -f %s; touch %s", cLogfileName, cLogfileName);
#endif
		system (cCommand);
		return (0);
	}
	sprintf (cLogfileName, "RECOVER");
#ifdef	_WIN32
	iResult = open("RECOVER", O_CREAT | O_TRUNC | O_RDWR | O_BINARY, 0666);
#else
	iResult = open("RECOVER", O_CREAT | O_TRUNC | O_RDWR, 0666);
#endif
	close(iResult);
	iResult = islogopen (cLogfileName);
	if (iResult < 0) {
		printf ("Error opening log: %d\n", iserrno);
		exit (-1);
	}

/*
	srand (time (NULL));
*/
	srand (9);
	for (iLoop = 0; iLoop < atoi (ppcArgv [1]); iLoop++)
	{
		if (!(iLoop % 100)) {
			printf ("iLoop=%d\n", iLoop);
			fflush(stdout);
		}

		iVBDlCount = 0;
		iVBRdCount = 0;
		iVBUpCount = 0;
		iVBWrCount = 0;
		iResult = isbegin ();
		if (iResult < 0) {
			printf ("Error begin transaction: %d\n", iserrno);
			exit (-1);
		}
		iHandle = isopen (cFileName, ISINOUT+ISFIXLEN+ISTRANS+ISAUTOLOCK);
		if (iHandle < 0) {
			printf ("Error opening database: %d\n", iserrno);
			exit (-1);
		}

		for (iLoop2 = 0; iLoop2 < 100; iLoop2++)
		{
			for (iLoop3 = 0; iLoop3 < 256; iLoop3++) {
				cRecord [iLoop3] = rand () % 256;
			}

			iResult =rand () % 4;
/*
			fprintf(stderr, "I %d\n", iResult);
*/
			switch (iResult) {
			case	0:
				if ((iResult = iswrite (iHandle, (char *) cRecord)) != 0) {
					if (iserrno != EDUPL && iserrno != ELOCKED) {
						printf ("Error writing: %d\n", iserrno);
						goto err;
					}
				} else {
					iVBWrCount++;
				}
				break;

			case	1:
				if ((iResult = isread (iHandle, (char *)cRecord, ISEQUAL)) != 0) {
					if (iserrno == ELOCKED) {
						; /* printf ("Locked during deletion\n"); */
					} else if (iserrno != ENOREC) {
						printf ("Error reading: %d\n", iserrno);
						goto err;
					}
				} else {
					iVBRdCount++;
				}
				break;

			case	2:
				for (iLoop3 = 0; iLoop3 < 256; iLoop3++) {
					cRecord [iLoop3] = rand () % 256;
				}
				if ((iResult = isrewrite (iHandle, (char *)cRecord)) != 0) {
					if (iserrno == ELOCKED) {
						; /* printf ("Locked during rewrite\n"); */
					} else if (iserrno != ENOREC) {
						printf ("Error rewriting: %d\n", iserrno);
						goto err;
					}
				} else {
					iVBUpCount++;
				}
				break;

			case	3:
				if ((iResult = isdelete (iHandle, (char *)cRecord)) != 0) {
					if (iserrno == ELOCKED) {
						; /* printf ("Locked during deletion\n"); */
					} else if (iserrno != ENOREC) {
						printf ("Error deleting: %d\n", iserrno);
						goto err;
					}
				}
				else
					iVBDlCount++;
				break;
			}
		}

		iResult = isflush (iHandle);
		if (iResult < 0) {
			printf ("Error flush: %d\n", iserrno);
			exit (-1);
		}
		iResult = isclose (iHandle);
		if (iResult < 0) {
			printf ("Error closing database: %d\n", iserrno);
			exit (-1);
		}

		iVBDlTotal += iVBDlCount;
		iVBRdTotal += iVBRdCount;
		iVBUpTotal += iVBUpCount;
		iVBWrTotal += iVBWrCount;
		switch (rand () % 2) {
		case	0:
			iVBDlCommit += iVBDlCount;
			iVBRdCommit += iVBRdCount;
			iVBUpCommit += iVBUpCount;
			iVBWrCommit += iVBWrCount;
			iResult = iscommit ();
			if (iResult < 0) {
				printf ("Error commit: %d\n", iserrno);
				exit (-1);
			}
			break;

		case	1:
			iResult = isrollback ();
			if (iResult < 0) {
				if (iserrno == EDUPL || iserrno == ENOREC) {
					printf ("Same BUG (%d) as in C-ISAM!\n", iserrno);
				} else {
					printf ("Error rollback: %d\n", iserrno);
					exit (-1);
				}
			}
			break;
		}
	}
err:
	printf ("                 Total Commited\n");
	printf ("              -------- --------\n");
	printf ("Delete Count: %8d %8d\n", iVBDlTotal, iVBDlCommit);
	printf ("Read   Count: %8d %8d\n", iVBRdTotal, iVBRdCommit);
	printf ("Update Count: %8d %8d\n", iVBUpTotal, iVBUpCommit);
	printf ("Write  Count: %8d %8d\n", iVBWrTotal, iVBWrCommit);
	printf ("              -------- --------\n");
	printf ("OPS OVERALL : %8d %8d\n", (iVBDlTotal + iVBRdTotal + iVBUpTotal + iVBWrTotal), (iVBDlCommit + iVBRdCommit + iVBUpCommit + iVBWrCommit));
	printf ("                       ========\n");
	printf ("ROWS ADDED THIS RUN:   %8d\n", (iVBWrCommit - iVBDlCommit));
	printf ("                       ========\n");
	return (iResult);
}
Ejemplo n.º 3
0
int
idxopen (unit *ftnunit, char *name, int create, flag idxerr)
{
   struct dictinfo info;
   int             mode =(ftnunit->ureadonly ? ISINPUT : ISINOUT) +
   (ftnunit->ushared ? ISAUTOLOCK : ISEXCLLOCK);
   register int    i;

   keys = ftnunit->ukeys;
   if (create) {
      if (ftnunit->url == 0)
	 err (idxerr, 153, "indexed open");
      if (ftnunit->unkeys == 0 || keys == NULL)
	 err (idxerr, 161, "indexed open");
      onekey.k_flags = ISNODUPS;
      KEYOFF (0)--;
      KEYEND (0)--;
      dokey (0, ONEKEY);
      if (ftnunit->unkeys == 1) {
	/* DLAI: need to change isbuild 2nd arg to XINT */
	 if ((ftnunit->isfd = isbuild (name, ftnunit->url, &onekey, mode)) < SUCCESS)
	    ierr (idxerr, iserrno, "indexed open");
      } else {
	 if ((ftnunit->isfd =
	      isbuild (name, ftnunit->url, &onekey, ISINOUT + ISEXCLLOCK)) < SUCCESS)
	    ierr (idxerr, iserrno, "indexed open");
	 onekey.k_flags = ISDUPS;
	 for (i = 1; i < ftnunit->unkeys; i++) {
	    KEYOFF (i)--;
	    KEYEND (i)--;
	    dokey (i, ONEKEY);
	    if (isaddindex (ftnunit->isfd, &onekey) < SUCCESS)
	       ierr (idxerr, iserrno, "indexed open");
	 }
	 if (ftnunit->ushared) {
	    if (isclose (ftnunit->isfd) < SUCCESS)
	       ierr (idxerr, iserrno, "indexed open");
	    if ((ftnunit->isfd = isopen (name, mode)) < SUCCESS)
	       ierr (idxerr, iserrno, "indexed open");
	 }
      }
   } else {
      if ((ftnunit->isfd = isopen (name, mode)) < SUCCESS)
	 ierr (idxerr, iserrno, "indexed open");
      if (isindexinfo (ftnunit->isfd, &info, 0) < SUCCESS)
	 ierr (idxerr, iserrno, "indexed open");
      if (ftnunit->unkeys != info.di_nkeys) {
	 if (ftnunit->unkeys) {
	    err (idxerr, 148, "indexed open");
	 } else
	    ftnunit->unkeys = info.di_nkeys;
      }
      if (!keys)
	 keys = (Keyspec *) malloc (sizeof (Keyspec) * info.di_nkeys);
      for (i = 0; i < info.di_nkeys; i++) {
	 if (isindexinfo (ftnunit->isfd, &onekey, i + 1) < SUCCESS)
	    ierr (idxerr, iserrno, "indexed open");
/* LHL 5/4/89
 * To fix bug 4428, problem about trying to open an existing indexed file.
 * This is put here because when the indexed file is created, the keys
 * are being stored like this.  Refer to the above code.
 */
	 KEYOFF (i)--;
	 KEYEND (i)--;
/* end of fix */
	 if (ftnunit->ukeys && dokey (i, NOMATCH)) {
	    err (idxerr, 148, "indexed open");
	 } else
	    dokey (i, UNITKEY);
      }
      ftnunit->url = info.di_recsize;
      ftnunit->ukeys = keys;
   }
   return SUCCESS;
}