示例#1
0
TCHDB *tc_open(const char *path) {
	TCHDB *hdb = NULL;

	if ((hdb = tchdbnew()) == NULL) {
		error("failed to create a new hdb object");
		return NULL;
	}

	if (!tchdbsetxmsiz(hdb, -1)) { 
		error("failed to set extra mmap size");
		return NULL;
	}


	debug("opening hdb (%s)", path);

	TC_RETRY_LOOP(hdb, path, tchdbopen(hdb, path, HDBOREADER | HDBONOLCK), goto hdb_error);

	debug("hdb opened (%s)", path);

	return hdb;

hdb_error:
	if (hdb != NULL)
		tchdbdel(hdb);

	return NULL;
}
示例#2
0
static mrb_value
hdb_set_xmsize(mrb_state *mrb, mrb_value self)
{
  hdb_context *context = DATA_PTR(self);
  mrb_int xmsize;

  mrb_get_args(mrb, "i", &xmsize);

  return mrb_bool_value(tchdbsetxmsiz(context->hdb, xmsize));
}
示例#3
0
文件: tctest.c 项目: Fleurer/nanodb
/* 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;
}
示例#4
0
/* setxmsiz */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_HDB_setxmsiz
(JNIEnv *env, jobject self, jlong xmsiz){
  TCHDB *hdb = (TCHDB *)(intptr_t)(*env)->GetLongField(env, self, hdb_fid_ptr);
  return tchdbsetxmsiz(hdb, xmsiz);
}