]> git.sur5r.net Git - bacula/bacula/commitdiff
ebl Add program to validate TCDBM lib with accurate mode
authorEric Bollengier <eric@eb.homelinux.org>
Tue, 15 Apr 2008 18:47:58 +0000 (18:47 +0000)
committerEric Bollengier <eric@eb.homelinux.org>
Tue, 15 Apr 2008 18:47:58 +0000 (18:47 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@6827 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/tools/tcdbtest.c [new file with mode: 0644]

diff --git a/bacula/src/tools/tcdbtest.c b/bacula/src/tools/tcdbtest.c
new file mode 100644 (file)
index 0000000..543526f
--- /dev/null
@@ -0,0 +1,75 @@
+#include <tcutil.h>
+#include <tchdb.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
+
+#define NITEMS 5000000
+
+int main(int argc, char **argv){
+
+  TCHDB *hdb;
+  int ecode;
+  char *key, *value;
+  int i;
+  char save_key[200];
+
+  /* create the object */
+  hdb = tchdbnew();
+
+  tchdbsetcache(hdb, 5000000);
+  tchdbtune(hdb, 9000000, -1, 16, 0);
+
+  /* open the database */
+  if(!tchdbopen(hdb, "casket.hdb", HDBOWRITER | HDBOCREAT)){
+    ecode = tchdbecode(hdb);
+    fprintf(stderr, "open error: %s\n", tchdberrmsg(ecode));
+  }
+
+   for (i=0; i<NITEMS; i++) {
+      char mkey[200];
+      char data[200];
+      sprintf(mkey, "This is htable item %d", i);
+      sprintf(data, "Data for key %d", i);
+      if (!tchdbputasync2(hdb, mkey, data)) {
+         ecode = tchdbecode(hdb);
+         fprintf(stderr, "put error: %s\n", tchdberrmsg(ecode));
+      }
+      if (i == 99) {
+         strcpy(save_key, mkey);
+      }
+   }
+
+  /* retrieve records */
+  value = tchdbget2(hdb, save_key);
+  if(value){
+    printf("%s\n", value);
+    free(value);
+  } else {
+    ecode = tchdbecode(hdb);
+    fprintf(stderr, "get error: %s\n", tchdberrmsg(ecode));
+  }
+
+  /* traverse records */
+  tchdbiterinit(hdb);
+  while((key = tchdbiternext2(hdb)) != NULL){
+    value = tchdbget2(hdb, key);
+    if(value){
+      printf("%s:%s\n", key, value);
+      free(value);
+    }
+    free(key);
+  }
+
+  /* close the database */
+  if(!tchdbclose(hdb)){
+    ecode = tchdbecode(hdb);
+    fprintf(stderr, "close error: %s\n", tchdberrmsg(ecode));
+  }
+
+  /* delete the object */
+  tchdbdel(hdb);
+
+  return 0;
+}