Ejemplo n.º 1
0
/* thread the remove function */
static void *threadremove(void *targ){
  TCMDB *mdb = ((TARGCOMBO *)targ)->mdb;
  TCNDB *ndb = ((TARGCOMBO *)targ)->ndb;
  int rnum = ((TARGCOMBO *)targ)->rnum;
  bool rnd = ((TARGCOMBO *)targ)->rnd;
  int id = ((TARGCOMBO *)targ)->id;
  double stime = tctime();
  if(id == 0) iprintf("removing:\n");
  int base = id * rnum;
  for(int i = 1; i <= rnum; i++){
    char buf[RECBUFSIZ];
    int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) : i));
    if(ndb){
      tcndbout(ndb, buf, len);
    } else {
      tcmdbout(mdb, buf, len);
    }
    if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
    }
  }
  if(id == 0) iprintf("time: %.3f\n", tctime() - stime);
  return NULL;
}
Ejemplo n.º 2
0
/* perform remove command */
static int procremove(const char *path, int tnum, int omode, bool rnd){
  iprintf("<Removing Test>\n  seed=%u  path=%s  tnum=%d  omode=%d  rnd=%d\n\n",
          g_randseed, path, tnum, omode, rnd);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(!tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  int rnum = tcfdbrnum(fdb) / tnum;
  TARGREMOVE targs[tnum];
  pthread_t threads[tnum];
  if(tnum == 1){
    targs[0].fdb = fdb;
    targs[0].rnum = rnum;
    targs[0].rnd = rnd;
    targs[0].id = 0;
    if(threadremove(targs) != NULL) err = true;
  } else {
    for(int i = 0; i < tnum; i++){
      targs[i].fdb = fdb;
      targs[i].rnum = rnum;
      targs[i].rnd = rnd;
      targs[i].id = i;
      if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){
        eprint(fdb, __LINE__, "pthread_create");
        targs[i].id = -1;
        err = true;
      }
    }
    for(int i = 0; i < tnum; i++){
      if(targs[i].id == -1) continue;
      void *rv;
      if(pthread_join(threads[i], &rv) != 0){
        eprint(fdb, __LINE__, "pthread_join");
        err = true;
      } else if(rv){
        err = true;
      }
    }
  }
  iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  iprintf("time: %.3f\n", tctime() - stime);
  iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Ejemplo n.º 3
0
/* perform read command */
static int procread(const char *path, bool mt, int omode, bool wb, bool rnd){
  my_my_my_iprintf("<Reading Test>\n  seed=%u  path=%s  mt=%d  omode=%d  wb=%d  rnd=%d\n\n",
          g_randseed, path, mt, omode, wb, rnd);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(mt && !tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOREADER | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  int rnum = tcfdbrnum(fdb);
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
    int vsiz;
    if(wb){
      char vbuf[RECBUFSIZ];
      int vsiz = tcfdbget4(fdb, i, vbuf, RECBUFSIZ);
      if(vsiz < 0 && !(rnd && tcfdbecode(fdb) == TCENOREC)){
        eprint(fdb, __LINE__, "tcfdbget4");
        err = true;
        break;
      }
    } else {
      char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
      if(!vbuf && !(rnd && tcfdbecode(fdb) == TCENOREC)){
        eprint(fdb, __LINE__, "tcfdbget");
        err = true;
        break;
      }
      tcfree(vbuf);
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  my_my_my_iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  my_my_my_iprintf("time: %.3f\n", tctime() - stime);
  my_my_my_iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Ejemplo n.º 4
0
/* perform typical command */
static int proctypical(int tnum, int rnum, int bnum, bool tr, bool nc, int rratio){
  iprintf("<Typical Access Test>\n  seed=%u  tnum=%d  rnum=%d  bnum=%d  tr=%d  nc=%d"
          "  rratio=%d\n\n", g_randseed, tnum, rnum, bnum, tr, nc, rratio);
  bool err = false;
  double stime = tctime();
  TCMDB *mdb = (bnum > 0) ? tcmdbnew2(bnum) : tcmdbnew();
  TCNDB *ndb = tcndbnew();
  TARGTYPICAL targs[tnum];
  pthread_t threads[tnum];
  if(tnum == 1){
    targs[0].mdb = mdb;
    targs[0].ndb = tr ? ndb : NULL;
    targs[0].rnum = rnum;
    targs[0].nc = nc;
    targs[0].rratio = rratio;
    targs[0].id = 0;
    if(threadtypical(targs) != NULL) err = true;
  } else {
    for(int i = 0; i < tnum; i++){
      targs[i].mdb = mdb;
      targs[i].ndb = tr ? ndb : NULL;
      targs[i].rnum = rnum;
      targs[i].nc = nc;
      targs[i].rratio= rratio;
      targs[i].id = i;
      if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){
        eprint(__LINE__, "pthread_create");
        targs[i].id = -1;
        err = true;
      }
    }
    for(int i = 0; i < tnum; i++){
      if(targs[i].id == -1) continue;
      void *rv;
      if(pthread_join(threads[i], &rv) != 0){
        eprint(__LINE__, "pthread_join");
        err = true;
      } else if(rv){
        err = true;
      }
    }
  }
  if(tr){
    iprintf("record number: %llu\n", (unsigned long long)tcndbrnum(ndb));
    iprintf("size: %llu\n", (unsigned long long)tcndbmsiz(ndb));
  } else {
    iprintf("record number: %llu\n", (unsigned long long)tcmdbrnum(mdb));
    iprintf("size: %llu\n", (unsigned long long)tcmdbmsiz(mdb));
  }
  tcndbdel(ndb);
  tcmdbdel(mdb);
  iprintf("time: %.3f\n", tctime() - stime);
  iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Ejemplo n.º 5
0
/* main routine */
int main(int argc, char **argv){
  g_progname = argv[0];
  const char *ebuf = getenv("TCRNDSEED");
  g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
  srand(g_randseed);
  ebuf = getenv("TCDBGFD");
  g_dbgfd = ebuf ? tcatoix(ebuf) : UINT16_MAX;
  if(argc < 2) usage();
  int rv = 0;
  if(!strcmp(argv[1], "write")){
    rv = runwrite(argc, argv);
  } else if(!strcmp(argv[1], "read")){
    rv = runread(argc, argv);
  } else if(!strcmp(argv[1], "remove")){
    rv = runremove(argc, argv);
  } else {
    usage();
  }
  if(rv != 0){
    printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
    for(int i = 0; i < argc; i++){
      printf(" %s", argv[i]);
    }
    printf("\n\n");
  }
  return rv;
}
Ejemplo n.º 6
0
/* perform write command */
static int procwrite(const char *path, int rnum, int width, int64_t limsiz,
                     bool mt, int omode, bool rnd){
  my_my_my_iprintf("<Writing Test>\n  seed=%u  path=%s  rnum=%d  width=%d  limsiz=%lld  mt=%d  omode=%d"
          "  rnd=%d\n\n", g_randseed, path, rnum, width, (long long)limsiz, mt, omode, rnd);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(mt && !tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbtune(fdb, width, limsiz)){
    eprint(fdb, __LINE__, "tcfdbtune");
    err = true;
  }
  if(!rnd) omode |= FDBOTRUNC;
  if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  for(int i = 1; i <= rnum; i++){
    char buf[RECBUFSIZ];
    int len = sprintf(buf, "%08d", rnd ? myrand(rnum) + 1 : i);
    if(!tcfdbput2(fdb, buf, len, buf, len)){
      eprint(fdb, __LINE__, "tcfdbput");
      err = true;
      break;
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  my_my_my_iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  my_my_my_iprintf("time: %.3f\n", tctime() - stime);
  my_my_my_iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Ejemplo n.º 7
0
/* thread the read function */
static void *threadread(void *targ){
  TCMDB *mdb = ((TARGCOMBO *)targ)->mdb;
  TCNDB *ndb = ((TARGCOMBO *)targ)->ndb;
  int rnum = ((TARGCOMBO *)targ)->rnum;
  bool rnd = ((TARGCOMBO *)targ)->rnd;
  int id = ((TARGCOMBO *)targ)->id;
  double stime = tctime();
  if(id == 0) iprintf("reading:\n");
  int base = id * rnum;
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i) : i));
    int vsiz;
    char *vbuf = ndb ? tcndbget(ndb, kbuf, ksiz, &vsiz) : tcmdbget(mdb, kbuf, ksiz, &vsiz);
    if(vbuf) tcfree(vbuf);
    if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
    }
  }
  if(id == 0) iprintf("time: %.3f\n", tctime() - stime);
  return NULL;
}
Ejemplo n.º 8
0
/* main routine */
int main(int argc, char **argv){
  g_progname = argv[0];
  const char *ebuf = getenv("TCRNDSEED");
  g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
  srand(g_randseed);
  ebuf = getenv("TCDBGFD");
  if (ebuf) {
	  int debugfd = tcatoix(ebuf);
#ifdef __MINGW32__
	  g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
	  g_dbgfd = debugfd;
#endif
  }
  if(argc < 2) usage();
  int rv = 0;
  if(!strcmp(argv[1], "write")){
    rv = runwrite(argc, argv);
  } else if(!strcmp(argv[1], "read")){
    rv = runread(argc, argv);
  } else if(!strcmp(argv[1], "remove")){
    rv = runremove(argc, argv);
  } else if(!strcmp(argv[1], "wicked")){
    rv = runwicked(argc, argv);
  } else if(!strcmp(argv[1], "typical")){
    rv = runtypical(argc, argv);
  } else {
    usage();
  }
  if(rv != 0){
    printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
    for(int i = 0; i < argc; i++){
      printf(" %s", argv[i]);
    }
    printf("\n\n");
  }
  return rv;
}
Ejemplo n.º 9
0
/* main routine */
int main(int argc, char **argv){
  g_progname = argv[0];
  const char *ebuf = getenv("TCRNDSEED");
  g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
  srand(g_randseed);
  if(argc < 2) usage();
  int rv = 0;
  if(!strcmp(argv[1], "combo")){
    rv = runcombo(argc, argv);
  } else if(!strcmp(argv[1], "typical")){
    rv = runtypical(argc, argv);
  } else {
    usage();
  }
  if(rv != 0){
    printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
    for(int i = 0; i < argc; i++){
      printf(" %s", argv[i]);
    }
    printf("\n\n");
  }
  return rv;
}
Ejemplo n.º 10
0
/* thread the wicked function */
static void *threadwicked(void *targ){
  TCFDB *fdb = ((TARGWICKED *)targ)->fdb;
  int rnum = ((TARGWICKED *)targ)->rnum;
  bool nc = ((TARGWICKED *)targ)->nc;
  int id = ((TARGWICKED *)targ)->id;
  TCMAP *map = ((TARGWICKED *)targ)->map;
  bool err = false;
  for(int i = 1; i <= rnum && !err; i++){
    uint64_t kid = myrand(rnum * (id + 1)) + 1;
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%llu", (unsigned long long)kid);
    char vbuf[RECBUFSIZ];
    int vsiz = myrand(RECBUFSIZ);
    memset(vbuf, '*', vsiz);
    vbuf[vsiz] = '\0';
    char *rbuf;
    if(!nc) tcglobalmutexlock();
    switch(myrand(16)){
      case 0:
        if(id == 0) iputchar('0');
        if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput2");
          err = true;
        }
        if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 1:
        if(id == 0) iputchar('1');
        if(!tcfdbput3(fdb, kbuf, vbuf)){
          eprint(fdb, __LINE__, "tcfdbput3");
          err = true;
        }
        if(!nc) tcmapput2(map, kbuf, vbuf);
        break;
      case 2:
        if(id == 0) iputchar('2');
        if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputkeep2");
          err = true;
        }
        if(!nc) tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 3:
        if(id == 0) iputchar('3');
        if(!tcfdbputkeep3(fdb, kbuf, vbuf) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputkeep3");
          err = true;
        }
        if(!nc) tcmapputkeep2(map, kbuf, vbuf);
        break;
      case 4:
        if(id == 0) iputchar('4');
        if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbputcat2");
          err = true;
        }
        if(!nc) tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 5:
        if(id == 0) iputchar('5');
        if(!tcfdbputcat3(fdb, kbuf, vbuf)){
          eprint(fdb, __LINE__, "tcfdbputcat3");
          err = true;
        }
        if(!nc) tcmapputcat2(map, kbuf, vbuf);
        break;
      case 6:
        if(id == 0) iputchar('6');
        if(myrand(2) == 0){
          if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbout2");
            err = true;
          }
          if(!nc) tcmapout(map, kbuf, ksiz);
        }
        break;
      case 7:
        if(id == 0) iputchar('7');
        if(myrand(2) == 0){
          if(!tcfdbout3(fdb, kbuf) && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbout3");
            err = true;
          }
          if(!nc) tcmapout2(map, kbuf);
        }
        break;
      case 8:
        if(id == 0) iputchar('8');
        if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz))){
          if(tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbget2");
            err = true;
          }
          rbuf = tcsprintf("[%d]", myrand(i + 1));
          vsiz = strlen(rbuf);
        }
        vsiz += myrand(vsiz);
        if(myrand(3) == 0) vsiz += PATH_MAX;
        rbuf = tcrealloc(rbuf, vsiz + 1);
        for(int j = 0; j < vsiz; j++){
          rbuf[j] = myrand(0x100);
        }
        if(!tcfdbput2(fdb, kbuf, ksiz, rbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput2");
          err = true;
        }
        if(!nc) tcmapput(map, kbuf, ksiz, rbuf, vsiz);
        tcfree(rbuf);
        break;
      case 9:
        if(id == 0) iputchar('9');
        if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz)) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbget2");
          err = true;
        }
        tcfree(rbuf);
        break;
      case 10:
        if(id == 0) iputchar('A');
        if(!(rbuf = tcfdbget3(fdb, kbuf)) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbge3");
          err = true;
        }
        tcfree(rbuf);
        break;
      case 11:
        if(id == 0) iputchar('B');
        if(myrand(1) == 0) vsiz = 1;
        if((vsiz = tcfdbget4(fdb, kid, vbuf, vsiz)) < 0 && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbget4");
          err = true;
        }
        break;
      case 14:
        if(id == 0) iputchar('E');
        if(myrand(rnum / 50) == 0){
          if(!tcfdbiterinit(fdb)){
            eprint(fdb, __LINE__, "tcfdbiterinit");
            err = true;
          }
        }
        for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
          if(tcfdbiternext(fdb) < 1){
            int ecode = tcfdbecode(fdb);
            if(ecode != TCEINVALID && ecode != TCENOREC){
              eprint(fdb, __LINE__, "tcfdbiternext");
              err = true;
            }
          }
        }
        break;
      default:
        if(id == 0) iputchar('@');
        if(tcfdbtranbegin(fdb)){
          if(myrand(2) == 0){
            if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
              eprint(fdb, __LINE__, "tcfdbput");
              err = true;
            }
            if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
          } else {
            if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
              eprint(fdb, __LINE__, "tcfdbout");
              err = true;
            }
            if(!nc) tcmapout(map, kbuf, ksiz);
          }
          if(nc && myrand(2) == 0){
            if(!tcfdbtranabort(fdb)){
              eprint(fdb, __LINE__, "tcfdbtranabort");
              err = true;
            }
          } else {
            if(!tcfdbtrancommit(fdb)){
              eprint(fdb, __LINE__, "tcfdbtrancommit");
              err = true;
            }
          }
        } else {
          eprint(fdb, __LINE__, "tcfdbtranbegin");
          err = true;
        }
        if(myrand(1000) == 0){
          if(!tcfdbforeach(fdb, iterfunc, NULL)){
            eprint(fdb, __LINE__, "tcfdbforeach");
            err = true;
          }
        }
        if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
        break;
    }
    if(!nc) tcglobalmutexunlock();
    if(id == 0){
      if(i % 50 == 0) iprintf(" (%08d)\n", i);
      if(id == 0 && i == rnum / 4){
        if(!tcfdboptimize(fdb, RECBUFSIZ, -1) && tcfdbecode(fdb) != TCEINVALID){
          eprint(fdb, __LINE__, "tcfdboptimize");
          err = true;
        }
        if(!tcfdbiterinit(fdb)){
          eprint(fdb, __LINE__, "tcfdbiterinit");
          err = true;
        }
      }
    }
  }
  return err ? "error" : NULL;
}
Ejemplo n.º 11
0
/* perform wicked command */
static int procwicked(const char *path, int tnum, int rnum, int omode, bool nc){
  iprintf("<Writing Test>\n  seed=%u  path=%s  tnum=%d  rnum=%d  omode=%d  nc=%d\n\n",
          g_randseed, path, tnum, rnum, omode, nc);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(!tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbtune(fdb, RECBUFSIZ * 2, EXHEADSIZ + (RECBUFSIZ * 2 + sizeof(int)) * rnum * tnum)){
    eprint(fdb, __LINE__, "tcfdbtune");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  if(!tcfdbiterinit(fdb)){
    eprint(fdb, __LINE__, "tcfdbiterinit");
    err = true;
  }
  TARGWICKED targs[tnum];
  pthread_t threads[tnum];
  TCMAP *map = tcmapnew();
  if(tnum == 1){
    targs[0].fdb = fdb;
    targs[0].rnum = rnum;
    targs[0].nc = nc;
    targs[0].id = 0;
    targs[0].map = map;
    if(threadwicked(targs) != NULL) err = true;
  } else {
    for(int i = 0; i < tnum; i++){
      targs[i].fdb = fdb;
      targs[i].rnum = rnum;
      targs[i].nc = nc;
      targs[i].id = i;
      targs[i].map = map;
      if(pthread_create(threads + i, NULL, threadwicked, targs + i) != 0){
        eprint(fdb, __LINE__, "pthread_create");
        targs[i].id = -1;
        err = true;
      }
    }
    for(int i = 0; i < tnum; i++){
      if(targs[i].id == -1) continue;
      void *rv;
      if(pthread_join(threads[i], &rv) != 0){
        eprint(fdb, __LINE__, "pthread_join");
        err = true;
      } else if(rv){
        err = true;
      }
    }
  }
  if(!nc){
    if(!tcfdbsync(fdb)){
      eprint(fdb, __LINE__, "tcfdbsync");
      err = true;
    }
    if(tcfdbrnum(fdb) != tcmaprnum(map)){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
    }
    int end = rnum * tnum;
    for(int i = 1; i <= end && !err; i++){
      char kbuf[RECBUFSIZ];
      int ksiz = sprintf(kbuf, "%d", i);
      int vsiz;
      const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
      int rsiz;
      char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
      if(vbuf){
        iputchar('.');
        if(vsiz > tcfdbwidth(fdb)) vsiz = tcfdbwidth(fdb);
        if(!rbuf){
          eprint(fdb, __LINE__, "tcfdbget");
          err = true;
        } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
          eprint(fdb, __LINE__, "(validation)");
          err = true;
        }
      } else {
        iputchar('*');
        if(rbuf || tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "(validation)");
          err = true;
        }
      }
      tcfree(rbuf);
      if(i % 50 == 0) iprintf(" (%08d)\n", i);
    }
    if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
  }
  tcmapdel(map);
  iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  iprintf("time: %.3f\n", tctime() - stime);
  iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Ejemplo n.º 12
