Exemple #1
0
/* perform inform command */
static int procinform(const char *path, int omode) {
    TCHDB *hdb = tchdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
    tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL);
    if (!tchdbopen(hdb, path, HDBOREADER | omode)) {
        printerr(hdb);
        tchdbdel(hdb);
        return 1;
    }
    bool err = false;
    const char *npath = tchdbpath(hdb);
    if (!npath) npath = "(unknown)";
    printf("path: %s\n", npath);
    const char *type = "(unknown)";
    switch (tchdbtype(hdb)) {
        case TCDBTHASH: type = "hash";
            break;
        case TCDBTBTREE: type = "btree";
            break;
        case TCDBTFIXED: type = "fixed";
            break;
        case TCDBTTABLE: type = "table";
            break;
    }
    printf("database type: %s\n", type);
    uint8_t flags = tchdbflags(hdb);
    printf("additional flags:");
    if (flags & HDBFOPEN) printf(" open");
    if (flags & HDBFFATAL) printf(" fatal");
    printf("\n");
    printf("bucket number: %" PRIu64 "\n", (uint64_t) tchdbbnum(hdb));
#ifndef NDEBUG
    if (hdb->cnt_writerec >= 0)
        printf("used bucket number: %" PRId64 "\n", (int64_t) tchdbbnumused(hdb));
#endif
    printf("alignment: %u\n", tchdbalign(hdb));
    printf("free block pool: %u\n", tchdbfbpmax(hdb));
    printf("inode number: %" PRId64 "\n", (int64_t) tchdbinode(hdb));
    char date[48];
    tcdatestrwww(tchdbmtime(hdb), INT_MAX, date);
    printf("modified time: %s\n", date);
    uint8_t opts = tchdbopts(hdb);
    printf("options:");
    if (opts & HDBTLARGE) printf(" large");
    if (opts & HDBTDEFLATE) printf(" deflate");
    if (opts & HDBTBZIP) printf(" bzip");
    if (opts & HDBTTCBS) printf(" tcbs");
    if (opts & HDBTEXCODEC) printf(" excodec");
    printf("\n");
    printf("record number: %" PRIu64 "\n", (uint64_t) tchdbrnum(hdb));
    printf("file size: %" PRIu64 "\n", (uint64_t) tchdbfsiz(hdb));
    if (!tchdbclose(hdb)) {
        if (!err) printerr(hdb);
        err = true;
    }
    tchdbdel(hdb);
    return err ? 1 : 0;
}
static bool Write(TCHDB *hdb, const void *key, int key_size, const void *value, int value_size)
{
    if (!tchdbput(hdb, key, key_size, value, value_size))
    {
        Log(LOG_LEVEL_ERR, "Could not write key to Tokyo path '%s'. (tchdbput: %s)",
              tchdbpath(hdb), ErrorMessage(hdb));
        return false;
    }
    return true;
}
Exemple #3
0
static bool Write(TCHDB *hdb, const void *key, int key_size, const void *value, int value_size)
{
    if (!tchdbput(hdb, key, key_size, value, value_size))
    {
        CfOut(cf_error, "", "!! tchdbput: Could not write key to DB \"%s\": %s",
              tchdbpath(hdb), ErrorMessage(hdb));
        return false;
    }
    return true;
}
Exemple #4
0
static mrb_value
hdb_path(mrb_state *mrb, mrb_value self)
{
  hdb_context *context = DATA_PTR(self);
  const char *path;

  path = tchdbpath(context->hdb);
  if (!path) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "internal error");
  }

  return mrb_str_new_static(mrb, path, strlen(path));
}
Exemple #5
0
/* path */
JNIEXPORT jstring JNICALL Java_tokyocabinet_HDB_path
(JNIEnv *env, jobject self){
  TCHDB *hdb = (TCHDB *)(intptr_t)(*env)->GetLongField(env, self, hdb_fid_ptr);
  const char *path = tchdbpath(hdb);
  jstring jpath;
  if(path){
    jpath = (*env)->NewStringUTF(env, path);
    if(!path){
      throwoutmem(env);
      return NULL;
    }
  } else {
    jpath = NULL;
  }
  return jpath;
}
Exemple #6
0
/* perform inform command */
static int procinform(const char *path, int omode){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOREADER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  const char *npath = tchdbpath(hdb);
  if(!npath) npath = "(unknown)";
  printf("path: %s\n", npath);
  const char *type = "(unknown)";
  switch(tchdbtype(hdb)){
  case HDBTHASH: type = "hash"; break;
  case HDBTBTREE: type = "btree"; break;
  }
  printf("database type: %s\n", type);
  uint8_t flags = tchdbflags(hdb);
  printf("additional flags:");
  if(flags & HDBFOPEN) printf(" open");
  if(flags & HDBFFATAL) printf(" fatal");
  printf("\n");
  printf("bucket number: %llu\n", (unsigned long long)tchdbbnum(hdb));
  if(hdb->cnt_writerec >= 0)
    printf("used bucket number: %lld\n", (long long)tchdbbnumused(hdb));
  printf("alignment: %u\n", tchdbalign(hdb));
  printf("free block pool: %u\n", tchdbfbpmax(hdb));
  uint8_t opts = tchdbopts(hdb);
  printf("options:");
  if(opts & HDBTLARGE) printf(" large");
  if(opts & HDBTDEFLATE) printf(" deflate");
  printf("\n");
  printf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb));
  printf("file size: %llu\n", (unsigned long long)tchdbfsiz(hdb));
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
Exemple #7
0
/* print error information */
static void printerr(TCHDB *hdb){
  const char *path = tchdbpath(hdb);
  int ecode = tchdbecode(hdb);
  fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tchdberrmsg(ecode));
}