Beispiel #1
0
/* perform inform command */
static int procinform(const char *name){
  TCADB *adb = tcadbnew();
  ADBSKEL skel;
  if(*name == '@'){
    setskeltran(&skel);
    if(!tcadbsetskel(adb, &skel)){
      printerr(adb);
      skel.del(skel.opq);
      tcadbdel(adb);
      return 1;
    }
    name++;
  } else if(*name == '%'){
    if(!tcadbsetskelmulti(adb, 8)){
      printerr(adb);
      tcadbdel(adb);
      return 1;
    }
    name++;
  }
  if(!tcadbopen(adb, name)){
    printerr(adb);
    tcadbdel(adb);
    return 1;
  }
  bool err = false;
  const char *path = tcadbpath(adb);
  if(!path) path = "(unknown)";
  printf("path: %s\n", path);
  const char *type = "(unknown)";
  switch(tcadbomode(adb)){
  case ADBOVOID: type = "not opened"; break;
  case ADBOMDB: type = "on-memory hash database"; break;
  case ADBONDB: type = "on-memory tree database"; break;
  case ADBOHDB: type = "hash database"; break;
  case ADBOBDB: type = "B+ tree database"; break;
  case ADBOFDB: type = "fixed-length database"; break;
  case ADBOTDB: type = "table database"; break;
  case ADBOSKEL: type = "skeleton database"; break;
  }
  printf("database type: %s\n", type);
  printf("record number: %llu\n", (unsigned long long)tcadbrnum(adb));
  printf("size: %llu\n", (unsigned long long)tcadbsize(adb));
  if(!tcadbclose(adb)){
    printerr(adb);
    err = true;
  }
  tcadbdel(adb);
  return err ? 1 : 0;
}
Beispiel #2
0
uint32_t
get_ht_size (TCADB * adb)
{
  return tcadbrnum (adb);
}
Beispiel #3
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;
}