0
/* perform typical command */
static int proctypical(const char *path, int tnum, int rnum, int width, int64_t limsiz,
                       int omode, bool nc, int rratio){
  iprintf("<Typical Access Test>\n  seed=%u  path=%s  tnum=%d  rnum=%d  width=%d  limsiz=%lld"
          "  omode=%d  nc=%d  rratio=%d\n\n",
          g_randseed, path, tnum, rnum, width, (long long)limsiz, omode, nc, rratio);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(!tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbtune(fdb, width, limsiz)){
    eprint(fdb, __LINE__, "tcfdbtune");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  TARGTYPICAL targs[tnum];
  pthread_t threads[tnum];
  if(tnum == 1){
    targs[0].fdb = fdb;
    targs[0].rnum = rnum;
    targs[0].nc = nc;
    targs[0].rratio = rratio;
    targs[0].id = 0;
    if(threadtypical(targs) != NULL) err = true;
  } else {
    for(int i = 0; i < tnum; i++){
      targs[i].fdb = fdb;
      targs[i].rnum = rnum;
      targs[i].nc = nc;
      targs[i].rratio= rratio;
      targs[i].id = i;
      if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){
        eprint(fdb, __LINE__, "pthread_create");
        targs[i].id = -1;
        err = true;
      }
    }
    for(int i = 0; i < tnum; i++){
      if(targs[i].id == -1) continue;
      void *rv;
      if(pthread_join(threads[i], &rv) != 0){
        eprint(fdb, __LINE__, "pthread_join");
        err = true;
      } else if(rv){
        err = true;
      }
    }
  }
  iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  iprintf("time: %.3f\n", tctime() - stime);
  iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Ejemplo n.º 13
0
/* perform search command */
static int procsearch(const char *path, TCLIST *conds, const char *oname, const char *otype,
                      int omode, int max, int skip, bool pv, bool px, bool kw, bool ph, int bt,
                      bool rm, const char *mtype){
  TCTDB *tdb = tctdbnew();
  if(g_dbgfd != INVALID_HANDLE_VALUE) tctdbsetdbgfd(tdb, g_dbgfd);
  if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
  if(!tctdbopen(tdb, path, (rm ? TDBOWRITER : TDBOREADER) | omode)){
    printerr(tdb);
    tctdbdel(tdb);
    return 1;
  }
  bool err = false;
  TDBQRY *qry = tctdbqrynew(tdb);
  int cnum = tclistnum(conds);
  for(int i = 0; i < cnum - 2; i += 3){
    const char *name = tclistval2(conds, i);
    const char *opstr = tclistval2(conds, i + 1);
    const char *expr  = tclistval2(conds, i + 2);
    int op = tctdbqrystrtocondop(opstr);
    if(op >= 0) tctdbqryaddcond(qry, name, op, expr);
  }
  if(oname){
    int type = tctdbqrystrtoordertype(otype);
    if(type >= 0) tctdbqrysetorder(qry, oname, type);
  }
  tctdbqrysetlimit(qry, max, skip);
  if(rm){
    double stime = tctime();
    if(!tctdbqrysearchout(qry)){
      printerr(tdb);
      err = true;
    }
    double etime = tctime();
    if(ph){
      TCLIST *hints = tcstrsplit(tctdbqryhint(qry), "\n");
      int hnum = tclistnum(hints);
      for(int i = 0; i < hnum; i++){
        const char *hint = tclistval2(hints, i);
        if(*hint == '\0') continue;
        printf("\t:::: %s\n", hint);
      }
      tclistdel(hints);
      printf("\t:::: number of records: %d\n", tctdbqrycount(qry));
      printf("\t:::: elapsed time: %.5f\n", etime - stime);
    }
  } else if(bt > 0){
    double sum = 0;
    for(int i = 1; i <= bt; i++){
      double stime = tctime();
      TCLIST *res = tctdbqrysearch(qry);
      double etime = tctime();
      tclistdel(res);
      printf("%d: %.5f sec.\n", i, etime - stime);
      sum += etime - stime;
    }
    printf("----\n");
    printf("total: %.5f sec. (%.5f s/q = %.5f q/s)\n", sum, sum / bt, bt / sum);
  } else {
    double stime = tctime();
    TCLIST *res;
    TCLIST *hints;
    int count;
    int mtnum = mtype ? tctdbmetastrtosettype(mtype) : -1;
    if(mtnum >= 0){
      TDBQRY *qrys[cnum/3+1];
      int qnum = 0;
      for(int i = 0; i < cnum - 2; i += 3){
        const char *name = tclistval2(conds, i);
        const char *opstr = tclistval2(conds, i + 1);
        const char *expr  = tclistval2(conds, i + 2);
        int op = tctdbqrystrtocondop(opstr);
        if(op >= 0){
          qrys[qnum] = tctdbqrynew(tdb);
          tctdbqryaddcond(qrys[qnum], name, op, expr);
          if(oname){
            int type = tctdbqrystrtoordertype(otype);
            if(type >= 0) tctdbqrysetorder(qrys[qnum], oname, type);
          }
          tctdbqrysetlimit(qrys[qnum], max, skip);
          qnum++;
        }
      }
      res = tctdbmetasearch(qrys, qnum, mtnum);
      hints = qnum > 0 ? tcstrsplit(tctdbqryhint(qrys[0]), "\n") : tclistnew2(1);
      count = qnum > 0 ? tctdbqrycount(qrys[0]) : 0;
      for(int i = 0; i < qnum; i++){
        tctdbqrydel(qrys[i]);
      }
    } else {
      res = tctdbqrysearch(qry);
      hints = tcstrsplit(tctdbqryhint(qry), "\n");
      count = tctdbqrycount(qry);
    }
    double etime = tctime();
    if(max < 0) max = INT_MAX;
    int rnum = tclistnum(res);
    for(int i = 0; i < rnum && max > 0; i++){
      int pksiz;
      const char *pkbuf = tclistval(res, i, &pksiz);
      if(kw){
        TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
        if(cols){
          TCLIST *texts = tctdbqrykwic(qry, cols, NULL, 16, TCKWMUTAB);
          int tnum = tclistnum(texts);
          for(int j = 0; j < tnum && max > 0; j++){
            int tsiz;
            const char *text = tclistval(texts, j, &tsiz);
            printdata(pkbuf, pksiz, px);
            putchar('\t');
            printdata(text, tsiz, px);
            putchar('\n');
            max--;
          }
          tclistdel(texts);
          tcmapdel(cols);
        }
      } else {
        printdata(pkbuf, pksiz, px);
        if(pv){
          TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
          if(cols){
            tcmapiterinit(cols);
            const char *kbuf;
            int ksiz;
            while((kbuf = tcmapiternext(cols, &ksiz)) != NULL){
              int vsiz;
              const char *vbuf = tcmapiterval(kbuf, &vsiz);
              putchar('\t');
              printdata(kbuf, ksiz, px);
              putchar('\t');
              printdata(vbuf, vsiz, px);
            }
            tcmapdel(cols);
          }
        }
        putchar('\n');
        max--;
      }
    }
    if(ph){
      int hnum = tclistnum(hints);
      for(int i = 0; i < hnum; i++){
        const char *hint = tclistval2(hints, i);
        if(*hint == '\0') continue;
        printf("\t:::: %s\n", hint);
      }
      printf("\t:::: number of records: %d\n", count);
      printf("\t:::: elapsed time: %.5f\n", etime - stime);
    }
    tclistdel(hints);
    tclistdel(res);
  }
  tctdbqrydel(qry);
  if(!tctdbclose(tdb)){
    if(!err) printerr(tdb);
    err = true;
  }
  tctdbdel(tdb);
  return err ? 1 : 0;
}
Ejemplo n.º 14
0
/* perform remove command */
static int procremove(const char *name, int tnum){
  iprintf("<Removing Test>\n  seed=%u  name=%s  tnum=%d\n\n", g_randseed, name, tnum);
  bool err = false;
  double stime = tctime();
  TCADB *adb = tcadbnew();
  ADBSKEL skel;
  if(*name == '@'){
    setskeltran(&skel);
    if(!tcadbsetskel(adb, &skel)){
      eprint(adb, __LINE__, "tcadbsetskel");
      err = true;
      skel.del(skel.opq);
    }
    name++;
  } else if(*name == '%'){
    if(!tcadbsetskelmulti(adb, MULDIVNUM)){
      eprint(adb, __LINE__, "tcadbsetskelmulti");
      err = true;
    }
    name++;
  }
  if(!tcadbopen(adb, name)){
    eprint(adb, __LINE__, "tcadbopen");
    err = true;
  }
  int rnum = tcadbrnum(adb) / tnum;
  TARGREMOVE targs[tnum];
  pthread_t threads[tnum];
  if(tnum == 1){
    targs[0].adb = adb;
    targs[0].rnum = rnum;
    targs[0].id = 0;
    if(threadremove(targs) != NULL) err = true;
  } else {
    for(int i = 0; i < tnum; i++){
      targs[i].adb = adb;
      targs[i].rnum = rnum;
      targs[i].id = i;
      if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){
        eprint(adb, __LINE__, "pthread_create");
        targs[i].id = -1;
        err = true;
      }
    }
    for(int i = 0; i < tnum; i++){
      if(targs[i].id == -1) continue;
      void *rv;
      if(pthread_join(threads[i], &rv) != 0){
        eprint(adb, __LINE__, "pthread_join");
        err = true;
      } else if(rv){
        err = true;
      }
    }
  }
  iprintf("record number: %llu\n", (unsigned long long)tcadbrnum(adb));
  iprintf("size: %llu\n", (unsigned long long)tcadbsize(adb));
  sysprint();
  if(!tcadbclose(adb)){
    eprint(adb, __LINE__, "tcadbclose");
    err = true;
  }
  tcadbdel(adb);
  iprintf("time: %.3f\n", tctime() - stime);
  iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Ejemplo n.º 15
0
/* perform rcat command */
static int procrcat(const char *path, int rnum, int width, int64_t limsiz,
                    bool mt, int omode, int pnum, bool dai, bool dad, bool rl, bool ru){
  my_my_my_iprintf("<Random Concatenating Test>\n"
          "  seed=%u  path=%s  rnum=%d  width=%d  limsiz=%lld  mt=%d  omode=%d  pnum=%d"
          "  dai=%d  dad=%d  rl=%d  ru=%d\n\n",
          g_randseed, path, rnum, width, (long long)limsiz, mt, omode, pnum, dai, dad, rl, ru);
  if(pnum < 1) pnum = rnum;
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(mt && !tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbtune(fdb, width, limsiz)){
    eprint(fdb, __LINE__, "tcfdbtune");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%d", myrand(pnum) + 1);
    if(dai){
      if(tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), myrand(3)) == INT_MIN){
        eprint(fdb, __LINE__, "tcfdbaddint");
        err = true;
        break;
      }
    } else if(dad){
      if(isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), myrand(30) / 10.0))){
        eprint(fdb, __LINE__, "tcfdbadddouble");
        err = true;
        break;
      }
    } else if(rl){
      char vbuf[PATH_MAX];
      int vsiz = myrand(PATH_MAX);
      for(int j = 0; j < vsiz; j++){
        vbuf[j] = myrand(0x100);
      }
      if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
        eprint(fdb, __LINE__, "tcfdbputcat");
        err = true;
        break;
      }
    } else if(ru){
      int id = myrand(pnum) + 1;
      switch(myrand(8)){
        case 0:
          if(!tcfdbput(fdb, id, kbuf, ksiz)){
            eprint(fdb, __LINE__, "tcfdbput");
            err = true;
          }
          break;
        case 1:
          if(!tcfdbputkeep(fdb, id, kbuf, ksiz) && tcfdbecode(fdb) != TCEKEEP){
            eprint(fdb, __LINE__, "tcfdbputkeep");
            err = true;
          }
          break;
        case 2:
          if(!tcfdbout(fdb, id) && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbout");
            err = true;
          }
          break;
        case 3:
          if(tcfdbaddint(fdb, id, 1) == INT_MIN && tcfdbecode(fdb) != TCEKEEP){
            eprint(fdb, __LINE__, "tcfdbaddint");
            err = true;
          }
          break;
        case 4:
          if(isnan(tcfdbadddouble(fdb, id, 1.0)) && tcfdbecode(fdb) != TCEKEEP){
            eprint(fdb, __LINE__, "tcfdbadddouble");
            err = true;
          }
          break;
        case 5:
          if(myrand(2) == 0){
            if(!tcfdbputproc(fdb, id, kbuf, ksiz, pdprocfunc, NULL) &&
               tcfdbecode(fdb) != TCEKEEP){
              eprint(fdb, __LINE__, "tcfdbputproc");
              err = true;
            }
          } else {
            if(!tcfdbputproc(fdb, id, NULL, 0, pdprocfunc, NULL) &&
               tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC){
              eprint(fdb, __LINE__, "tcfdbputproc");
              err = true;
            }
          }
          break;
        default:
          if(!tcfdbputcat(fdb, id, kbuf, ksiz)){
            eprint(fdb, __LINE__, "tcfdbputcat");
            err = true;
          }
          break;
      }
      if(err) break;
    } else {
      if(!tcfdbputcat2(fdb, kbuf, ksiz, kbuf, ksiz)){
        eprint(fdb, __LINE__, "tcfdbputcat");
        err = true;
        break;
      }
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  my_my_my_iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  my_my_my_iprintf("time: %.3f\n", tctime() - stime);
  my_my_my_iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Ejemplo n.º 16
0
/* perform misc command */
static int procmisc(const char *path, int rnum, bool mt, int omode){
  my_my_my_iprintf("<Miscellaneous Test>\n  seed=%u  path=%s  rnum=%d  mt=%d  omode=%d\n\n",
          g_randseed, path, rnum, mt, omode);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(mt && !tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbtune(fdb, RECBUFSIZ, EXHEADSIZ + (RECBUFSIZ + sizeof(int)) * rnum)){
    eprint(fdb, __LINE__, "tcfdbtune");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  if(TCUSEPTHREAD){
    TCFDB *fdbdup = tcfdbnew();
    if(tcfdbopen(fdbdup, path, FDBOREADER)){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
    } else if(tcfdbecode(fdbdup) != TCETHREAD){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
    }
    tcfdbdel(fdbdup);
  }
  my_my_my_iprintf("writing:\n");
  for(int i = 1; i <= rnum; i++){
    char buf[RECBUFSIZ];
    int len = sprintf(buf, "%08d", i);
    if(!tcfdbputkeep2(fdb, buf, len, buf, len)){
      eprint(fdb, __LINE__, "tcfdbputkeep");
      err = true;
      break;
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("reading:\n");
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%08d", i);
    int vsiz;
    char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
    if(!vbuf){
      eprint(fdb, __LINE__, "tcfdbget");
      err = true;
      break;
    } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
      tcfree(vbuf);
      break;
    }
    tcfree(vbuf);
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  if(tcfdbrnum(fdb) != rnum){
    eprint(fdb, __LINE__, "(validation)");
    err = true;
  }
  my_my_my_iprintf("random writing:\n");
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
    char vbuf[RECBUFSIZ];
    int vsiz = myrand(RECBUFSIZ);
    memset(vbuf, '*', vsiz);
    if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
      eprint(fdb, __LINE__, "tcfdbput");
      err = true;
      break;
    }
    int rsiz;
    char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
    if(!rbuf){
      eprint(fdb, __LINE__, "tcfdbget");
      err = true;
      break;
    }
    if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
      tcfree(rbuf);
      break;
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
    tcfree(rbuf);
  }
  my_my_my_iprintf("random erasing:\n");
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
    if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
      eprint(fdb, __LINE__, "tcfdbout");
      err = true;
      break;
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("writing:\n");
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "[%d]", i);
    char vbuf[RECBUFSIZ];
    int vsiz = i % RECBUFSIZ;
    memset(vbuf, '*', vsiz);
    if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
      eprint(fdb, __LINE__, "tcfdbputkeep");
      err = true;
      break;
    }
    if(vsiz < 1){
      char tbuf[PATH_MAX];
      for(int j = 0; j < PATH_MAX; j++){
        tbuf[j] = myrand(0x100);
      }
      if(!tcfdbput2(fdb, kbuf, ksiz, tbuf, PATH_MAX)){
        eprint(fdb, __LINE__, "tcfdbput");
        err = true;
        break;
      }
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("erasing:\n");
  for(int i = 1; i <= rnum; i++){
    if(i % 2 == 1){
      char kbuf[RECBUFSIZ];
      int ksiz = sprintf(kbuf, "[%d]", i);
      if(!tcfdbout2(fdb, kbuf, ksiz)){
        eprint(fdb, __LINE__, "tcfdbout");
        err = true;
        break;
      }
      if(tcfdbout2(fdb, kbuf, ksiz) || tcfdbecode(fdb) != TCENOREC){
        eprint(fdb, __LINE__, "tcfdbout");
        err = true;
        break;
      }
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("random writing and reopening:\n");
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
    int vsiz = myrand(RECBUFSIZ);
    char *vbuf = tcmalloc(vsiz + 1);
    memset(vbuf, '*', vsiz);
    switch(myrand(3)){
      case 0:
        if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput");
          err = true;
        }
        break;
      case 1:
        if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbputcat");
          err = true;
        }
        break;
      case 2:
        if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbout");
          err = true;
        }
        break;
    }
    tcfree(vbuf);
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  my_my_my_iprintf("checking:\n");
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "[%d]", i);
    int vsiz;
    char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
    if(vbuf){
      tcfree(vbuf);
    } else if(tcfdbecode(fdb) != TCENOREC){
      eprint(fdb, __LINE__, "tcfdbget");
      err = true;
      break;
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("writing:\n");
  for(int i = 1; i <= rnum; i++){
    char buf[RECBUFSIZ];
    int len = sprintf(buf, "%08d", i);
    if(!tcfdbput2(fdb, buf, len, buf, len)){
      eprint(fdb, __LINE__, "tcfdbput");
      err = true;
      break;
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("reading:\n");
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%08d", i);
    int vsiz;
    char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
    if(!vbuf){
      eprint(fdb, __LINE__, "tcfdbget");
      err = true;
      break;
    } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
      tcfree(vbuf);
      break;
    }
    tcfree(vbuf);
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("checking iterator:\n");
  if(!tcfdbiterinit(fdb)){
    eprint(fdb, __LINE__, "tcfdbiterinit");
    err = true;
  }
  char *kbuf;
  int ksiz;
  int inum = 0;
  for(int i = 1; (kbuf = tcfdbiternext2(fdb, &ksiz)) != NULL; i++, inum++){
    int vsiz;
    char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
    if(!vbuf){
      eprint(fdb, __LINE__, "tcfdbget2");
      err = true;
      tcfree(kbuf);
      break;
    }
    tcfree(vbuf);
    tcfree(kbuf);
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  if(tcfdbecode(fdb) != TCENOREC || inum != tcfdbrnum(fdb)){
    eprint(fdb, __LINE__, "(validation)");
    err = true;
  }
  my_my_my_iprintf("iteration updating:\n");
  if(!tcfdbiterinit(fdb)){
    eprint(fdb, __LINE__, "tcfdbiterinit");
    err = true;
  }
  inum = 0;
  for(int i = 1; (kbuf = tcfdbiternext2(fdb, &ksiz)) != NULL; i++, inum++){
    if(myrand(2) == 0){
      if(!tcfdbputcat2(fdb, kbuf, ksiz, "0123456789", 10)){
        eprint(fdb, __LINE__, "tcfdbputcat2");
        err = true;
        tcfree(kbuf);
        break;
      }
    } else {
      if(!tcfdbout2(fdb, kbuf, ksiz)){
        eprint(fdb, __LINE__, "tcfdbout");
        err = true;
        tcfree(kbuf);
        break;
      }
    }
    tcfree(kbuf);
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  if(tcfdbecode(fdb) != TCENOREC || inum < tcfdbrnum(fdb)){
    eprint(fdb, __LINE__, "(validation)");
    err = true;
  }
  if(myrand(10) == 0 && !tcfdbsync(fdb)){
    eprint(fdb, __LINE__, "tcfdbsync");
    err = true;
  }
  if(!tcfdbvanish(fdb)){
    eprint(fdb, __LINE__, "tcfdbvanish");
    err = true;
  }
  TCMAP *map = tcmapnew();
  my_my_my_iprintf("random writing:\n");
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
    char vbuf[RECBUFSIZ];
    int vsiz = sprintf(vbuf, "%d", myrand(rnum) + 1);
    switch(myrand(7)){
      case 0:
        if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput2");
          err = true;
        }
        tcmapput(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 1:
        if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputkeep2");
          err = true;
        }
        tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 2:
        if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputcat2");
          err = true;
        }
        tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 3:
        if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbout2");
          err = true;
        }
        tcmapout(map, kbuf, ksiz);
        break;
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  my_my_my_iprintf("checking transaction commit:\n");
  if(!tcfdbtranbegin(fdb)){
    eprint(fdb, __LINE__, "tcfdbtranbegin");
    err = true;
  }
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
    char vbuf[RECBUFSIZ];
    int vsiz = sprintf(vbuf, "[%d]", myrand(rnum) + 1);
    switch(myrand(7)){
      case 0:
        if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput2");
          err = true;
        }
        tcmapput(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 1:
        if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputkeep2");
          err = true;
        }
        tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 2:
        if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbputcat2");
          err = true;
        }
        tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 3:
        if(tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), 1) == INT_MIN &&
           tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbaddint");
          err = true;
        }
        tcmapaddint(map, kbuf, ksiz, 1);
        break;
      case 4:
        if(isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), 1.0)) &&
           tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbadddouble");
          err = true;
        }
        tcmapadddouble(map, kbuf, ksiz, 1.0);
        break;
      case 5:
        if(myrand(2) == 0){
          void *op = (void *)(intptr_t)(myrand(3) + 1);
          if(!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), vbuf, vsiz, pdprocfunc, op) &&
             tcfdbecode(fdb) != TCEKEEP){
            eprint(fdb, __LINE__, "tcfdbputproc");
            err = true;
          }
          tcmapputproc(map, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op);
        } else {
          vsiz = myrand(10);
          void *op = (void *)(intptr_t)(myrand(3) + 1);
          if(!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), NULL, vsiz, pdprocfunc, op) &&
             tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbputproc");
            err = true;
          }
          tcmapputproc(map, kbuf, ksiz, NULL, vsiz, pdprocfunc, op);
        }
        break;
      case 6:
        if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbout2");
          err = true;
        }
        tcmapout(map, kbuf, ksiz);
        break;
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  if(!tcfdbtrancommit(fdb)){
    eprint(fdb, __LINE__, "tcfdbtrancommit");
    err = true;
  }
  my_my_my_iprintf("checking transaction abort:\n");
  uint64_t ornum = tcfdbrnum(fdb);
  uint64_t ofsiz = tcfdbfsiz(fdb);
  if(!tcfdbtranbegin(fdb)){
    eprint(fdb, __LINE__, "tcfdbtranbegin");
    err = true;
  }
  for(int i = 1; i <= rnum; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
    char vbuf[RECBUFSIZ];
    int vsiz = sprintf(vbuf, "[%d]", myrand(rnum) + 1);
    switch(myrand(7)){
      case 0:
        if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput2");
          err = true;
        }
        break;
      case 1:
        if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputkeep2");
          err = true;
        }
        break;
      case 2:
        if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbputcat2");
          err = true;
        }
        break;
      case 3:
        if(tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), 1) == INT_MIN &&
           tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbaddint");
          err = true;
        }
        break;
      case 4:
        if(isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), 1.0)) &&
           tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbadddouble");
          err = true;
        }
        break;
      case 5:
        if(myrand(2) == 0){
          void *op = (void *)(intptr_t)(myrand(3) + 1);
          if(!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), vbuf, vsiz, pdprocfunc, op) &&
             tcfdbecode(fdb) != TCEKEEP){
            eprint(fdb, __LINE__, "tcfdbputproc");
            err = true;
          }
        } else {
          vsiz = myrand(10);
          void *op = (void *)(intptr_t)(myrand(3) + 1);
          if(!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), NULL, vsiz, pdprocfunc, op) &&
             tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbputproc");
            err = true;
          }
        }
        break;
      case 6:
        if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbout2");
          err = true;
        }
        break;
    }
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  if(!tcfdbtranabort(fdb)){
    eprint(fdb, __LINE__, "tcfdbtranabort");
    err = true;
  }
  my_my_my_iprintf("checking consistency:\n");
  if(tcfdbrnum(fdb) != ornum || tcfdbfsiz(fdb) != ofsiz || tcfdbrnum(fdb) != tcmaprnum(map)){
    eprint(fdb, __LINE__, "(validation)");
    err = true;
  }
  inum = 0;
  tcmapiterinit(map);
  const char *tkbuf;
  int tksiz;
  for(int i = 1; (tkbuf = tcmapiternext(map, &tksiz)) != NULL; i++, inum++){
    int tvsiz;
    const char *tvbuf = tcmapiterval(tkbuf, &tvsiz);
    if(tvsiz > RECBUFSIZ) tvsiz = RECBUFSIZ;
    int rsiz;
    char *rbuf = tcfdbget2(fdb, tkbuf, tksiz, &rsiz);
    if(!rbuf || rsiz != tvsiz || memcmp(rbuf, tvbuf, rsiz)){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
      tcfree(rbuf);
      break;
    }
    tcfree(rbuf);
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  if(rnum > 250) my_my_my_iprintf(" (%08d)\n", inum);
  inum = 0;
  if(!tcfdbiterinit(fdb)){
    eprint(fdb, __LINE__, "tcfdbiterinit");
    err = true;
  }
  for(int i = 1; (kbuf = tcfdbiternext2(fdb, &ksiz)) != NULL; i++, inum++){
    int vsiz;
    char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
    int rsiz;
    const char *rbuf = tcmapget(map, kbuf, ksiz, &rsiz);
    if(rsiz > RECBUFSIZ) rsiz = RECBUFSIZ;
    if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
      tcfree(vbuf);
      tcfree(kbuf);
      break;
    }
    tcfree(vbuf);
    tcfree(kbuf);
    if(rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) my_my_my_iprintf(" (%08d)\n", i);
    }
  }
  if(rnum > 250) my_my_my_iprintf(" (%08d)\n", inum);
  tcmapdel(map);
  if(!tcfdbvanish(fdb)){
    eprint(fdb, __LINE__, "tcfdbvanish");
    err = true;
  }
  if(rnum >= 100){
    if(!tcfdbtranbegin(fdb)){
      eprint(fdb, __LINE__, "tcfdbtranbegin");
      err = true;
    }
    if(!tcfdbput3(fdb, "99", "hirabayashi")){
      eprint(fdb, __LINE__, "tcfdbput3");
      err = true;
    }
    for(int i = 0; i < 10; i++){
      char buf[RECBUFSIZ];
      int size = sprintf(buf, "%d", myrand(rnum) + 1);
      if(!tcfdbput2(fdb, buf, size, buf, size)){
        eprint(fdb, __LINE__, "tcfdbput2");
        err = true;
      }
    }
    for(int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)){
      char vbuf[i];
      memset(vbuf, '@', i - 1);
      vbuf[i-1] = '\0';
      if(!tcfdbput3(fdb, "99", vbuf)){
        eprint(fdb, __LINE__, "tcfdbput3");
        err = true;
      }
    }
    if(!tcfdbforeach(fdb, iterfunc, NULL)){
      eprint(fdb, __LINE__, "tcfdbforeach");
      err = true;
    }
  }
  my_my_my_iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  my_my_my_iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  my_my_my_iprintf("time: %.3f\n", tctime() - stime);
  my_my_my_iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}
