void Retsu::Column::create() { tchdbtune(database, -1, -1, -1, HDBTLARGE | HDBTDEFLATE); if(open(HDBOWRITER | HDBOCREAT)) { this->close(); } else { throw StorageError("Could not create column at " + path()); } }
static mrb_value hdb_tune(mrb_state *mrb, mrb_value self) { hdb_context *context = DATA_PTR(self); bool result; mrb_int bnum, apow, fpow , opts; mrb_get_args(mrb, "iiii", &bnum, &apow, &fpow, &opts); result = tchdbtune(context->hdb, bnum, apow, fpow, opts); return mrb_bool_value(result); }
/* perform write command */ int dowrite(char *name, int rnum){ TCHDB *hdb; int i, err, len; char buf[RECBUFSIZ]; if(showprgr) printf("<Writing Test of Hash>\n name=%s rnum=%d\n\n", name, rnum); /* open a database */ hdb = tchdbnew(); tchdbtune(hdb, rnum * 3, 0, 0, 0); tchdbsetxmsiz(hdb, rnum * 48); if(!tchdbopen(hdb, name, HDBOWRITER | HDBOCREAT | HDBOTRUNC)){ fprintf(stderr, "tchdbopen failed\n"); tchdbdel(hdb); return 1; } err = FALSE; /* loop for each record */ for(i = 1; i <= rnum; i++){ /* store a record */ len = sprintf(buf, "%08d", i); if(!tchdbputasync(hdb, buf, len, buf, len)){ fprintf(stderr, "tchdbputasync failed\n"); err = TRUE; break; } /* print progression */ if(showprgr && rnum > 250 && i % (rnum / 250) == 0){ putchar('.'); fflush(stdout); if(i == rnum || i % (rnum / 10) == 0){ printf(" (%08d)\n", i); fflush(stdout); } } } /* close the database */ if(!tchdbclose(hdb)){ fprintf(stderr, "tchdbclose failed\n"); tchdbdel(hdb); return 1; } tchdbdel(hdb); if(showprgr && !err) printf("ok\n\n"); return err ? 1 : 0; }
/* perform create command */ static int proccreate(const char *path, int bnum, int apow, int fpow, int opts){ TCHDB *hdb = tchdbnew(); if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd); if(!tchdbtune(hdb, bnum, apow, fpow, opts)){ printerr(hdb); tchdbdel(hdb); return 1; } if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC)){ printerr(hdb); tchdbdel(hdb); return 1; } bool err = false; if(!tchdbclose(hdb)){ printerr(hdb); err = true; } tchdbdel(hdb); return err ? 1 : 0; }
bool open_cabinet_db(int64_t bnum, bool optimize) { int ecode; if (optimize) fprintf(stdout, "Opening database optimized for %d items\n", bnum); /* tune up the db*/ if (optimize && !tchdbtune(hdb, bnum, -1, -1, HDBTLARGE)) { ecode = tchdbecode(hdb); fprintf(stdout, "Failed to tune up database, error: %s\n", tchdberrmsg(ecode)); return false; } /* open the database */ if (!tchdbopen(hdb, tcxstrptr(db_file), HDBOWRITER | HDBOCREAT)) { ecode = tchdbecode(hdb); fprintf(stdout, "Failed to open database, error: %s\n", tchdberrmsg(ecode)); return false; } return true; }
/* perform create command */ static int proccreate(const char *path, int bnum, int apow, int fpow, int opts) { TCHDB *hdb = tchdbnew(); if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd); if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb); if (!tchdbtune(hdb, bnum, apow, fpow, opts)) { printerr(hdb); tchdbdel(hdb); return 1; } if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC)) { printerr(hdb); tchdbdel(hdb); return 1; } bool err = false; if (!tchdbclose(hdb)) { printerr(hdb); err = true; } tchdbdel(hdb); return err ? 1 : 0; }
bool db_obj_local::dbtune(int64_t bnum, int8_t apow, int8_t fpow, uint8_t opts) { return tchdbtune(_hdb,bnum,apow,fpow,opts); }
/* tune */ JNIEXPORT jboolean JNICALL Java_tokyocabinet_HDB_tune (JNIEnv *env, jobject self, jlong bnum, jint apow, jint fpow, jint opts){ TCHDB *hdb = (TCHDB *)(intptr_t)(*env)->GetLongField(env, self, hdb_fid_ptr); return tchdbtune(hdb, bnum, apow, fpow, opts); }