Esempio n. 1
0
static mrb_value
hdb_put(mrb_state *mrb, mrb_value self)
{
  mrb_value key, value;
  mrb_bool sync;
  bool result = false;
  mrb_int args;
  void *kbuf, *vbuf;
  int ksize, vsize;
  mrb_int kint, vint;
  hdb_context *context = DATA_PTR(self);

  args = mrb_get_args(mrb, "oo|b", &key, &value, &sync);
  if (args == 2) {
    sync = true;
  }

  if (!get_content(key, &kint, &kbuf, &ksize)) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid type of key");
  }

  if (!get_content(value, &vint, &vbuf, &vsize)) {
    mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid type of value");
  }

  if (sync) {
    result = tchdbput(context->hdb, kbuf, ksize, vbuf, vsize);
  } else {
    result = tchdbputasync(context->hdb, kbuf, ksize, vbuf, vsize);
  }

  return mrb_bool_value(result);
}
Esempio n. 2
0
/* put */
JNIEXPORT jboolean JNICALL Java_tokyocabinet_HDB_put
(JNIEnv *env, jobject self, jbyteArray key, jbyteArray val){
  if(!key || !val){
    throwillarg(env);
    return false;
  }
  TCHDB *hdb = (TCHDB *)(intptr_t)(*env)->GetLongField(env, self, hdb_fid_ptr);
  jboolean ick;
  jbyte *kbuf = (*env)->GetByteArrayElements(env, key, &ick);
  if(!kbuf){
    throwoutmem(env);
    return false;
  }
  int ksiz = (*env)->GetArrayLength(env, key);
  jboolean icv;
  jbyte *vbuf = (*env)->GetByteArrayElements(env, val, &icv);
  if(!vbuf){
    throwoutmem(env);
    return false;
  }
  int vsiz = (*env)->GetArrayLength(env, val);
  bool rv = tchdbput(hdb, kbuf, ksiz, vbuf, vsiz);
  if(icv) (*env)->ReleaseByteArrayElements(env, val, vbuf, JNI_ABORT);
  if(ick) (*env)->ReleaseByteArrayElements(env, key, kbuf, JNI_ABORT);
  return rv;
}
Esempio n. 3
0
 bool put(
    void const * pkey, size_t const ksize,
    void const * pval, size_t const vsize
    )
 {
    assert_data_store_open();
    return tchdbput(pdb_, pkey, ksize, pval, vsize);
 }
Esempio n. 4
0
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
        int omode, int dmode) {
    TCHDB *hdb = tchdbnew();
    if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
    if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(hdb);
    if (!tchdbopen(hdb, path, HDBOWRITER | omode)) {
        printerr(hdb);
        tchdbdel(hdb);
        return 1;
    }
    bool err = false;
    int inum;
    double dnum;
    switch (dmode) {
        case -1:
            if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(hdb);
                err = true;
            }
            break;
        case 1:
            if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(hdb);
                err = true;
            }
            break;
        case 10:
            inum = tchdbaddint(hdb, kbuf, ksiz, tcatoi(vbuf));
            if (inum == INT_MIN) {
                printerr(hdb);
                err = true;
            } else {
                printf("%d\n", inum);
            }
            break;
        case 11:
            dnum = tchdbadddouble(hdb, kbuf, ksiz, tcatof(vbuf));
            if (isnan(dnum)) {
                printerr(hdb);
                err = true;
            } else {
                printf("%.6f\n", dnum);
            }
            break;
        default:
            if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
                printerr(hdb);
                err = true;
            }
            break;
    }
    if (!tchdbclose(hdb)) {
        if (!err) printerr(hdb);
        err = true;
    }
    tchdbdel(hdb);
    return err ? 1 : 0;
}
Esempio n. 5
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;
}
Esempio n. 6
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;
}
Esempio n. 7
0
/** 
 * set a record to database 
 */