Ejemplo n.º 17
-1
/* perform wicked command */
static int procwicked(const char *path, int rnum, bool mt, int omode){
  my_my_my_iprintf("<Wicked Writing Test>\n  seed=%u  path=%s  rnum=%d  mt=%d  omode=%d\n\n",
          g_randseed, path, rnum, mt, omode);
  bool err = false;
  double stime = tctime();
  TCFDB *fdb = tcfdbnew();
  if(g_dbgfd >= 0) tcfdbsetdbgfd(fdb, g_dbgfd);
  if(mt && !tcfdbsetmutex(fdb)){
    eprint(fdb, __LINE__, "tcfdbsetmutex");
    err = true;
  }
  if(!tcfdbtune(fdb, RECBUFSIZ * 2, EXHEADSIZ + (RECBUFSIZ * 2 + sizeof(int)) * rnum)){
    eprint(fdb, __LINE__, "tcfdbtune");
    err = true;
  }
  if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
    eprint(fdb, __LINE__, "tcfdbopen");
    err = true;
  }
  if(!tcfdbiterinit(fdb)){
    eprint(fdb, __LINE__, "tcfdbiterinit");
    err = true;
  }
  TCMAP *map = tcmapnew2(rnum / 5);
  for(int i = 1; i <= rnum && !err; i++){
    uint64_t id = myrand(rnum) + 1;
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%llu", (unsigned long long)id);
    char vbuf[RECBUFSIZ];
    int vsiz = myrand(RECBUFSIZ);
    memset(vbuf, '*', vsiz);
    vbuf[vsiz] = '\0';
    char *rbuf;
    switch(myrand(16)){
      case 0:
        iputchar('0');
        if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput2");
          err = true;
        }
        tcmapput(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 1:
        iputchar('1');
        if(!tcfdbput3(fdb, kbuf, vbuf)){
          eprint(fdb, __LINE__, "tcfdbput3");
          err = true;
        }
        tcmapput2(map, kbuf, vbuf);
        break;
      case 2:
        iputchar('2');
        if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputkeep2");
          err = true;
        }
        tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 3:
        iputchar('3');
        if(!tcfdbputkeep3(fdb, kbuf, vbuf) && tcfdbecode(fdb) != TCEKEEP){
          eprint(fdb, __LINE__, "tcfdbputkeep3");
          err = true;
        }
        tcmapputkeep2(map, kbuf, vbuf);
        break;
      case 4:
        iputchar('4');
        if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbputcat2");
          err = true;
        }
        tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
        break;
      case 5:
        iputchar('5');
        if(!tcfdbputcat3(fdb, kbuf, vbuf)){
          eprint(fdb, __LINE__, "tcfdbputcat3");
          err = true;
        }
        tcmapputcat2(map, kbuf, vbuf);
        break;
      case 6:
        iputchar('6');
        if(myrand(10) == 0){
          if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbout2");
            err = true;
          }
          tcmapout(map, kbuf, ksiz);
        }
        break;
      case 7:
        iputchar('7');
        if(myrand(10) == 0){
          if(!tcfdbout3(fdb, kbuf) && tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbout3");
            err = true;
          }
          tcmapout2(map, kbuf);
        }
        break;
      case 8:
        iputchar('8');
        if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz))){
          if(tcfdbecode(fdb) != TCENOREC){
            eprint(fdb, __LINE__, "tcfdbget2");
            err = true;
          }
          rbuf = tcsprintf("[%d]", myrand(i + 1));
          vsiz = strlen(rbuf);
        }
        vsiz += myrand(vsiz);
        rbuf = tcrealloc(rbuf, vsiz + 1);
        for(int j = 0; j < vsiz; j++){
          rbuf[j] = myrand(0x100);
        }
        if(!tcfdbput2(fdb, kbuf, ksiz, rbuf, vsiz)){
          eprint(fdb, __LINE__, "tcfdbput2");
          err = true;
        }
        tcmapput(map, kbuf, ksiz, rbuf, vsiz);
        tcfree(rbuf);
        break;
      case 9:
        iputchar('9');
        if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz)) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbget2");
          err = true;
        }
        tcfree(rbuf);
        break;
      case 10:
        iputchar('A');
        if(!(rbuf = tcfdbget3(fdb, kbuf)) && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbget3");
          err = true;
        }
        tcfree(rbuf);
        break;
      case 11:
        iputchar('B');
        if(myrand(1) == 0) vsiz = 1;
        if((vsiz = tcfdbget4(fdb, id, vbuf, vsiz)) < 0 && tcfdbecode(fdb) != TCENOREC){
          eprint(fdb, __LINE__, "tcfdbget4");
          err = true;
        }
        break;
      case 12:
        iputchar('C');
        if(myrand(rnum / 128) == 0){
          if(myrand(2) == 0){
            if(!tcfdbiterinit(fdb)){
              eprint(fdb, __LINE__, "tcfdbiterinit");
              err = true;
            }
          } else {
            if(!tcfdbiterinit2(fdb, myrand(rnum) + 1) && tcfdbecode(fdb) != TCENOREC){
              eprint(fdb, __LINE__, "tcfdbiterinit2");
              err = true;
            }
          }
        }
        for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
          if(tcfdbiternext(fdb) < 0){
            int ecode = tcfdbecode(fdb);
            if(ecode != TCEINVALID && ecode != TCENOREC){
              eprint(fdb, __LINE__, "tcfdbiternext");
              err = true;
            }
          }
        }
        break;
      default:
        iputchar('@');
        if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
        if(myrand(rnum / 16 + 1) == 0){
          int cnt = myrand(30);
          for(int j = 0; j < rnum && !err; j++){
            ksiz = sprintf(kbuf, "%d", i + j);
            if(tcfdbout2(fdb, kbuf, ksiz)){
              cnt--;
            } else if(tcfdbecode(fdb) != TCENOREC){
              eprint(fdb, __LINE__, "tcfdbout2");
              err = true;
            }
            tcmapout(map, kbuf, ksiz);
            if(cnt < 0) break;
          }
        }
        break;
    }
    if(i % 50 == 0) my_my_my_iprintf(" (%08d)\n", i);
    if(i == rnum / 2){
      if(!tcfdbclose(fdb)){
        eprint(fdb, __LINE__, "tcfdbclose");
        err = true;
      }
      if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
        eprint(fdb, __LINE__, "tcfdbopen");
        err = true;
      }
    } else if(i == rnum / 4){
      char *npath = tcsprintf("%s-tmp", path);
      if(!tcfdbcopy(fdb, npath)){
        eprint(fdb, __LINE__, "tcfdbcopy");
        err = true;
      }
      TCFDB *nfdb = tcfdbnew();
      if(!tcfdbopen(nfdb, npath, FDBOREADER | omode)){
        eprint(nfdb, __LINE__, "tcfdbopen");
        err = true;
      }
      tcfdbdel(nfdb);
      unlink(npath);
      tcfree(npath);
      if(!tcfdboptimize(fdb, RECBUFSIZ, -1)){
        eprint(fdb, __LINE__, "tcfdboptimize");
        err = true;
      }
      if(!tcfdbiterinit(fdb)){
        eprint(fdb, __LINE__, "tcfdbiterinit");
        err = true;
      }
    } else if(i == rnum / 8){
      if(!tcfdbtranbegin(fdb)){
        eprint(fdb, __LINE__, "tcfdbtranbegin");
        err = true;
      }
    } else if(i == rnum / 8 + rnum / 16){
      if(!tcfdbtrancommit(fdb)){
        eprint(fdb, __LINE__, "tcfdbtrancommit");
        err = true;
      }
    }
  }
  if(rnum % 50 > 0) my_my_my_iprintf(" (%08d)\n", rnum);
  if(!tcfdbsync(fdb)){
    eprint(fdb, __LINE__, "tcfdbsync");
    err = true;
  }
  if(tcfdbrnum(fdb) != tcmaprnum(map)){
    eprint(fdb, __LINE__, "(validation)");
    err = true;
  }
  for(int i = 1; i <= rnum && !err; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%d", i);
    int vsiz;
    const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
    int rsiz;
    char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
    if(vbuf){
      iputchar('.');
      if(vsiz > RECBUFSIZ) vsiz = RECBUFSIZ;
      if(!rbuf){
        eprint(fdb, __LINE__, "tcfdbget2");
        err = true;
      } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
        eprint(fdb, __LINE__, "(validation)");
        err = true;
      }
    } else {
      iputchar('*');
      if(rbuf || tcfdbecode(fdb) != TCENOREC){
        eprint(fdb, __LINE__, "(validation)");
        err = true;
      }
    }
    tcfree(rbuf);
    if(i % 50 == 0) my_my_my_iprintf(" (%08d)\n", i);
  }
  if(rnum % 50 > 0) my_my_my_iprintf(" (%08d)\n", rnum);
  tcmapiterinit(map);
  int ksiz;
  const char *kbuf;
  for(int i = 1; (kbuf = tcmapiternext(map, &ksiz)) != NULL; i++){
    iputchar('+');
    int vsiz;
    const char *vbuf = tcmapiterval(kbuf, &vsiz);
    if(vsiz > tcfdbwidth(fdb)) vsiz = tcfdbwidth(fdb);
    int rsiz;
    char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
    if(!rbuf){
      eprint(fdb, __LINE__, "tcfdbget2");
      err = true;
    } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
      eprint(fdb, __LINE__, "(validation)");
      err = true;
    }
    tcfree(rbuf);
    if(!tcfdbout2(fdb, kbuf, ksiz)){
      eprint(fdb, __LINE__, "tcfdbout2");
      err = true;
    }
    if(i % 50 == 0) my_my_my_iprintf(" (%08d)\n", i);
  }
  int mrnum = tcmaprnum(map);
  if(mrnum % 50 > 0) my_my_my_iprintf(" (%08d)\n", mrnum);
  if(tcfdbrnum(fdb) != 0){
    eprint(fdb, __LINE__, "(validation)");
    err = true;
  }
  my_my_my_iprintf("record number: %llu\n", (unsigned long long)tcfdbrnum(fdb));
  my_my_my_iprintf("size: %llu\n", (unsigned long long)tcfdbfsiz(fdb));
  mprint(fdb);
  sysprint();
  tcmapdel(map);
  if(!tcfdbclose(fdb)){
    eprint(fdb, __LINE__, "tcfdbclose");
    err = true;
  }
  tcfdbdel(fdb);
  my_my_my_iprintf("time: %.3f\n", tctime() - stime);
  my_my_my_iprintf("%s\n\n", err ? "error" : "ok");
  return err ? 1 : 0;
}