示例#1
0
uint64_t
get_cumulative_from_key (int data_nkey, GModule module, GMetric metric)
{
  TCADB *adb = NULL;
  GStorageMetrics *metrics;
  void *value_ptr;
  uint64_t ret = 0;
  int sp = 0;

  metrics = get_storage_metrics_by_module (module);
  /* bandwidth modules */
  switch (metric) {
  case MTRC_BW:
    adb = metrics->bw;
    break;
  case MTRC_TIME_SERVED:
    adb = metrics->time_served;
    break;
  default:
    adb = NULL;
  }

  if (adb == NULL)
    return 0;

  value_ptr = tcadbget (adb, &data_nkey, sizeof (int), &sp);
  if (value_ptr != NULL) {
    ret = (*(uint64_t *) value_ptr);
    free (value_ptr);
  }

  return ret;
}
示例#2
0
int
ht_insert_host_agent (TCADB * adb, int data_nkey, int agent_nkey)
{
  GSLList *list, *match;
  int sp = 0;

  if (adb == NULL)
    return (EINVAL);

  if ((list = tcadbget (adb, &data_nkey, sizeof (int), &sp)) != NULL) {
    if ((match = list_find (list, find_host_agent_in_list, &agent_nkey)))
      goto out;
    list = list_insert_prepend (list, int2ptr (agent_nkey));
  } else {
    list = list_create (int2ptr (agent_nkey));
  }

  if (!tcadbput (adb, &data_nkey, sizeof (int), list, sizeof (GSLList)))
    LOG_DEBUG (("Unable to tcadbput\n"));

out:
  free (list);

  return 0;
}
示例#3
0
void *
get_host_agent_list (int data_nkey)
{
#ifdef TCB_MEMHASH
  TCADB *db;
  void *list;
  int sp = 0;
#endif
#ifdef TCB_BTREE
  TCBDB *db;
  TCLIST *tclist;
#endif

  db = get_storage_metric (HOSTS, MTRC_AGENTS);
#ifdef TCB_MEMHASH
  if ((list = tcadbget (db, &data_nkey, sizeof (data_nkey), &sp)))
    return list;
#endif
#ifdef TCB_BTREE
  if ((tclist = tcbdbget4 (db, &data_nkey, sizeof (int))) != NULL) {
    return tclist;
  }
#endif

  return NULL;
}
示例#4
0
int
ht_insert_hit (TCADB * adb, int data_nkey, int uniq_nkey, int root_nkey)
{
  int sp = 0;
  GDataMap *map;

  if (adb == NULL)
    return (EINVAL);

  if ((map = tcadbget (adb, &data_nkey, sizeof (int), &sp)) != NULL) {
    map->data++;
  } else {
    map = xcalloc (1, sizeof (GDataMap));
    map->data = 1;
    map->root = root_nkey;
    map->uniq = uniq_nkey;
  }
  if (!tcadbput (adb, &data_nkey, sizeof (int), map, sizeof (GDataMap)))
    LOG_DEBUG (("Unable to tcadbput\n"));

  if (map)
    free (map);

  return 0;
}
示例#5
0
static void
free_key (TCADB * adb, void *key, int ksize, GO_UNUSED void *user_data)
{
  void *value;
  int sp = 0;

  value = tcadbget (adb, key, ksize, &sp);
  if (value)
    free (value);
  free (key);
}
示例#6
0
static void
free_agent_values (TCADB * adb, void *key, int ksize, GO_UNUSED void *user_data)
{
  void *list;
  int sp = 0;

  list = tcadbget (adb, key, ksize, &sp);
  if (list)
    list_remove_nodes (list);
  free (key);
}
示例#7
0
static void
data_iter_generic (TCADB * adb, void *key, int ksize, void *user_data)
{
  GRawData *raw_data = user_data;
  void *value;
  int sp = 0;

  value = tcadbget (adb, key, ksize, &sp);
  if (value)
    set_raw_data (key, value, raw_data);
}
示例#8
0
void *
get_host_agent_list (int data_nkey)
{
  TCADB *adb;
  void *list;
  int sp = 0;

  adb = get_storage_metric (HOSTS, MTRC_AGENTS);
  if ((list = tcadbget (adb, &data_nkey, sizeof (data_nkey), &sp)))
    return list;
  return NULL;
}
示例#9
0
int
ht_insert_nkey_nval (TCADB * adb, int nkey, int nval)
{
  int sp = 0;

  if (adb == NULL)
    return (EINVAL);

  if (tcadbget (adb, &nkey, sizeof (int), &sp) != NULL)
    return 1;

  tcadbput (adb, &nkey, sizeof (int), &nval, sizeof (int));

  return 0;
}
示例#10
0
char *
get_str_from_int_key (TCADB * adb, int nkey)
{
  void *value_ptr;
  int sp = 0;

  if (adb == NULL)
    return NULL;

  value_ptr = tcadbget (adb, &nkey, sizeof (int), &sp);
  if (value_ptr != NULL)
    return (char *) value_ptr;

  return NULL;
}
示例#11
0
int
ht_insert_nkey_nval (TCADB * adb, int nkey, int nval)
{
  int sp = 0;

  if (adb == NULL)
    return (EINVAL);

  if (tcadbget (adb, &nkey, sizeof (int), &sp) != NULL)
    return 1;

  if (!tcadbput (adb, &nkey, sizeof (int), &nval, sizeof (int)))
    LOG_DEBUG (("Unable to tcadbput\n"));

  return 0;
}
示例#12
0
char *
get_root_from_key (int root_nkey, GModule module)
{
  TCADB *adb = NULL;
  void *value_ptr;
  int sp = 0;

  adb = get_storage_metric (module, MTRC_ROOTMAP);
  if (adb == NULL)
    return NULL;

  value_ptr = tcadbget (adb, &root_nkey, sizeof (int), &sp);
  if (value_ptr != NULL)
    return (char *) value_ptr;

  return NULL;
}
示例#13
0
unsigned int
get_uint_from_str_key (TCADB * adb, const char *key)
{
  void *value_ptr;
  int sp = 0, ret = 0;

  if (adb == NULL)
    return (EINVAL);

  value_ptr = tcadbget (adb, key, strlen (key), &sp);
  if (value_ptr != NULL) {
    ret = (*(unsigned int *) value_ptr);
    free (value_ptr);
  }

  return ret;
}
示例#14
0
static int
get_int_from_int_key (TCADB * adb, int nkey)
{
  void *value_ptr;
  int sp = 0, ret = 0;

  if (adb == NULL)
    return (EINVAL);

  value_ptr = tcadbget (adb, &nkey, sizeof (int), &sp);
  if (value_ptr != NULL) {
    ret = (*(int *) value_ptr);
    free (value_ptr);
  }

  return ret;
}
示例#15
0
文件: tcamgr.c 项目: Fleurer/nanodb
/* perform get command */
static int procget(const char *name, const char *kbuf, int ksiz, int sep, bool px, bool pz){
  TCADB *adb = tcadbnew();
  ADBSKEL skel;
  if(*name == '@'){
    setskeltran(&skel);
    if(!tcadbsetskel(adb, &skel)){
      printerr(adb);
      skel.del(skel.opq);
      tcadbdel(adb);
      return 1;
    }
    name++;
  } else if(*name == '%'){
    if(!tcadbsetskelmulti(adb, 8)){
      printerr(adb);
      tcadbdel(adb);
      return 1;
    }
    name++;
  }
  if(!tcadbopen(adb, name)){
    printerr(adb);
    tcadbdel(adb);
    return 1;
  }
  bool err = false;
  int vsiz;
  char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
  if(vbuf){
    printdata(vbuf, vsiz, px, sep);
    if(!pz) putchar('\n');
    tcfree(vbuf);
  } else {
    printerr(adb);
    err = true;
  }
  if(!tcadbclose(adb)){
    if(!err) printerr(adb);
    err = true;
  }
  tcadbdel(adb);
  return err ? 1 : 0;
}
示例#16
0
static void get_test(void *db, int num, int vsiz, unsigned int seed)
{
	TCADB *adb = db;
	struct keygen keygen;
	int i;

	keygen_init(&keygen, seed);

	for (i = 0; i < num; i++) {
		const char *key = keygen_next_key(&keygen);
		void *value;
		int siz;

		value = tcadbget(adb, key, strlen(key), &siz);
		if (debug && vsiz != siz)
			die("Unexpected value size: %d", siz);
			
		free(value);
	}
}
示例#17
0
int
ht_max_u64_from_int_key (TCADB * adb, int data_nkey, uint64_t newval)
{
  int sp = 0;
  void *value_ptr;
  uint64_t curval = 0;

  if (adb == NULL)
    return (EINVAL);

  if ((value_ptr = tcadbget (adb, &data_nkey, sizeof (data_nkey), &sp)) != NULL) {
    curval = (*(uint64_t *) value_ptr);
    free (value_ptr);
  }

  if (curval < newval)
    tcadbput (adb, &data_nkey, sizeof (data_nkey), &newval, sizeof (uint64_t));

  return 0;
}
示例#18
0
static int
ht_inc_u64_from_key (TCADB * adb, const void *key, size_t ksize, uint64_t inc)
{
  int sp = 0;
  void *value_ptr;
  uint64_t add_value;

  if (adb == NULL)
    return (EINVAL);

  if ((value_ptr = tcadbget (adb, key, ksize, &sp)) != NULL) {
    add_value = (*(uint64_t *) value_ptr) + inc;
    free (value_ptr);
  } else {
    add_value = 0 + inc;
  }

  tcadbput (adb, key, ksize, &add_value, sizeof (uint64_t));

  return 0;
}
示例#19
0
static int
ht_inc_int_from_key (TCADB * adb, const void *key, size_t ksize, int inc)
{
  int sp = 0;
  void *value_ptr;
  int add_value;

  if (adb == NULL)
    return (EINVAL);

  if ((value_ptr = tcadbget (adb, key, ksize, &sp)) != NULL) {
    add_value = (*(int *) value_ptr) + inc;
    free (value_ptr);
  } else {
    add_value = 0 + inc;
  }

  if (!tcadbput (adb, key, ksize, &add_value, sizeof (int)))
    LOG_DEBUG (("Unable to tcadbput\n"));

  return 0;
}
示例#20
0
文件: pycabinet.c 项目: Frish/ntfs
static PyObject *
list(PyObject *self,PyObject *args){
    const char *dbname;
    if (!PyArg_ParseTuple(args, "s", &dbname))
        return NULL;
    TCADB *adb = openadb(dbname);
    PyObject* pDict = PyDict_New();
    if(!tcadbiterinit(adb)){
        return NULL;
    }
    int ksiz;
    char *kbuf;
    while((kbuf = tcadbiternext(adb, &ksiz)) != NULL){
        int vsiz;
        char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
        PyDict_SetItemString(pDict,kbuf,Py_BuildValue("s",vbuf));
        tcfree(vbuf);
        tcfree(kbuf);
    }
    closeadb(adb);
    return Py_BuildValue("O",pDict);
}
示例#21
0
/* thread the read function */
static void *threadread(void *targ){
  TCADB *adb = ((TARGREAD *)targ)->adb;
  int rnum = ((TARGREAD *)targ)->rnum;
  int id = ((TARGREAD *)targ)->id;
  bool err = false;
  int base = id * rnum;
  for(int i = 1; i <= rnum && !err; i++){
    char kbuf[RECBUFSIZ];
    int ksiz = sprintf(kbuf, "%08d", base + i + 1);
    int vsiz;
    char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
    if(!vbuf){
      eprint(adb, __LINE__, "tcadbget");
      err = true;
    }
    tcfree(vbuf);
    if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
      iputchar('.');
      if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
    }
  }
  return err ? "error" : NULL;
}
示例#22
0
文件: tcamgr.c 项目: Fleurer/nanodb
/* perform list command */
static int proclist(const char *name, int sep, int max, bool pv, bool px, const char *fmstr){
  TCADB *adb = tcadbnew();
  ADBSKEL skel;
  if(*name == '@'){
    setskeltran(&skel);
    if(!tcadbsetskel(adb, &skel)){
      printerr(adb);
      skel.del(skel.opq);
      tcadbdel(adb);
      return 1;
    }
    name++;
  } else if(*name == '%'){
    if(!tcadbsetskelmulti(adb, 8)){
      printerr(adb);
      tcadbdel(adb);
      return 1;
    }
    name++;
  }
  if(!tcadbopen(adb, name)){
    printerr(adb);
    tcadbdel(adb);
    return 1;
  }
  bool err = false;
  if(fmstr){
    TCLIST *keys = tcadbfwmkeys2(adb, fmstr, max);
    for(int i = 0; i < tclistnum(keys); i++){
      int ksiz;
      const char *kbuf = tclistval(keys, i, &ksiz);
      printdata(kbuf, ksiz, px, sep);
      if(pv){
        int vsiz;
        char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
        if(vbuf){
          putchar('\t');
          printdata(vbuf, vsiz, px, sep);
          tcfree(vbuf);
        }
      }
      putchar('\n');
    }
    tclistdel(keys);
  } else {
    if(!tcadbiterinit(adb)){
      printerr(adb);
      err = true;
    }
    int ksiz;
    char *kbuf;
    int cnt = 0;
    while((kbuf = tcadbiternext(adb, &ksiz)) != NULL){
      printdata(kbuf, ksiz, px, sep);
      if(pv){
        int vsiz;
        char *vbuf = tcadbget(adb, kbuf, ksiz, &vsiz);
        if(vbuf){
          putchar('\t');
          printdata(vbuf, vsiz, px, sep);
          tcfree(vbuf);
        }
      }
      putchar('\n');
      tcfree(kbuf);
      if(max >= 0 && ++cnt >= max) break;
    }
  }
  if(!tcadbclose(adb)){
    if(!err) printerr(adb);
    err = true;
  }
  tcadbdel(adb);
  return err ? 1 : 0;
}