int SetRecord(tcDatabase hdb, tcKey key, tcValue value)
{
    int ecode;
    if (!tchdbput((TCHDB*)hdb, &key, sizeof(tcKey), value.str, value.len))
    {
        ecode = tchdbecode((TCHDB*)hdb);
        fprintf(stderr, "put error: %s\n", tchdberrmsg(ecode));
        return FAILURE;
    } 
    //printf("set successfully!\n");
    return SUCCESS;  
}
Esempio n. 8
0
static int
_tc_store (mu_dbm_file_t db,
	   struct mu_dbm_datum const *key,
	   struct mu_dbm_datum const *contents,
	   int replace)
{
  TCHDB *hdb = db->db_descr;
  bool result;

  if (replace)
    result = tchdbput (hdb, key->mu_dptr, key->mu_dsize,
		       contents->mu_dptr, contents->mu_dsize);
  else
    result = tchdbputkeep (hdb, key->mu_dptr, key->mu_dsize,
			   contents->mu_dptr, contents->mu_dsize);
  if (result)
    return 0;
  db->db_errno.n = tchdbecode (hdb);
  if (db->db_errno.n == TCEKEEP)
    return MU_ERR_EXISTS;
  return MU_ERR_FAILURE;
}
Esempio n. 9
0
File: tchmgr.c Progetto: kadoma/fms
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
                   int omode, int dmode){
  TCHDB *hdb = tchdbnew();
  if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
  if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
    printerr(hdb);
    tchdbdel(hdb);
    return 1;
  }
  bool err = false;
  switch(dmode){
  case -1:
    if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)){
      printerr(hdb);
      err = true;
    }
    break;
  case 1:
    if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
      printerr(hdb);
      err = true;
    }
    break;
  default:
    if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
      printerr(hdb);
      err = true;
    }
    break;
  }
  if(!tchdbclose(hdb)){
    if(!err) printerr(hdb);
    err = true;
  }
  tchdbdel(hdb);
  return err ? 1 : 0;
}
Esempio n. 10
0
int pack_file(char *file, TCXSTR *root_key, bool resume) {

    struct stat st;
    int ecode;

    TCXSTR *key;
    key = tcxstrdup(root_key);

    size_t file_path_len;
    file_path_len = strlen(file);


    char *file_name;
    file_name = get_file_name(file, file_path_len);

    tcxstrcat2(key, file_name);

    if (resume && key_exists(tcxstrptr(key))) {
        fprintf(stdout, "already exists");
        return;
    }



    if (-1 == stat(file, &st)) {
        return 1;
    }

    if (!S_ISREG(st.st_mode)) {
        fprintf(stdout, "Not regular file: %s", file);
        return 2;
    }

    int fd;
    if (-1 == (fd = open(file, O_RDONLY))) {
        fprintf(stdout, "***Failed open file %s", file);
        return 1;
    }

    void *fmap;
    if (MAP_FAILED == (fmap = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0))) {
        fprintf(stdout, "mmaping failed for %s", file);

        close(fd);
        return -1;
    }

    /* store records */
    if (use_cabinet_lib) {
        if (!tchdbput(hdb, tcxstrptr(key), tcxstrsize(key), fmap, st.st_size)) {
            ecode = tchdbecode(hdb);
            fprintf(stdout, "put error: %s", tchdberrmsg(ecode));
        }
    } else {
        if (!tcrdbput(tdb, tcxstrptr(key), tcxstrsize(key), fmap, st.st_size)) {
            ecode = tcrdbecode(tdb);
            fprintf(stdout, "put error: %s", tcrdberrmsg(ecode));
        }


    }

    fprintf(stdout, "%d bytes", st.st_size);

    munmap(fmap, st.st_size);
    close(fd);
    tcxstrdel(key);
}
Esempio n. 11
0
bool Retsu::Column::insert(const RecordID key, const double& value) {
  return tchdbput(database, &key, sizeof(RecordID), &value, sizeof(double));
}
Esempio n. 12
0
bool Retsu::Column::insert(const RecordID key, const string& value) {
	return tchdbput(database, &key, sizeof(RecordID), value.c_str(), value.size());
}
Esempio n. 13
0
int main(int argc, char *argv[])
{
	int rc;
	char *val;
	char str[30];
	
	bool ret;
	uint64_t id;
	uint64_t re;
	unsigned int num;
	TCHDB *loong_info;
	
	char username[] = "lijinxing";
//	id  = 1210519264165944251LL;
	
	memset(&str, 0, sizeof(str));

	id  = ident_key();
	
	snprintf(str, sizeof(str), "%llu", id);

	num	= strhash(str);

	printf("num = %u\r\nmod = %u\r\nstr = %s\r\n", num, num % 10, str);
	
	unlink("test.db");
	loong_info = tchdbnew();
	if(!tchdbopen(loong_info, "test.db", HDBOWRITER | HDBOCREAT))
	{
		rc = tchdbecode(loong_info);
		printf("loong_info.db open error: %s\r\n", tchdberrmsg(rc));
		return 0;
	}

	if(!tchdbput(loong_info, username, strlen(username), str, strlen(str)))
	{
		rc = tchdbecode(loong_info);
		printf("loong_user error: %s\r\n", tchdberrmsg(rc));
	}

	if(!tchdbput(loong_info, (char *)&(id), sizeof(uint64_t), str, strlen(str)))
	{
		rc = tchdbecode(loong_info);
		printf("loong_user error: %s\r\n", tchdberrmsg(rc));
	}

	val = tchdbget2(loong_info, username);

	if(val == NULL)
	{
		printf("ûÕÒµ½\r\n");
	}
	else
	{
		printf("val = %s\r\n", val);
		free(val);
	}

	if(!tchdbput(loong_info, username, strlen(username), "Àî½õÐÇ", strlen("Àî½õÐÇ")))
	{
		rc = tchdbecode(loong_info);
		printf("loong_user error: %s\r\n", tchdberrmsg(rc));
	}


	val = tchdbget2(loong_info, username);

	if(val == NULL)
	{
		printf("ûÕÒµ½\r\n");
	}
	else
	{
		printf("val = %s\r\n", val);
		free(val);
	}

/*
	ret = tchdbout(loong_info, (char *)&(id), sizeof(uint64_t));
	if(ret)
	{
		printf("uint64_tɾ³ý³É¹¦\r\n");
	}
	else
	{
		printf("uint64_tɾ³ýʧ°Ü\r\n");
	}


	val = tchdbget(loong_info, (char *)&(id), sizeof(uint64_t), &rc);
	if(val == NULL)
	{
		printf("id ûÕÒµ½\r\n");
	}
	else
	{
		printf("id val = %s\r\n", val);
		free(val);
	}
	
	ret = tchdbout(loong_info, username, strlen(username));
	if(ret)
	{
		printf("stringɾ³ý³É¹¦\r\n");
	}
	else
	{
		printf("stringɾ³ýʧ°Ü\r\n");
	}

	val = tchdbget2(loong_info, username);

	if(val == NULL)
	{
		printf("ûÕÒµ½\r\n");
	}
	else
	{
		printf("val = %s\r\n", val);
		free(val);
	}

*/
	tchdbclose(loong_info);
	tchdbdel(loong_info);
	
	Test_out();

//	fetch_user_info("1220582278313757000");
	return 0;
}
Esempio n. 14
0
 bool db_obj_local::dbput(const void *kbuf, int ksiz,
                          const void *vbuf, int vsiz)
 {
   return tchdbput(_hdb,kbuf,ksiz,vbuf,vsiz);
 }