コード例 #1
0
ファイル: tcbmgr.c プロジェクト: SumiTomohiko/o
/* perform inform command */
static int procinform(const char *path, int omode){
  TCBDB *bdb = tcbdbnew();
  if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd);
  tcbdbsetcmpfunc(bdb, mycmpfunc, NULL);
  tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL);
  if(!tcbdbopen(bdb, path, BDBOREADER | omode)){
    printerr(bdb);
    tcbdbdel(bdb);
    return 1;
  }
  bool err = false;
  const char *npath = tcbdbpath(bdb);
  if(!npath) npath = "(unknown)";
  printf("path: %s\n", npath);
  printf("database type: btree\n");
  uint8_t flags = tcbdbflags(bdb);
  printf("additional flags:");
  if(flags & BDBFOPEN) printf(" open");
  if(flags & BDBFFATAL) printf(" fatal");
  printf("\n");
  TCCMP cmp = tcbdbcmpfunc(bdb);
  printf("comparison function: ");
  if(cmp == tccmplexical){
    printf("lexical");
  } else if(cmp == tccmpdecimal){
    printf("decimal");
  } else if(cmp == tccmpint32){
    printf("int32");
  } else if(cmp == tccmpint64){
    printf("int64");
  } else {
    printf("custom");
  }
  printf("\n");
  printf("max leaf member: %d\n", tcbdblmemb(bdb));
  printf("max node member: %d\n", tcbdbnmemb(bdb));
  printf("leaf number: %llu\n", (unsigned long long)tcbdblnum(bdb));
  printf("node number: %llu\n", (unsigned long long)tcbdbnnum(bdb));
  printf("bucket number: %llu\n", (unsigned long long)tcbdbbnum(bdb));
  if(bdb->hdb->cnt_writerec >= 0)
    printf("used bucket number: %lld\n", (long long)tcbdbbnumused(bdb));
  printf("alignment: %u\n", tcbdbalign(bdb));
  printf("free block pool: %u\n", tcbdbfbpmax(bdb));
  printf("inode number: %lld\n", (long long)tcbdbinode(bdb));
  char date[48];
  tcdatestrwww(tcbdbmtime(bdb), INT_MAX, date);
  printf("modified time: %s\n", date);
  uint8_t opts = tcbdbopts(bdb);
  printf("options:");
  if(opts & BDBTLARGE) printf(" large");
  if(opts & BDBTDEFLATE) printf(" deflate");
  if(opts & BDBTBZIP) printf(" bzip");
  if(opts & BDBTTCBS) printf(" tcbs");
  if(opts & BDBTEXCODEC) printf(" excodec");
  printf("\n");
  printf("record number: %llu\n", (unsigned long long)tcbdbrnum(bdb));
  printf("file size: %llu\n", (unsigned long long)tcbdbfsiz(bdb));
  if(!tcbdbclose(bdb)){
    if(!err) printerr(bdb);
    err = true;
  }
  tcbdbdel(bdb);
  return err ? 1 : 0;
}
コード例 #2
0
ファイル: tcbmgr.c プロジェクト: SumiTomohiko/o
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
                   TCCMP cmp, int omode, int dmode){
  TCBDB *bdb = tcbdbnew();
  if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd);
  if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
  if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
  if(!tcbdbopen(bdb, path, BDBOWRITER | omode)){
    printerr(bdb);
    tcbdbdel(bdb);
    return 1;
  }
  bool err = false;
  int inum;
  double dnum;
  switch(dmode){
    case -1:
      if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz)){
        printerr(bdb);
        err = true;
      }
      break;
    case 1:
      if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
        printerr(bdb);
        err = true;
      }
      break;
    case 2:
      if(!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)){
        printerr(bdb);
        err = true;
      }
      break;
    case 3:
      if(!tcbdbputdupback(bdb, kbuf, ksiz, vbuf, vsiz)){
        printerr(bdb);
        err = true;
      }
      break;
    case 10:
      inum = tcbdbaddint(bdb, kbuf, ksiz, tcatoi(vbuf));
      if(inum == INT_MIN){
        printerr(bdb);
        err = true;
      } else {
        printf("%d\n", inum);
      }
      break;
    case 11:
      dnum = tcbdbadddouble(bdb, kbuf, ksiz, tcatof(vbuf));
      if(isnan(dnum)){
        printerr(bdb);
        err = true;
      } else {
        printf("%.6f\n", dnum);
      }
      break;
    default:
      if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
        printerr(bdb);
        err = true;
      }
      break;
  }
  if(!tcbdbclose(bdb)){
    if(!err) printerr(bdb);
    err = true;
  }
  tcbdbdel(bdb);
  return err ? 1 : 0;
}
コード例 #3
0
/* initialize */
JNIEXPORT void JNICALL Java_tokyocabinet_BDB_initialize
(JNIEnv *env, jobject self){
  TCBDB *bdb = tcbdbnew();
  tcbdbsetmutex(bdb);
  (*env)->SetLongField(env, self, bdb_fid_ptr, (intptr_t)bdb);
}