/tcejdb/samples/sample1/sample1
/tcejdb/samples/sample1/addressbook*
+/tcejdb/testejdb/Makefile
/tcejdb/testejdb/dbt*
/tcejdb/testejdb/t1
/tcejdb/testejdb/t2
/jejdb/target
/jejdb/*.so
/jejdb/*.so.*
+/jejdb/Makefile
+
+
+++ /dev/null
-#================================================================
-# Setting Variables
-#================================================================
-
-
-SHELL = /bin/bash
-
-# Package information
-PACKAGE = jejdb
-VERSION = 1.0.1
-LIBVER = 9
-LIBREV = 11
-FORMATVER = 1.0
-
-# Targets
-LIBRARYFILES = libjejdb.so.9.11.0 libjejdb.so.9 libjejdb.so
-
-
-# Install destinations
-prefix = /usr
-exec_prefix = ${prefix}
-LIBDIR = ${exec_prefix}/lib
-DESTDIR =
-
-
-# Directories
-SRCDIR = ./src/cpp/
-
-# Building configuration
-CC = gcc
-CPPFLAGS = -I. -I. -I../tcejdb -I/usr/lib/jvm/java-6-oracle//include -I/usr/lib/jvm/java-6-oracle//include/linux -I$(INCLUDEDIR) -I/home/tve/include -I/usr/local/include -D_UNICODE -DNDEBUG -D_GNU_SOURCE=1 -D_REENTRANT -D__EXTENSIONS__
-CFLAGS = -std=c99 -Wall -fPIC -fsigned-char -O2
-LDFLAGS = -L. -L$(LIBDIR) -L/home/tve/lib -L/usr/local/lib
-LIBS = -lz -ltcejdb -lrt -lpthread -lm -lc
-
-
-#================================================================
-# Actions
-#================================================================
-
-all: $(LIBRARYFILES) jejdb tests
- @printf '\n'
- @printf '#================================================================\n'
- @printf '# Ready to install.\n'
- @printf '#================================================================\n'
-
-compile-native : $(LIBRARYFILES)
-
-jejdb:
- ant build
-
-tests:
- ant build.and.test
-
-doc:
- ant build.doc
-
-install:
- install -d $(DESTDIR)$(LIBDIR)
- cp -Rf $(LIBRARYFILES) $(DESTDIR)$(LIBDIR)
- chmod -R 755 $(DESTDIR)$(LIBDIR)
- @printf '\n'
- @printf '#================================================================\n'
- @printf '# Java Bindinig binaries installed to %s.\n' "$(DESTDIR)$(LIBDIR)"
- @printf '# Ensure that LD_LIBRARY_PATH environment variable contains "%s".\n' "$(DESTDIR)$(LIBDIR)"
- @printf '#================================================================\n'
- @printf '# Thanks for using Java Binding of Tokyo Cabinet EJDB edition.\n'
- @printf '#================================================================\n'
-
-
-clean:
- rm -rf $(LIBRARYFILES)
- ant clean
-
-
-#================================================================
-# Building binaries
-#================================================================
-
-
-libjejdb.so.$(LIBVER).$(LIBREV).0 :
- $(CC) $(CPPFLAGS) $(CFLAGS) -shared $(LDFLAGS) -o $@ $(SRCDIR)jejdb.c $(LIBS)
-
-libjejdb.so.$(LIBVER) : libjejdb.so.$(LIBVER).$(LIBREV).0
- ln -f -s libjejdb.so.$(LIBVER).$(LIBREV).0 $@
-
-
-libjejdb.so : libjejdb.so.$(LIBVER).$(LIBREV).0
- ln -f -s libjejdb.so.$(LIBVER).$(LIBREV).0 $@
/* global variables */
const char *g_progname; // program name
unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
/* global variables */
-const char *g_progname; // program name
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
static int runimporttsv(int argc, char **argv);
static int runversion(int argc, char **argv);
static int proccreate(const char *path, int lmemb, int nmemb,
- int bnum, int apow, int fpow, TCCMP cmp, int opts);
+ int bnum, int apow, int fpow, TCCMP cmp, int opts);
static int procinform(const char *path, int omode);
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- TCCMP cmp, int omode, int dmode);
+ TCCMP cmp, int omode, int dmode);
static int procout(const char *path, const char *kbuf, int ksiz, TCCMP cmp, int omode);
static int procget(const char *path, const char *kbuf, int ksiz, TCCMP cmp, int omode,
- bool px, bool pz);
+ bool px, bool pz);
static int proclist(const char *path, TCCMP cmp, int omode, int max, bool pv, bool px, bool bk,
- const char *jstr, const char *bstr, const char *estr, const char *fmstr);
+ const char *jstr, const char *bstr, const char *estr, const char *fmstr);
static int procoptimize(const char *path, int lmemb, int nmemb,
- int bnum, int apow, int fpow, TCCMP cmp, int opts, int omode, bool df);
+ int bnum, int apow, int fpow, TCCMP cmp, int opts, int omode, bool df);
static int procimporttsv(const char *path, const char *file, int omode, bool sc);
static int procversion(void);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- g_dbgfd = INVALID_HANDLE_VALUE;
- const char *ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ g_dbgfd = INVALID_HANDLE_VALUE;
+ const char *ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "create")){
- rv = runcreate(argc, argv);
- } else if(!strcmp(argv[1], "inform")){
- rv = runinform(argc, argv);
- } else if(!strcmp(argv[1], "put")){
- rv = runput(argc, argv);
- } else if(!strcmp(argv[1], "out")){
- rv = runout(argc, argv);
- } else if(!strcmp(argv[1], "get")){
- rv = runget(argc, argv);
- } else if(!strcmp(argv[1], "list")){
- rv = runlist(argc, argv);
- } else if(!strcmp(argv[1], "optimize")){
- rv = runoptimize(argc, argv);
- } else if(!strcmp(argv[1], "importtsv")){
- rv = runimporttsv(argc, argv);
- } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){
- rv = runversion(argc, argv);
- } else {
- usage();
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "create")) {
+ rv = runcreate(argc, argv);
+ } else if (!strcmp(argv[1], "inform")) {
+ rv = runinform(argc, argv);
+ } else if (!strcmp(argv[1], "put")) {
+ rv = runput(argc, argv);
+ } else if (!strcmp(argv[1], "out")) {
+ rv = runout(argc, argv);
+ } else if (!strcmp(argv[1], "get")) {
+ rv = runget(argc, argv);
+ } else if (!strcmp(argv[1], "list")) {
+ rv = runlist(argc, argv);
+ } else if (!strcmp(argv[1], "optimize")) {
+ rv = runoptimize(argc, argv);
+ } else if (!strcmp(argv[1], "importtsv")) {
+ rv = runimporttsv(argc, argv);
+ } else if (!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")) {
+ rv = runversion(argc, argv);
+ } else {
+ usage();
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: the command line utility of the B+ tree database API\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s create [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] path"
- " [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
- fprintf(stderr, " %s inform [-nl|-nb] path\n", g_progname);
- fprintf(stderr, " %s put [-cd|-ci|-cj] [-nl|-nb] [-sx] [-dk|-dc|-dd|-db|-dai|-dad] path"
- " key value\n", g_progname);
- fprintf(stderr, " %s out [-cd|-ci|-cj] [-nl|-nb] [-sx] path key\n", g_progname);
- fprintf(stderr, " %s get [-cd|-ci|-cj] [-nl|-nb] [-sx] [-px] [-pz] path key\n", g_progname);
- fprintf(stderr, " %s list [-cd|-ci|-cj] [-nl|-nb] [-m num] [-bk] [-pv] [-px] [-j str]"
- " [-rb bkey ekey] [-fm str] path\n", g_progname);
- fprintf(stderr, " %s optimize [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] [-tz] [-nl|-nb] [-df]"
- " path [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
- fprintf(stderr, " %s importtsv [-nl|-nb] [-sc] path [file]\n", g_progname);
- fprintf(stderr, " %s version\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: the command line utility of the B+ tree database API\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s create [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] path"
+ " [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
+ fprintf(stderr, " %s inform [-nl|-nb] path\n", g_progname);
+ fprintf(stderr, " %s put [-cd|-ci|-cj] [-nl|-nb] [-sx] [-dk|-dc|-dd|-db|-dai|-dad] path"
+ " key value\n", g_progname);
+ fprintf(stderr, " %s out [-cd|-ci|-cj] [-nl|-nb] [-sx] path key\n", g_progname);
+ fprintf(stderr, " %s get [-cd|-ci|-cj] [-nl|-nb] [-sx] [-px] [-pz] path key\n", g_progname);
+ fprintf(stderr, " %s list [-cd|-ci|-cj] [-nl|-nb] [-m num] [-bk] [-pv] [-px] [-j str]"
+ " [-rb bkey ekey] [-fm str] path\n", g_progname);
+ fprintf(stderr, " %s optimize [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] [-tz] [-nl|-nb] [-df]"
+ " path [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
+ fprintf(stderr, " %s importtsv [-nl|-nb] [-sc] path [file]\n", g_progname);
+ fprintf(stderr, " %s version\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print error information */
-static void printerr(TCBDB *bdb){
- const char *path = tcbdbpath(bdb);
- int ecode = tcbdbecode(bdb);
- fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tcbdberrmsg(ecode));
+static void printerr(TCBDB *bdb) {
+ const char *path = tcbdbpath(bdb);
+ int ecode = tcbdbecode(bdb);
+ fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tcbdberrmsg(ecode));
}
-
/* print record data */
-static int printdata(const char *ptr, int size, bool px){
- int len = 0;
- while(size-- > 0){
- if(px){
- if(len > 0) putchar(' ');
- len += printf("%02X", *(unsigned char *)ptr);
- } else {
- putchar(*ptr);
- len++;
+static int printdata(const char *ptr, int size, bool px) {
+ int len = 0;
+ while (size-- > 0) {
+ if (px) {
+ if (len > 0) putchar(' ');
+ len += printf("%02X", *(unsigned char *) ptr);
+ } else {
+ putchar(*ptr);
+ len++;
+ }
+ ptr++;
}
- ptr++;
- }
- return len;
+ return len;
}
-
/* read a line from a file descriptor */
-static char *mygetline(FILE *ifp){
- int len = 0;
- int blen = 1024;
- char *buf = tcmalloc(blen + 1);
- bool end = true;
- int c;
- while((c = fgetc(ifp)) != EOF){
- end = false;
- if(c == '\0') continue;
- if(blen <= len){
- blen *= 2;
- buf = tcrealloc(buf, blen + 1);
+static char *mygetline(FILE *ifp) {
+ int len = 0;
+ int blen = 1024;
+ char *buf = tcmalloc(blen + 1);
+ bool end = true;
+ int c;
+ while ((c = fgetc(ifp)) != EOF) {
+ end = false;
+ if (c == '\0') continue;
+ if (blen <= len) {
+ blen *= 2;
+ buf = tcrealloc(buf, blen + 1);
+ }
+ if (c == '\n' || c == '\r') c = '\0';
+ buf[len++] = c;
+ if (c == '\0') break;
+ }
+ if (end) {
+ tcfree(buf);
+ return NULL;
}
- if(c == '\n' || c == '\r') c = '\0';
- buf[len++] = c;
- if(c == '\0') break;
- }
- if(end){
- tcfree(buf);
- return NULL;
- }
- buf[len] = '\0';
- return buf;
+ buf[len] = '\0';
+ return buf;
}
-
/* dummy comparison function */
-static int mycmpfunc(const char *aptr, int asiz, const char *bptr, int bsiz, void *op){
- return 0;
+static int mycmpfunc(const char *aptr, int asiz, const char *bptr, int bsiz, void *op) {
+ return 0;
}
-
/* parse arguments of create command */
-static int runcreate(int argc, char **argv){
- char *path = NULL;
- char *lmstr = NULL;
- char *nmstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- TCCMP cmp = NULL;
- int opts = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!lmstr){
- lmstr = argv[i];
- } else if(!nmstr){
- nmstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
+static int runcreate(int argc, char **argv) {
+ char *path = NULL;
+ char *lmstr = NULL;
+ char *nmstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ TCCMP cmp = NULL;
+ int opts = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!lmstr) {
+ lmstr = argv[i];
+ } else if (!nmstr) {
+ nmstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int lmemb = lmstr ? tcatoix(lmstr) : -1;
- int nmemb = nmstr ? tcatoix(nmstr) : -1;
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = proccreate(path, lmemb, nmemb, bnum, apow, fpow, cmp, opts);
- return rv;
+ if (!path) usage();
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = proccreate(path, lmemb, nmemb, bnum, apow, fpow, cmp, opts);
+ return rv;
}
-
/* parse arguments of inform command */
-static int runinform(int argc, char **argv){
- char *path = NULL;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runinform(int argc, char **argv) {
+ char *path = NULL;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procinform(path, omode);
- return rv;
+ if (!path) usage();
+ int rv = procinform(path, omode);
+ return rv;
}
-
/* parse arguments of put command */
-static int runput(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- char *value = NULL;
- TCCMP cmp = NULL;
- int omode = 0;
- int dmode = 0;
- bool sx = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-dk")){
- dmode = -1;
- } else if(!strcmp(argv[i], "-dc")){
- dmode = 1;
- } else if(!strcmp(argv[i], "-dd")){
- dmode = 2;
- } else if(!strcmp(argv[i], "-db")){
- dmode = 3;
- } else if(!strcmp(argv[i], "-dai")){
- dmode = 10;
- } else if(!strcmp(argv[i], "-dad")){
- dmode = 11;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!key){
- key = argv[i];
- } else if(!value){
- value = argv[i];
+static int runput(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ char *value = NULL;
+ TCCMP cmp = NULL;
+ int omode = 0;
+ int dmode = 0;
+ bool sx = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-dk")) {
+ dmode = -1;
+ } else if (!strcmp(argv[i], "-dc")) {
+ dmode = 1;
+ } else if (!strcmp(argv[i], "-dd")) {
+ dmode = 2;
+ } else if (!strcmp(argv[i], "-db")) {
+ dmode = 3;
+ } else if (!strcmp(argv[i], "-dai")) {
+ dmode = 10;
+ } else if (!strcmp(argv[i], "-dad")) {
+ dmode = 11;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else if (!value) {
+ value = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !key || !value) usage();
+ char *kbuf, *vbuf;
+ int ksiz, vsiz;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
+ vbuf = tchexdecode(value, &vsiz);
} else {
- usage();
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
+ vsiz = strlen(value);
+ vbuf = tcmemdup(value, vsiz);
}
- }
- if(!path || !key || !value) usage();
- char *kbuf, *vbuf;
- int ksiz, vsiz;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- vbuf = tchexdecode(value, &vsiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- vsiz = strlen(value);
- vbuf = tcmemdup(value, vsiz);
- }
- int rv = procput(path, kbuf, ksiz, vbuf, vsiz, cmp, omode, dmode);
- tcfree(vbuf);
- tcfree(kbuf);
- return rv;
+ int rv = procput(path, kbuf, ksiz, vbuf, vsiz, cmp, omode, dmode);
+ tcfree(vbuf);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of out command */
-static int runout(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- TCCMP cmp = NULL;
- int omode = 0;
- bool sx = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!key){
- key = argv[i];
+static int runout(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ TCCMP cmp = NULL;
+ int omode = 0;
+ bool sx = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !key) usage();
+ int ksiz;
+ char *kbuf;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
} else {
- usage();
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
}
- }
- if(!path || !key) usage();
- int ksiz;
- char *kbuf;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- }
- int rv = procout(path, kbuf, ksiz, cmp, omode);
- tcfree(kbuf);
- return rv;
+ int rv = procout(path, kbuf, ksiz, cmp, omode);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of get command */
-static int runget(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- TCCMP cmp = NULL;
- int omode = 0;
- bool sx = false;
- bool px = false;
- bool pz = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-pz")){
- pz = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!key){
- key = argv[i];
+static int runget(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ TCCMP cmp = NULL;
+ int omode = 0;
+ bool sx = false;
+ bool px = false;
+ bool pz = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-pz")) {
+ pz = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !key) usage();
+ int ksiz;
+ char *kbuf;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
} else {
- usage();
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
}
- }
- if(!path || !key) usage();
- int ksiz;
- char *kbuf;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- }
- int rv = procget(path, kbuf, ksiz, cmp, omode, px, pz);
- tcfree(kbuf);
- return rv;
+ int rv = procget(path, kbuf, ksiz, cmp, omode, px, pz);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of list command */
-static int runlist(int argc, char **argv){
- char *path = NULL;
- TCCMP cmp = NULL;
- int omode = 0;
- int max = -1;
- bool pv = false;
- bool px = false;
- bool bk = false;
- char *jstr = NULL;
- char *bstr = NULL;
- char *estr = NULL;
- char *fmstr = NULL;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-m")){
- if(++i >= argc) usage();
- max = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-bk")){
- bk = true;
- } else if(!strcmp(argv[i], "-pv")){
- pv = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-j")){
- if(++i >= argc) usage();
- jstr = argv[i];
- } else if(!strcmp(argv[i], "-rb")){
- if(++i >= argc) usage();
- bstr = argv[i];
- if(++i >= argc) usage();
- estr = argv[i];
- } else if(!strcmp(argv[i], "-fm")){
- if(++i >= argc) usage();
- fmstr = argv[i];
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runlist(int argc, char **argv) {
+ char *path = NULL;
+ TCCMP cmp = NULL;
+ int omode = 0;
+ int max = -1;
+ bool pv = false;
+ bool px = false;
+ bool bk = false;
+ char *jstr = NULL;
+ char *bstr = NULL;
+ char *estr = NULL;
+ char *fmstr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-m")) {
+ if (++i >= argc) usage();
+ max = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-bk")) {
+ bk = true;
+ } else if (!strcmp(argv[i], "-pv")) {
+ pv = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-j")) {
+ if (++i >= argc) usage();
+ jstr = argv[i];
+ } else if (!strcmp(argv[i], "-rb")) {
+ if (++i >= argc) usage();
+ bstr = argv[i];
+ if (++i >= argc) usage();
+ estr = argv[i];
+ } else if (!strcmp(argv[i], "-fm")) {
+ if (++i >= argc) usage();
+ fmstr = argv[i];
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = proclist(path, cmp, omode, max, pv, px, bk, jstr, bstr, estr, fmstr);
- return rv;
+ if (!path) usage();
+ int rv = proclist(path, cmp, omode, max, pv, px, bk, jstr, bstr, estr, fmstr);
+ return rv;
}
-
/* parse arguments of optimize command */
-static int runoptimize(int argc, char **argv){
- char *path = NULL;
- char *lmstr = NULL;
- char *nmstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- TCCMP cmp = NULL;
- int opts = UINT8_MAX;
- int omode = 0;
- bool df = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-tl")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-tz")){
- if(opts == UINT8_MAX) opts = 0;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-df")){
- df = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!lmstr){
- lmstr = argv[i];
- } else if(!nmstr){
- nmstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
+static int runoptimize(int argc, char **argv) {
+ char *path = NULL;
+ char *lmstr = NULL;
+ char *nmstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ TCCMP cmp = NULL;
+ int opts = UINT8_MAX;
+ int omode = 0;
+ bool df = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-tl")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-tz")) {
+ if (opts == UINT8_MAX) opts = 0;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-df")) {
+ df = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!lmstr) {
+ lmstr = argv[i];
+ } else if (!nmstr) {
+ nmstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int lmemb = lmstr ? tcatoix(lmstr) : -1;
- int nmemb = nmstr ? tcatoix(nmstr) : -1;
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procoptimize(path, lmemb, nmemb, bnum, apow, fpow, cmp, opts, omode, df);
- return rv;
+ if (!path) usage();
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procoptimize(path, lmemb, nmemb, bnum, apow, fpow, cmp, opts, omode, df);
+ return rv;
}
-
/* parse arguments of importtsv command */
-static int runimporttsv(int argc, char **argv){
- char *path = NULL;
- char *file = NULL;
- int omode = 0;
- bool sc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-sc")){
- sc = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!file){
- file = argv[i];
- } else {
- usage();
+static int runimporttsv(int argc, char **argv) {
+ char *path = NULL;
+ char *file = NULL;
+ int omode = 0;
+ bool sc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sc")) {
+ sc = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!file) {
+ file = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procimporttsv(path, file, omode, sc);
- return rv;
+ if (!path) usage();
+ int rv = procimporttsv(path, file, omode, sc);
+ return rv;
}
-
/* parse arguments of version command */
-static int runversion(int argc, char **argv){
- int rv = procversion();
- return rv;
+static int runversion(int argc, char **argv) {
+ int rv = procversion();
+ return rv;
}
-
/* perform create command */
static int proccreate(const char *path, int lmemb, int nmemb,
- int bnum, int apow, int fpow, TCCMP cmp, int opts){
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
- if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
- printerr(bdb);
- tcbdbdel(bdb);
- return 1;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC)){
- printerr(bdb);
+ int bnum, int apow, int fpow, TCCMP cmp, int opts) {
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
+ if (!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) {
+ printerr(bdb);
+ tcbdbdel(bdb);
+ return 1;
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC)) {
+ printerr(bdb);
+ tcbdbdel(bdb);
+ return 1;
+ }
+ bool err = false;
+ if (!tcbdbclose(bdb)) {
+ printerr(bdb);
+ err = true;
+ }
tcbdbdel(bdb);
- return 1;
- }
- bool err = false;
- if(!tcbdbclose(bdb)){
- printerr(bdb);
- err = true;
- }
- tcbdbdel(bdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform inform command */
-static int procinform(const char *path, int omode){
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- tcbdbsetcmpfunc(bdb, mycmpfunc, NULL);
- tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL);
- if(!tcbdbopen(bdb, path, BDBOREADER | omode)){
- printerr(bdb);
- tcbdbdel(bdb);
- return 1;
- }
- bool err = false;
- const char *npath = tcbdbpath(bdb);
- if(!npath) npath = "(unknown)";
- printf("path: %s\n", npath);
- printf("database type: btree\n");
- uint8_t flags = tcbdbflags(bdb);
- printf("additional flags:");
- if(flags & BDBFOPEN) printf(" open");
- if(flags & BDBFFATAL) printf(" fatal");
- printf("\n");
- TCCMP cmp = tcbdbcmpfunc(bdb);
- printf("comparison function: ");
- if(cmp == tccmplexical){
- printf("lexical");
- } else if(cmp == tccmpdecimal){
- printf("decimal");
- } else if(cmp == tccmpint32){
- printf("int32");
- } else if(cmp == tccmpint64){
- printf("int64");
- } else {
- printf("custom");
- }
- printf("\n");
- printf("max leaf member: %d\n", tcbdblmemb(bdb));
- printf("max node member: %d\n", tcbdbnmemb(bdb));
- printf("leaf number: %" PRIuMAX "\n", (uint64_t)tcbdblnum(bdb));
- printf("node number: %" PRIuMAX "\n", (uint64_t)tcbdbnnum(bdb));
- printf("bucket number: %" PRIuMAX "\n", (uint64_t)tcbdbbnum(bdb));
+static int procinform(const char *path, int omode) {
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ tcbdbsetcmpfunc(bdb, mycmpfunc, NULL);
+ tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL);
+ if (!tcbdbopen(bdb, path, BDBOREADER | omode)) {
+ printerr(bdb);
+ tcbdbdel(bdb);
+ return 1;
+ }
+ bool err = false;
+ const char *npath = tcbdbpath(bdb);
+ if (!npath) npath = "(unknown)";
+ printf("path: %s\n", npath);
+ printf("database type: btree\n");
+ uint8_t flags = tcbdbflags(bdb);
+ printf("additional flags:");
+ if (flags & BDBFOPEN) printf(" open");
+ if (flags & BDBFFATAL) printf(" fatal");
+ printf("\n");
+ TCCMP cmp = tcbdbcmpfunc(bdb);
+ printf("comparison function: ");
+ if (cmp == tccmplexical) {
+ printf("lexical");
+ } else if (cmp == tccmpdecimal) {
+ printf("decimal");
+ } else if (cmp == tccmpint32) {
+ printf("int32");
+ } else if (cmp == tccmpint64) {
+ printf("int64");
+ } else {
+ printf("custom");
+ }
+ printf("\n");
+ printf("max leaf member: %d\n", tcbdblmemb(bdb));
+ printf("max node member: %d\n", tcbdbnmemb(bdb));
+ printf("leaf number: %" PRIuMAX "\n", (uint64_t) tcbdblnum(bdb));
+ printf("node number: %" PRIuMAX "\n", (uint64_t) tcbdbnnum(bdb));
+ printf("bucket number: %" PRIuMAX "\n", (uint64_t) tcbdbbnum(bdb));
#ifndef NDEBUG
- if(bdb->hdb->cnt_writerec >= 0)
- printf("used bucket number: %" PRIdMAX "\n", (int64_t) tcbdbbnumused(bdb));
+ if (bdb->hdb->cnt_writerec >= 0)
+ printf("used bucket number: %" PRIdMAX "\n", (int64_t) tcbdbbnumused(bdb));
#endif
- printf("alignment: %u\n", tcbdbalign(bdb));
- printf("free block pool: %u\n", tcbdbfbpmax(bdb));
- printf("inode number: %" PRIdMAX "\n", (int64_t) tcbdbinode(bdb));
- char date[48];
- tcdatestrwww(tcbdbmtime(bdb), INT_MAX, date);
- printf("modified time: %s\n", date);
- uint8_t opts = tcbdbopts(bdb);
- printf("options:");
- if(opts & BDBTLARGE) printf(" large");
- if(opts & BDBTDEFLATE) printf(" deflate");
- if(opts & BDBTBZIP) printf(" bzip");
- if(opts & BDBTTCBS) printf(" tcbs");
- if(opts & BDBTEXCODEC) printf(" excodec");
- printf("\n");
- printf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- printf("file size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- if(!tcbdbclose(bdb)){
- if(!err) printerr(bdb);
- err = true;
- }
- tcbdbdel(bdb);
- return err ? 1 : 0;
+ printf("alignment: %u\n", tcbdbalign(bdb));
+ printf("free block pool: %u\n", tcbdbfbpmax(bdb));
+ printf("inode number: %" PRIdMAX "\n", (int64_t) tcbdbinode(bdb));
+ char date[48];
+ tcdatestrwww(tcbdbmtime(bdb), INT_MAX, date);
+ printf("modified time: %s\n", date);
+ uint8_t opts = tcbdbopts(bdb);
+ printf("options:");
+ if (opts & BDBTLARGE) printf(" large");
+ if (opts & BDBTDEFLATE) printf(" deflate");
+ if (opts & BDBTBZIP) printf(" bzip");
+ if (opts & BDBTTCBS) printf(" tcbs");
+ if (opts & BDBTEXCODEC) printf(" excodec");
+ printf("\n");
+ printf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ printf("file size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ if (!tcbdbclose(bdb)) {
+ if (!err) printerr(bdb);
+ err = true;
+ }
+ tcbdbdel(bdb);
+ return err ? 1 : 0;
}
-
/* perform put command */
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- TCCMP cmp, int omode, int dmode){
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
- if(!tcbdbopen(bdb, path, BDBOWRITER | omode)){
- printerr(bdb);
- tcbdbdel(bdb);
- return 1;
- }
- bool err = false;
- int inum;
- double dnum;
- switch(dmode){
- case -1:
- if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz)){
- printerr(bdb);
- err = true;
- }
- break;
- case 1:
- if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
- printerr(bdb);
- err = true;
- }
- break;
- case 2:
- if(!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)){
- printerr(bdb);
- err = true;
- }
- break;
- case 3:
- if(!tcbdbputdupback(bdb, kbuf, ksiz, vbuf, vsiz)){
+ TCCMP cmp, int omode, int dmode) {
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
+ if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) {
printerr(bdb);
+ tcbdbdel(bdb);
+ return 1;
+ }
+ bool err = false;
+ int inum;
+ double dnum;
+ switch (dmode) {
+ case -1:
+ if (!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(bdb);
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(bdb);
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(bdb);
+ err = true;
+ }
+ break;
+ case 3:
+ if (!tcbdbputdupback(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(bdb);
+ err = true;
+ }
+ break;
+ case 10:
+ inum = tcbdbaddint(bdb, kbuf, ksiz, tcatoi(vbuf));
+ if (inum == INT_MIN) {
+ printerr(bdb);
+ err = true;
+ } else {
+ printf("%d\n", inum);
+ }
+ break;
+ case 11:
+ dnum = tcbdbadddouble(bdb, kbuf, ksiz, tcatof(vbuf));
+ if (isnan(dnum)) {
+ printerr(bdb);
+ err = true;
+ } else {
+ printf("%.6f\n", dnum);
+ }
+ break;
+ default:
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ printerr(bdb);
+ err = true;
+ }
+ break;
+ }
+ if (!tcbdbclose(bdb)) {
+ if (!err) printerr(bdb);
err = true;
- }
- break;
- case 10:
- inum = tcbdbaddint(bdb, kbuf, ksiz, tcatoi(vbuf));
- if(inum == INT_MIN){
+ }
+ tcbdbdel(bdb);
+ return err ? 1 : 0;
+}
+
+/* perform out command */
+static int procout(const char *path, const char *kbuf, int ksiz, TCCMP cmp, int omode) {
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
+ if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) {
printerr(bdb);
- err = true;
- } else {
- printf("%d\n", inum);
- }
- break;
- case 11:
- dnum = tcbdbadddouble(bdb, kbuf, ksiz, tcatof(vbuf));
- if(isnan(dnum)){
+ tcbdbdel(bdb);
+ return 1;
+ }
+ bool err = false;
+ if (!tcbdbout(bdb, kbuf, ksiz)) {
printerr(bdb);
err = true;
- } else {
- printf("%.6f\n", dnum);
- }
- break;
- default:
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- printerr(bdb);
+ }
+ if (!tcbdbclose(bdb)) {
+ if (!err) printerr(bdb);
err = true;
- }
- break;
- }
- if(!tcbdbclose(bdb)){
- if(!err) printerr(bdb);
- err = true;
- }
- tcbdbdel(bdb);
- return err ? 1 : 0;
-}
-
-
-/* perform out command */
-static int procout(const char *path, const char *kbuf, int ksiz, TCCMP cmp, int omode){
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
- if(!tcbdbopen(bdb, path, BDBOWRITER | omode)){
- printerr(bdb);
+ }
tcbdbdel(bdb);
- return 1;
- }
- bool err = false;
- if(!tcbdbout(bdb, kbuf, ksiz)){
- printerr(bdb);
- err = true;
- }
- if(!tcbdbclose(bdb)){
- if(!err) printerr(bdb);
- err = true;
- }
- tcbdbdel(bdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform get command */
static int procget(const char *path, const char *kbuf, int ksiz, TCCMP cmp, int omode,
- bool px, bool pz){
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
- if(!tcbdbopen(bdb, path, BDBOREADER | omode)){
- printerr(bdb);
+ bool px, bool pz) {
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
+ if (!tcbdbopen(bdb, path, BDBOREADER | omode)) {
+ printerr(bdb);
+ tcbdbdel(bdb);
+ return 1;
+ }
+ bool err = false;
+ int vsiz;
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ printdata(vbuf, vsiz, px);
+ if (!pz) putchar('\n');
+ tcfree(vbuf);
+ } else {
+ printerr(bdb);
+ err = true;
+ }
+ if (!tcbdbclose(bdb)) {
+ if (!err) printerr(bdb);
+ err = true;
+ }
tcbdbdel(bdb);
- return 1;
- }
- bool err = false;
- int vsiz;
- char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- printdata(vbuf, vsiz, px);
- if(!pz) putchar('\n');
- tcfree(vbuf);
- } else {
- printerr(bdb);
- err = true;
- }
- if(!tcbdbclose(bdb)){
- if(!err) printerr(bdb);
- err = true;
- }
- tcbdbdel(bdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform list command */
static int proclist(const char *path, TCCMP cmp, int omode, int max, bool pv, bool px, bool bk,
- const char *jstr, const char *bstr, const char *estr, const char *fmstr){
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
- if(!tcbdbopen(bdb, path, BDBOREADER | omode)){
- printerr(bdb);
- tcbdbdel(bdb);
- return 1;
- }
- bool err = false;
- if(bstr || fmstr){
- TCLIST *keys = fmstr ? tcbdbfwmkeys2(bdb, fmstr, max) :
- tcbdbrange(bdb, bstr, strlen(bstr), true, estr, strlen(estr), true, max);
- int cnt = 0;
- for(int i = 0; i < tclistnum(keys); i++){
- int ksiz;
- const char *kbuf = tclistval(keys, i, &ksiz);
- if(pv){
- TCLIST *vals = tcbdbget4(bdb, kbuf, ksiz);
- if(vals){
- for(int j = 0; j < tclistnum(vals); j++){
- int vsiz;
- const char *vbuf = tclistval(vals, j, &vsiz);
- printdata(kbuf, ksiz, px);
- putchar('\t');
- printdata(vbuf, vsiz, px);
- putchar('\n');
- if(max >= 0 && ++cnt >= max) break;
- }
- tclistdel(vals);
- }
- } else {
- int num = tcbdbvnum(bdb, kbuf, ksiz);
- for(int j = 0; j < num; j++){
- printdata(kbuf, ksiz, px);
- putchar('\n');
- if(max >= 0 && ++cnt >= max) break;
- }
- }
- if(max >= 0 && cnt >= max) break;
+ const char *jstr, const char *bstr, const char *estr, const char *fmstr) {
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
+ if (!tcbdbopen(bdb, path, BDBOREADER | omode)) {
+ printerr(bdb);
+ tcbdbdel(bdb);
+ return 1;
}
- tclistdel(keys);
- } else {
- BDBCUR *cur = tcbdbcurnew(bdb);
- if(bk){
- if(jstr){
- if(!tcbdbcurjumpback(cur, jstr, strlen(jstr)) && tcbdbecode(bdb) != TCENOREC){
- printerr(bdb);
- err = true;
- }
- } else {
- if(!tcbdbcurlast(cur) && tcbdbecode(bdb) != TCENOREC){
- printerr(bdb);
- err = true;
+ bool err = false;
+ if (bstr || fmstr) {
+ TCLIST *keys = fmstr ? tcbdbfwmkeys2(bdb, fmstr, max) :
+ tcbdbrange(bdb, bstr, strlen(bstr), true, estr, strlen(estr), true, max);
+ int cnt = 0;
+ for (int i = 0; i < tclistnum(keys); i++) {
+ int ksiz;
+ const char *kbuf = tclistval(keys, i, &ksiz);
+ if (pv) {
+ TCLIST *vals = tcbdbget4(bdb, kbuf, ksiz);
+ if (vals) {
+ for (int j = 0; j < tclistnum(vals); j++) {
+ int vsiz;
+ const char *vbuf = tclistval(vals, j, &vsiz);
+ printdata(kbuf, ksiz, px);
+ putchar('\t');
+ printdata(vbuf, vsiz, px);
+ putchar('\n');
+ if (max >= 0 && ++cnt >= max) break;
+ }
+ tclistdel(vals);
+ }
+ } else {
+ int num = tcbdbvnum(bdb, kbuf, ksiz);
+ for (int j = 0; j < num; j++) {
+ printdata(kbuf, ksiz, px);
+ putchar('\n');
+ if (max >= 0 && ++cnt >= max) break;
+ }
+ }
+ if (max >= 0 && cnt >= max) break;
}
- }
+ tclistdel(keys);
} else {
- if(jstr){
- if(!tcbdbcurjump(cur, jstr, strlen(jstr)) && tcbdbecode(bdb) != TCENOREC){
- printerr(bdb);
- err = true;
+ BDBCUR *cur = tcbdbcurnew(bdb);
+ if (bk) {
+ if (jstr) {
+ if (!tcbdbcurjumpback(cur, jstr, strlen(jstr)) && tcbdbecode(bdb) != TCENOREC) {
+ printerr(bdb);
+ err = true;
+ }
+ } else {
+ if (!tcbdbcurlast(cur) && tcbdbecode(bdb) != TCENOREC) {
+ printerr(bdb);
+ err = true;
+ }
+ }
+ } else {
+ if (jstr) {
+ if (!tcbdbcurjump(cur, jstr, strlen(jstr)) && tcbdbecode(bdb) != TCENOREC) {
+ printerr(bdb);
+ err = true;
+ }
+ } else {
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ printerr(bdb);
+ err = true;
+ }
+ }
}
- } else {
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- printerr(bdb);
- err = true;
+ TCXSTR *key = tcxstrnew();
+ TCXSTR *val = tcxstrnew();
+ int cnt = 0;
+ while (tcbdbcurrec(cur, key, val)) {
+ printdata(tcxstrptr(key), tcxstrsize(key), px);
+ if (pv) {
+ putchar('\t');
+ printdata(tcxstrptr(val), tcxstrsize(val), px);
+ }
+ putchar('\n');
+ if (bk) {
+ if (!tcbdbcurprev(cur) && tcbdbecode(bdb) != TCENOREC) {
+ printerr(bdb);
+ err = true;
+ }
+ } else {
+ if (!tcbdbcurnext(cur) && tcbdbecode(bdb) != TCENOREC) {
+ printerr(bdb);
+ err = true;
+ }
+ }
+ if (max >= 0 && ++cnt >= max) break;
}
- }
+ tcxstrdel(val);
+ tcxstrdel(key);
+ tcbdbcurdel(cur);
}
- TCXSTR *key = tcxstrnew();
- TCXSTR *val = tcxstrnew();
- int cnt = 0;
- while(tcbdbcurrec(cur, key, val)){
- printdata(tcxstrptr(key), tcxstrsize(key), px);
- if(pv){
- putchar('\t');
- printdata(tcxstrptr(val), tcxstrsize(val), px);
- }
- putchar('\n');
- if(bk){
- if(!tcbdbcurprev(cur) && tcbdbecode(bdb) != TCENOREC){
- printerr(bdb);
- err = true;
- }
- } else {
- if(!tcbdbcurnext(cur) && tcbdbecode(bdb) != TCENOREC){
- printerr(bdb);
- err = true;
- }
- }
- if(max >= 0 && ++cnt >= max) break;
+ if (!tcbdbclose(bdb)) {
+ if (!err) printerr(bdb);
+ err = true;
}
- tcxstrdel(val);
- tcxstrdel(key);
- tcbdbcurdel(cur);
- }
- if(!tcbdbclose(bdb)){
- if(!err) printerr(bdb);
- err = true;
- }
- tcbdbdel(bdb);
- return err ? 1 : 0;
+ tcbdbdel(bdb);
+ return err ? 1 : 0;
}
-
/* perform optimize command */
static int procoptimize(const char *path, int lmemb, int nmemb,
- int bnum, int apow, int fpow, TCCMP cmp, int opts, int omode, bool df){
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
- if(!tcbdbopen(bdb, path, BDBOWRITER | omode)){
- printerr(bdb);
- tcbdbdel(bdb);
- return 1;
- }
- bool err = false;
- if(df){
- if(!tcbdbdefrag(bdb, INT64_MAX)){
- printerr(bdb);
- err = true;
+ int bnum, int apow, int fpow, TCCMP cmp, int opts, int omode, bool df) {
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) printerr(bdb);
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
+ if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) {
+ printerr(bdb);
+ tcbdbdel(bdb);
+ return 1;
}
- } else {
- if(!tcbdboptimize(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
- printerr(bdb);
- err = true;
+ bool err = false;
+ if (df) {
+ if (!tcbdbdefrag(bdb, INT64_MAX)) {
+ printerr(bdb);
+ err = true;
+ }
+ } else {
+ if (!tcbdboptimize(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) {
+ printerr(bdb);
+ err = true;
+ }
+ }
+ if (!tcbdbclose(bdb)) {
+ if (!err) printerr(bdb);
+ err = true;
}
- }
- if(!tcbdbclose(bdb)){
- if(!err) printerr(bdb);
- err = true;
- }
- tcbdbdel(bdb);
- return err ? 1 : 0;
+ tcbdbdel(bdb);
+ return err ? 1 : 0;
}
-
/* perform importtsv command */
-static int procimporttsv(const char *path, const char *file, int omode, bool sc){
- FILE *ifp = file ? fopen(file, "rb") : stdin;
- if(!ifp){
- fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
- return 1;
- }
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | omode)){
- printerr(bdb);
- tcbdbdel(bdb);
- if(ifp != stdin) fclose(ifp);
- return 1;
- }
- bool err = false;
- char *line;
- int cnt = 0;
- while(!err && (line = mygetline(ifp)) != NULL){
- char *pv = strchr(line, '\t');
- if(!pv){
- tcfree(line);
- continue;
+static int procimporttsv(const char *path, const char *file, int omode, bool sc) {
+ FILE *ifp = file ? fopen(file, "rb") : stdin;
+ if (!ifp) {
+ fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
+ return 1;
+ }
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(bdb);
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | omode)) {
+ printerr(bdb);
+ tcbdbdel(bdb);
+ if (ifp != stdin) fclose(ifp);
+ return 1;
}
- *pv = '\0';
- if(sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
- if(!tcbdbputdup2(bdb, line, pv + 1)){
- printerr(bdb);
- err = true;
+ bool err = false;
+ char *line;
+ int cnt = 0;
+ while (!err && (line = mygetline(ifp)) != NULL) {
+ char *pv = strchr(line, '\t');
+ if (!pv) {
+ tcfree(line);
+ continue;
+ }
+ *pv = '\0';
+ if (sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
+ if (!tcbdbputdup2(bdb, line, pv + 1)) {
+ printerr(bdb);
+ err = true;
+ }
+ tcfree(line);
+ if (cnt > 0 && cnt % 100 == 0) {
+ putchar('.');
+ fflush(stdout);
+ if (cnt % 5000 == 0) printf(" (%08d)\n", cnt);
+ }
+ cnt++;
}
- tcfree(line);
- if(cnt > 0 && cnt % 100 == 0){
- putchar('.');
- fflush(stdout);
- if(cnt % 5000 == 0) printf(" (%08d)\n", cnt);
+ printf(" (%08d)\n", cnt);
+ if (!tcbdbclose(bdb)) {
+ if (!err) printerr(bdb);
+ err = true;
}
- cnt++;
- }
- printf(" (%08d)\n", cnt);
- if(!tcbdbclose(bdb)){
- if(!err) printerr(bdb);
- err = true;
- }
- tcbdbdel(bdb);
- if(ifp != stdin) fclose(ifp);
- return err ? 1 : 0;
+ tcbdbdel(bdb);
+ if (ifp != stdin) fclose(ifp);
+ return err ? 1 : 0;
}
-
/* perform version command */
-static int procversion(void){
- printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
- tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
- printf("Copyright (C) 2006-2012 FAL Labs\n");
- return 0;
+static int procversion(void) {
+ printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
+ tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
+ printf("Copyright (C) 2006-2012 FAL Labs\n");
+ return 0;
}
#define RECBUFSIZ 48 // buffer for records
-typedef struct { // type of structure for write thread
- TCBDB *bdb;
- int rnum;
- bool rnd;
- int id;
+typedef struct { // type of structure for write thread
+ TCBDB *bdb;
+ int rnum;
+ bool rnd;
+ int id;
} TARGWRITE;
-typedef struct { // type of structure for read thread
- TCBDB *bdb;
- int rnum;
- bool wb;
- bool rnd;
- int id;
+typedef struct { // type of structure for read thread
+ TCBDB *bdb;
+ int rnum;
+ bool wb;
+ bool rnd;
+ int id;
} TARGREAD;
-typedef struct { // type of structure for remove thread
- TCBDB *bdb;
- int rnum;
- bool rnd;
- int id;
+typedef struct { // type of structure for remove thread
+ TCBDB *bdb;
+ int rnum;
+ bool rnd;
+ int id;
} TARGREMOVE;
-typedef struct { // type of structure for wicked thread
- TCBDB *bdb;
- int rnum;
- bool nc;
- int id;
- TCMAP *map;
+typedef struct { // type of structure for wicked thread
+ TCBDB *bdb;
+ int rnum;
+ bool nc;
+ int id;
+ TCMAP *map;
} TARGWICKED;
-typedef struct { // type of structure for typical thread
- TCBDB *bdb;
- int rnum;
- bool nc;
- int rratio;
- int id;
+typedef struct { // type of structure for typical thread
+ TCBDB *bdb;
+ int rnum;
+ bool nc;
+ int rratio;
+ int id;
} TARGTYPICAL;
-typedef struct { // type of structure for race thread
- TCBDB *bdb;
- int rnum;
- int id;
+typedef struct { // type of structure for race thread
+ TCBDB *bdb;
+ int rnum;
+ int id;
} TARGRACE;
/* global variables */
-const char *g_progname; // program name
-unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+unsigned int g_randseed; // random seed
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
static int runtypical(int argc, char **argv);
static int runrace(int argc, char **argv);
static int procwrite(const char *path, int tnum, int rnum, int lmemb, int nmemb,
- int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
- bool rnd);
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
+ bool rnd);
static int procread(const char *path, int tnum, int xmsiz, int dfunit, int omode,
- bool wb, bool rnd);
+ bool wb, bool rnd);
static int procremove(const char *path, int tnum, int xmsiz, int dfunit, int omode, bool rnd);
static int procwicked(const char *path, int tnum, int rnum, int opts, int omode, bool nc);
static int proctypical(const char *path, int tnum, int rnum, int lmemb, int nmemb,
- int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
- bool nc, int rratio);
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
+ bool nc, int rratio);
static int procrace(const char *path, int tnum, int rnum, int lmemb, int nmemb,
- int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode);
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode);
static void *threadwrite(void *targ);
static void *threadread(void *targ);
static void *threadremove(void *targ);
static void *threadtypical(void *targ);
static void *threadrace(void *targ);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- const char *ebuf = getenv("TCRNDSEED");
- g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
- srand(g_randseed);
- ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ const char *ebuf = getenv("TCRNDSEED");
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
+ srand(g_randseed);
+ ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "remove")){
- rv = runremove(argc, argv);
- } else if(!strcmp(argv[1], "wicked")){
- rv = runwicked(argc, argv);
- } else if(!strcmp(argv[1], "typical")){
- rv = runtypical(argc, argv);
- } else if(!strcmp(argv[1], "race")){
- rv = runrace(argc, argv);
- } else {
- usage();
- }
- if(rv != 0){
- printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
- for(int i = 0; i < argc; i++){
- printf(" %s", argv[i]);
- }
- printf("\n\n");
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "write")) {
+ rv = runwrite(argc, argv);
+ } else if (!strcmp(argv[1], "read")) {
+ rv = runread(argc, argv);
+ } else if (!strcmp(argv[1], "remove")) {
+ rv = runremove(argc, argv);
+ } else if (!strcmp(argv[1], "wicked")) {
+ rv = runwicked(argc, argv);
+ } else if (!strcmp(argv[1], "typical")) {
+ rv = runtypical(argc, argv);
+ } else if (!strcmp(argv[1], "race")) {
+ rv = runrace(argc, argv);
+ } else {
+ usage();
+ }
+ if (rv != 0) {
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int) getpid());
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\n\n");
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: test cases of the B+ tree database API of Tokyo Cabinet\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb] [-rnd]"
- " path tnum rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
- fprintf(stderr, " %s read [-xm num] [-df num] [-nl|-nb] [-wb] [-rnd] path tnum\n",
- g_progname);
- fprintf(stderr, " %s remove [-xm num] [-df num] [-nl|-nb] [-rnd] path tnum\n", g_progname);
- fprintf(stderr, " %s wicked [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] [-nc] path tnum rnum\n",
- g_progname);
- fprintf(stderr, " %s typical [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb]"
- " [-nc] [-rr num] path tnum rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
- fprintf(stderr, " %s race [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb]"
- " path tnum rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: test cases of the B+ tree database API of Tokyo Cabinet\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s write [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb] [-rnd]"
+ " path tnum rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
+ fprintf(stderr, " %s read [-xm num] [-df num] [-nl|-nb] [-wb] [-rnd] path tnum\n",
+ g_progname);
+ fprintf(stderr, " %s remove [-xm num] [-df num] [-nl|-nb] [-rnd] path tnum\n", g_progname);
+ fprintf(stderr, " %s wicked [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] [-nc] path tnum rnum\n",
+ g_progname);
+ fprintf(stderr, " %s typical [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb]"
+ " [-nc] [-rr num] path tnum rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
+ fprintf(stderr, " %s race [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb]"
+ " path tnum rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print formatted information string and flush the buffer */
-static void iprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- fflush(stdout);
- va_end(ap);
+static void iprintf(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ fflush(stdout);
+ va_end(ap);
}
-
/* print a character and flush the buffer */
-static void iputchar(int c){
- putchar(c);
- fflush(stdout);
+static void iputchar(int c) {
+ putchar(c);
+ fflush(stdout);
}
-
/* print error message of hash database */
-static void eprint(TCBDB *bdb, int line, const char *func){
- const char *path = tcbdbpath(bdb);
- int ecode = tcbdbecode(bdb);
- fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
- g_progname, path ? path : "-", line, func, ecode, tcbdberrmsg(ecode));
+static void eprint(TCBDB *bdb, int line, const char *func) {
+ const char *path = tcbdbpath(bdb);
+ int ecode = tcbdbecode(bdb);
+ fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
+ g_progname, path ? path : "-", line, func, ecode, tcbdberrmsg(ecode));
}
-
/* print members of hash database */
-static void mprint(TCBDB *bdb){
- if(bdb->hdb->cnt_writerec < 0) return;
- iprintf("max leaf member: %d\n", tcbdblmemb(bdb));
- iprintf("max node member: %d\n", tcbdbnmemb(bdb));
- iprintf("leaf number: %" PRIdMAX "\n", (int64_t)tcbdblnum(bdb));
- iprintf("node number: %" PRIdMAX "\n", (int64_t)tcbdbnnum(bdb));
- iprintf("bucket number: %" PRIdMAX "\n", (int64_t)tcbdbbnum(bdb));
- iprintf("used bucket number: %" PRIdMAX "\n", (int64_t)tcbdbbnumused(bdb));
- iprintf("cnt_saveleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_saveleaf);
- iprintf("cnt_loadleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_loadleaf);
- iprintf("cnt_killleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_killleaf);
- iprintf("cnt_adjleafc: %" PRIdMAX "\n", (int64_t)bdb->cnt_adjleafc);
- iprintf("cnt_savenode: %" PRIdMAX "\n", (int64_t)bdb->cnt_savenode);
- iprintf("cnt_loadnode: %" PRIdMAX "\n", (int64_t)bdb->cnt_loadnode);
- iprintf("cnt_adjnodec: %" PRIdMAX "\n", (int64_t)bdb->cnt_adjnodec);
- iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_writerec);
- iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_reuserec);
- iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_moverec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_readrec);
- iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_searchfbp);
- iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_insertfbp);
- iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_splicefbp);
- iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_dividefbp);
- iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_mergefbp);
- iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_reducefbp);
- iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_appenddrp);
- iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_deferdrp);
- iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_flushdrp);
- iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_adjrecc);
- iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_defrag);
- iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_shiftrec);
- iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_trunc);
+static void mprint(TCBDB *bdb) {
+ if (bdb->hdb->cnt_writerec < 0) return;
+ iprintf("max leaf member: %d\n", tcbdblmemb(bdb));
+ iprintf("max node member: %d\n", tcbdbnmemb(bdb));
+ iprintf("leaf number: %" PRIdMAX "\n", (int64_t) tcbdblnum(bdb));
+ iprintf("node number: %" PRIdMAX "\n", (int64_t) tcbdbnnum(bdb));
+ iprintf("bucket number: %" PRIdMAX "\n", (int64_t) tcbdbbnum(bdb));
+ iprintf("used bucket number: %" PRIdMAX "\n", (int64_t) tcbdbbnumused(bdb));
+ iprintf("cnt_saveleaf: %" PRIdMAX "\n", (int64_t) bdb->cnt_saveleaf);
+ iprintf("cnt_loadleaf: %" PRIdMAX "\n", (int64_t) bdb->cnt_loadleaf);
+ iprintf("cnt_killleaf: %" PRIdMAX "\n", (int64_t) bdb->cnt_killleaf);
+ iprintf("cnt_adjleafc: %" PRIdMAX "\n", (int64_t) bdb->cnt_adjleafc);
+ iprintf("cnt_savenode: %" PRIdMAX "\n", (int64_t) bdb->cnt_savenode);
+ iprintf("cnt_loadnode: %" PRIdMAX "\n", (int64_t) bdb->cnt_loadnode);
+ iprintf("cnt_adjnodec: %" PRIdMAX "\n", (int64_t) bdb->cnt_adjnodec);
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_writerec);
+ iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_reuserec);
+ iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_moverec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_readrec);
+ iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_searchfbp);
+ iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_insertfbp);
+ iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_splicefbp);
+ iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_dividefbp);
+ iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_mergefbp);
+ iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_reducefbp);
+ iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_appenddrp);
+ iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_deferdrp);
+ iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_flushdrp);
+ iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_adjrecc);
+ iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_defrag);
+ iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_shiftrec);
+ iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_trunc);
}
-
/* print system information */
-static void sysprint(void){
- TCMAP *info = tcsysinfo();
- if(info){
- tcmapiterinit(info);
- const char *kbuf;
- while((kbuf = tcmapiternext2(info)) != NULL){
- iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
- }
- tcmapdel(info);
- }
+static void sysprint(void) {
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ tcmapiterinit(info);
+ const char *kbuf;
+ while ((kbuf = tcmapiternext2(info)) != NULL) {
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+ }
+ tcmapdel(info);
+ }
}
-
/* get a random number */
-static int myrand(int range){
- if(range < 2) return 0;
- int high = (unsigned int)rand() >> 4;
- int low = range * (rand() / (RAND_MAX + 1.0));
- low &= (unsigned int)INT_MAX >> 4;
- return (high + low) % range;
+static int myrand(int range) {
+ if (range < 2) return 0;
+ int high = (unsigned int) rand() >> 4;
+ int low = range * (rand() / (RAND_MAX + 1.0));
+ low &= (unsigned int) INT_MAX >> 4;
+ return (high + low) % range;
}
-
/* get a random number based on normal distribution */
-static int myrandnd(int range){
- int num = (int)tcdrandnd(range >> 1, range / 10);
- return (num < 0 || num >= range) ? 0 : num;
+static int myrandnd(int range) {
+ int num = (int) tcdrandnd(range >> 1, range / 10);
+ return (num < 0 || num >= range) ? 0 : num;
}
-
/* iterator function */
-static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op){
- unsigned int sum = 0;
- while(--ksiz >= 0){
- sum += ((char *)kbuf)[ksiz];
- }
- while(--vsiz >= 0){
- sum += ((char *)vbuf)[vsiz];
- }
- return myrand(100 + (sum & 0xff)) > 0;
+static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op) {
+ unsigned int sum = 0;
+ while (--ksiz >= 0) {
+ sum += ((char *) kbuf)[ksiz];
+ }
+ while (--vsiz >= 0) {
+ sum += ((char *) vbuf)[vsiz];
+ }
+ return myrand(100 + (sum & 0xff)) > 0;
}
-
/* parse arguments of write command */
-static int runwrite(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *lmstr = NULL;
- char *nmstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!lmstr){
- lmstr = argv[i];
- } else if(!nmstr){
- nmstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int lmemb = lmstr ? tcatoix(lmstr) : -1;
- int nmemb = nmstr ? tcatoix(nmstr) : -1;
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procwrite(path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
- omode, rnd);
- return rv;
+static int runwrite(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *lmstr = NULL;
+ char *nmstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!lmstr) {
+ lmstr = argv[i];
+ } else if (!nmstr) {
+ nmstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procwrite(path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
+ omode, rnd);
+ return rv;
}
-
/* parse arguments of read command */
-static int runread(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool rnd = false;
- bool wb = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-wb")){
- wb = true;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procread(path, tnum, xmsiz, dfunit, omode, wb, rnd);
- return rv;
+static int runread(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool rnd = false;
+ bool wb = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-wb")) {
+ wb = true;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procread(path, tnum, xmsiz, dfunit, omode, wb, rnd);
+ return rv;
}
-
/* parse arguments of remove command */
-static int runremove(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procremove(path, tnum, xmsiz, dfunit, omode, rnd);
- return rv;
+static int runremove(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procremove(path, tnum, xmsiz, dfunit, omode, rnd);
+ return rv;
}
-
/* parse arguments of wicked command */
-static int runwicked(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- int opts = 0;
- int omode = 0;
- bool nc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-nc")){
- nc = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int rv = procwicked(path, tnum, rnum, opts, omode, nc);
- return rv;
+static int runwicked(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ int opts = 0;
+ int omode = 0;
+ bool nc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-nc")) {
+ nc = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int rv = procwicked(path, tnum, rnum, opts, omode, nc);
+ return rv;
}
-
/* parse arguments of typical command */
-static int runtypical(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *lmstr = NULL;
- char *nmstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- int rratio = -1;
- bool nc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-nc")){
- nc = true;
- } else if(!strcmp(argv[i], "-rr")){
- if(++i >= argc) usage();
- rratio = tcatoix(argv[i]);
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!lmstr){
- lmstr = argv[i];
- } else if(!nmstr){
- nmstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int lmemb = lmstr ? tcatoix(lmstr) : -1;
- int nmemb = nmstr ? tcatoix(nmstr) : -1;
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = proctypical(path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
- omode, nc, rratio);
- return rv;
+static int runtypical(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *lmstr = NULL;
+ char *nmstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ int rratio = -1;
+ bool nc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-nc")) {
+ nc = true;
+ } else if (!strcmp(argv[i], "-rr")) {
+ if (++i >= argc) usage();
+ rratio = tcatoix(argv[i]);
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!lmstr) {
+ lmstr = argv[i];
+ } else if (!nmstr) {
+ nmstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = proctypical(path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
+ omode, nc, rratio);
+ return rv;
}
-
/* parse arguments of race command */
-static int runrace(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *lmstr = NULL;
- char *nmstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!lmstr){
- lmstr = argv[i];
- } else if(!nmstr){
- nmstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int lmemb = lmstr ? tcatoix(lmstr) : -1;
- int nmemb = nmstr ? tcatoix(nmstr) : -1;
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procrace(path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
- omode);
- return rv;
+static int runrace(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *lmstr = NULL;
+ char *nmstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!lmstr) {
+ lmstr = argv[i];
+ } else if (!nmstr) {
+ nmstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procrace(path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
+ omode);
+ return rv;
}
-
/* perform write command */
static int procwrite(const char *path, int tnum, int rnum, int lmemb, int nmemb,
- int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
- bool rnd){
- iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d lmemb=%d nmemb=%d"
- " bnum=%d apow=%d fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d rnd=%d\n\n",
- g_randseed, path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
- omode, rnd);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(!tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
- eprint(bdb, __LINE__, "tcbdbtune");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- TARGWRITE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].bdb = bdb;
- targs[0].rnum = rnum;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadwrite(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].bdb = bdb;
- targs[i].rnum = rnum;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadwrite, targs + i) != 0){
- eprint(bdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
+ bool rnd) {
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d lmemb=%d nmemb=%d"
+ " bnum=%d apow=%d fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d rnd=%d\n\n",
+ g_randseed, path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
+ omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (!tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
+ err = true;
+ }
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
+ err = true;
+ }
+ if (!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) {
+ eprint(bdb, __LINE__, "tcbdbtune");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(bdb, __LINE__, "pthread_join");
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
err = true;
- } else if(rv){
+ }
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ TARGWRITE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].bdb = bdb;
+ targs[0].rnum = rnum;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadwrite(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].bdb = bdb;
+ targs[i].rnum = rnum;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadwrite, targs + i) != 0) {
+ eprint(bdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(bdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform read command */
static int procread(const char *path, int tnum, int xmsiz, int dfunit, int omode,
- bool wb, bool rnd){
- iprintf("<Reading Test>\n seed=%u path=%s tnum=%d xmsiz=%d dfunit=%d omode=%d"
- " wb=%d rnd=%d\n\n", g_randseed, path, tnum, xmsiz, dfunit, omode, wb, rnd);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(!tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOREADER | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- int rnum = tcbdbrnum(bdb) / tnum;
- TARGREAD targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].bdb = bdb;
- targs[0].rnum = rnum;
- targs[0].wb = wb;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadread(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].bdb = bdb;
- targs[i].rnum = rnum;
- targs[i].wb = wb;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadread, targs + i) != 0){
- eprint(bdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ bool wb, bool rnd) {
+ iprintf("<Reading Test>\n seed=%u path=%s tnum=%d xmsiz=%d dfunit=%d omode=%d"
+ " wb=%d rnd=%d\n\n", g_randseed, path, tnum, xmsiz, dfunit, omode, wb, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (!tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(bdb, __LINE__, "pthread_join");
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
err = true;
- } else if(rv){
+ }
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOREADER | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ int rnum = tcbdbrnum(bdb) / tnum;
+ TARGREAD targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].bdb = bdb;
+ targs[0].rnum = rnum;
+ targs[0].wb = wb;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadread(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].bdb = bdb;
+ targs[i].rnum = rnum;
+ targs[i].wb = wb;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadread, targs + i) != 0) {
+ eprint(bdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(bdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform remove command */
-static int procremove(const char *path, int tnum, int xmsiz, int dfunit, int omode, bool rnd){
- iprintf("<Removing Test>\n seed=%u path=%s tnum=%d xmsiz=%d dfunit=%d omode=%d"
- " rnd=%d\n\n", g_randseed, path, tnum, xmsiz, dfunit, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(!tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- int rnum = tcbdbrnum(bdb) / tnum;
- TARGREMOVE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].bdb = bdb;
- targs[0].rnum = rnum;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadremove(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].bdb = bdb;
- targs[i].rnum = rnum;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){
- eprint(bdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+static int procremove(const char *path, int tnum, int xmsiz, int dfunit, int omode, bool rnd) {
+ iprintf("<Removing Test>\n seed=%u path=%s tnum=%d xmsiz=%d dfunit=%d omode=%d"
+ " rnd=%d\n\n", g_randseed, path, tnum, xmsiz, dfunit, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (!tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
+ err = true;
+ }
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(bdb, __LINE__, "pthread_join");
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
err = true;
- } else if(rv){
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ int rnum = tcbdbrnum(bdb) / tnum;
+ TARGREMOVE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].bdb = bdb;
+ targs[0].rnum = rnum;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadremove(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].bdb = bdb;
+ targs[i].rnum = rnum;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadremove, targs + i) != 0) {
+ eprint(bdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(bdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform wicked command */
-static int procwicked(const char *path, int tnum, int rnum, int opts, int omode, bool nc){
- iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d opts=%d omode=%d nc=%d\n\n",
- g_randseed, path, tnum, rnum, opts, omode, nc);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(!tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbtune(bdb, 10, 10, rnum / 50, 10, -1, opts)){
- eprint(bdb, __LINE__, "tcbdbtune");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- TARGWICKED targs[tnum];
- pthread_t threads[tnum];
- TCMAP *map = tcmapnew();
- if(tnum == 1){
- targs[0].bdb = bdb;
- targs[0].rnum = rnum;
- targs[0].nc = nc;
- targs[0].id = 0;
- targs[0].map = map;
- if(threadwicked(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].bdb = bdb;
- targs[i].rnum = rnum;
- targs[i].nc = nc;
- targs[i].id = i;
- targs[i].map = map;
- if(pthread_create(threads + i, NULL, threadwicked, targs + i) != 0){
- eprint(bdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+static int procwicked(const char *path, int tnum, int rnum, int opts, int omode, bool nc) {
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d opts=%d omode=%d nc=%d\n\n",
+ g_randseed, path, tnum, rnum, opts, omode, nc);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (!tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(bdb, __LINE__, "pthread_join");
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
err = true;
- } else if(rv){
+ }
+ if (!tcbdbtune(bdb, 10, 10, rnum / 50, 10, -1, opts)) {
+ eprint(bdb, __LINE__, "tcbdbtune");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
err = true;
- }
- }
- }
- if(!nc){
- if(!tcbdbsync(bdb)){
- eprint(bdb, __LINE__, "tcbdbsync");
- err = true;
- }
- if(tcbdbrnum(bdb) != tcmaprnum(map)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- int end = rnum * tnum;
- for(int i = 1; i <= end && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", i - 1);
- int vsiz;
- const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
- int rsiz;
- char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
- if(vbuf){
- iputchar('.');
- if(!rbuf){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
+ }
+ TARGWICKED targs[tnum];
+ pthread_t threads[tnum];
+ TCMAP *map = tcmapnew();
+ if (tnum == 1) {
+ targs[0].bdb = bdb;
+ targs[0].rnum = rnum;
+ targs[0].nc = nc;
+ targs[0].id = 0;
+ targs[0].map = map;
+ if (threadwicked(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].bdb = bdb;
+ targs[i].rnum = rnum;
+ targs[i].nc = nc;
+ targs[i].id = i;
+ targs[i].map = map;
+ if (pthread_create(threads + i, NULL, threadwicked, targs + i) != 0) {
+ eprint(bdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(bdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ if (!nc) {
+ if (!tcbdbsync(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsync");
+ err = true;
}
- } else {
- iputchar('*');
- if(rbuf || tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
+ if (tcbdbrnum(bdb) != tcmaprnum(map)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
}
- }
- tcfree(rbuf);
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- }
- if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
- }
- tcmapdel(map);
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ int end = rnum * tnum;
+ for (int i = 1; i <= end && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", i - 1);
+ int vsiz;
+ const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
+ int rsiz;
+ char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
+ if (vbuf) {
+ iputchar('.');
+ if (!rbuf) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ } else {
+ iputchar('*');
+ if (rbuf || tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ tcfree(rbuf);
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ }
+ if (rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
+ }
+ tcmapdel(map);
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform typical command */
static int proctypical(const char *path, int tnum, int rnum, int lmemb, int nmemb,
- int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
- bool nc, int rratio){
- iprintf("<Typical Access Test>\n seed=%u path=%s tnum=%d rnum=%d lmemb=%d nmemb=%d"
- " bnum=%d apow=%d fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d"
- " nc=%d rratio=%d\n\n",
- g_randseed, path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
- omode, nc, rratio);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(!tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
- eprint(bdb, __LINE__, "tcbdbtune");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- TARGTYPICAL targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].bdb = bdb;
- targs[0].rnum = rnum;
- targs[0].nc = nc;
- targs[0].rratio = rratio;
- targs[0].id = 0;
- if(threadtypical(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].bdb = bdb;
- targs[i].rnum = rnum;
- targs[i].nc = nc;
- targs[i].rratio = rratio;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){
- eprint(bdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
+ bool nc, int rratio) {
+ iprintf("<Typical Access Test>\n seed=%u path=%s tnum=%d rnum=%d lmemb=%d nmemb=%d"
+ " bnum=%d apow=%d fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d"
+ " nc=%d rratio=%d\n\n",
+ g_randseed, path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
+ omode, nc, rratio);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (!tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(bdb, __LINE__, "pthread_join");
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
err = true;
- } else if(rv){
+ }
+ if (!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) {
+ eprint(bdb, __LINE__, "tcbdbtune");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ TARGTYPICAL targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].bdb = bdb;
+ targs[0].rnum = rnum;
+ targs[0].nc = nc;
+ targs[0].rratio = rratio;
+ targs[0].id = 0;
+ if (threadtypical(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].bdb = bdb;
+ targs[i].rnum = rnum;
+ targs[i].nc = nc;
+ targs[i].rratio = rratio;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadtypical, targs + i) != 0) {
+ eprint(bdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(bdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform race command */
static int procrace(const char *path, int tnum, int rnum, int lmemb, int nmemb,
- int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode){
- iprintf("<Race Condition Test>\n seed=%u path=%s tnum=%d rnum=%d lmemb=%d nmemb=%d"
- " bnum=%d apow=%d fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d\n\n",
- g_randseed, path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts,
- xmsiz, dfunit, omode);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(!tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
- eprint(bdb, __LINE__, "tcbdbtune");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- TARGRACE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].bdb = bdb;
- targs[0].rnum = rnum;
- targs[0].id = 0;
- if(threadrace(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].bdb = bdb;
- targs[i].rnum = rnum;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadrace, targs + i) != 0){
- eprint(bdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode) {
+ iprintf("<Race Condition Test>\n seed=%u path=%s tnum=%d rnum=%d lmemb=%d nmemb=%d"
+ " bnum=%d apow=%d fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d\n\n",
+ g_randseed, path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts,
+ xmsiz, dfunit, omode);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (!tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(bdb, __LINE__, "pthread_join");
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
err = true;
- } else if(rv){
+ }
+ if (!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) {
+ eprint(bdb, __LINE__, "tcbdbtune");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
-}
-
-
-/* thread the write function */
-static void *threadwrite(void *targ){
- TCBDB *bdb = ((TARGWRITE *)targ)->bdb;
- int rnum = ((TARGWRITE *)targ)->rnum;
- bool rnd = ((TARGWRITE *)targ)->rnd;
- int id = ((TARGWRITE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) : i));
- if(!tcbdbput(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- break;
- }
- 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;
-}
-
-
-/* thread the read function */
-static void *threadread(void *targ){
- TCBDB *bdb = ((TARGREAD *)targ)->bdb;
- int rnum = ((TARGREAD *)targ)->rnum;
- bool wb = ((TARGREAD *)targ)->wb;
- bool rnd = ((TARGREAD *)targ)->rnd;
- 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 + (rnd ? myrandnd(i) : i));
- int vsiz;
- if(wb){
- int vsiz;
- const char *vbuf = tcbdbget3(bdb, kbuf, ksiz, &vsiz);
- if(!vbuf && (!rnd || tcbdbecode(bdb) != TCENOREC)){
- eprint(bdb, __LINE__, "tcbdbget3");
+ }
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
err = true;
- }
- } else {
- char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
- if(!vbuf && (!rnd || tcbdbecode(bdb) != TCENOREC)){
- eprint(bdb, __LINE__, "tcbdbget");
+ }
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
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);
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
}
- }
- return err ? "error" : NULL;
-}
-
-
-/* thread the remove function */
-static void *threadremove(void *targ){
- TCBDB *bdb = ((TARGREMOVE *)targ)->bdb;
- int rnum = ((TARGREMOVE *)targ)->rnum;
- bool rnd = ((TARGREMOVE *)targ)->rnd;
- int id = ((TARGREMOVE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i + 1) : i));
- if(!tcbdbout(bdb, kbuf, ksiz) && (!rnd || tcbdbecode(bdb) != TCENOREC)){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- break;
- }
- 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;
-}
-
-
-/* thread the wicked function */
-static void *threadwicked(void *targ){
- TCBDB *bdb = ((TARGWICKED *)targ)->bdb;
- int rnum = ((TARGWICKED *)targ)->rnum;
- bool nc = ((TARGWICKED *)targ)->nc;
- int id = ((TARGWICKED *)targ)->id;
- TCMAP *map = ((TARGWICKED *)targ)->map;
- BDBCUR *cur = tcbdbcurnew(bdb);
- bool err = false;
- for(int i = 1; i <= rnum && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum * (id + 1)));
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '*', vsiz);
- vbuf[vsiz] = '\0';
- char *rbuf;
- if(!nc) tcglobalmutexlock();
- switch(myrand(16)){
- case 0:
- if(id == 0) iputchar('0');
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- if(id == 0) iputchar('1');
- if(!tcbdbput2(bdb, kbuf, vbuf)){
- eprint(bdb, __LINE__, "tcbdbput2");
- err = true;
- }
- if(!nc) tcmapput2(map, kbuf, vbuf);
- break;
- case 2:
- if(id == 0) iputchar('2');
- if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
- }
- if(!nc) tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- if(id == 0) iputchar('3');
- if(!tcbdbputkeep2(bdb, kbuf, vbuf) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep2");
- err = true;
- }
- if(!nc) tcmapputkeep2(map, kbuf, vbuf);
- break;
- case 4:
- if(id == 0) iputchar('4');
- if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
+ TARGRACE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].bdb = bdb;
+ targs[0].rnum = rnum;
+ targs[0].id = 0;
+ if (threadrace(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].bdb = bdb;
+ targs[i].rnum = rnum;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadrace, targs + i) != 0) {
+ eprint(bdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
}
- if(!nc) tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 5:
- if(id == 0) iputchar('5');
- if(!tcbdbputcat2(bdb, kbuf, vbuf)){
- eprint(bdb, __LINE__, "tcbdbputcat2");
- err = true;
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(bdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
}
- if(!nc) tcmapputcat2(map, kbuf, vbuf);
- break;
- case 6:
- if(id == 0) iputchar('6');
- if(nc){
- if(!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputdup");
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
+}
+
+/* thread the write function */
+static void *threadwrite(void *targ) {
+ TCBDB *bdb = ((TARGWRITE *) targ)->bdb;
+ int rnum = ((TARGWRITE *) targ)->rnum;
+ bool rnd = ((TARGWRITE *) targ)->rnd;
+ int id = ((TARGWRITE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) : i));
+ if (!tcbdbput(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbput");
err = true;
- }
+ break;
}
- break;
- case 7:
- if(id == 0) iputchar('7');
- if(nc){
- if(!tcbdbputdup2(bdb, kbuf, vbuf)){
- eprint(bdb, __LINE__, "tcbdbputdup2");
- err = true;
- }
+ if (id <= 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- break;
- case 8:
- if(id == 0) iputchar('8');
- if(myrand(2) == 0){
- if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- }
- if(!nc) tcmapout(map, kbuf, ksiz);
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the read function */
+static void *threadread(void *targ) {
+ TCBDB *bdb = ((TARGREAD *) targ)->bdb;
+ int rnum = ((TARGREAD *) targ)->rnum;
+ bool wb = ((TARGREAD *) targ)->wb;
+ bool rnd = ((TARGREAD *) targ)->rnd;
+ 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 + (rnd ? myrandnd(i) : i));
+ int vsiz;
+ if (wb) {
+ int vsiz;
+ const char *vbuf = tcbdbget3(bdb, kbuf, ksiz, &vsiz);
+ if (!vbuf && (!rnd || tcbdbecode(bdb) != TCENOREC)) {
+ eprint(bdb, __LINE__, "tcbdbget3");
+ err = true;
+ }
+ } else {
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
+ if (!vbuf && (!rnd || tcbdbecode(bdb) != TCENOREC)) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ }
+ tcfree(vbuf);
}
- break;
- case 9:
- if(id == 0) iputchar('9');
- if(myrand(2) == 0){
- if(!tcbdbout2(bdb, kbuf) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout2");
- err = true;
- }
- if(!nc) tcmapout2(map, kbuf);
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- break;
- case 10:
- if(id == 0) iputchar('A');
- if(!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz))){
- if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbget");
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the remove function */
+static void *threadremove(void *targ) {
+ TCBDB *bdb = ((TARGREMOVE *) targ)->bdb;
+ int rnum = ((TARGREMOVE *) targ)->rnum;
+ bool rnd = ((TARGREMOVE *) targ)->rnd;
+ int id = ((TARGREMOVE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i + 1) : i));
+ if (!tcbdbout(bdb, kbuf, ksiz) && (!rnd || tcbdbecode(bdb) != TCENOREC)) {
+ eprint(bdb, __LINE__, "tcbdbout");
err = true;
- }
- rbuf = tcsprintf("[%d]", myrand(i + 1));
- vsiz = strlen(rbuf);
- }
- vsiz += myrand(vsiz);
- if(myrand(3) == 0) vsiz += PATH_MAX;
- rbuf = tcrealloc(rbuf, vsiz + 1);
- for(int j = 0; j < vsiz; j++){
- rbuf[j] = myrand(0x100);
+ break;
}
- if(!tcbdbput(bdb, kbuf, ksiz, rbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- if(!nc) tcmapput(map, kbuf, ksiz, rbuf, vsiz);
- tcfree(rbuf);
- break;
- case 11:
- if(id == 0) iputchar('B');
- if(!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz)) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- }
- tcfree(rbuf);
- break;
- case 12:
- if(id == 0) iputchar('C');
- if(!(rbuf = tcbdbget2(bdb, kbuf)) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbget2");
- err = true;
- }
- tcfree(rbuf);
- break;
- case 13:
- if(id == 0) iputchar('D');
- if(!tcbdbget3(bdb, kbuf, ksiz, &vsiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbget3");
- err = true;
- }
- break;
- case 14:
- if(id == 0) iputchar('E');
- if(myrand(rnum / 50) == 0){
- switch(myrand(5)){
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the wicked function */
+static void *threadwicked(void *targ) {
+ TCBDB *bdb = ((TARGWICKED *) targ)->bdb;
+ int rnum = ((TARGWICKED *) targ)->rnum;
+ bool nc = ((TARGWICKED *) targ)->nc;
+ int id = ((TARGWICKED *) targ)->id;
+ TCMAP *map = ((TARGWICKED *) targ)->map;
+ BDBCUR *cur = tcbdbcurnew(bdb);
+ bool err = false;
+ for (int i = 1; i <= rnum && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum * (id + 1)));
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '*', vsiz);
+ vbuf[vsiz] = '\0';
+ char *rbuf;
+ if (!nc) tcglobalmutexlock();
+ switch (myrand(16)) {
case 0:
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- break;
+ if (id == 0) iputchar('0');
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
case 1:
- if(!tcbdbcurlast(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurlast");
- err = true;
- }
- break;
+ if (id == 0) iputchar('1');
+ if (!tcbdbput2(bdb, kbuf, vbuf)) {
+ eprint(bdb, __LINE__, "tcbdbput2");
+ err = true;
+ }
+ if (!nc) tcmapput2(map, kbuf, vbuf);
+ break;
+ case 2:
+ if (id == 0) iputchar('2');
+ if (!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ }
+ if (!nc) tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ if (id == 0) iputchar('3');
+ if (!tcbdbputkeep2(bdb, kbuf, vbuf) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep2");
+ err = true;
+ }
+ if (!nc) tcmapputkeep2(map, kbuf, vbuf);
+ break;
+ case 4:
+ if (id == 0) iputchar('4');
+ if (!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ if (!nc) tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 5:
+ if (id == 0) iputchar('5');
+ if (!tcbdbputcat2(bdb, kbuf, vbuf)) {
+ eprint(bdb, __LINE__, "tcbdbputcat2");
+ err = true;
+ }
+ if (!nc) tcmapputcat2(map, kbuf, vbuf);
+ break;
+ case 6:
+ if (id == 0) iputchar('6');
+ if (nc) {
+ if (!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputdup");
+ err = true;
+ }
+ }
+ break;
+ case 7:
+ if (id == 0) iputchar('7');
+ if (nc) {
+ if (!tcbdbputdup2(bdb, kbuf, vbuf)) {
+ eprint(bdb, __LINE__, "tcbdbputdup2");
+ err = true;
+ }
+ }
+ break;
+ case 8:
+ if (id == 0) iputchar('8');
+ if (myrand(2) == 0) {
+ if (!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ if (!nc) tcmapout(map, kbuf, ksiz);
+ }
+ break;
+ case 9:
+ if (id == 0) iputchar('9');
+ if (myrand(2) == 0) {
+ if (!tcbdbout2(bdb, kbuf) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout2");
+ err = true;
+ }
+ if (!nc) tcmapout2(map, kbuf);
+ }
+ break;
+ case 10:
+ if (id == 0) iputchar('A');
+ if (!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz))) {
+ if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ }
+ rbuf = tcsprintf("[%d]", myrand(i + 1));
+ vsiz = strlen(rbuf);
+ }
+ vsiz += myrand(vsiz);
+ if (myrand(3) == 0) vsiz += PATH_MAX;
+ rbuf = tcrealloc(rbuf, vsiz + 1);
+ for (int j = 0; j < vsiz; j++) {
+ rbuf[j] = myrand(0x100);
+ }
+ if (!tcbdbput(bdb, kbuf, ksiz, rbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, rbuf, vsiz);
+ tcfree(rbuf);
+ break;
+ case 11:
+ if (id == 0) iputchar('B');
+ if (!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz)) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 12:
+ if (id == 0) iputchar('C');
+ if (!(rbuf = tcbdbget2(bdb, kbuf)) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget2");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 13:
+ if (id == 0) iputchar('D');
+ if (!tcbdbget3(bdb, kbuf, ksiz, &vsiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget3");
+ err = true;
+ }
+ break;
+ case 14:
+ if (id == 0) iputchar('E');
+ if (myrand(rnum / 50) == 0) {
+ switch (myrand(5)) {
+ case 0:
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcbdbcurlast(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurlast");
+ err = true;
+ }
+ break;
+ default:
+ if (!tcbdbcurjump(cur, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurjump");
+ err = true;
+ }
+ break;
+ }
+ }
+ TCXSTR *ikey = tcxstrnew();
+ TCXSTR *ival = tcxstrnew();
+ for (int j = myrand(rnum) / 1000 + 1; j >= 0; j--) {
+ if (j % 3 == 0) {
+ if (!tcbdbcurrec(cur, ikey, ival)) {
+ int ecode = tcbdbecode(bdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurrec");
+ err = true;
+ }
+ }
+ } else {
+ int iksiz;
+ if (!tcbdbcurkey3(cur, &iksiz)) {
+ int ecode = tcbdbecode(bdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurkey3");
+ err = true;
+ }
+ }
+ }
+ if (myrand(5) == 0) {
+ if (!tcbdbcurprev(cur)) {
+ int ecode = tcbdbecode(bdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurprev");
+ err = true;
+ }
+ }
+ } else {
+ if (!tcbdbcurnext(cur)) {
+ int ecode = tcbdbecode(bdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurnext");
+ err = true;
+ }
+ }
+ }
+ }
+ tcxstrdel(ival);
+ tcxstrdel(ikey);
+ break;
default:
- if(!tcbdbcurjump(cur, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurjump");
- err = true;
- }
- break;
- }
+ if (id == 0) iputchar('@');
+ if (tcbdbtranbegin(bdb)) {
+ if (myrand(2) == 0) {
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ } else {
+ if (!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ if (!nc) tcmapout(map, kbuf, ksiz);
+ }
+ if (nc && myrand(2) == 0) {
+ if (!tcbdbtranabort(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbtranabort");
+ err = true;
+ }
+ } else {
+ if (!tcbdbtrancommit(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbtrancommit");
+ err = true;
+ }
+ }
+ } else {
+ eprint(bdb, __LINE__, "tcbdbtranbegin");
+ err = true;
+ }
+ if (myrand(1000) == 0) {
+ if (!tcbdbforeach(bdb, iterfunc, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbforeach");
+ err = true;
+ }
+ }
+ if (myrand(10000) == 0) srand((unsigned int) (tctime() * 1000) % UINT_MAX);
+ break;
}
- TCXSTR *ikey = tcxstrnew();
- TCXSTR *ival = tcxstrnew();
- for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
- if(j % 3 == 0){
- if(!tcbdbcurrec(cur, ikey, ival)){
- int ecode = tcbdbecode(bdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurrec");
- err = true;
- }
+ if (!nc) tcglobalmutexunlock();
+ if (id == 0) {
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ if (id == 0 && i == rnum / 4) {
+ if (!tcbdboptimize(bdb, -1, -1, -1, -1, -1, -1) && tcbdbecode(bdb) != TCEINVALID) {
+ eprint(bdb, __LINE__, "tcbdboptimize");
+ err = true;
+ }
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
}
- } else {
- int iksiz;
- if(!tcbdbcurkey3(cur, &iksiz)){
- int ecode = tcbdbecode(bdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurkey3");
+ }
+ }
+ tcbdbcurdel(cur);
+ return err ? "error" : NULL;
+}
+
+/* thread the typical function */
+static void *threadtypical(void *targ) {
+ TCBDB *bdb = ((TARGTYPICAL *) targ)->bdb;
+ int rnum = ((TARGTYPICAL *) targ)->rnum;
+ bool nc = ((TARGTYPICAL *) targ)->nc;
+ int rratio = ((TARGTYPICAL *) targ)->rratio;
+ int id = ((TARGTYPICAL *) targ)->id;
+ bool err = false;
+ TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL;
+ int base = id * rnum;
+ int mrange = tclmax(50 + rratio, 100);
+ BDBCUR *cur = tcbdbcurnew(bdb);
+ for (int i = 1; !err && i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", base + myrandnd(i));
+ int rnd = myrand(mrange);
+ if (rnd < 10) {
+ if (!tcbdbput(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbput");
err = true;
- }
}
- }
- if(myrand(5) == 0){
- if(!tcbdbcurprev(cur)){
- int ecode = tcbdbecode(bdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurprev");
+ if (map) tcmapput(map, buf, len, buf, len);
+ } else if (rnd < 15) {
+ if (!tcbdbputkeep(bdb, buf, len, buf, len) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
err = true;
- }
}
- } else {
- if(!tcbdbcurnext(cur)){
- int ecode = tcbdbecode(bdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurnext");
+ if (map) tcmapputkeep(map, buf, len, buf, len);
+ } else if (rnd < 20) {
+ if (!tcbdbputcat(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
err = true;
- }
- }
- }
- }
- tcxstrdel(ival);
- tcxstrdel(ikey);
- break;
- default:
- if(id == 0) iputchar('@');
- if(tcbdbtranbegin(bdb)){
- if(myrand(2) == 0){
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- } else {
- if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
}
- if(!nc) tcmapout(map, kbuf, ksiz);
- }
- if(nc && myrand(2) == 0){
- if(!tcbdbtranabort(bdb)){
- eprint(bdb, __LINE__, "tcbdbtranabort");
- err = true;
+ if (map) tcmapputcat(map, buf, len, buf, len);
+ } else if (rnd < 25) {
+ if (!tcbdbout(bdb, buf, len) && tcbdbecode(bdb) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
}
- } else {
- if(!tcbdbtrancommit(bdb)){
- eprint(bdb, __LINE__, "tcbdbtrancommit");
- err = true;
+ if (map) tcmapout(map, buf, len);
+ } else if (rnd < 27) {
+ switch (myrand(3)) {
+ case 0:
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ for (int j = 0; !err && j < 10; j++) {
+ int ksiz;
+ char *kbuf = tcbdbcurkey(cur, &ksiz);
+ if (kbuf) {
+ int vsiz;
+ char *vbuf = tcbdbcurval(cur, &vsiz);
+ if (vbuf) {
+ tcfree(vbuf);
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurval");
+ err = true;
+ }
+ tcfree(kbuf);
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurkey");
+ err = true;
+ }
+ tcbdbcurnext(cur);
+ }
+ break;
+ case 1:
+ if (!tcbdbcurlast(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurlast");
+ err = true;
+ }
+ for (int j = 0; !err && j < 10; j++) {
+ int ksiz;
+ char *kbuf = tcbdbcurkey(cur, &ksiz);
+ if (kbuf) {
+ int vsiz;
+ char *vbuf = tcbdbcurval(cur, &vsiz);
+ if (vbuf) {
+ tcfree(vbuf);
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurval");
+ err = true;
+ }
+ tcfree(kbuf);
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurkey");
+ err = true;
+ }
+ tcbdbcurprev(cur);
+ }
+ break;
+ case 2:
+ if (!tcbdbcurjump(cur, buf, len) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurjump");
+ err = true;
+ }
+ for (int j = 0; !err && j < 10; j++) {
+ int ksiz;
+ char *kbuf = tcbdbcurkey(cur, &ksiz);
+ if (kbuf) {
+ int vsiz;
+ char *vbuf = tcbdbcurval(cur, &vsiz);
+ if (vbuf) {
+ tcfree(vbuf);
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurval");
+ err = true;
+ }
+ tcfree(kbuf);
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurkey");
+ err = true;
+ }
+ tcbdbcurnext(cur);
+ }
+ break;
}
- }
} else {
- eprint(bdb, __LINE__, "tcbdbtranbegin");
- err = true;
- }
- if(myrand(1000) == 0){
- if(!tcbdbforeach(bdb, iterfunc, NULL)){
- eprint(bdb, __LINE__, "tcbdbforeach");
- err = true;
- }
+ int vsiz;
+ char *vbuf = tcbdbget(bdb, buf, len, &vsiz);
+ if (vbuf) {
+ if (map) {
+ int msiz;
+ const char *mbuf = tcmapget(map, buf, len, &msiz);
+ if (!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ tcfree(vbuf);
+ } else {
+ if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ }
+ if (map && tcmapget(map, buf, len, &vsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
}
- if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
- break;
- }
- if(!nc) tcglobalmutexunlock();
- if(id == 0){
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- if(id == 0 && i == rnum / 4){
- if(!tcbdboptimize(bdb, -1, -1, -1, -1, -1, -1) && tcbdbecode(bdb) != TCEINVALID){
- eprint(bdb, __LINE__, "tcbdboptimize");
- err = true;
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
+ }
+ tcbdbcurdel(cur);
+ if (map) {
+ tcmapiterinit(map);
+ int ksiz;
+ const char *kbuf;
+ while (!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL) {
+ int vsiz;
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ int msiz;
+ const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz);
+ if (!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ tcfree(vbuf);
+ } else {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
}
- }
+ tcmapdel(map);
}
- }
- tcbdbcurdel(cur);
- return err ? "error" : NULL;
+ return err ? "error" : NULL;
}
-
-/* thread the typical function */
-static void *threadtypical(void *targ){
- TCBDB *bdb = ((TARGTYPICAL *)targ)->bdb;
- int rnum = ((TARGTYPICAL *)targ)->rnum;
- bool nc = ((TARGTYPICAL *)targ)->nc;
- int rratio = ((TARGTYPICAL *)targ)->rratio;
- int id = ((TARGTYPICAL *)targ)->id;
- bool err = false;
- TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL;
- int base = id * rnum;
- int mrange = tclmax(50 + rratio, 100);
- BDBCUR *cur = tcbdbcurnew(bdb);
- for(int i = 1; !err && i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", base + myrandnd(i));
- int rnd = myrand(mrange);
- if(rnd < 10){
- if(!tcbdbput(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- if(map) tcmapput(map, buf, len, buf, len);
- } else if(rnd < 15){
- if(!tcbdbputkeep(bdb, buf, len, buf, len) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
- }
- if(map) tcmapputkeep(map, buf, len, buf, len);
- } else if(rnd < 20){
- if(!tcbdbputcat(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
- }
- if(map) tcmapputcat(map, buf, len, buf, len);
- } else if(rnd < 25){
- if(!tcbdbout(bdb, buf, len) && tcbdbecode(bdb) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- }
- if(map) tcmapout(map, buf, len);
- } else if(rnd < 27){
- switch(myrand(3)){
- case 0:
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- for(int j = 0; !err && j < 10; j++){
- int ksiz;
- char *kbuf = tcbdbcurkey(cur, &ksiz);
- if(kbuf){
- int vsiz;
- char *vbuf = tcbdbcurval(cur, &vsiz);
- if(vbuf){
- tcfree(vbuf);
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurval");
+/* thread the race function */
+static void *threadrace(void *targ) {
+ TCBDB *bdb = ((TARGRACE *) targ)->bdb;
+ int rnum = ((TARGRACE *) targ)->rnum;
+ int id = ((TARGRACE *) targ)->id;
+ bool err = false;
+ int mid = rnum * 2;
+ for (int i = 1; !err && i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%d", myrandnd(i));
+ int rnd = myrand(100);
+ if (rnd < 10) {
+ if (!tcbdbputkeep(bdb, buf, len, buf, len) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
err = true;
- }
- tcfree(kbuf);
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurkey");
- err = true;
}
- tcbdbcurnext(cur);
- }
- break;
- case 1:
- if(!tcbdbcurlast(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurlast");
- err = true;
- }
- for(int j = 0; !err && j < 10; j++){
- int ksiz;
- char *kbuf = tcbdbcurkey(cur, &ksiz);
- if(kbuf){
- int vsiz;
- char *vbuf = tcbdbcurval(cur, &vsiz);
- if(vbuf){
- tcfree(vbuf);
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurval");
+ } else if (rnd < 20) {
+ if (!tcbdbputcat(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
err = true;
- }
- tcfree(kbuf);
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurkey");
- err = true;
}
- tcbdbcurprev(cur);
- }
- break;
- case 2:
- if(!tcbdbcurjump(cur, buf, len) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurjump");
- err = true;
- }
- for(int j = 0; !err && j < 10; j++){
- int ksiz;
- char *kbuf = tcbdbcurkey(cur, &ksiz);
- if(kbuf){
- int vsiz;
- char *vbuf = tcbdbcurval(cur, &vsiz);
- if(vbuf){
- tcfree(vbuf);
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurval");
+ } else if (rnd < 30) {
+ if (!tcbdbputdup(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbputdup");
+ err = true;
+ }
+ } else if (rnd < 40) {
+ if (!tcbdbputdupback(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbputdupback");
+ err = true;
+ }
+ } else if (rnd < 50) {
+ if (!tcbdbout(bdb, buf, len) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
err = true;
- }
- tcfree(kbuf);
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurkey");
- err = true;
}
- tcbdbcurnext(cur);
- }
- break;
- }
- } else {
- int vsiz;
- char *vbuf = tcbdbget(bdb, buf, len, &vsiz);
- if(vbuf){
- if(map){
- int msiz;
- const char *mbuf = tcmapget(map, buf, len, &msiz);
- if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- }
- tcfree(vbuf);
- } else {
- if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- }
- if(map && tcmapget(map, buf, len, &vsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- }
- }
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- tcbdbcurdel(cur);
- if(map){
- tcmapiterinit(map);
- int ksiz;
- const char *kbuf;
- while(!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL){
- int vsiz;
- char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- int msiz;
- const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz);
- if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- tcfree(vbuf);
- } else {
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- }
- tcmapdel(map);
- }
- return err ? "error" : NULL;
-}
-
-
-/* thread the race function */
-static void *threadrace(void *targ){
- TCBDB *bdb = ((TARGRACE *)targ)->bdb;
- int rnum = ((TARGRACE *)targ)->rnum;
- int id = ((TARGRACE *)targ)->id;
- bool err = false;
- int mid = rnum * 2;
- for(int i = 1; !err && i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%d", myrandnd(i));
- int rnd = myrand(100);
- if(rnd < 10){
- if(!tcbdbputkeep(bdb, buf, len, buf, len) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
- }
- } else if(rnd < 20){
- if(!tcbdbputcat(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
- }
- } else if(rnd < 30){
- if(!tcbdbputdup(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbputdup");
- err = true;
- }
- } else if(rnd < 40){
- if(!tcbdbputdupback(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbputdupback");
- err = true;
- }
- } else if(rnd < 50){
- if(!tcbdbout(bdb, buf, len) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- }
- } else {
- if(myrand(10) == 0){
- int rsiz = myrand(1024);
- char *rbuf = tcmalloc(rsiz + 1);
- for(int j = 0; j < rsiz; j++){
- rbuf[j] = myrand('z' - 'a') + 'a';
- }
- if(myrand(2) == 0){
- if(!tcbdbput(bdb, buf, len, rbuf, rsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
- }
} else {
- if(!tcbdbputcat(bdb, buf, len, rbuf, rsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
- }
- }
- tcfree(rbuf);
- } else {
- if(!tcbdbput(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- }
- }
- if(id == 0){
- if(myrand(mid) == 0){
- iprintf("[v]");
- if(!tcbdbvanish(bdb)){
- eprint(bdb, __LINE__, "tcbdbvanish");
- err = true;
- }
- }
- if(myrand(mid) == 0){
- iprintf("[o]");
- if(!tcbdboptimize(bdb, -1, -1, myrand(rnum) + 1, myrand(10), myrand(10), 0)){
- eprint(bdb, __LINE__, "tcbdbvanish");
- err = true;
- }
- }
- if(myrand(mid) == 0){
- iprintf("[d]");
- if(!tcbdbdefrag(bdb, -1)){
- eprint(bdb, __LINE__, "tcbdbdefrag");
- err = true;
- }
- }
- if(myrand(mid) == 0){
- iprintf("[i]");
- BDBCUR *cur = tcbdbcurnew(bdb);
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- char *kbuf;
- int ksiz;
- while((kbuf = tcbdbcurkey(cur, &ksiz)) != NULL){
- int vsiz;
- char *vbuf = tcbdbcurval(cur, &vsiz);
- if(vbuf){
- tcfree(vbuf);
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- }
- tcfree(kbuf);
- tcbdbcurnext(cur);
+ if (myrand(10) == 0) {
+ int rsiz = myrand(1024);
+ char *rbuf = tcmalloc(rsiz + 1);
+ for (int j = 0; j < rsiz; j++) {
+ rbuf[j] = myrand('z' - 'a') + 'a';
+ }
+ if (myrand(2) == 0) {
+ if (!tcbdbput(bdb, buf, len, rbuf, rsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ } else {
+ if (!tcbdbputcat(bdb, buf, len, rbuf, rsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ }
+ tcfree(rbuf);
+ } else {
+ if (!tcbdbput(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ }
}
- if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
+ if (id == 0) {
+ if (myrand(mid) == 0) {
+ iprintf("[v]");
+ if (!tcbdbvanish(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbvanish");
+ err = true;
+ }
+ }
+ if (myrand(mid) == 0) {
+ iprintf("[o]");
+ if (!tcbdboptimize(bdb, -1, -1, myrand(rnum) + 1, myrand(10), myrand(10), 0)) {
+ eprint(bdb, __LINE__, "tcbdbvanish");
+ err = true;
+ }
+ }
+ if (myrand(mid) == 0) {
+ iprintf("[d]");
+ if (!tcbdbdefrag(bdb, -1)) {
+ eprint(bdb, __LINE__, "tcbdbdefrag");
+ err = true;
+ }
+ }
+ if (myrand(mid) == 0) {
+ iprintf("[i]");
+ BDBCUR *cur = tcbdbcurnew(bdb);
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ char *kbuf;
+ int ksiz;
+ while ((kbuf = tcbdbcurkey(cur, &ksiz)) != NULL) {
+ int vsiz;
+ char *vbuf = tcbdbcurval(cur, &vsiz);
+ if (vbuf) {
+ tcfree(vbuf);
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ }
+ tcfree(kbuf);
+ tcbdbcurnext(cur);
+ }
+ if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ tcbdbcurdel(cur);
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
}
- tcbdbcurdel(cur);
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- return err ? "error" : NULL;
+ }
+ return err ? "error" : NULL;
}
/* global variables */
-const char *g_progname; // program name
-unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+unsigned int g_randseed; // random seed
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
static int runmisc(int argc, char **argv);
static int runwicked(int argc, char **argv);
static int procwrite(const char *path, int rnum, int lmemb, int nmemb, int bnum,
- int apow, int fpow, bool mt, TCCMP cmp, int opts, int lcnum, int ncnum,
- int xmsiz, int dfunit, int lsmax, int capnum, int omode, bool rnd);
+ int apow, int fpow, bool mt, TCCMP cmp, int opts, int lcnum, int ncnum,
+ int xmsiz, int dfunit, int lsmax, int capnum, int omode, bool rnd);
static int procread(const char *path, bool mt, TCCMP cmp, int lcnum, int ncnum,
- int xmsiz, int dfunit, int omode, bool wb, bool rnd);
+ int xmsiz, int dfunit, int omode, bool wb, bool rnd);
static int procremove(const char *path, bool mt, TCCMP cmp, int lcnum, int ncnum,
- int xmsiz, int dfunit, int omode, bool rnd);
+ int xmsiz, int dfunit, int omode, bool rnd);
static int procrcat(const char *path, int rnum,
- int lmemb, int nmemb, int bnum, int apow, int fpow,
- bool mt, TCCMP cmp, int opts, int lcnum, int ncnum, int xmsiz, int dfunit,
- int lsmax, int capnum, int omode, int pnum, bool dai, bool dad,
- bool rl, bool ru);
+ int lmemb, int nmemb, int bnum, int apow, int fpow,
+ bool mt, TCCMP cmp, int opts, int lcnum, int ncnum, int xmsiz, int dfunit,
+ int lsmax, int capnum, int omode, int pnum, bool dai, bool dad,
+ bool rl, bool ru);
static int procqueue(const char *path, int rnum, int lmemb, int nmemb, int bnum,
- int apow, int fpow, bool mt, TCCMP cmp, int opts,
- int lcnum, int ncnum, int xmsiz, int dfunit, int lsmax, int capnum,
- int omode);
+ int apow, int fpow, bool mt, TCCMP cmp, int opts,
+ int lcnum, int ncnum, int xmsiz, int dfunit, int lsmax, int capnum,
+ int omode);
static int procmisc(const char *path, int rnum, bool mt, int opts, int omode);
static int procwicked(const char *path, int rnum, bool mt, int opts, int omode);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- const char *ebuf = getenv("TCRNDSEED");
- g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
- srand(g_randseed);
- ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ const char *ebuf = getenv("TCRNDSEED");
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
+ srand(g_randseed);
+ ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "remove")){
- rv = runremove(argc, argv);
- } else if(!strcmp(argv[1], "rcat")){
- rv = runrcat(argc, argv);
- } else if(!strcmp(argv[1], "queue")){
- rv = runqueue(argc, argv);
- } else if(!strcmp(argv[1], "misc")){
- rv = runmisc(argc, argv);
- } else if(!strcmp(argv[1], "wicked")){
- rv = runwicked(argc, argv);
- } else {
- usage();
- }
- if(rv != 0){
- printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
- for(int i = 0; i < argc; i++){
- printf(" %s", argv[i]);
- }
- printf("\n\n");
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "write")) {
+ rv = runwrite(argc, argv);
+ } else if (!strcmp(argv[1], "read")) {
+ rv = runread(argc, argv);
+ } else if (!strcmp(argv[1], "remove")) {
+ rv = runremove(argc, argv);
+ } else if (!strcmp(argv[1], "rcat")) {
+ rv = runrcat(argc, argv);
+ } else if (!strcmp(argv[1], "queue")) {
+ rv = runqueue(argc, argv);
+ } else if (!strcmp(argv[1], "misc")) {
+ rv = runmisc(argc, argv);
+ } else if (!strcmp(argv[1], "wicked")) {
+ rv = runwicked(argc, argv);
+ } else {
+ usage();
+ }
+ if (rv != 0) {
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int) getpid());
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\n\n");
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: test cases of the B+ tree database API of Tokyo Cabinet\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write [-mt] [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] [-lc num] [-nc num]"
- " [-xm num] [-df num] [-ls num] [-ca num] [-nl|-nb] [-rnd] path rnum"
- " [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
- fprintf(stderr, " %s read [-mt] [-cd|-ci|-cj] [-lc num] [-nc num] [-xm num] [-df num]"
- " [-nl|-nb] [-wb] [-rnd] path\n", g_progname);
- fprintf(stderr, " %s remove [-mt] [-cd|-ci|-cj] [-lc num] [-nc num] [-xm num] [-df num]"
- " [-nl|-nb] [-rnd] path\n", g_progname);
- fprintf(stderr, " %s rcat [-mt] [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] [-lc num] [-nc num]"
- " [-xm num] [-df num] [-ls num] [-ca num] [-nl|-nb] [-pn num] [-dai|-dad|-rl|-ru]"
- " path rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
- fprintf(stderr, " %s queue [-mt] [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] [-lc num] [-nc num]"
- " [-xm num] [-df num] [-ls num] [-ca num] [-nl|-nb] path rnum"
- " [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
- fprintf(stderr, " %s misc [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
- fprintf(stderr, " %s wicked [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: test cases of the B+ tree database API of Tokyo Cabinet\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s write [-mt] [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] [-lc num] [-nc num]"
+ " [-xm num] [-df num] [-ls num] [-ca num] [-nl|-nb] [-rnd] path rnum"
+ " [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
+ fprintf(stderr, " %s read [-mt] [-cd|-ci|-cj] [-lc num] [-nc num] [-xm num] [-df num]"
+ " [-nl|-nb] [-wb] [-rnd] path\n", g_progname);
+ fprintf(stderr, " %s remove [-mt] [-cd|-ci|-cj] [-lc num] [-nc num] [-xm num] [-df num]"
+ " [-nl|-nb] [-rnd] path\n", g_progname);
+ fprintf(stderr, " %s rcat [-mt] [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] [-lc num] [-nc num]"
+ " [-xm num] [-df num] [-ls num] [-ca num] [-nl|-nb] [-pn num] [-dai|-dad|-rl|-ru]"
+ " path rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
+ fprintf(stderr, " %s queue [-mt] [-cd|-ci|-cj] [-tl] [-td|-tb|-tt|-tx] [-lc num] [-nc num]"
+ " [-xm num] [-df num] [-ls num] [-ca num] [-nl|-nb] path rnum"
+ " [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
+ fprintf(stderr, " %s misc [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
+ fprintf(stderr, " %s wicked [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print formatted information string and flush the buffer */
-static void iprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- fflush(stdout);
- va_end(ap);
+static void iprintf(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ fflush(stdout);
+ va_end(ap);
}
-
/* print a character and flush the buffer */
-static void iputchar(int c){
- putchar(c);
- fflush(stdout);
+static void iputchar(int c) {
+ putchar(c);
+ fflush(stdout);
}
-
/* print error message of hash database */
-static void eprint(TCBDB *bdb, int line, const char *func){
- const char *path = tcbdbpath(bdb);
- int ecode = tcbdbecode(bdb);
- fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
- g_progname, path ? path : "-", line, func, ecode, tcbdberrmsg(ecode));
+static void eprint(TCBDB *bdb, int line, const char *func) {
+ const char *path = tcbdbpath(bdb);
+ int ecode = tcbdbecode(bdb);
+ fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
+ g_progname, path ? path : "-", line, func, ecode, tcbdberrmsg(ecode));
}
-
/* print members of B+ tree database */
-static void mprint(TCBDB *bdb){
- if(bdb->hdb->cnt_writerec < 0) return;
- iprintf("max leaf member: %d\n", tcbdblmemb(bdb));
- iprintf("max node member: %d\n", tcbdbnmemb(bdb));
- iprintf("leaf number: %" PRIdMAX "\n", (int64_t)tcbdblnum(bdb));
- iprintf("node number: %" PRIdMAX "\n", (int64_t)tcbdbnnum(bdb));
- iprintf("bucket number: %" PRIdMAX "\n", (int64_t)tcbdbbnum(bdb));
- iprintf("used bucket number: %" PRIdMAX "\n", (int64_t)tcbdbbnumused(bdb));
- iprintf("cnt_saveleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_saveleaf);
- iprintf("cnt_loadleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_loadleaf);
- iprintf("cnt_killleaf: %" PRIdMAX "\n", (int64_t)bdb->cnt_killleaf);
- iprintf("cnt_adjleafc: %" PRIdMAX "\n", (int64_t)bdb->cnt_adjleafc);
- iprintf("cnt_savenode: %" PRIdMAX "\n", (int64_t)bdb->cnt_savenode);
- iprintf("cnt_loadnode: %" PRIdMAX "\n", (int64_t)bdb->cnt_loadnode);
- iprintf("cnt_adjnodec: %" PRIdMAX "\n", (int64_t)bdb->cnt_adjnodec);
- iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_writerec);
- iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_reuserec);
- iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_moverec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_readrec);
- iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_searchfbp);
- iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_insertfbp);
- iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_splicefbp);
- iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_dividefbp);
- iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_mergefbp);
- iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_reducefbp);
- iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_appenddrp);
- iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_deferdrp);
- iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_flushdrp);
- iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_adjrecc);
- iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_defrag);
- iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_shiftrec);
- iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t)bdb->hdb->cnt_trunc);
+static void mprint(TCBDB *bdb) {
+ if (bdb->hdb->cnt_writerec < 0) return;
+ iprintf("max leaf member: %d\n", tcbdblmemb(bdb));
+ iprintf("max node member: %d\n", tcbdbnmemb(bdb));
+ iprintf("leaf number: %" PRIdMAX "\n", (int64_t) tcbdblnum(bdb));
+ iprintf("node number: %" PRIdMAX "\n", (int64_t) tcbdbnnum(bdb));
+ iprintf("bucket number: %" PRIdMAX "\n", (int64_t) tcbdbbnum(bdb));
+ iprintf("used bucket number: %" PRIdMAX "\n", (int64_t) tcbdbbnumused(bdb));
+ iprintf("cnt_saveleaf: %" PRIdMAX "\n", (int64_t) bdb->cnt_saveleaf);
+ iprintf("cnt_loadleaf: %" PRIdMAX "\n", (int64_t) bdb->cnt_loadleaf);
+ iprintf("cnt_killleaf: %" PRIdMAX "\n", (int64_t) bdb->cnt_killleaf);
+ iprintf("cnt_adjleafc: %" PRIdMAX "\n", (int64_t) bdb->cnt_adjleafc);
+ iprintf("cnt_savenode: %" PRIdMAX "\n", (int64_t) bdb->cnt_savenode);
+ iprintf("cnt_loadnode: %" PRIdMAX "\n", (int64_t) bdb->cnt_loadnode);
+ iprintf("cnt_adjnodec: %" PRIdMAX "\n", (int64_t) bdb->cnt_adjnodec);
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_writerec);
+ iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_reuserec);
+ iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_moverec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_readrec);
+ iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_searchfbp);
+ iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_insertfbp);
+ iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_splicefbp);
+ iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_dividefbp);
+ iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_mergefbp);
+ iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_reducefbp);
+ iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_appenddrp);
+ iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_deferdrp);
+ iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_flushdrp);
+ iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_adjrecc);
+ iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_defrag);
+ iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_shiftrec);
+ iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t) bdb->hdb->cnt_trunc);
}
-
/* print system information */
-static void sysprint(void){
- TCMAP *info = tcsysinfo();
- if(info){
- tcmapiterinit(info);
- const char *kbuf;
- while((kbuf = tcmapiternext2(info)) != NULL){
- iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+static void sysprint(void) {
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ tcmapiterinit(info);
+ const char *kbuf;
+ while ((kbuf = tcmapiternext2(info)) != NULL) {
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+ }
+ tcmapdel(info);
}
- tcmapdel(info);
- }
}
-
/* get a random number */
-static int myrand(int range){
- if(range < 2) return 0;
- int high = (unsigned int)rand() >> 4;
- int low = range * (rand() / (RAND_MAX + 1.0));
- low &= (unsigned int)INT_MAX >> 4;
- return (high + low) % range;
+static int myrand(int range) {
+ if (range < 2) return 0;
+ int high = (unsigned int) rand() >> 4;
+ int low = range * (rand() / (RAND_MAX + 1.0));
+ low &= (unsigned int) INT_MAX >> 4;
+ return (high + low) % range;
}
-
/* duplication callback function */
-static void *pdprocfunc(const void *vbuf, int vsiz, int *sp, void *op){
- if(op){
- char *buf = NULL;
- int len = 0;
- switch((int)(intptr_t)op){
- case 1:
- len = vsiz + 1;
- buf = tcmalloc(len + 1);
- memset(buf, '*', len);
- break;
- case 2:
- buf = (void *)-1;
- break;
+static void *pdprocfunc(const void *vbuf, int vsiz, int *sp, void *op) {
+ if (op) {
+ char *buf = NULL;
+ int len = 0;
+ switch ((int) (intptr_t) op) {
+ case 1:
+ len = vsiz + 1;
+ buf = tcmalloc(len + 1);
+ memset(buf, '*', len);
+ break;
+ case 2:
+ buf = (void *) - 1;
+ break;
+ }
+ *sp = len;
+ return buf;
}
+ if (myrand(4) == 0) return (void *) - 1;
+ if (myrand(2) == 0) return NULL;
+ int len = myrand(RECBUFSIZ);
+ char buf[RECBUFSIZ];
+ memset(buf, '*', len);
*sp = len;
- return buf;
- }
- if(myrand(4) == 0) return (void *)-1;
- if(myrand(2) == 0) return NULL;
- int len = myrand(RECBUFSIZ);
- char buf[RECBUFSIZ];
- memset(buf, '*', len);
- *sp = len;
- return tcmemdup(buf, len);
+ return tcmemdup(buf, len);
}
-
/* iterator function */
-static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op){
- unsigned int sum = 0;
- while(--ksiz >= 0){
- sum += ((char *)kbuf)[ksiz];
- }
- while(--vsiz >= 0){
- sum += ((char *)vbuf)[vsiz];
- }
- return myrand(100 + (sum & 0xff)) > 0;
+static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op) {
+ unsigned int sum = 0;
+ while (--ksiz >= 0) {
+ sum += ((char *) kbuf)[ksiz];
+ }
+ while (--vsiz >= 0) {
+ sum += ((char *) vbuf)[vsiz];
+ }
+ return myrand(100 + (sum & 0xff)) > 0;
}
-
/* parse arguments of write command */
-static int runwrite(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- char *lmstr = NULL;
- char *nmstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- bool mt = false;
- TCCMP cmp = NULL;
- int opts = 0;
- int lcnum = 0;
- int ncnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int lsmax = 0;
- int capnum = 0;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-lc")){
- if(++i >= argc) usage();
- lcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nc")){
- if(++i >= argc) usage();
- ncnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-ls")){
- if(++i >= argc) usage();
- lsmax = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-ca")){
- if(++i >= argc) usage();
- capnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!lmstr){
- lmstr = argv[i];
- } else if(!nmstr){
- nmstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int lmemb = lmstr ? tcatoix(lmstr) : -1;
- int nmemb = nmstr ? tcatoix(nmstr) : -1;
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procwrite(path, rnum, lmemb, nmemb, bnum, apow, fpow,
- mt, cmp, opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode, rnd);
- return rv;
+static int runwrite(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ char *lmstr = NULL;
+ char *nmstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ bool mt = false;
+ TCCMP cmp = NULL;
+ int opts = 0;
+ int lcnum = 0;
+ int ncnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int lsmax = 0;
+ int capnum = 0;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-lc")) {
+ if (++i >= argc) usage();
+ lcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nc")) {
+ if (++i >= argc) usage();
+ ncnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-ls")) {
+ if (++i >= argc) usage();
+ lsmax = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-ca")) {
+ if (++i >= argc) usage();
+ capnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!lmstr) {
+ lmstr = argv[i];
+ } else if (!nmstr) {
+ nmstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procwrite(path, rnum, lmemb, nmemb, bnum, apow, fpow,
+ mt, cmp, opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode, rnd);
+ return rv;
}
-
/* parse arguments of read command */
-static int runread(int argc, char **argv){
- char *path = NULL;
- bool mt = false;
- TCCMP cmp = NULL;
- int lcnum = 0;
- int ncnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool wb = false;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-lc")){
- if(++i >= argc) usage();
- lcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nc")){
- if(++i >= argc) usage();
- ncnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-wb")){
- wb = true;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runread(int argc, char **argv) {
+ char *path = NULL;
+ bool mt = false;
+ TCCMP cmp = NULL;
+ int lcnum = 0;
+ int ncnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool wb = false;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-lc")) {
+ if (++i >= argc) usage();
+ lcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nc")) {
+ if (++i >= argc) usage();
+ ncnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-wb")) {
+ wb = true;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procread(path, mt, cmp, lcnum, ncnum, xmsiz, dfunit, omode, wb, rnd);
- return rv;
+ if (!path) usage();
+ int rv = procread(path, mt, cmp, lcnum, ncnum, xmsiz, dfunit, omode, wb, rnd);
+ return rv;
}
-
/* parse arguments of remove command */
-static int runremove(int argc, char **argv){
- char *path = NULL;
- bool mt = false;
- TCCMP cmp = NULL;
- int lcnum = 0;
- int ncnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-lc")){
- if(++i >= argc) usage();
- lcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nc")){
- if(++i >= argc) usage();
- ncnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runremove(int argc, char **argv) {
+ char *path = NULL;
+ bool mt = false;
+ TCCMP cmp = NULL;
+ int lcnum = 0;
+ int ncnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-lc")) {
+ if (++i >= argc) usage();
+ lcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nc")) {
+ if (++i >= argc) usage();
+ ncnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procremove(path, mt, cmp, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
- return rv;
+ if (!path) usage();
+ int rv = procremove(path, mt, cmp, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
+ return rv;
}
-
/* parse arguments of rcat command */
-static int runrcat(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- char *lmstr = NULL;
- char *nmstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- bool mt = false;
- TCCMP cmp = NULL;
- int opts = 0;
- int lcnum = 0;
- int ncnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int lsmax = 0;
- int capnum = 0;
- int omode = 0;
- int pnum = 0;
- bool dai = false;
- bool dad = false;
- bool rl = false;
- bool ru = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-lc")){
- if(++i >= argc) usage();
- lcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nc")){
- if(++i >= argc) usage();
- ncnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-ls")){
- if(++i >= argc) usage();
- lsmax = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-ca")){
- if(++i >= argc) usage();
- capnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else if(!strcmp(argv[i], "-pn")){
- if(++i >= argc) usage();
- pnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-dai")){
- dai = true;
- } else if(!strcmp(argv[i], "-dad")){
- dad = true;
- } else if(!strcmp(argv[i], "-rl")){
- rl = true;
- } else if(!strcmp(argv[i], "-ru")){
- ru = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!lmstr){
- lmstr = argv[i];
- } else if(!nmstr){
- nmstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int lmemb = lmstr ? tcatoix(lmstr) : -1;
- int nmemb = nmstr ? tcatoix(nmstr) : -1;
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procrcat(path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, cmp, opts,
- lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode, pnum, dai, dad, rl, ru);
- return rv;
+static int runrcat(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ char *lmstr = NULL;
+ char *nmstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ bool mt = false;
+ TCCMP cmp = NULL;
+ int opts = 0;
+ int lcnum = 0;
+ int ncnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int lsmax = 0;
+ int capnum = 0;
+ int omode = 0;
+ int pnum = 0;
+ bool dai = false;
+ bool dad = false;
+ bool rl = false;
+ bool ru = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-lc")) {
+ if (++i >= argc) usage();
+ lcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nc")) {
+ if (++i >= argc) usage();
+ ncnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-ls")) {
+ if (++i >= argc) usage();
+ lsmax = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-ca")) {
+ if (++i >= argc) usage();
+ capnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else if (!strcmp(argv[i], "-pn")) {
+ if (++i >= argc) usage();
+ pnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-dai")) {
+ dai = true;
+ } else if (!strcmp(argv[i], "-dad")) {
+ dad = true;
+ } else if (!strcmp(argv[i], "-rl")) {
+ rl = true;
+ } else if (!strcmp(argv[i], "-ru")) {
+ ru = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!lmstr) {
+ lmstr = argv[i];
+ } else if (!nmstr) {
+ nmstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procrcat(path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, cmp, opts,
+ lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode, pnum, dai, dad, rl, ru);
+ return rv;
}
-
/* parse arguments of queue command */
-static int runqueue(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- char *lmstr = NULL;
- char *nmstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- bool mt = false;
- TCCMP cmp = NULL;
- int opts = 0;
- int lcnum = 0;
- int ncnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int lsmax = 0;
- int capnum = 0;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-cd")){
- cmp = tccmpdecimal;
- } else if(!strcmp(argv[i], "-ci")){
- cmp = tccmpint32;
- } else if(!strcmp(argv[i], "-cj")){
- cmp = tccmpint64;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-lc")){
- if(++i >= argc) usage();
- lcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nc")){
- if(++i >= argc) usage();
- ncnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-ls")){
- if(++i >= argc) usage();
- lsmax = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-ca")){
- if(++i >= argc) usage();
- capnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!lmstr){
- lmstr = argv[i];
- } else if(!nmstr){
- nmstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int lmemb = lmstr ? tcatoix(lmstr) : -1;
- int nmemb = nmstr ? tcatoix(nmstr) : -1;
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procqueue(path, rnum, lmemb, nmemb, bnum, apow, fpow,
- mt, cmp, opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode);
- return rv;
+static int runqueue(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ char *lmstr = NULL;
+ char *nmstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ bool mt = false;
+ TCCMP cmp = NULL;
+ int opts = 0;
+ int lcnum = 0;
+ int ncnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int lsmax = 0;
+ int capnum = 0;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-cd")) {
+ cmp = tccmpdecimal;
+ } else if (!strcmp(argv[i], "-ci")) {
+ cmp = tccmpint32;
+ } else if (!strcmp(argv[i], "-cj")) {
+ cmp = tccmpint64;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-lc")) {
+ if (++i >= argc) usage();
+ lcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nc")) {
+ if (++i >= argc) usage();
+ ncnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-ls")) {
+ if (++i >= argc) usage();
+ lsmax = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-ca")) {
+ if (++i >= argc) usage();
+ capnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!lmstr) {
+ lmstr = argv[i];
+ } else if (!nmstr) {
+ nmstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procqueue(path, rnum, lmemb, nmemb, bnum, apow, fpow,
+ mt, cmp, opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode);
+ return rv;
}
-
/* parse arguments of misc command */
-static int runmisc(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- bool mt = false;
- int opts = 0;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int rv = procmisc(path, rnum, mt, opts, omode);
- return rv;
+static int runmisc(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ bool mt = false;
+ int opts = 0;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int rv = procmisc(path, rnum, mt, opts, omode);
+ return rv;
}
-
/* parse arguments of wicked command */
-static int runwicked(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- bool mt = false;
- int opts = 0;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= BDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= BDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= BDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= BDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= BDBTEXCODEC;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= BDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= BDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int rv = procwicked(path, rnum, mt, opts, omode);
- return rv;
+static int runwicked(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ bool mt = false;
+ int opts = 0;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= BDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= BDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= BDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= BDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= BDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= BDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= BDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int rv = procwicked(path, rnum, mt, opts, omode);
+ return rv;
}
-
/* perform write command */
static int procwrite(const char *path, int rnum, int lmemb, int nmemb, int bnum,
- int apow, int fpow, bool mt, TCCMP cmp, int opts, int lcnum, int ncnum,
- int xmsiz, int dfunit, int lsmax, int capnum, int omode, bool rnd){
- iprintf("<Writing Test>\n seed=%u path=%s rnum=%d lmemb=%d nmemb=%d bnum=%d apow=%d"
- " fpow=%d mt=%d cmp=%p opts=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d lsmax=%d"
- " capnum=%d omode=%d rnd=%d\n\n",
- g_randseed, path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, (void *)(intptr_t)cmp,
- opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(mt && !tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
- eprint(bdb, __LINE__, "tcbdbtune");
- err = true;
- }
- if(!tcbdbsetcache(bdb, lcnum, ncnum)){
- eprint(bdb, __LINE__, "tcbdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbsetlsmax(bdb, lsmax)){
- eprint(bdb, __LINE__, "tcbdbsetlsmax");
- err = true;
- }
- if(!tcbdbsetcapnum(bdb, capnum)){
- eprint(bdb, __LINE__, "tcbdbsetcapnum");
- err = true;
- }
- if(!rnd) omode |= BDBOTRUNC;
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len;
- if(cmp == tccmpdecimal){
- len = sprintf(buf, "%d", rnd ? myrand(rnum) + 1 : i);
- } else if(cmp == tccmpint32){
- int32_t lnum = rnd ? myrand(rnum) + 1 : i;
- memcpy(buf, &lnum, sizeof(lnum));
- len = sizeof(lnum);
- } else if(cmp == tccmpint64){
- int64_t llnum = rnd ? myrand(rnum) + 1 : i;
- memcpy(buf, &llnum, sizeof(llnum));
- len = sizeof(llnum);
- } else {
- len = sprintf(buf, "%08d", rnd ? myrand(rnum) + 1 : i);
- }
- if(!tcbdbput(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ int apow, int fpow, bool mt, TCCMP cmp, int opts, int lcnum, int ncnum,
+ int xmsiz, int dfunit, int lsmax, int capnum, int omode, bool rnd) {
+ iprintf("<Writing Test>\n seed=%u path=%s rnum=%d lmemb=%d nmemb=%d bnum=%d apow=%d"
+ " fpow=%d mt=%d cmp=%p opts=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d lsmax=%d"
+ " capnum=%d omode=%d rnd=%d\n\n",
+ g_randseed, path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, (void *) (intptr_t) cmp,
+ opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (mt && !tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
+ err = true;
+ }
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
+ err = true;
+ }
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
+ err = true;
+ }
+ if (!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) {
+ eprint(bdb, __LINE__, "tcbdbtune");
+ err = true;
+ }
+ if (!tcbdbsetcache(bdb, lcnum, ncnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
+ err = true;
+ }
+ if (!tcbdbsetlsmax(bdb, lsmax)) {
+ eprint(bdb, __LINE__, "tcbdbsetlsmax");
+ err = true;
+ }
+ if (!tcbdbsetcapnum(bdb, capnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetcapnum");
+ err = true;
+ }
+ if (!rnd) omode |= BDBOTRUNC;
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len;
+ if (cmp == tccmpdecimal) {
+ len = sprintf(buf, "%d", rnd ? myrand(rnum) + 1 : i);
+ } else if (cmp == tccmpint32) {
+ int32_t lnum = rnd ? myrand(rnum) + 1 : i;
+ memcpy(buf, &lnum, sizeof (lnum));
+ len = sizeof (lnum);
+ } else if (cmp == tccmpint64) {
+ int64_t llnum = rnd ? myrand(rnum) + 1 : i;
+ memcpy(buf, &llnum, sizeof (llnum));
+ len = sizeof (llnum);
+ } else {
+ len = sprintf(buf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ }
+ if (!tcbdbput(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform read command */
static int procread(const char *path, bool mt, TCCMP cmp, int lcnum, int ncnum,
- int xmsiz, int dfunit, int omode, bool wb, bool rnd){
- iprintf("<Reading Test>\n seed=%u path=%s mt=%d cmp=%p lcnum=%d ncnum=%d"
- " xmsiz=%d dfunit=%d omode=%d wb=%d rnd=%d\n\n",
- g_randseed, path, mt, (void *)(intptr_t)cmp, lcnum, ncnum, xmsiz, dfunit,
- omode, wb, rnd);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(mt && !tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbsetcache(bdb, lcnum, ncnum)){
- eprint(bdb, __LINE__, "tcbdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOREADER | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- int rnum = tcbdbrnum(bdb);
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz;
- if(cmp == tccmpdecimal){
- ksiz = sprintf(kbuf, "%d", rnd ? myrand(rnum) + 1 : i);
- } else if(cmp == tccmpint32){
- int32_t lnum = rnd ? myrand(rnum) + 1 : i;
- memcpy(kbuf, &lnum, sizeof(lnum));
- ksiz = sizeof(lnum);
- } else if(cmp == tccmpint64){
- int64_t llnum = rnd ? myrand(rnum) + 1 : i;
- memcpy(kbuf, &llnum, sizeof(llnum));
- ksiz = sizeof(llnum);
- } else {
- ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ int xmsiz, int dfunit, int omode, bool wb, bool rnd) {
+ iprintf("<Reading Test>\n seed=%u path=%s mt=%d cmp=%p lcnum=%d ncnum=%d"
+ " xmsiz=%d dfunit=%d omode=%d wb=%d rnd=%d\n\n",
+ g_randseed, path, mt, (void *) (intptr_t) cmp, lcnum, ncnum, xmsiz, dfunit,
+ omode, wb, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (mt && !tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
+ err = true;
}
- int vsiz;
- if(wb){
- int vsiz;
- const char *vbuf = tcbdbget3(bdb, kbuf, ksiz, &vsiz);
- if(!vbuf && !(rnd && tcbdbecode(bdb) == TCENOREC)){
- eprint(bdb, __LINE__, "tcbdbget3");
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
err = true;
- break;
- }
- } else {
- char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
- if(!vbuf && !(rnd && tcbdbecode(bdb) == TCENOREC)){
- eprint(bdb, __LINE__, "tcbdbget");
+ }
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
err = true;
- break;
- }
- tcfree(vbuf);
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
-}
-
-
-/* perform remove command */
-static int procremove(const char *path, bool mt, TCCMP cmp, int lcnum, int ncnum,
- int xmsiz, int dfunit, int omode, bool rnd){
- iprintf("<Removing Test>\n seed=%u path=%s mt=%d cmp=%p lcnum=%d ncnum=%d"
- " xmsiz=%d dfunit=%d omode=%d rnd=%d\n\n",
- g_randseed, path, mt, (void *)(intptr_t)cmp, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(mt && !tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbsetcache(bdb, lcnum, ncnum)){
- eprint(bdb, __LINE__, "tcbdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- int rnum = tcbdbrnum(bdb);
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz;
- if(cmp == tccmpdecimal){
- ksiz = sprintf(kbuf, "%d", rnd ? myrand(rnum) + 1 : i);
- } else if(cmp == tccmpint32){
- int32_t lnum = rnd ? myrand(rnum) + 1 : i;
- memcpy(kbuf, &lnum, sizeof(lnum));
- ksiz = sizeof(lnum);
- } else if(cmp == tccmpint64){
- int64_t llnum = rnd ? myrand(rnum) + 1 : i;
- memcpy(kbuf, &llnum, sizeof(llnum));
- ksiz = sizeof(llnum);
- } else {
- ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
- }
- if(!tcbdbout(bdb, kbuf, ksiz) && !(rnd && tcbdbecode(bdb) == TCENOREC)){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
-}
-
-
-/* perform rcat command */
-static int procrcat(const char *path, int rnum,
- int lmemb, int nmemb, int bnum, int apow, int fpow,
- bool mt, TCCMP cmp, int opts, int lcnum, int ncnum, int xmsiz, int dfunit,
- int lsmax, int capnum, int omode, int pnum, bool dai, bool dad,
- bool rl, bool ru){
- iprintf("<Random Concatenating Test>\n"
- " seed=%u path=%s rnum=%d lmemb=%d nmemb=%d bnum=%d apow=%d fpow=%d"
- " mt=%d cmp=%p opts=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d"
- " lsmax=%d capnum=%d omode=%d pnum=%d dai=%d dad=%d rl=%d ru=%d\n\n",
- g_randseed, path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, (void *)(intptr_t)cmp,
- opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode, pnum, dai, dad, rl, ru);
- if(pnum < 1) pnum = rnum;
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(mt && !tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
- eprint(bdb, __LINE__, "tcbdbtune");
- err = true;
- }
- if(!tcbdbsetcache(bdb, lcnum, ncnum)){
- eprint(bdb, __LINE__, "tcbdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbsetlsmax(bdb, lsmax)){
- eprint(bdb, __LINE__, "tcbdbsetlsmax");
- err = true;
- }
- if(!tcbdbsetcapnum(bdb, capnum)){
- eprint(bdb, __LINE__, "tcbdbsetcapnum");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- if(ru){
- char fmt[RECBUFSIZ];
- sprintf(fmt, "%%0%dd", myrand(RECBUFSIZ));
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, fmt, myrand(pnum));
- switch(myrand(10)){
- case 0:
- if(!tcbdbput(bdb, kbuf, ksiz, kbuf, ksiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- break;
- case 1:
- if(!tcbdbputkeep(bdb, kbuf, ksiz, kbuf, ksiz) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
- }
- break;
- case 2:
- if(!tcbdbputdup(bdb, kbuf, ksiz, kbuf, ksiz) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
- }
- break;
- case 3:
- if(!tcbdbputdupback(bdb, kbuf, ksiz, kbuf, ksiz) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
- }
- break;
- case 4:
- if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- }
- break;
- case 5:
- if(tcbdbaddint(bdb, kbuf, ksiz, 1) == INT_MIN && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbaddint");
- err = true;
- }
- break;
- case 6:
- if(isnan(tcbdbadddouble(bdb, kbuf, ksiz, 1.0)) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbadddouble");
- err = true;
- }
- break;
- case 7:
- if(myrand(2) == 0){
- if(!tcbdbputproc(bdb, kbuf, ksiz, kbuf, ksiz, pdprocfunc, NULL) &&
- tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputproc");
- err = true;
+ }
+ if (!tcbdbsetcache(bdb, lcnum, ncnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOREADER | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ int rnum = tcbdbrnum(bdb);
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz;
+ if (cmp == tccmpdecimal) {
+ ksiz = sprintf(kbuf, "%d", rnd ? myrand(rnum) + 1 : i);
+ } else if (cmp == tccmpint32) {
+ int32_t lnum = rnd ? myrand(rnum) + 1 : i;
+ memcpy(kbuf, &lnum, sizeof (lnum));
+ ksiz = sizeof (lnum);
+ } else if (cmp == tccmpint64) {
+ int64_t llnum = rnd ? myrand(rnum) + 1 : i;
+ memcpy(kbuf, &llnum, sizeof (llnum));
+ ksiz = sizeof (llnum);
+ } else {
+ ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ }
+ int vsiz;
+ if (wb) {
+ int vsiz;
+ const char *vbuf = tcbdbget3(bdb, kbuf, ksiz, &vsiz);
+ if (!vbuf && !(rnd && tcbdbecode(bdb) == TCENOREC)) {
+ eprint(bdb, __LINE__, "tcbdbget3");
+ err = true;
+ break;
}
- } else {
- if(!tcbdbputproc(bdb, kbuf, ksiz, NULL, 0, pdprocfunc, NULL) &&
- tcbdbecode(bdb) != TCEKEEP && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbputproc");
- err = true;
+ } else {
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
+ if (!vbuf && !(rnd && tcbdbecode(bdb) == TCENOREC)) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ break;
}
- }
- break;
- default:
- if(!tcbdbputcat(bdb, kbuf, ksiz, kbuf, ksiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
- }
- break;
- }
- if(err) break;
- } else {
- char kbuf[RECBUFSIZ];
- int ksiz;
- if(cmp == tccmpdecimal){
- ksiz = sprintf(kbuf, "%d", myrand(pnum));
- } else if(cmp == tccmpint32){
- int32_t lnum = myrand(pnum);
- memcpy(kbuf, &lnum, sizeof(lnum));
- ksiz = sizeof(lnum);
- } else if(cmp == tccmpint64){
- int64_t llnum = myrand(pnum);
- memcpy(kbuf, &llnum, sizeof(llnum));
- ksiz = sizeof(llnum);
- } else {
- ksiz = sprintf(kbuf, "%d", myrand(pnum));
- }
- if(dai){
- if(tcbdbaddint(bdb, kbuf, ksiz, myrand(3)) == INT_MIN){
- eprint(bdb, __LINE__, "tcbdbaddint");
- err = true;
- break;
- }
- } else if(dad){
- if(isnan(tcbdbadddouble(bdb, kbuf, ksiz, myrand(30) / 10.0))){
- eprint(bdb, __LINE__, "tcbdbadddouble");
- err = true;
- break;
- }
- } else if(rl){
- char vbuf[PATH_MAX];
- int vsiz = myrand(PATH_MAX);
- for(int j = 0; j < vsiz; j++){
- vbuf[j] = myrand(0x100);
- }
- if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
- break;
- }
- } else {
- if(!tcbdbputcat(bdb, kbuf, ksiz, kbuf, ksiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
- break;
- }
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ tcfree(vbuf);
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
-/* perform queue command */
-static int procqueue(const char *path, int rnum, int lmemb, int nmemb, int bnum,
- int apow, int fpow, bool mt, TCCMP cmp, int opts,
- int lcnum, int ncnum, int xmsiz, int dfunit, int lsmax, int capnum,
- int omode){
- iprintf("<Queueing Test>\n seed=%u path=%s rnum=%d lmemb=%d nmemb=%d bnum=%d apow=%d"
- " fpow=%d mt=%d cmp=%p opts=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d"
- " lsmax=%d capnum=%d omode=%d\n\n",
- g_randseed, path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, (void *)(intptr_t)cmp,
- opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(mt && !tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
- eprint(bdb, __LINE__, "tcbdbtune");
- err = true;
- }
- if(!tcbdbsetcache(bdb, lcnum, ncnum)){
- eprint(bdb, __LINE__, "tcbdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbsetlsmax(bdb, lsmax)){
- eprint(bdb, __LINE__, "tcbdbsetlsmax");
- err = true;
- }
- if(!tcbdbsetcapnum(bdb, capnum)){
- eprint(bdb, __LINE__, "tcbdbsetcapnum");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- int deqfreq = (lmemb > 0) ? lmemb * 10 : 256;
- BDBCUR *cur = tcbdbcurnew(bdb);
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len;
- if(cmp == tccmpdecimal){
- len = sprintf(buf, "%d", i);
- } else if(cmp == tccmpint32){
- int32_t lnum = i;
- memcpy(buf, &lnum, sizeof(lnum));
- len = sizeof(lnum);
- } else if(cmp == tccmpint64){
- int64_t llnum = i;
- memcpy(buf, &llnum, sizeof(llnum));
- len = sizeof(llnum);
- } else {
- len = sprintf(buf, "%08d", i);
+/* perform remove command */
+static int procremove(const char *path, bool mt, TCCMP cmp, int lcnum, int ncnum,
+ int xmsiz, int dfunit, int omode, bool rnd) {
+ iprintf("<Removing Test>\n seed=%u path=%s mt=%d cmp=%p lcnum=%d ncnum=%d"
+ " xmsiz=%d dfunit=%d omode=%d rnd=%d\n\n",
+ g_randseed, path, mt, (void *) (intptr_t) cmp, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (mt && !tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
+ err = true;
+ }
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
+ err = true;
}
- if(!tcbdbput(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- break;
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
+ err = true;
}
- if(myrand(deqfreq) == 0){
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
+ if (!tcbdbsetcache(bdb, lcnum, ncnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetcache");
err = true;
- break;
- }
- int num = myrand(deqfreq * 2 + 1);
- while(num >= 0){
- if(tcbdbcurout(cur)){
- num--;
+ }
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ int rnum = tcbdbrnum(bdb);
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz;
+ if (cmp == tccmpdecimal) {
+ ksiz = sprintf(kbuf, "%d", rnd ? myrand(rnum) + 1 : i);
+ } else if (cmp == tccmpint32) {
+ int32_t lnum = rnd ? myrand(rnum) + 1 : i;
+ memcpy(kbuf, &lnum, sizeof (lnum));
+ ksiz = sizeof (lnum);
+ } else if (cmp == tccmpint64) {
+ int64_t llnum = rnd ? myrand(rnum) + 1 : i;
+ memcpy(kbuf, &llnum, sizeof (llnum));
+ ksiz = sizeof (llnum);
} else {
- if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurout");
+ ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ }
+ if (!tcbdbout(bdb, kbuf, ksiz) && !(rnd && tcbdbecode(bdb) == TCENOREC)) {
+ eprint(bdb, __LINE__, "tcbdbout");
err = true;
- }
- break;
- }
- }
- if(err) break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- while(true){
- if(tcbdbcurout(cur)) continue;
- if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurout");
- err = true;
- }
- break;
- }
- tcbdbcurdel(cur);
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
-/* perform misc command */
-static int procmisc(const char *path, int rnum, bool mt, int opts, int omode){
- iprintf("<Miscellaneous Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
- g_randseed, path, rnum, mt, opts, omode);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(mt && !tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbtune(bdb, 10, 10, rnum / 50, 100, -1, opts)){
- eprint(bdb, __LINE__, "tcbdbtune");
- err = true;
- }
- if(!tcbdbsetcache(bdb, 128, 256)){
- eprint(bdb, __LINE__, "tcbdbsetcache");
- err = true;
- }
- if(!tcbdbsetxmsiz(bdb, rnum)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(!tcbdbsetdfunit(bdb, 8)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- if(1){
- TCBDB *bdbdup = tcbdbnew();
- if(tcbdbopen(bdbdup, path, BDBOREADER)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- } else if(tcbdbecode(bdbdup) != TCETHREAD){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- tcbdbdel(bdbdup);
- }
- iprintf("writing:\n");
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- if(!tcbdbputkeep(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("reading:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", i);
- int vsiz;
- char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- break;
- } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- tcfree(vbuf);
- break;
- }
- tcfree(vbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(tcbdbrnum(bdb) != rnum){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- iprintf("random writing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '*', vsiz);
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- break;
- }
- int rsiz;
- char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
- if(!rbuf){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- break;
- }
- if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- tcfree(rbuf);
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- tcfree(rbuf);
- }
- iprintf("word writing:\n");
- const char *words[] = {
- "a", "A", "bb", "BB", "ccc", "CCC", "dddd", "DDDD", "eeeee", "EEEEEE",
- "mikio", "hirabayashi", "tokyo", "cabinet", "hyper", "estraier", "19780211", "birth day",
- "one", "first", "two", "second", "three", "third", "four", "fourth", "five", "fifth",
- "_[1]_", "uno", "_[2]_", "dos", "_[3]_", "tres", "_[4]_", "cuatro", "_[5]_", "cinco",
- "[\xe5\xb9\xb3\xe6\x9e\x97\xe5\xb9\xb9\xe9\x9b\x84]", "[\xe9\xa6\xac\xe9\xb9\xbf]", NULL
- };
- for(int i = 0; words[i] != NULL; i += 2){
- const char *kbuf = words[i];
- int ksiz = strlen(kbuf);
- const char *vbuf = words[i+1];
- int vsiz = strlen(vbuf);
- if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
- break;
- }
- if(rnum > 250) iputchar('.');
- }
- if(rnum > 250) iprintf(" (%08d)\n", (int)(sizeof(words) / sizeof(*words)));
- iprintf("random erasing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("writing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "[%d]", i);
- char vbuf[RECBUFSIZ];
- int vsiz = i % RECBUFSIZ;
- memset(vbuf, '*', vsiz);
- if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
- break;
- }
- if(vsiz < 1){
- char tbuf[PATH_MAX];
- for(int j = 0; j < PATH_MAX; j++){
- tbuf[j] = myrand(0x100);
- }
- if(!tcbdbput(bdb, kbuf, ksiz, tbuf, PATH_MAX)){
- eprint(bdb, __LINE__, "tcbdbput");
+/* perform rcat command */
+static int procrcat(const char *path, int rnum,
+ int lmemb, int nmemb, int bnum, int apow, int fpow,
+ bool mt, TCCMP cmp, int opts, int lcnum, int ncnum, int xmsiz, int dfunit,
+ int lsmax, int capnum, int omode, int pnum, bool dai, bool dad,
+ bool rl, bool ru) {
+ iprintf("<Random Concatenating Test>\n"
+ " seed=%u path=%s rnum=%d lmemb=%d nmemb=%d bnum=%d apow=%d fpow=%d"
+ " mt=%d cmp=%p opts=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d"
+ " lsmax=%d capnum=%d omode=%d pnum=%d dai=%d dad=%d rl=%d ru=%d\n\n",
+ g_randseed, path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, (void *) (intptr_t) cmp,
+ opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode, pnum, dai, dad, rl, ru);
+ if (pnum < 1) pnum = rnum;
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (mt && !tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
err = true;
- break;
- }
}
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
+ err = true;
}
- }
- iprintf("erasing:\n");
- for(int i = 1; i <= rnum; i++){
- if(i % 2 == 1){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "[%d]", i);
- if(!tcbdbout(bdb, kbuf, ksiz)){
- eprint(bdb, __LINE__, "tcbdbout");
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
err = true;
- break;
- }
- if(tcbdbout(bdb, kbuf, ksiz) || tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
+ }
+ if (!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) {
+ eprint(bdb, __LINE__, "tcbdbtune");
err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("random writing and reopening:\n");
- for(int i = 1; i <= rnum; i++){
- if(myrand(10) == 0){
- int ksiz, vsiz;
- char *kbuf, *vbuf;
- ksiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
- kbuf = tcmalloc(ksiz + 1);
- for(int j = 0; j < ksiz; j++){
- kbuf[j] = 128 + myrand(128);
- }
- vsiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
- vbuf = tcmalloc(vsiz + 1);
- for(int j = 0; j < vsiz; j++){
- vbuf[j] = myrand(256);
- }
- switch(myrand(5)){
- case 0:
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- break;
- case 1:
- if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
- }
- break;
- case 2:
- if(!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputdup");
- err = true;
- }
- break;
- case 3:
- if(!tcbdbputdupback(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputdupback");
- err = true;
- }
- break;
- default:
- if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- }
- break;
- }
- tcfree(vbuf);
- tcfree(kbuf);
- } else {
- char kbuf[RECBUFSIZ];
- int ksiz = myrand(RECBUFSIZ);
- memset(kbuf, '@', ksiz);
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '@', vsiz);
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
+ }
+ if (!tcbdbsetcache(bdb, lcnum, ncnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetcache");
err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- iprintf("checking:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "[%d]", i);
- int vsiz;
- char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
- if(i % 2 == 0){
- if(!vbuf){
- eprint(bdb, __LINE__, "tcbdbget");
+ }
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
err = true;
- break;
- }
- if(vsiz != i % RECBUFSIZ && vsiz != PATH_MAX){
- eprint(bdb, __LINE__, "(validation)");
+ }
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
err = true;
- tcfree(vbuf);
- break;
- }
- } else {
- if(vbuf || tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "(validation)");
+ }
+ if (!tcbdbsetlsmax(bdb, lsmax)) {
+ eprint(bdb, __LINE__, "tcbdbsetlsmax");
err = true;
- tcfree(vbuf);
- break;
- }
}
- tcfree(vbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ if (!tcbdbsetcapnum(bdb, capnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetcapnum");
+ err = true;
}
- }
- iprintf("writing:\n");
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- if(!tcbdbput(bdb, buf, len, buf, len)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- break;
- }
- if(i % 10 == 0){
- TCLIST *vals = tclistnew();
- for(int j = myrand(5) + 1; j >= 0; j--){
- tclistpush(vals, buf, len);
- }
- if(!tcbdbputdup3(bdb, buf, len, vals)){
- eprint(bdb, __LINE__, "tcbdbput3");
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
err = true;
- break;
- }
- tclistdel(vals);
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("reading:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", i);
- int vsiz;
- char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- break;
- } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- tcfree(vbuf);
- break;
- }
- tcfree(vbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("checking words:\n");
- for(int i = 0; words[i] != NULL; i += 2){
- const char *kbuf = words[i];
- int ksiz = strlen(kbuf);
- const char *vbuf = words[i+1];
- int vsiz = strlen(vbuf);
- int rsiz;
- char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
- if(!rbuf){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- break;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- tcfree(rbuf);
- break;
- }
- tcfree(rbuf);
- if(rnum > 250) iputchar('.');
- }
- if(rnum > 250) iprintf(" (%08d)\n", (int)(sizeof(words) / sizeof(*words)));
- iprintf("checking cursor:\n");
- BDBCUR *cur = tcbdbcurnew(bdb);
- int inum = 0;
- if(!tcbdbcurfirst(cur)){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- char *kbuf;
- int ksiz;
- for(int i = 1; (kbuf = tcbdbcurkey(cur, &ksiz)) != NULL; i++, inum++){
- int vsiz;
- char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- tcfree(kbuf);
- break;
- }
- tcfree(vbuf);
- tcfree(kbuf);
- tcbdbcurnext(cur);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- if(tcbdbecode(bdb) != TCENOREC || inum != tcbdbrnum(bdb)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- iprintf("cursor updating:\n");
- if(!tcbdbcurfirst(cur)){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- inum = 0;
- for(int i = 1; !err && (kbuf = tcbdbcurkey(cur, &ksiz)) != NULL; i++, inum++){
- switch(myrand(6)){
- case 0:
- if(!tcbdbputdup(bdb, kbuf, ksiz, "0123456789", 10)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
- }
- break;
- case 1:
- if(!tcbdbout(bdb, kbuf, ksiz)){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- }
- break;
- case 2:
- if(!tcbdbcurput(cur, kbuf, ksiz, BDBCPCURRENT)){
- eprint(bdb, __LINE__, "tcbdbcurput");
- err = true;
- }
- break;
- case 3:
- if(!tcbdbcurput(cur, kbuf, ksiz, BDBCPBEFORE)){
- eprint(bdb, __LINE__, "tcbdbcurput");
- err = true;
- }
- break;
- case 4:
- if(!tcbdbcurput(cur, kbuf, ksiz, BDBCPAFTER)){
- eprint(bdb, __LINE__, "tcbdbcurput");
- err = true;
+ }
+ for (int i = 1; i <= rnum; i++) {
+ if (ru) {
+ char fmt[RECBUFSIZ];
+ sprintf(fmt, "%%0%dd", myrand(RECBUFSIZ));
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, fmt, myrand(pnum));
+ switch (myrand(10)) {
+ case 0:
+ if (!tcbdbput(bdb, kbuf, ksiz, kbuf, ksiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcbdbputkeep(bdb, kbuf, ksiz, kbuf, ksiz) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tcbdbputdup(bdb, kbuf, ksiz, kbuf, ksiz) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ }
+ break;
+ case 3:
+ if (!tcbdbputdupback(bdb, kbuf, ksiz, kbuf, ksiz) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ }
+ break;
+ case 4:
+ if (!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ break;
+ case 5:
+ if (tcbdbaddint(bdb, kbuf, ksiz, 1) == INT_MIN && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbaddint");
+ err = true;
+ }
+ break;
+ case 6:
+ if (isnan(tcbdbadddouble(bdb, kbuf, ksiz, 1.0)) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbadddouble");
+ err = true;
+ }
+ break;
+ case 7:
+ if (myrand(2) == 0) {
+ if (!tcbdbputproc(bdb, kbuf, ksiz, kbuf, ksiz, pdprocfunc, NULL) &&
+ tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputproc");
+ err = true;
+ }
+ } else {
+ if (!tcbdbputproc(bdb, kbuf, ksiz, NULL, 0, pdprocfunc, NULL) &&
+ tcbdbecode(bdb) != TCEKEEP && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbputproc");
+ err = true;
+ }
+ }
+ break;
+ default:
+ if (!tcbdbputcat(bdb, kbuf, ksiz, kbuf, ksiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ break;
+ }
+ if (err) break;
+ } else {
+ char kbuf[RECBUFSIZ];
+ int ksiz;
+ if (cmp == tccmpdecimal) {
+ ksiz = sprintf(kbuf, "%d", myrand(pnum));
+ } else if (cmp == tccmpint32) {
+ int32_t lnum = myrand(pnum);
+ memcpy(kbuf, &lnum, sizeof (lnum));
+ ksiz = sizeof (lnum);
+ } else if (cmp == tccmpint64) {
+ int64_t llnum = myrand(pnum);
+ memcpy(kbuf, &llnum, sizeof (llnum));
+ ksiz = sizeof (llnum);
+ } else {
+ ksiz = sprintf(kbuf, "%d", myrand(pnum));
+ }
+ if (dai) {
+ if (tcbdbaddint(bdb, kbuf, ksiz, myrand(3)) == INT_MIN) {
+ eprint(bdb, __LINE__, "tcbdbaddint");
+ err = true;
+ break;
+ }
+ } else if (dad) {
+ if (isnan(tcbdbadddouble(bdb, kbuf, ksiz, myrand(30) / 10.0))) {
+ eprint(bdb, __LINE__, "tcbdbadddouble");
+ err = true;
+ break;
+ }
+ } else if (rl) {
+ char vbuf[PATH_MAX];
+ int vsiz = myrand(PATH_MAX);
+ for (int j = 0; j < vsiz; j++) {
+ vbuf[j] = myrand(0x100);
+ }
+ if (!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ break;
+ }
+ } else {
+ if (!tcbdbputcat(bdb, kbuf, ksiz, kbuf, ksiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ break;
+ }
+ }
}
- break;
- default:
- if(!tcbdbcurout(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurout");
- err = true;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- break;
}
- tcfree(kbuf);
- tcbdbcurnext(cur);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- if(myrand(10) == 0 && !tcbdbsync(bdb)){
- eprint(bdb, __LINE__, "tcbdbsync");
- err = true;
- }
- iprintf("cursor updating from empty:\n");
- tcbdbcurfirst(cur);
- inum = 0;
- for(int i = 1; (kbuf = tcbdbcurkey(cur, &ksiz)) != NULL; i++, inum++){
- tcfree(kbuf);
- if(!tcbdbcurout(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurout");
- err = true;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- if(tcbdbrnum(bdb) != 0){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- if(!tcbdbput2(bdb, "one", "first")){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- if(!tcbdbcurlast(cur)){
- eprint(bdb, __LINE__, "tcbdbcurlast");
- err = true;
- }
- if(!tcbdbcurput2(cur, "second", BDBCPCURRENT) || !tcbdbcurput2(cur, "first", BDBCPBEFORE) ||
- !tcbdbcurput2(cur, "zero", BDBCPBEFORE) || !tcbdbcurput2(cur, "top", BDBCPBEFORE)){
- eprint(bdb, __LINE__, "tcbdbcurput2");
- err = true;
- }
- if(!tcbdbcurlast(cur)){
- eprint(bdb, __LINE__, "tcbdbcurlast");
- err = true;
- }
- if(!tcbdbcurput2(cur, "third", BDBCPAFTER) || !tcbdbcurput2(cur, "fourth", BDBCPAFTER) ||
- !tcbdbcurput2(cur, "end", BDBCPCURRENT) || !tcbdbcurput2(cur, "bottom", BDBCPAFTER)){
- eprint(bdb, __LINE__, "tcbdbcurput2");
- err = true;
- }
- if(!tcbdbvanish(bdb)){
- eprint(bdb, __LINE__, "tcbdbvanish");
- err = true;
- }
- TCMAP *map = tcmapnew();
- iprintf("random writing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = sprintf(vbuf, "%d", myrand(rnum));
- switch(myrand(4)){
- case 0:
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
+}
+
+/* perform queue command */
+static int procqueue(const char *path, int rnum, int lmemb, int nmemb, int bnum,
+ int apow, int fpow, bool mt, TCCMP cmp, int opts,
+ int lcnum, int ncnum, int xmsiz, int dfunit, int lsmax, int capnum,
+ int omode) {
+ iprintf("<Queueing Test>\n seed=%u path=%s rnum=%d lmemb=%d nmemb=%d bnum=%d apow=%d"
+ " fpow=%d mt=%d cmp=%p opts=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d"
+ " lsmax=%d capnum=%d omode=%d\n\n",
+ g_randseed, path, rnum, lmemb, nmemb, bnum, apow, fpow, mt, (void *) (intptr_t) cmp,
+ opts, lcnum, ncnum, xmsiz, dfunit, lsmax, capnum, omode);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (mt && !tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
+ err = true;
+ }
+ if (cmp && !tcbdbsetcmpfunc(bdb, cmp, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcmpfunc");
+ err = true;
+ }
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
+ err = true;
+ }
+ if (!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)) {
+ eprint(bdb, __LINE__, "tcbdbtune");
+ err = true;
+ }
+ if (!tcbdbsetcache(bdb, lcnum, ncnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
+ err = true;
+ }
+ if (!tcbdbsetlsmax(bdb, lsmax)) {
+ eprint(bdb, __LINE__, "tcbdbsetlsmax");
+ err = true;
+ }
+ if (!tcbdbsetcapnum(bdb, capnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetcapnum");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ int deqfreq = (lmemb > 0) ? lmemb * 10 : 256;
+ BDBCUR *cur = tcbdbcurnew(bdb);
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len;
+ if (cmp == tccmpdecimal) {
+ len = sprintf(buf, "%d", i);
+ } else if (cmp == tccmpint32) {
+ int32_t lnum = i;
+ memcpy(buf, &lnum, sizeof (lnum));
+ len = sizeof (lnum);
+ } else if (cmp == tccmpint64) {
+ int64_t llnum = i;
+ memcpy(buf, &llnum, sizeof (llnum));
+ len = sizeof (llnum);
+ } else {
+ len = sprintf(buf, "%08d", i);
}
- tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 2:
- if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
+ if (!tcbdbput(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ break;
}
- tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
+ if (myrand(deqfreq) == 0) {
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ break;
+ }
+ int num = myrand(deqfreq * 2 + 1);
+ while (num >= 0) {
+ if (tcbdbcurout(cur)) {
+ num--;
+ } else {
+ if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurout");
+ err = true;
+ }
+ break;
+ }
+ }
+ if (err) break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcmapout(map, kbuf, ksiz);
- break;
}
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(myrand(4) == 0 && !tcbdbdefrag(bdb, 0)){
- eprint(bdb, __LINE__, "tcbdbdefrag");
- err = true;
- }
- if(myrand(4) == 0 && !tcbdbcacheclear(bdb)){
- eprint(bdb, __LINE__, "tcbdbcacheclear");
- err = true;
- }
- iprintf("checking transaction commit:\n");
- if(!tcbdbtranbegin(bdb)){
- eprint(bdb, __LINE__, "tcbdbtranbegin");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = sprintf(vbuf, "[%d]", myrand(rnum));
- switch(myrand(7)){
- case 0:
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ while (true) {
+ if (tcbdbcurout(cur)) continue;
+ if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurout");
+ err = true;
}
- tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
break;
- case 2:
- if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
+ }
+ tcbdbcurdel(cur);
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
+}
+
+/* perform misc command */
+static int procmisc(const char *path, int rnum, bool mt, int opts, int omode) {
+ iprintf("<Miscellaneous Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
+ g_randseed, path, rnum, mt, opts, omode);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (mt && !tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
+ err = true;
+ }
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
+ err = true;
+ }
+ if (!tcbdbtune(bdb, 10, 10, rnum / 50, 100, -1, opts)) {
+ eprint(bdb, __LINE__, "tcbdbtune");
+ err = true;
+ }
+ if (!tcbdbsetcache(bdb, 128, 256)) {
+ eprint(bdb, __LINE__, "tcbdbsetcache");
+ err = true;
+ }
+ if (!tcbdbsetxmsiz(bdb, rnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
+ err = true;
+ }
+ if (!tcbdbsetdfunit(bdb, 8)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ if (1) {
+ TCBDB *bdbdup = tcbdbnew();
+ if (tcbdbopen(bdbdup, path, BDBOREADER)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ } else if (tcbdbecode(bdbdup) != TCETHREAD) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
}
- tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- if(tcbdbaddint(bdb, kbuf, ksiz, 1) == INT_MIN && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbaddint");
- err = true;
+ tcbdbdel(bdbdup);
+ }
+ iprintf("writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", i);
+ if (!tcbdbputkeep(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ break;
}
- tcmapaddint(map, kbuf, ksiz, 1);
- break;
- case 4:
- if(isnan(tcbdbadddouble(bdb, kbuf, ksiz, 1.0)) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbadddouble");
- err = true;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcmapadddouble(map, kbuf, ksiz, 1.0);
- break;
- case 5:
- if(myrand(2) == 0){
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tcbdbputproc(bdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
- tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputproc");
+ }
+ iprintf("reading:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", i);
+ int vsiz;
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
+ eprint(bdb, __LINE__, "tcbdbget");
err = true;
- }
- tcmapputproc(map, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op);
- } else {
- vsiz = myrand(10);
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tcbdbputproc(bdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
- tcbdbecode(bdb) != TCEKEEP && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbputproc");
+ break;
+ } else if (vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
err = true;
- }
- tcmapputproc(map, kbuf, ksiz, NULL, vsiz, pdprocfunc, op);
+ tcfree(vbuf);
+ break;
}
- break;
- case 6:
- if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
+ tcfree(vbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcmapout(map, kbuf, ksiz);
- break;
}
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tcbdbtrancommit(bdb)){
- eprint(bdb, __LINE__, "tcbdbtrancommit");
- err = true;
- }
- iprintf("checking transaction abort:\n");
- uint64_t ornum = tcbdbrnum(bdb);
- uint64_t ofsiz = tcbdbfsiz(bdb);
- if(!tcbdbtranbegin(bdb)){
- eprint(bdb, __LINE__, "tcbdbtranbegin");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = sprintf(vbuf, "((%d))", myrand(rnum));
- switch(myrand(8)){
- case 0:
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
+ if (tcbdbrnum(bdb) != rnum) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ iprintf("random writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '*', vsiz);
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ break;
}
- break;
- case 1:
- if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
+ int rsiz;
+ char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
+ if (!rbuf) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ break;
}
- break;
- case 2:
- if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
+ if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(rbuf);
+ break;
}
- break;
- case 3:
- if(!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputdup");
- err = true;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- break;
- case 4:
- if(tcbdbaddint(bdb, kbuf, ksiz, 1) == INT_MIN && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbaddint");
- err = true;
+ tcfree(rbuf);
+ }
+ iprintf("word writing:\n");
+ const char *words[] = {
+ "a", "A", "bb", "BB", "ccc", "CCC", "dddd", "DDDD", "eeeee", "EEEEEE",
+ "mikio", "hirabayashi", "tokyo", "cabinet", "hyper", "estraier", "19780211", "birth day",
+ "one", "first", "two", "second", "three", "third", "four", "fourth", "five", "fifth",
+ "_[1]_", "uno", "_[2]_", "dos", "_[3]_", "tres", "_[4]_", "cuatro", "_[5]_", "cinco",
+ "[\xe5\xb9\xb3\xe6\x9e\x97\xe5\xb9\xb9\xe9\x9b\x84]", "[\xe9\xa6\xac\xe9\xb9\xbf]", NULL
+ };
+ for (int i = 0; words[i] != NULL; i += 2) {
+ const char *kbuf = words[i];
+ int ksiz = strlen(kbuf);
+ const char *vbuf = words[i + 1];
+ int vsiz = strlen(vbuf);
+ if (!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ break;
}
- break;
- case 5:
- if(isnan(tcbdbadddouble(bdb, kbuf, ksiz, 1.0)) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbadddouble");
- err = true;
+ if (rnum > 250) iputchar('.');
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", (int) (sizeof (words) / sizeof (*words)));
+ iprintf("random erasing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ if (!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ break;
}
- break;
- case 6:
- if(myrand(2) == 0){
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tcbdbputproc(bdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
- tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputproc");
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "[%d]", i);
+ char vbuf[RECBUFSIZ];
+ int vsiz = i % RECBUFSIZ;
+ memset(vbuf, '*', vsiz);
+ if (!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
err = true;
- }
+ break;
+ }
+ if (vsiz < 1) {
+ char tbuf[PATH_MAX];
+ for (int j = 0; j < PATH_MAX; j++) {
+ tbuf[j] = myrand(0x100);
+ }
+ if (!tcbdbput(bdb, kbuf, ksiz, tbuf, PATH_MAX)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ break;
+ }
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("erasing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ if (i % 2 == 1) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "[%d]", i);
+ if (!tcbdbout(bdb, kbuf, ksiz)) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ break;
+ }
+ if (tcbdbout(bdb, kbuf, ksiz) || tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ break;
+ }
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("random writing and reopening:\n");
+ for (int i = 1; i <= rnum; i++) {
+ if (myrand(10) == 0) {
+ int ksiz, vsiz;
+ char *kbuf, *vbuf;
+ ksiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
+ kbuf = tcmalloc(ksiz + 1);
+ for (int j = 0; j < ksiz; j++) {
+ kbuf[j] = 128 + myrand(128);
+ }
+ vsiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
+ vbuf = tcmalloc(vsiz + 1);
+ for (int j = 0; j < vsiz; j++) {
+ vbuf[j] = myrand(256);
+ }
+ switch (myrand(5)) {
+ case 0:
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputdup");
+ err = true;
+ }
+ break;
+ case 3:
+ if (!tcbdbputdupback(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputdupback");
+ err = true;
+ }
+ break;
+ default:
+ if (!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ break;
+ }
+ tcfree(vbuf);
+ tcfree(kbuf);
} else {
- vsiz = myrand(10);
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tcbdbputproc(bdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
- tcbdbecode(bdb) != TCEKEEP && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbputproc");
- err = true;
- }
+ char kbuf[RECBUFSIZ];
+ int ksiz = myrand(RECBUFSIZ);
+ memset(kbuf, '@', ksiz);
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '@', vsiz);
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ break;
+ }
}
- break;
- case 7:
- if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- break;
}
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tcbdbtranabort(bdb)){
- eprint(bdb, __LINE__, "tcbdbtranabort");
- err = true;
- }
- iprintf("checking consistency:\n");
- if(tcbdbrnum(bdb) != ornum || tcbdbfsiz(bdb) != ofsiz || tcbdbrnum(bdb) != tcmaprnum(map)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- inum = 0;
- tcmapiterinit(map);
- const char *tkbuf;
- int tksiz;
- for(int i = 1; (tkbuf = tcmapiternext(map, &tksiz)) != NULL; i++, inum++){
- int tvsiz;
- const char *tvbuf = tcmapiterval(tkbuf, &tvsiz);
- int rsiz;
- char *rbuf = tcbdbget(bdb, tkbuf, tksiz, &rsiz);
- if(!rbuf || rsiz != tvsiz || memcmp(rbuf, tvbuf, rsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- tcfree(rbuf);
- break;
- }
- tcfree(rbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- inum = 0;
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- for(int i = 1; (kbuf = tcbdbcurkey(cur, &ksiz)) != NULL; i++, inum++){
- int vsiz;
- char *vbuf = tcbdbcurval(cur, &vsiz);
- int rsiz;
- const char *rbuf = tcmapget(map, kbuf, ksiz, &rsiz);
- if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- tcfree(vbuf);
- tcfree(kbuf);
- break;
- }
- tcfree(vbuf);
- tcfree(kbuf);
- tcbdbcurnext(cur);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- tcmapdel(map);
- if(!tcbdbvanish(bdb)){
- eprint(bdb, __LINE__, "tcbdbvanish");
- err = true;
- }
- if(!tcbdbtranbegin(bdb)){
- eprint(bdb, __LINE__, "tcbdbtranbegin");
- err = true;
- }
- if(!tcbdbput2(bdb, "mikio", "hirabayashi")){
- eprint(bdb, __LINE__, "tcbdbput2");
- err = true;
- }
- for(int i = 0; i < 10; i++){
- char buf[RECBUFSIZ];
- int size = sprintf(buf, "%d", myrand(rnum));
- if(!tcbdbput(bdb, buf, size, buf, size)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- }
- for(int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)){
- char vbuf[i];
- memset(vbuf, '@', i - 1);
- vbuf[i-1] = '\0';
- if(!tcbdbput2(bdb, "mikio", vbuf)){
- eprint(bdb, __LINE__, "tcbdbput2");
- err = true;
- }
- }
- if(!tcbdbforeach(bdb, iterfunc, NULL)){
- eprint(bdb, __LINE__, "tcbdbforeach");
- err = true;
- }
- tcbdbcurdel(cur);
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
-}
-
-
-/* perform wicked command */
-static int procwicked(const char *path, int rnum, bool mt, int opts, int omode){
- iprintf("<Wicked Writing Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
- g_randseed, path, rnum, mt, opts, omode);
- bool err = false;
- double stime = tctime();
- TCBDB *bdb = tcbdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
- if(mt && !tcbdbsetmutex(bdb)){
- eprint(bdb, __LINE__, "tcbdbsetmutex");
- err = true;
- }
- if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbtune(bdb, 10, 10, rnum / 50, 100, -1, opts)){
- eprint(bdb, __LINE__, "tcbdbtune");
- err = true;
- }
- if(!tcbdbsetcache(bdb, 128, 256)){
- eprint(bdb, __LINE__, "tcbdbsetcache");
- err = true;
- }
- if(!tcbdbsetxmsiz(bdb, rnum)){
- eprint(bdb, __LINE__, "tcbdbsetxmsiz");
- err = true;
- }
- if(!tcbdbsetdfunit(bdb, 8)){
- eprint(bdb, __LINE__, "tcbdbsetdfunit");
- err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- BDBCUR *cur = tcbdbcurnew(bdb);
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- TCMAP *map = tcmapnew2(rnum / 5);
- for(int i = 1; i <= rnum && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '*', vsiz);
- vbuf[vsiz] = '\0';
- char *rbuf;
- switch(myrand(16)){
- case 0:
- iputchar('0');
- if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- iputchar('1');
- if(!tcbdbput2(bdb, kbuf, vbuf)){
- eprint(bdb, __LINE__, "tcbdbput2");
- err = true;
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ iprintf("checking:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "[%d]", i);
+ int vsiz;
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
+ if (i % 2 == 0) {
+ if (!vbuf) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ break;
+ }
+ if (vsiz != i % RECBUFSIZ && vsiz != PATH_MAX) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(vbuf);
+ break;
+ }
+ } else {
+ if (vbuf || tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(vbuf);
+ break;
+ }
}
- tcmapput2(map, kbuf, vbuf);
- break;
- case 2:
- iputchar('2');
- if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep");
- err = true;
+ tcfree(vbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- iputchar('3');
- if(!tcbdbputkeep2(bdb, kbuf, vbuf) && tcbdbecode(bdb) != TCEKEEP){
- eprint(bdb, __LINE__, "tcbdbputkeep2");
- err = true;
+ }
+ iprintf("writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", i);
+ if (!tcbdbput(bdb, buf, len, buf, len)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ break;
}
- tcmapputkeep2(map, kbuf, vbuf);
- break;
- case 4:
- iputchar('4');
- if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbputcat");
- err = true;
+ if (i % 10 == 0) {
+ TCLIST *vals = tclistnew();
+ for (int j = myrand(5) + 1; j >= 0; j--) {
+ tclistpush(vals, buf, len);
+ }
+ if (!tcbdbputdup3(bdb, buf, len, vals)) {
+ eprint(bdb, __LINE__, "tcbdbput3");
+ err = true;
+ break;
+ }
+ tclistdel(vals);
}
- tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 5:
- iputchar('5');
- if(!tcbdbputcat2(bdb, kbuf, vbuf)){
- eprint(bdb, __LINE__, "tcbdbputcat2");
- err = true;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcmapputcat2(map, kbuf, vbuf);
- break;
- case 6:
- iputchar('6');
- if(myrand(10) == 0){
- if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
+ }
+ iprintf("reading:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", i);
+ int vsiz;
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ break;
+ } else if (vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
err = true;
- }
- tcmapout(map, kbuf, ksiz);
+ tcfree(vbuf);
+ break;
}
- break;
- case 7:
- iputchar('7');
- if(myrand(10) == 0){
- if(!tcbdbout2(bdb, kbuf) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout2");
+ tcfree(vbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("checking words:\n");
+ for (int i = 0; words[i] != NULL; i += 2) {
+ const char *kbuf = words[i];
+ int ksiz = strlen(kbuf);
+ const char *vbuf = words[i + 1];
+ int vsiz = strlen(vbuf);
+ int rsiz;
+ char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
+ if (!rbuf) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ break;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
err = true;
- }
- tcmapout2(map, kbuf);
+ tcfree(rbuf);
+ break;
}
- break;
- case 8:
- iputchar('8');
- if(!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz))){
- if(tcbdbecode(bdb) != TCENOREC){
+ tcfree(rbuf);
+ if (rnum > 250) iputchar('.');
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", (int) (sizeof (words) / sizeof (*words)));
+ iprintf("checking cursor:\n");
+ BDBCUR *cur = tcbdbcurnew(bdb);
+ int inum = 0;
+ if (!tcbdbcurfirst(cur)) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ char *kbuf;
+ int ksiz;
+ for (int i = 1; (kbuf = tcbdbcurkey(cur, &ksiz)) != NULL; i++, inum++) {
+ int vsiz;
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
eprint(bdb, __LINE__, "tcbdbget");
err = true;
- }
- rbuf = tcsprintf("[%d]", myrand(i + 1));
- vsiz = strlen(rbuf);
+ tcfree(kbuf);
+ break;
}
- vsiz += myrand(vsiz);
- if(myrand(3) == 0) vsiz += PATH_MAX;
- rbuf = tcrealloc(rbuf, vsiz + 1);
- for(int j = 0; j < vsiz; j++){
- rbuf[j] = myrand(0x100);
+ tcfree(vbuf);
+ tcfree(kbuf);
+ tcbdbcurnext(cur);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- if(!tcbdbput(bdb, kbuf, ksiz, rbuf, vsiz)){
- eprint(bdb, __LINE__, "tcbdbput");
- err = true;
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ if (tcbdbecode(bdb) != TCENOREC || inum != tcbdbrnum(bdb)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ iprintf("cursor updating:\n");
+ if (!tcbdbcurfirst(cur)) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ inum = 0;
+ for (int i = 1; !err && (kbuf = tcbdbcurkey(cur, &ksiz)) != NULL; i++, inum++) {
+ switch (myrand(6)) {
+ case 0:
+ if (!tcbdbputdup(bdb, kbuf, ksiz, "0123456789", 10)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcbdbout(bdb, kbuf, ksiz)) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tcbdbcurput(cur, kbuf, ksiz, BDBCPCURRENT)) {
+ eprint(bdb, __LINE__, "tcbdbcurput");
+ err = true;
+ }
+ break;
+ case 3:
+ if (!tcbdbcurput(cur, kbuf, ksiz, BDBCPBEFORE)) {
+ eprint(bdb, __LINE__, "tcbdbcurput");
+ err = true;
+ }
+ break;
+ case 4:
+ if (!tcbdbcurput(cur, kbuf, ksiz, BDBCPAFTER)) {
+ eprint(bdb, __LINE__, "tcbdbcurput");
+ err = true;
+ }
+ break;
+ default:
+ if (!tcbdbcurout(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurout");
+ err = true;
+ }
+ break;
}
- tcmapput(map, kbuf, ksiz, rbuf, vsiz);
- tcfree(rbuf);
- break;
- case 9:
- iputchar('9');
- if(!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz)) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
+ tcfree(kbuf);
+ tcbdbcurnext(cur);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcfree(rbuf);
- break;
- case 10:
- iputchar('A');
- if(!(rbuf = tcbdbget2(bdb, kbuf)) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbget2");
- err = true;
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ if (myrand(10) == 0 && !tcbdbsync(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsync");
+ err = true;
+ }
+ iprintf("cursor updating from empty:\n");
+ tcbdbcurfirst(cur);
+ inum = 0;
+ for (int i = 1; (kbuf = tcbdbcurkey(cur, &ksiz)) != NULL; i++, inum++) {
+ tcfree(kbuf);
+ if (!tcbdbcurout(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurout");
+ err = true;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ if (tcbdbrnum(bdb) != 0) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ if (!tcbdbput2(bdb, "one", "first")) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ if (!tcbdbcurlast(cur)) {
+ eprint(bdb, __LINE__, "tcbdbcurlast");
+ err = true;
+ }
+ if (!tcbdbcurput2(cur, "second", BDBCPCURRENT) || !tcbdbcurput2(cur, "first", BDBCPBEFORE) ||
+ !tcbdbcurput2(cur, "zero", BDBCPBEFORE) || !tcbdbcurput2(cur, "top", BDBCPBEFORE)) {
+ eprint(bdb, __LINE__, "tcbdbcurput2");
+ err = true;
+ }
+ if (!tcbdbcurlast(cur)) {
+ eprint(bdb, __LINE__, "tcbdbcurlast");
+ err = true;
+ }
+ if (!tcbdbcurput2(cur, "third", BDBCPAFTER) || !tcbdbcurput2(cur, "fourth", BDBCPAFTER) ||
+ !tcbdbcurput2(cur, "end", BDBCPCURRENT) || !tcbdbcurput2(cur, "bottom", BDBCPAFTER)) {
+ eprint(bdb, __LINE__, "tcbdbcurput2");
+ err = true;
+ }
+ if (!tcbdbvanish(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbvanish");
+ err = true;
+ }
+ TCMAP *map = tcmapnew();
+ iprintf("random writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = sprintf(vbuf, "%d", myrand(rnum));
+ switch (myrand(4)) {
+ case 0:
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ if (!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ }
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 2:
+ if (!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ if (!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (myrand(4) == 0 && !tcbdbdefrag(bdb, 0)) {
+ eprint(bdb, __LINE__, "tcbdbdefrag");
+ err = true;
+ }
+ if (myrand(4) == 0 && !tcbdbcacheclear(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbcacheclear");
+ err = true;
+ }
+ iprintf("checking transaction commit:\n");
+ if (!tcbdbtranbegin(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbtranbegin");
+ err = true;
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = sprintf(vbuf, "[%d]", myrand(rnum));
+ switch (myrand(7)) {
+ case 0:
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ if (!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ }
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 2:
+ if (!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ if (tcbdbaddint(bdb, kbuf, ksiz, 1) == INT_MIN && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbaddint");
+ err = true;
+ }
+ tcmapaddint(map, kbuf, ksiz, 1);
+ break;
+ case 4:
+ if (isnan(tcbdbadddouble(bdb, kbuf, ksiz, 1.0)) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbadddouble");
+ err = true;
+ }
+ tcmapadddouble(map, kbuf, ksiz, 1.0);
+ break;
+ case 5:
+ if (myrand(2) == 0) {
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tcbdbputproc(bdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
+ tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputproc");
+ err = true;
+ }
+ tcmapputproc(map, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op);
+ } else {
+ vsiz = myrand(10);
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tcbdbputproc(bdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
+ tcbdbecode(bdb) != TCEKEEP && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbputproc");
+ err = true;
+ }
+ tcmapputproc(map, kbuf, ksiz, NULL, vsiz, pdprocfunc, op);
+ }
+ break;
+ case 6:
+ if (!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (!tcbdbtrancommit(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbtrancommit");
+ err = true;
+ }
+ iprintf("checking transaction abort:\n");
+ uint64_t ornum = tcbdbrnum(bdb);
+ uint64_t ofsiz = tcbdbfsiz(bdb);
+ if (!tcbdbtranbegin(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbtranbegin");
+ err = true;
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = sprintf(vbuf, "((%d))", myrand(rnum));
+ switch (myrand(8)) {
+ case 0:
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ break;
+ case 3:
+ if (!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputdup");
+ err = true;
+ }
+ break;
+ case 4:
+ if (tcbdbaddint(bdb, kbuf, ksiz, 1) == INT_MIN && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbaddint");
+ err = true;
+ }
+ break;
+ case 5:
+ if (isnan(tcbdbadddouble(bdb, kbuf, ksiz, 1.0)) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbadddouble");
+ err = true;
+ }
+ break;
+ case 6:
+ if (myrand(2) == 0) {
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tcbdbputproc(bdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
+ tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputproc");
+ err = true;
+ }
+ } else {
+ vsiz = myrand(10);
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tcbdbputproc(bdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
+ tcbdbecode(bdb) != TCEKEEP && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbputproc");
+ err = true;
+ }
+ }
+ break;
+ case 7:
+ if (!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (!tcbdbtranabort(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbtranabort");
+ err = true;
+ }
+ iprintf("checking consistency:\n");
+ if (tcbdbrnum(bdb) != ornum || tcbdbfsiz(bdb) != ofsiz || tcbdbrnum(bdb) != tcmaprnum(map)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ inum = 0;
+ tcmapiterinit(map);
+ const char *tkbuf;
+ int tksiz;
+ for (int i = 1; (tkbuf = tcmapiternext(map, &tksiz)) != NULL; i++, inum++) {
+ int tvsiz;
+ const char *tvbuf = tcmapiterval(tkbuf, &tvsiz);
+ int rsiz;
+ char *rbuf = tcbdbget(bdb, tkbuf, tksiz, &rsiz);
+ if (!rbuf || rsiz != tvsiz || memcmp(rbuf, tvbuf, rsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(rbuf);
+ break;
}
tcfree(rbuf);
- break;
- case 11:
- iputchar('B');
- if(myrand(1) == 0) vsiz = 1;
- if(!tcbdbget3(bdb, kbuf, ksiz, &vsiz) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbget3");
- err = true;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- break;
- case 12:
- iputchar('C');
- if(myrand(rnum / 50) == 0){
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ inum = 0;
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ for (int i = 1; (kbuf = tcbdbcurkey(cur, &ksiz)) != NULL; i++, inum++) {
+ int vsiz;
+ char *vbuf = tcbdbcurval(cur, &vsiz);
+ int rsiz;
+ const char *rbuf = tcmapget(map, kbuf, ksiz, &rsiz);
+ if (!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
err = true;
- }
- }
- TCXSTR *ikey = tcxstrnew();
- TCXSTR *ival = tcxstrnew();
- for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
- if(j % 3 == 0){
- if(tcbdbcurrec(cur, ikey, ival)){
- if(tcbdbvnum(bdb, tcxstrptr(ikey), tcxstrsize(ikey)) != 1){
- eprint(bdb, __LINE__, "(validation)");
+ tcfree(vbuf);
+ tcfree(kbuf);
+ break;
+ }
+ tcfree(vbuf);
+ tcfree(kbuf);
+ tcbdbcurnext(cur);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ tcmapdel(map);
+ if (!tcbdbvanish(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbvanish");
+ err = true;
+ }
+ if (!tcbdbtranbegin(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbtranbegin");
+ err = true;
+ }
+ if (!tcbdbput2(bdb, "mikio", "hirabayashi")) {
+ eprint(bdb, __LINE__, "tcbdbput2");
+ err = true;
+ }
+ for (int i = 0; i < 10; i++) {
+ char buf[RECBUFSIZ];
+ int size = sprintf(buf, "%d", myrand(rnum));
+ if (!tcbdbput(bdb, buf, size, buf, size)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ }
+ for (int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)) {
+ char vbuf[i];
+ memset(vbuf, '@', i - 1);
+ vbuf[i - 1] = '\0';
+ if (!tcbdbput2(bdb, "mikio", vbuf)) {
+ eprint(bdb, __LINE__, "tcbdbput2");
+ err = true;
+ }
+ }
+ if (!tcbdbforeach(bdb, iterfunc, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbforeach");
+ err = true;
+ }
+ tcbdbcurdel(cur);
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
+}
+
+/* perform wicked command */
+static int procwicked(const char *path, int rnum, bool mt, int opts, int omode) {
+ iprintf("<Wicked Writing Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
+ g_randseed, path, rnum, mt, opts, omode);
+ bool err = false;
+ double stime = tctime();
+ TCBDB *bdb = tcbdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcbdbsetdbgfd(bdb, g_dbgfd);
+ if (mt && !tcbdbsetmutex(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
+ err = true;
+ }
+ if (!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
+ err = true;
+ }
+ if (!tcbdbtune(bdb, 10, 10, rnum / 50, 100, -1, opts)) {
+ eprint(bdb, __LINE__, "tcbdbtune");
+ err = true;
+ }
+ if (!tcbdbsetcache(bdb, 128, 256)) {
+ eprint(bdb, __LINE__, "tcbdbsetcache");
+ err = true;
+ }
+ if (!tcbdbsetxmsiz(bdb, rnum)) {
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
+ err = true;
+ }
+ if (!tcbdbsetdfunit(bdb, 8)) {
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
+ err = true;
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
+ err = true;
+ }
+ BDBCUR *cur = tcbdbcurnew(bdb);
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ TCMAP *map = tcmapnew2(rnum / 5);
+ for (int i = 1; i <= rnum && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '*', vsiz);
+ vbuf[vsiz] = '\0';
+ char *rbuf;
+ switch (myrand(16)) {
+ case 0:
+ iputchar('0');
+ if (!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ iputchar('1');
+ if (!tcbdbput2(bdb, kbuf, vbuf)) {
+ eprint(bdb, __LINE__, "tcbdbput2");
+ err = true;
+ }
+ tcmapput2(map, kbuf, vbuf);
+ break;
+ case 2:
+ iputchar('2');
+ if (!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep");
+ err = true;
+ }
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ iputchar('3');
+ if (!tcbdbputkeep2(bdb, kbuf, vbuf) && tcbdbecode(bdb) != TCEKEEP) {
+ eprint(bdb, __LINE__, "tcbdbputkeep2");
+ err = true;
+ }
+ tcmapputkeep2(map, kbuf, vbuf);
+ break;
+ case 4:
+ iputchar('4');
+ if (!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbputcat");
+ err = true;
+ }
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 5:
+ iputchar('5');
+ if (!tcbdbputcat2(bdb, kbuf, vbuf)) {
+ eprint(bdb, __LINE__, "tcbdbputcat2");
+ err = true;
+ }
+ tcmapputcat2(map, kbuf, vbuf);
+ break;
+ case 6:
+ iputchar('6');
+ if (myrand(10) == 0) {
+ if (!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ }
+ break;
+ case 7:
+ iputchar('7');
+ if (myrand(10) == 0) {
+ if (!tcbdbout2(bdb, kbuf) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout2");
+ err = true;
+ }
+ tcmapout2(map, kbuf);
+ }
+ break;
+ case 8:
+ iputchar('8');
+ if (!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz))) {
+ if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ }
+ rbuf = tcsprintf("[%d]", myrand(i + 1));
+ vsiz = strlen(rbuf);
+ }
+ vsiz += myrand(vsiz);
+ if (myrand(3) == 0) vsiz += PATH_MAX;
+ rbuf = tcrealloc(rbuf, vsiz + 1);
+ for (int j = 0; j < vsiz; j++) {
+ rbuf[j] = myrand(0x100);
+ }
+ if (!tcbdbput(bdb, kbuf, ksiz, rbuf, vsiz)) {
+ eprint(bdb, __LINE__, "tcbdbput");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, rbuf, vsiz);
+ tcfree(rbuf);
+ break;
+ case 9:
+ iputchar('9');
+ if (!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz)) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 10:
+ iputchar('A');
+ if (!(rbuf = tcbdbget2(bdb, kbuf)) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget2");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 11:
+ iputchar('B');
+ if (myrand(1) == 0) vsiz = 1;
+ if (!tcbdbget3(bdb, kbuf, ksiz, &vsiz) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbget3");
+ err = true;
+ }
+ break;
+ case 12:
+ iputchar('C');
+ if (myrand(rnum / 50) == 0) {
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ }
+ TCXSTR *ikey = tcxstrnew();
+ TCXSTR *ival = tcxstrnew();
+ for (int j = myrand(rnum) / 1000 + 1; j >= 0; j--) {
+ if (j % 3 == 0) {
+ if (tcbdbcurrec(cur, ikey, ival)) {
+ if (tcbdbvnum(bdb, tcxstrptr(ikey), tcxstrsize(ikey)) != 1) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ if (tcxstrsize(ival) != tcbdbvsiz(bdb, tcxstrptr(ikey), tcxstrsize(ikey))) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ } else {
+ int ecode = tcbdbecode(bdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurrec");
+ err = true;
+ }
+ }
+ } else {
+ int iksiz;
+ char *ikbuf = tcbdbcurkey(cur, &iksiz);
+ if (ikbuf) {
+ tcfree(ikbuf);
+ } else {
+ int ecode = tcbdbecode(bdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurkey");
+ err = true;
+ }
+ }
+ }
+ tcbdbcurnext(cur);
+ }
+ tcxstrdel(ival);
+ tcxstrdel(ikey);
+ break;
+ default:
+ iputchar('@');
+ if (myrand(10000) == 0) srand((unsigned int) (tctime() * 1000) % UINT_MAX);
+ if (myrand(rnum / 32 + 1) == 0) {
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ int cnt = myrand(30);
+ for (int j = 0; j < rnum && !err; j++) {
+ ksiz = sprintf(kbuf, "%d", i + j);
+ if (myrand(4) == 0) {
+ if (tcbdbout3(bdb, kbuf, ksiz)) {
+ cnt--;
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout3");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ } else if (myrand(30) == 0) {
+ int tksiz;
+ char *tkbuf = tcbdbcurkey(cur, &tksiz);
+ if (tkbuf) {
+ if (tcbdbcurout(cur)) {
+ cnt--;
+ } else {
+ eprint(bdb, __LINE__, "tcbdbcurout");
+ err = true;
+ }
+ tcmapout(map, tkbuf, tksiz);
+ tcfree(tkbuf);
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurkey");
+ err = true;
+ }
+ } else {
+ if (tcbdbout(bdb, kbuf, ksiz)) {
+ cnt--;
+ } else if (tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ }
+ if (cnt < 0) break;
+ }
+ }
+ break;
+ }
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ if (i == rnum / 2) {
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
err = true;
- }
- if(tcxstrsize(ival) != tcbdbvsiz(bdb, tcxstrptr(ikey), tcxstrsize(ikey))){
- eprint(bdb, __LINE__, "(validation)");
+ }
+ if (!tcbdbopen(bdb, path, BDBOWRITER | omode)) {
+ eprint(bdb, __LINE__, "tcbdbopen");
err = true;
- }
- } else {
- int ecode = tcbdbecode(bdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurrec");
+ }
+ } else if (i == rnum / 4) {
+ char *npath = tcsprintf("%s-tmp", path);
+ if (!tcbdbcopy(bdb, npath)) {
+ eprint(bdb, __LINE__, "tcbdbcopy");
err = true;
- }
}
- } else {
- int iksiz;
- char *ikbuf = tcbdbcurkey(cur, &iksiz);
- if(ikbuf){
- tcfree(ikbuf);
- } else {
- int ecode = tcbdbecode(bdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurkey");
+ TCBDB *nbdb = tcbdbnew();
+ if (!tcbdbsetcodecfunc(nbdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(nbdb, __LINE__, "tcbdbsetcodecfunc");
err = true;
- }
}
- }
- tcbdbcurnext(cur);
- }
- tcxstrdel(ival);
- tcxstrdel(ikey);
- break;
- default:
- iputchar('@');
- if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
- if(myrand(rnum / 32 + 1) == 0){
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- int cnt = myrand(30);
- for(int j = 0; j < rnum && !err; j++){
- ksiz = sprintf(kbuf, "%d", i + j);
- if(myrand(4) == 0){
- if(tcbdbout3(bdb, kbuf, ksiz)){
- cnt--;
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout3");
+ if (!tcbdbopen(nbdb, npath, BDBOREADER | omode)) {
+ eprint(nbdb, __LINE__, "tcbdbopen");
err = true;
- }
- tcmapout(map, kbuf, ksiz);
- } else if(myrand(30) == 0){
- int tksiz;
- char *tkbuf = tcbdbcurkey(cur, &tksiz);
- if(tkbuf){
- if(tcbdbcurout(cur)){
- cnt--;
- } else {
- eprint(bdb, __LINE__, "tcbdbcurout");
- err = true;
- }
- tcmapout(map, tkbuf, tksiz);
- tcfree(tkbuf);
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurkey");
+ }
+ tcbdbdel(nbdb);
+ unlink(npath);
+ tcfree(npath);
+ if (!tcbdboptimize(bdb, -1, -1, -1, -1, -1, -1)) {
+ eprint(bdb, __LINE__, "tcbdboptimize");
err = true;
- }
- } else {
- if(tcbdbout(bdb, kbuf, ksiz)){
- cnt--;
- } else if(tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbout");
+ }
+ if (!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
+ err = true;
+ }
+ } else if (i == rnum / 8) {
+ if (!tcbdbtranbegin(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbtranbegin");
+ err = true;
+ }
+ } else if (i == rnum / 8 + rnum / 16) {
+ if (!tcbdbtrancommit(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbtrancommit");
err = true;
- }
- tcmapout(map, kbuf, ksiz);
}
- if(cnt < 0) break;
- }
}
- break;
}
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- if(i == rnum / 2){
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
+ if (rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
+ if (!tcbdbsync(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbsync");
err = true;
- }
- if(!tcbdbopen(bdb, path, BDBOWRITER | omode)){
- eprint(bdb, __LINE__, "tcbdbopen");
- err = true;
- }
- } else if(i == rnum / 4){
- char *npath = tcsprintf("%s-tmp", path);
- if(!tcbdbcopy(bdb, npath)){
- eprint(bdb, __LINE__, "tcbdbcopy");
- err = true;
- }
- TCBDB *nbdb = tcbdbnew();
- if(!tcbdbsetcodecfunc(nbdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(nbdb, __LINE__, "tcbdbsetcodecfunc");
- err = true;
- }
- if(!tcbdbopen(nbdb, npath, BDBOREADER | omode)){
- eprint(nbdb, __LINE__, "tcbdbopen");
- err = true;
- }
- tcbdbdel(nbdb);
- unlink(npath);
- tcfree(npath);
- if(!tcbdboptimize(bdb, -1, -1, -1, -1, -1, -1)){
- eprint(bdb, __LINE__, "tcbdboptimize");
- err = true;
- }
- if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
- eprint(bdb, __LINE__, "tcbdbcurfirst");
- err = true;
- }
- } else if(i == rnum / 8){
- if(!tcbdbtranbegin(bdb)){
- eprint(bdb, __LINE__, "tcbdbtranbegin");
- err = true;
- }
- } else if(i == rnum / 8 + rnum / 16){
- if(!tcbdbtrancommit(bdb)){
- eprint(bdb, __LINE__, "tcbdbtrancommit");
- err = true;
- }
- }
- }
- if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
- if(!tcbdbsync(bdb)){
- eprint(bdb, __LINE__, "tcbdbsync");
- err = true;
- }
- if(tcbdbrnum(bdb) != tcmaprnum(map)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- for(int i = 1; i <= rnum && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", i - 1);
- int vsiz;
- const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
- int rsiz;
- char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
- if(vbuf){
- iputchar('.');
- if(!rbuf){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
+ }
+ if (tcbdbrnum(bdb) != tcmaprnum(map)) {
eprint(bdb, __LINE__, "(validation)");
err = true;
- }
- } else {
- iputchar('*');
- if(rbuf || tcbdbecode(bdb) != TCENOREC){
+ }
+ for (int i = 1; i <= rnum && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", i - 1);
+ int vsiz;
+ const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
+ int rsiz;
+ char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
+ if (vbuf) {
+ iputchar('.');
+ if (!rbuf) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ } else {
+ iputchar('*');
+ if (rbuf || tcbdbecode(bdb) != TCENOREC) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ tcfree(rbuf);
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ }
+ if (rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
+ tcmapiterinit(map);
+ int ksiz;
+ const char *kbuf;
+ for (int i = 1; (kbuf = tcmapiternext(map, &ksiz)) != NULL; i++) {
+ iputchar('+');
+ int vsiz;
+ const char *vbuf = tcmapiterval(kbuf, &vsiz);
+ int rsiz;
+ char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
+ if (!rbuf) {
+ eprint(bdb, __LINE__, "tcbdbget");
+ err = true;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(bdb, __LINE__, "(validation)");
+ err = true;
+ }
+ tcfree(rbuf);
+ if (!tcbdbout(bdb, kbuf, ksiz)) {
+ eprint(bdb, __LINE__, "tcbdbout");
+ err = true;
+ }
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ }
+ int mrnum = tcmaprnum(map);
+ if (mrnum % 50 > 0) iprintf(" (%08d)\n", mrnum);
+ if (tcbdbrnum(bdb) != 0) {
eprint(bdb, __LINE__, "(validation)");
err = true;
- }
- }
- tcfree(rbuf);
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- }
- if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
- tcmapiterinit(map);
- int ksiz;
- const char *kbuf;
- for(int i = 1; (kbuf = tcmapiternext(map, &ksiz)) != NULL; i++){
- iputchar('+');
- int vsiz;
- const char *vbuf = tcmapiterval(kbuf, &vsiz);
- int rsiz;
- char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
- if(!rbuf){
- eprint(bdb, __LINE__, "tcbdbget");
- err = true;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- tcfree(rbuf);
- if(!tcbdbout(bdb, kbuf, ksiz)){
- eprint(bdb, __LINE__, "tcbdbout");
- err = true;
- }
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- }
- int mrnum = tcmaprnum(map);
- if(mrnum % 50 > 0) iprintf(" (%08d)\n", mrnum);
- if(tcbdbrnum(bdb) != 0){
- eprint(bdb, __LINE__, "(validation)");
- err = true;
- }
- tcbdbcurdel(cur);
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcbdbrnum(bdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcbdbfsiz(bdb));
- mprint(bdb);
- sysprint();
- tcmapdel(map);
- if(!tcbdbclose(bdb)){
- eprint(bdb, __LINE__, "tcbdbclose");
- err = true;
- }
- tcbdbdel(bdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ tcbdbcurdel(cur);
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcbdbrnum(bdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcbdbfsiz(bdb));
+ mprint(bdb);
+ sysprint();
+ tcmapdel(map);
+ if (!tcbdbclose(bdb)) {
+ eprint(bdb, __LINE__, "tcbdbclose");
+ err = true;
+ }
+ tcbdbdel(bdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
/* global variables */
const char *g_progname; // program name
-HANDLE g_dbgfd; // debugging output
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
/* global variables */
const char *g_progname; // program name
unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
/* global variables */
-const char *g_progname; // program name
-unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+unsigned int g_randseed; // random seed
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
static int runmisc(int argc, char **argv);
static int runwicked(int argc, char **argv);
static int procwrite(const char *path, int rnum, int width, int64_t limsiz,
- bool mt, int omode, bool rnd);
+ bool mt, int omode, bool rnd);
static int procread(const char *path, bool mt, int omode, bool wb, bool rnd);
static int procremove(const char *path, bool mt, int omode, bool rnd);
static int procrcat(const char *path, int rnum, int width, int64_t limsiz,
- bool mt, int omode, int pnum, bool dai, bool dad, bool rl, bool ru);
+ bool mt, int omode, int pnum, bool dai, bool dad, bool rl, bool ru);
static int procmisc(const char *path, int rnum, bool mt, int omode);
static int procwicked(const char *path, int rnum, bool mt, int omode);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- const char *ebuf = getenv("TCRNDSEED");
- g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
- srand(g_randseed);
- g_dbgfd = INVALID_HANDLE_VALUE;
- ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ const char *ebuf = getenv("TCRNDSEED");
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
+ srand(g_randseed);
+ g_dbgfd = INVALID_HANDLE_VALUE;
+ ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "remove")){
- rv = runremove(argc, argv);
- } else if(!strcmp(argv[1], "rcat")){
- rv = runrcat(argc, argv);
- } else if(!strcmp(argv[1], "misc")){
- rv = runmisc(argc, argv);
- } else if(!strcmp(argv[1], "wicked")){
- rv = runwicked(argc, argv);
- } else {
- usage();
- }
- if(rv != 0){
- printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
- for(int i = 0; i < argc; i++){
- printf(" %s", argv[i]);
- }
- printf("\n\n");
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "write")) {
+ rv = runwrite(argc, argv);
+ } else if (!strcmp(argv[1], "read")) {
+ rv = runread(argc, argv);
+ } else if (!strcmp(argv[1], "remove")) {
+ rv = runremove(argc, argv);
+ } else if (!strcmp(argv[1], "rcat")) {
+ rv = runrcat(argc, argv);
+ } else if (!strcmp(argv[1], "misc")) {
+ rv = runmisc(argc, argv);
+ } else if (!strcmp(argv[1], "wicked")) {
+ rv = runwicked(argc, argv);
+ } else {
+ usage();
+ }
+ if (rv != 0) {
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int) getpid());
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\n\n");
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: test cases of the fixed-length database API of Tokyo Cabinet\n",
- g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write [-mt] [-nl|-nb] [-rnd] path rnum [width [limsiz]]\n", g_progname);
- fprintf(stderr, " %s read [-mt] [-nl|-nb] [-wb] [-rnd] path\n", g_progname);
- fprintf(stderr, " %s remove [-mt] [-nl|-nb] [-rnd] path\n", g_progname);
- fprintf(stderr, " %s rcat [-mt] [-nl|-nb] [-pn num] [-dai|-dad|-rl|-ru]"
- " path rnum [width [limsiz]]\n", g_progname);
- fprintf(stderr, " %s misc [-mt] [-nl|-nb] path rnum\n", g_progname);
- fprintf(stderr, " %s wicked [-mt] [-nl|-nb] path rnum\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: test cases of the fixed-length database API of Tokyo Cabinet\n",
+ g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s write [-mt] [-nl|-nb] [-rnd] path rnum [width [limsiz]]\n", g_progname);
+ fprintf(stderr, " %s read [-mt] [-nl|-nb] [-wb] [-rnd] path\n", g_progname);
+ fprintf(stderr, " %s remove [-mt] [-nl|-nb] [-rnd] path\n", g_progname);
+ fprintf(stderr, " %s rcat [-mt] [-nl|-nb] [-pn num] [-dai|-dad|-rl|-ru]"
+ " path rnum [width [limsiz]]\n", g_progname);
+ fprintf(stderr, " %s misc [-mt] [-nl|-nb] path rnum\n", g_progname);
+ fprintf(stderr, " %s wicked [-mt] [-nl|-nb] path rnum\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print formatted information string and flush the buffer */
-static void iprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- fflush(stdout);
- va_end(ap);
+static void iprintf(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ fflush(stdout);
+ va_end(ap);
}
-
/* print a character and flush the buffer */
-static void iputchar(int c){
- putchar(c);
- fflush(stdout);
+static void iputchar(int c) {
+ putchar(c);
+ fflush(stdout);
}
-
/* print error message of fixed-length database */
-static void eprint(TCFDB *fdb, int line, const char *func){
- const char *path = tcfdbpath(fdb);
- int ecode = tcfdbecode(fdb);
- int stderrno = errno;
+static void eprint(TCFDB *fdb, int line, const char *func) {
+ const char *path = tcfdbpath(fdb);
+ int ecode = tcfdbecode(fdb);
+ int stderrno = errno;
#ifdef _WIN32
- DWORD myerrno = GetLastError();
- LPTSTR errorText = NULL;
- DWORD ret = FormatMessage(
- // use system message tables to retrieve error text
- FORMAT_MESSAGE_FROM_SYSTEM
- // allocate buffer on local heap for error text
- |FORMAT_MESSAGE_ALLOCATE_BUFFER
- // Important! will fail otherwise, since we're not
- // (and CANNOT) pass insertion parameters
- |FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM
- myerrno,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- (LPTSTR)&errorText, // output
- 0, // minimum size for output buffer
- NULL); // arguments - see note
+ DWORD myerrno = GetLastError();
+ LPTSTR errorText = NULL;
+ DWORD ret = FormatMessage(
+ // use system message tables to retrieve error text
+ FORMAT_MESSAGE_FROM_SYSTEM
+ // allocate buffer on local heap for error text
+ | FORMAT_MESSAGE_ALLOCATE_BUFFER
+ // Important! will fail otherwise, since we're not
+ // (and CANNOT) pass insertion parameters
+ | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, // unused with FORMAT_MESSAGE_FROM_SYSTEM
+ myerrno,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) & errorText, // output
+ 0, // minimum size for output buffer
+ NULL); // arguments - see note
if (!ret) {
- if (errorText) LocalFree(errorText);
- errorText = NULL;
+ if (errorText) LocalFree(errorText);
+ errorText = NULL;
}
fprintf(stderr, "%s: %s: %d: %s: error: %d:%s:%d:%s:%d:%s\n",
- g_progname, path ? path : "-",
- line, func,
- ecode, tcfdberrmsg(ecode),
- myerrno, errorText ? errorText : "-",
- stderrno, strerror(stderrno));
+ g_progname, path ? path : "-",
+ line, func,
+ ecode, tcfdberrmsg(ecode),
+ myerrno, errorText ? errorText : "-",
+ stderrno, strerror(stderrno));
if (errorText) LocalFree(errorText);
#else
- fprintf(stderr, "%s: %s: %d: %s: error: %d:%s:%d:%s\n",
- g_progname, path ? path : "-",
- line, func,
- ecode, tcfdberrmsg(ecode),
- stderrno, strerror(stderrno));
+ fprintf(stderr, "%s: %s: %d: %s: error: %d:%s:%d:%s\n",
+ g_progname, path ? path : "-",
+ line, func,
+ ecode, tcfdberrmsg(ecode),
+ stderrno, strerror(stderrno));
#endif
}
-
/* print members of fixed-length database */
-static void mprint(TCFDB *fdb){
- iprintf("minimum ID number: %" PRIuMAX "\n", (uint64_t)tcfdbmin(fdb));
- iprintf("maximum ID number: %" PRIuMAX "\n", (uint64_t)tcfdbmax(fdb));
- iprintf("width of the value: %u\n", (unsigned int)tcfdbwidth(fdb));
- iprintf("limit file size: %" PRIuMAX "\n", (uint64_t)tcfdblimsiz(fdb));
- iprintf("limit ID number: %" PRIuMAX "\n", (uint64_t)tcfdblimid(fdb));
+static void mprint(TCFDB *fdb) {
+ iprintf("minimum ID number: %" PRIuMAX "\n", (uint64_t) tcfdbmin(fdb));
+ iprintf("maximum ID number: %" PRIuMAX "\n", (uint64_t) tcfdbmax(fdb));
+ iprintf("width of the value: %u\n", (unsigned int) tcfdbwidth(fdb));
+ iprintf("limit file size: %" PRIuMAX "\n", (uint64_t) tcfdblimsiz(fdb));
+ iprintf("limit ID number: %" PRIuMAX "\n", (uint64_t) tcfdblimid(fdb));
#ifndef NDEBUG
- if(fdb->cnt_writerec < 0) return;
- iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)fdb->cnt_writerec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)fdb->cnt_readrec);
- iprintf("cnt_truncfile: %" PRIdMAX "\n", (int64_t)fdb->cnt_truncfile);
+ if (fdb->cnt_writerec < 0) return;
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t) fdb->cnt_writerec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t) fdb->cnt_readrec);
+ iprintf("cnt_truncfile: %" PRIdMAX "\n", (int64_t) fdb->cnt_truncfile);
#endif
}
-
/* print system information */
-static void sysprint(void){
- TCMAP *info = tcsysinfo();
- if(info){
- tcmapiterinit(info);
- const char *kbuf;
- while((kbuf = tcmapiternext2(info)) != NULL){
- iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+static void sysprint(void) {
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ tcmapiterinit(info);
+ const char *kbuf;
+ while ((kbuf = tcmapiternext2(info)) != NULL) {
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+ }
+ tcmapdel(info);
}
- tcmapdel(info);
- }
}
-
/* get a random number */
-static int myrand(int range){
- if(range < 2) return 0;
- int high = (unsigned int)rand() >> 4;
- int low = range * (rand() / (RAND_MAX + 1.0));
- low &= (unsigned int)INT_MAX >> 4;
- return (high + low) % range;
+static int myrand(int range) {
+ if (range < 2) return 0;
+ int high = (unsigned int) rand() >> 4;
+ int low = range * (rand() / (RAND_MAX + 1.0));
+ low &= (unsigned int) INT_MAX >> 4;
+ return (high + low) % range;
}
-
/* duplication callback function */
-static void *pdprocfunc(const void *vbuf, int vsiz, int *sp, void *op){
- if(op){
- char *buf = NULL;
- int len = 0;
- switch((int)(intptr_t)op){
- case 1:
- len = vsiz + 1;
- buf = tcmalloc(len + 1);
- memset(buf, '*', len);
- break;
- case 2:
- buf = (void *)-1;
- break;
+static void *pdprocfunc(const void *vbuf, int vsiz, int *sp, void *op) {
+ if (op) {
+ char *buf = NULL;
+ int len = 0;
+ switch ((int) (intptr_t) op) {
+ case 1:
+ len = vsiz + 1;
+ buf = tcmalloc(len + 1);
+ memset(buf, '*', len);
+ break;
+ case 2:
+ buf = (void *) - 1;
+ break;
+ }
+ *sp = len;
+ return buf;
}
+ if (myrand(4) == 0) return (void *) - 1;
+ if (myrand(2) == 0) return NULL;
+ int len = myrand(RECBUFSIZ);
+ char buf[RECBUFSIZ];
+ memset(buf, '*', len);
*sp = len;
- return buf;
- }
- if(myrand(4) == 0) return (void *)-1;
- if(myrand(2) == 0) return NULL;
- int len = myrand(RECBUFSIZ);
- char buf[RECBUFSIZ];
- memset(buf, '*', len);
- *sp = len;
- return tcmemdup(buf, len);
+ return tcmemdup(buf, len);
}
-
/* iterator function */
-static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op){
- unsigned int sum = 0;
- while(--ksiz >= 0){
- sum += ((char *)kbuf)[ksiz];
- }
- while(--vsiz >= 0){
- sum += ((char *)vbuf)[vsiz];
- }
- return myrand(100 + (sum & 0xff)) > 0;
+static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op) {
+ unsigned int sum = 0;
+ while (--ksiz >= 0) {
+ sum += ((char *) kbuf)[ksiz];
+ }
+ while (--vsiz >= 0) {
+ sum += ((char *) vbuf)[vsiz];
+ }
+ return myrand(100 + (sum & 0xff)) > 0;
}
-
/* parse arguments of write command */
-static int runwrite(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- char *wstr = NULL;
- char *lstr = NULL;
- bool mt = false;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!wstr){
- wstr = argv[i];
- } else if(!lstr){
- lstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int width = wstr ? tcatoix(wstr) : -1;
- int64_t limsiz = lstr ? tcatoix(lstr) : -1;
- int rv = procwrite(path, rnum, width, limsiz, mt, omode, rnd);
- return rv;
+static int runwrite(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ char *wstr = NULL;
+ char *lstr = NULL;
+ bool mt = false;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!wstr) {
+ wstr = argv[i];
+ } else if (!lstr) {
+ lstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int width = wstr ? tcatoix(wstr) : -1;
+ int64_t limsiz = lstr ? tcatoix(lstr) : -1;
+ int rv = procwrite(path, rnum, width, limsiz, mt, omode, rnd);
+ return rv;
}
-
/* parse arguments of read command */
-static int runread(int argc, char **argv){
- char *path = NULL;
- bool mt = false;
- int omode = 0;
- bool wb = false;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-wb")){
- wb = true;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runread(int argc, char **argv) {
+ char *path = NULL;
+ bool mt = false;
+ int omode = 0;
+ bool wb = false;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-wb")) {
+ wb = true;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procread(path, mt, omode, wb, rnd);
- return rv;
+ if (!path) usage();
+ int rv = procread(path, mt, omode, wb, rnd);
+ return rv;
}
-
/* parse arguments of remove command */
-static int runremove(int argc, char **argv){
- char *path = NULL;
- bool mt = false;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runremove(int argc, char **argv) {
+ char *path = NULL;
+ bool mt = false;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procremove(path, mt, omode, rnd);
- return rv;
+ if (!path) usage();
+ int rv = procremove(path, mt, omode, rnd);
+ return rv;
}
-
/* parse arguments of rcat command */
-static int runrcat(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- char *wstr = NULL;
- char *lstr = NULL;
- bool mt = false;
- int omode = 0;
- int pnum = 0;
- bool dai = false;
- bool dad = false;
- bool rl = false;
- bool ru = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else if(!strcmp(argv[i], "-pn")){
- if(++i >= argc) usage();
- pnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-dai")){
- dai = true;
- } else if(!strcmp(argv[i], "-dad")){
- dad = true;
- } else if(!strcmp(argv[i], "-rl")){
- rl = true;
- } else if(!strcmp(argv[i], "-ru")){
- ru = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!wstr){
- wstr = argv[i];
- } else if(!lstr){
- lstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int width = wstr ? tcatoix(wstr) : -1;
- int64_t limsiz = lstr ? tcatoix(lstr) : -1;
- int rv = procrcat(path, rnum, width, limsiz, mt, omode, pnum, dai, dad, rl, ru);
- return rv;
+static int runrcat(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ char *wstr = NULL;
+ char *lstr = NULL;
+ bool mt = false;
+ int omode = 0;
+ int pnum = 0;
+ bool dai = false;
+ bool dad = false;
+ bool rl = false;
+ bool ru = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else if (!strcmp(argv[i], "-pn")) {
+ if (++i >= argc) usage();
+ pnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-dai")) {
+ dai = true;
+ } else if (!strcmp(argv[i], "-dad")) {
+ dad = true;
+ } else if (!strcmp(argv[i], "-rl")) {
+ rl = true;
+ } else if (!strcmp(argv[i], "-ru")) {
+ ru = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!wstr) {
+ wstr = argv[i];
+ } else if (!lstr) {
+ lstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int width = wstr ? tcatoix(wstr) : -1;
+ int64_t limsiz = lstr ? tcatoix(lstr) : -1;
+ int rv = procrcat(path, rnum, width, limsiz, mt, omode, pnum, dai, dad, rl, ru);
+ return rv;
}
-
/* parse arguments of misc command */
-static int runmisc(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- bool mt = false;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int rv = procmisc(path, rnum, mt, omode);
- return rv;
+static int runmisc(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ bool mt = false;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int rv = procmisc(path, rnum, mt, omode);
+ return rv;
}
-
/* parse arguments of wicked command */
-static int runwicked(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- bool mt = false;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= FDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= FDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int rv = procwicked(path, rnum, mt, omode);
- return rv;
+static int runwicked(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ bool mt = false;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= FDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= FDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int rv = procwicked(path, rnum, mt, omode);
+ return rv;
}
-
/* perform write command */
static int procwrite(const char *path, int rnum, int width, int64_t limsiz,
- bool mt, int omode, bool rnd){
- iprintf("<Writing Test>\n seed=%u path=%s rnum=%d width=%d limsiz=%" PRIdMAX " mt=%d omode=%d"
- " rnd=%d\n\n", g_randseed, path, rnum, width, (int64_t)limsiz, mt, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(mt && !tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbtune(fdb, width, limsiz)){
- eprint(fdb, __LINE__, "tcfdbtune");
- err = true;
- }
- if(!rnd) omode |= FDBOTRUNC;
- if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", rnd ? myrand(rnum) + 1 : i);
- if(!tcfdbput2(fdb, buf, len, buf, len)){
- eprint(fdb, __LINE__, "tcfdbput");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ bool mt, int omode, bool rnd) {
+ iprintf("<Writing Test>\n seed=%u path=%s rnum=%d width=%d limsiz=%" PRIdMAX " mt=%d omode=%d"
+ " rnd=%d\n\n", g_randseed, path, rnum, width, (int64_t) limsiz, mt, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (mt && !tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
+ err = true;
+ }
+ if (!tcfdbtune(fdb, width, limsiz)) {
+ eprint(fdb, __LINE__, "tcfdbtune");
+ err = true;
+ }
+ if (!rnd) omode |= FDBOTRUNC;
+ if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
+ err = true;
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ if (!tcfdbput2(fdb, buf, len, buf, len)) {
+ eprint(fdb, __LINE__, "tcfdbput");
+ err = true;
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
+ err = true;
+ }
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform read command */
-static int procread(const char *path, bool mt, int omode, bool wb, bool rnd){
- iprintf("<Reading Test>\n seed=%u path=%s mt=%d omode=%d wb=%d rnd=%d\n\n",
- g_randseed, path, mt, omode, wb, rnd);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(mt && !tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOREADER | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- int rnum = tcfdbrnum(fdb);
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
- int vsiz;
- if(wb){
- char vbuf[RECBUFSIZ];
- int vsiz = tcfdbget4(fdb, i, vbuf, RECBUFSIZ);
- if(vsiz < 0 && !(rnd && tcfdbecode(fdb) == TCENOREC)){
- eprint(fdb, __LINE__, "tcfdbget4");
+static int procread(const char *path, bool mt, int omode, bool wb, bool rnd) {
+ iprintf("<Reading Test>\n seed=%u path=%s mt=%d omode=%d wb=%d rnd=%d\n\n",
+ g_randseed, path, mt, omode, wb, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (mt && !tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
err = true;
- break;
- }
- } else {
- char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
- if(!vbuf && !(rnd && tcfdbecode(fdb) == TCENOREC)){
- eprint(fdb, __LINE__, "tcfdbget");
+ }
+ if (!tcfdbopen(fdb, path, FDBOREADER | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
+ err = true;
+ }
+ int rnum = tcfdbrnum(fdb);
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ int vsiz;
+ if (wb) {
+ char vbuf[RECBUFSIZ];
+ int vsiz = tcfdbget4(fdb, i, vbuf, RECBUFSIZ);
+ if (vsiz < 0 && !(rnd && tcfdbecode(fdb) == TCENOREC)) {
+ eprint(fdb, __LINE__, "tcfdbget4");
+ err = true;
+ break;
+ }
+ } else {
+ char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
+ if (!vbuf && !(rnd && tcfdbecode(fdb) == TCENOREC)) {
+ eprint(fdb, __LINE__, "tcfdbget");
+ err = true;
+ break;
+ }
+ tcfree(vbuf);
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
err = true;
- break;
- }
- tcfree(vbuf);
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform remove command */
-static int procremove(const char *path, bool mt, int omode, bool rnd){
- iprintf("<Removing Test>\n seed=%u path=%s mt=%d omode=%d rnd=%d\n\n",
- g_randseed, path, mt, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(mt && !tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- int rnum = tcfdbrnum(fdb);
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
- if(!tcfdbout2(fdb, kbuf, ksiz) && !(rnd && tcfdbecode(fdb) == TCENOREC)){
- eprint(fdb, __LINE__, "tcfdbout");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+static int procremove(const char *path, bool mt, int omode, bool rnd) {
+ iprintf("<Removing Test>\n seed=%u path=%s mt=%d omode=%d rnd=%d\n\n",
+ g_randseed, path, mt, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (mt && !tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
+ err = true;
+ }
+ if (!tcfdbopen(fdb, path, FDBOWRITER | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
+ err = true;
+ }
+ int rnum = tcfdbrnum(fdb);
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ if (!tcfdbout2(fdb, kbuf, ksiz) && !(rnd && tcfdbecode(fdb) == TCENOREC)) {
+ eprint(fdb, __LINE__, "tcfdbout");
+ err = true;
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
+ err = true;
+ }
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform rcat command */
static int procrcat(const char *path, int rnum, int width, int64_t limsiz,
- bool mt, int omode, int pnum, bool dai, bool dad, bool rl, bool ru){
- iprintf("<Random Concatenating Test>\n"
- " seed=%u path=%s rnum=%d width=%d limsiz=%" PRIdMAX " mt=%d omode=%d pnum=%d"
- " dai=%d dad=%d rl=%d ru=%d\n\n",
- g_randseed, path, rnum, width, (int64_t)limsiz, mt, omode, pnum, dai, dad, rl, ru);
- if(pnum < 1) pnum = rnum;
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(mt && !tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbtune(fdb, width, limsiz)){
- eprint(fdb, __LINE__, "tcfdbtune");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(pnum) + 1);
- if(dai){
- if(tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), myrand(3)) == INT_MIN){
- eprint(fdb, __LINE__, "tcfdbaddint");
+ bool mt, int omode, int pnum, bool dai, bool dad, bool rl, bool ru) {
+ iprintf("<Random Concatenating Test>\n"
+ " seed=%u path=%s rnum=%d width=%d limsiz=%" PRIdMAX " mt=%d omode=%d pnum=%d"
+ " dai=%d dad=%d rl=%d ru=%d\n\n",
+ g_randseed, path, rnum, width, (int64_t) limsiz, mt, omode, pnum, dai, dad, rl, ru);
+ if (pnum < 1) pnum = rnum;
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (mt && !tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
err = true;
- break;
- }
- } else if(dad){
- if(isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), myrand(30) / 10.0))){
- eprint(fdb, __LINE__, "tcfdbadddouble");
+ }
+ if (!tcfdbtune(fdb, width, limsiz)) {
+ eprint(fdb, __LINE__, "tcfdbtune");
err = true;
- break;
- }
- } else if(rl){
- char vbuf[PATH_MAX];
- int vsiz = myrand(PATH_MAX);
- for(int j = 0; j < vsiz; j++){
- vbuf[j] = myrand(0x100);
- }
- if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbputcat");
+ }
+ if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
err = true;
- break;
- }
- } else if(ru){
- int id = myrand(pnum) + 1;
- switch(myrand(8)){
- case 0:
- if(!tcfdbput(fdb, id, kbuf, ksiz)){
- eprint(fdb, __LINE__, "tcfdbput");
- err = true;
- }
- break;
- case 1:
- if(!tcfdbputkeep(fdb, id, kbuf, ksiz) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep");
- err = true;
- }
- break;
- case 2:
- if(!tcfdbout(fdb, id) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout");
- err = true;
- }
- break;
- case 3:
- if(tcfdbaddint(fdb, id, 1) == INT_MIN && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbaddint");
- err = true;
- }
- break;
- case 4:
- if(isnan(tcfdbadddouble(fdb, id, 1.0)) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbadddouble");
- err = true;
- }
- break;
- case 5:
- if(myrand(2) == 0){
- if(!tcfdbputproc(fdb, id, kbuf, ksiz, pdprocfunc, NULL) &&
- tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputproc");
- err = true;
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(pnum) + 1);
+ if (dai) {
+ if (tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), myrand(3)) == INT_MIN) {
+ eprint(fdb, __LINE__, "tcfdbaddint");
+ err = true;
+ break;
}
- } else {
- if(!tcfdbputproc(fdb, id, NULL, 0, pdprocfunc, NULL) &&
- tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbputproc");
- err = true;
+ } else if (dad) {
+ if (isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), myrand(30) / 10.0))) {
+ eprint(fdb, __LINE__, "tcfdbadddouble");
+ err = true;
+ break;
}
- }
- break;
- default:
- if(!tcfdbputcat(fdb, id, kbuf, ksiz)){
- eprint(fdb, __LINE__, "tcfdbputcat");
- err = true;
- }
- break;
- }
- if(err) break;
- } else {
- if(!tcfdbputcat2(fdb, kbuf, ksiz, kbuf, ksiz)){
- eprint(fdb, __LINE__, "tcfdbputcat");
+ } else if (rl) {
+ char vbuf[PATH_MAX];
+ int vsiz = myrand(PATH_MAX);
+ for (int j = 0; j < vsiz; j++) {
+ vbuf[j] = myrand(0x100);
+ }
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbputcat");
+ err = true;
+ break;
+ }
+ } else if (ru) {
+ int id = myrand(pnum) + 1;
+ switch (myrand(8)) {
+ case 0:
+ if (!tcfdbput(fdb, id, kbuf, ksiz)) {
+ eprint(fdb, __LINE__, "tcfdbput");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcfdbputkeep(fdb, id, kbuf, ksiz) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tcfdbout(fdb, id) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout");
+ err = true;
+ }
+ break;
+ case 3:
+ if (tcfdbaddint(fdb, id, 1) == INT_MIN && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbaddint");
+ err = true;
+ }
+ break;
+ case 4:
+ if (isnan(tcfdbadddouble(fdb, id, 1.0)) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbadddouble");
+ err = true;
+ }
+ break;
+ case 5:
+ if (myrand(2) == 0) {
+ if (!tcfdbputproc(fdb, id, kbuf, ksiz, pdprocfunc, NULL) &&
+ tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputproc");
+ err = true;
+ }
+ } else {
+ if (!tcfdbputproc(fdb, id, NULL, 0, pdprocfunc, NULL) &&
+ tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbputproc");
+ err = true;
+ }
+ }
+ break;
+ default:
+ if (!tcfdbputcat(fdb, id, kbuf, ksiz)) {
+ eprint(fdb, __LINE__, "tcfdbputcat");
+ err = true;
+ }
+ break;
+ }
+ if (err) break;
+ } else {
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, kbuf, ksiz)) {
+ eprint(fdb, __LINE__, "tcfdbputcat");
+ err = true;
+ break;
+ }
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform misc command */
-static int procmisc(const char *path, int rnum, bool mt, int omode){
- iprintf("<Miscellaneous Test>\n seed=%u path=%s rnum=%d mt=%d omode=%d\n\n",
- g_randseed, path, rnum, mt, omode);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(mt && !tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbtune(fdb, RECBUFSIZ, EXHEADSIZ + (RECBUFSIZ + sizeof(int)) * rnum)){
- eprint(fdb, __LINE__, "tcfdbtune");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- if(1){
- TCFDB *fdbdup = tcfdbnew();
- if(tcfdbopen(fdbdup, path, FDBOREADER)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- } else if(tcfdbecode(fdbdup) != TCETHREAD){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
- tcfdbdel(fdbdup);
- }
- iprintf("writing:\n");
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- if(!tcfdbputkeep2(fdb, buf, len, buf, len)){
- eprint(fdb, __LINE__, "tcfdbputkeep");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("reading:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", i);
- int vsiz;
- char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(fdb, __LINE__, "tcfdbget");
- err = true;
- break;
- } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- tcfree(vbuf);
- break;
- }
- tcfree(vbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(tcfdbrnum(fdb) != rnum){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
- iprintf("random writing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '*', vsiz);
- if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput");
- err = true;
- break;
- }
- int rsiz;
- char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
- if(!rbuf){
- eprint(fdb, __LINE__, "tcfdbget");
- err = true;
- break;
- }
- if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- tcfree(rbuf);
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- tcfree(rbuf);
- }
- iprintf("random erasing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
- if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("writing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "[%d]", i);
- char vbuf[RECBUFSIZ];
- int vsiz = i % RECBUFSIZ;
- memset(vbuf, '*', vsiz);
- if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep");
- err = true;
- break;
- }
- if(vsiz < 1){
- char tbuf[PATH_MAX];
- for(int j = 0; j < PATH_MAX; j++){
- tbuf[j] = myrand(0x100);
- }
- if(!tcfdbput2(fdb, kbuf, ksiz, tbuf, PATH_MAX)){
- eprint(fdb, __LINE__, "tcfdbput");
- err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("erasing:\n");
- for(int i = 1; i <= rnum; i++){
- if(i % 2 == 1){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "[%d]", i);
- if(!tcfdbout2(fdb, kbuf, ksiz)){
- eprint(fdb, __LINE__, "tcfdbout");
- err = true;
- break;
- }
- if(tcfdbout2(fdb, kbuf, ksiz) || tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout");
+static int procmisc(const char *path, int rnum, bool mt, int omode) {
+ iprintf("<Miscellaneous Test>\n seed=%u path=%s rnum=%d mt=%d omode=%d\n\n",
+ g_randseed, path, rnum, mt, omode);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (mt && !tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("random writing and reopening:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
- int vsiz = myrand(RECBUFSIZ);
- char *vbuf = tcmalloc(vsiz + 1);
- memset(vbuf, '*', vsiz);
- switch(myrand(3)){
- case 0:
- if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput");
- err = true;
- }
- break;
- case 1:
- if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbputcat");
- err = true;
- }
- break;
- case 2:
- if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout");
- err = true;
- }
- break;
- }
- tcfree(vbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- iprintf("checking:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "[%d]", i);
- int vsiz;
- char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- tcfree(vbuf);
- } else if(tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbget");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("writing:\n");
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- if(!tcfdbput2(fdb, buf, len, buf, len)){
- eprint(fdb, __LINE__, "tcfdbput");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("reading:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", i);
- int vsiz;
- char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(fdb, __LINE__, "tcfdbget");
- err = true;
- break;
- } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- tcfree(vbuf);
- break;
- }
- tcfree(vbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("checking iterator:\n");
- if(!tcfdbiterinit(fdb)){
- eprint(fdb, __LINE__, "tcfdbiterinit");
- err = true;
- }
- char *kbuf;
- int ksiz;
- int inum = 0;
- for(int i = 1; (kbuf = tcfdbiternext2(fdb, &ksiz)) != NULL; i++, inum++){
- int vsiz;
- char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(fdb, __LINE__, "tcfdbget2");
- err = true;
- tcfree(kbuf);
- break;
- }
- tcfree(vbuf);
- tcfree(kbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(tcfdbecode(fdb) != TCENOREC || inum != tcfdbrnum(fdb)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
- iprintf("iteration updating:\n");
- if(!tcfdbiterinit(fdb)){
- eprint(fdb, __LINE__, "tcfdbiterinit");
- err = true;
- }
- inum = 0;
- for(int i = 1; (kbuf = tcfdbiternext2(fdb, &ksiz)) != NULL; i++, inum++){
- if(myrand(2) == 0){
- if(!tcfdbputcat2(fdb, kbuf, ksiz, "0123456789", 10)){
- eprint(fdb, __LINE__, "tcfdbputcat2");
+ }
+ if (!tcfdbtune(fdb, RECBUFSIZ, EXHEADSIZ + (RECBUFSIZ + sizeof (int)) * rnum)) {
+ eprint(fdb, __LINE__, "tcfdbtune");
err = true;
- tcfree(kbuf);
- break;
- }
- } else {
- if(!tcfdbout2(fdb, kbuf, ksiz)){
- eprint(fdb, __LINE__, "tcfdbout");
+ }
+ if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
err = true;
- tcfree(kbuf);
- break;
- }
- }
- tcfree(kbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(tcfdbecode(fdb) != TCENOREC || inum < tcfdbrnum(fdb)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
- if(myrand(10) == 0 && !tcfdbsync(fdb)){
- eprint(fdb, __LINE__, "tcfdbsync");
- err = true;
- }
- if(!tcfdbvanish(fdb)){
- eprint(fdb, __LINE__, "tcfdbvanish");
- err = true;
- }
- TCMAP *map = tcmapnew();
- iprintf("random writing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
- char vbuf[RECBUFSIZ];
- int vsiz = sprintf(vbuf, "%d", myrand(rnum) + 1);
- switch(myrand(7)){
- case 0:
- if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep2");
- err = true;
- }
- tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 2:
- if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputcat2");
- err = true;
- }
- tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout2");
- err = true;
- }
- tcmapout(map, kbuf, ksiz);
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("checking transaction commit:\n");
- if(!tcfdbtranbegin(fdb)){
- eprint(fdb, __LINE__, "tcfdbtranbegin");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
- char vbuf[RECBUFSIZ];
- int vsiz = sprintf(vbuf, "[%d]", myrand(rnum) + 1);
- switch(myrand(7)){
- case 0:
- if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep2");
- err = true;
- }
- tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 2:
- if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbputcat2");
- err = true;
- }
- tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- if(tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), 1) == INT_MIN &&
- tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbaddint");
- err = true;
- }
- tcmapaddint(map, kbuf, ksiz, 1);
- break;
- case 4:
- if(isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), 1.0)) &&
- tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbadddouble");
- err = true;
- }
- tcmapadddouble(map, kbuf, ksiz, 1.0);
- break;
- case 5:
- if(myrand(2) == 0){
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), vbuf, vsiz, pdprocfunc, op) &&
- tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputproc");
+ }
+ if (1) {
+ TCFDB *fdbdup = tcfdbnew();
+ if (tcfdbopen(fdbdup, path, FDBOREADER)) {
+ eprint(fdb, __LINE__, "(validation)");
err = true;
- }
- tcmapputproc(map, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op);
- } else {
- vsiz = myrand(10);
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), NULL, vsiz, pdprocfunc, op) &&
- tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbputproc");
+ } else if (tcfdbecode(fdbdup) != TCETHREAD) {
+ eprint(fdb, __LINE__, "(validation)");
err = true;
- }
- tcmapputproc(map, kbuf, ksiz, NULL, vsiz, pdprocfunc, op);
- }
- break;
- case 6:
- if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout2");
- err = true;
- }
- tcmapout(map, kbuf, ksiz);
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tcfdbtrancommit(fdb)){
- eprint(fdb, __LINE__, "tcfdbtrancommit");
- err = true;
- }
- iprintf("checking transaction abort:\n");
- uint64_t ornum = tcfdbrnum(fdb);
- uint64_t ofsiz = tcfdbfsiz(fdb);
- if(!tcfdbtranbegin(fdb)){
- eprint(fdb, __LINE__, "tcfdbtranbegin");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
- char vbuf[RECBUFSIZ];
- int vsiz = sprintf(vbuf, "[%d]", myrand(rnum) + 1);
- switch(myrand(7)){
- case 0:
- if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
- }
- break;
- case 1:
- if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep2");
- err = true;
- }
- break;
- case 2:
- if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbputcat2");
- err = true;
- }
- break;
- case 3:
- if(tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), 1) == INT_MIN &&
- tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbaddint");
- err = true;
- }
- break;
- case 4:
- if(isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), 1.0)) &&
- tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbadddouble");
- err = true;
- }
- break;
- case 5:
- if(myrand(2) == 0){
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), vbuf, vsiz, pdprocfunc, op) &&
- tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputproc");
+ }
+ tcfdbdel(fdbdup);
+ }
+ iprintf("writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", i);
+ if (!tcfdbputkeep2(fdb, buf, len, buf, len)) {
+ eprint(fdb, __LINE__, "tcfdbputkeep");
err = true;
- }
- } else {
- vsiz = myrand(10);
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), NULL, vsiz, pdprocfunc, op) &&
- tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbputproc");
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("reading:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", i);
+ int vsiz;
+ char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
+ eprint(fdb, __LINE__, "tcfdbget");
err = true;
- }
- }
- break;
- case 6:
- if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout2");
- err = true;
- }
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tcfdbtranabort(fdb)){
- eprint(fdb, __LINE__, "tcfdbtranabort");
- err = true;
- }
- iprintf("checking consistency:\n");
- if(tcfdbrnum(fdb) != ornum || tcfdbfsiz(fdb) != ofsiz || tcfdbrnum(fdb) != tcmaprnum(map)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
- inum = 0;
- tcmapiterinit(map);
- const char *tkbuf;
- int tksiz;
- for(int i = 1; (tkbuf = tcmapiternext(map, &tksiz)) != NULL; i++, inum++){
- int tvsiz;
- const char *tvbuf = tcmapiterval(tkbuf, &tvsiz);
- if(tvsiz > RECBUFSIZ) tvsiz = RECBUFSIZ;
- int rsiz;
- char *rbuf = tcfdbget2(fdb, tkbuf, tksiz, &rsiz);
- if(!rbuf || rsiz != tvsiz || memcmp(rbuf, tvbuf, rsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- tcfree(rbuf);
- break;
- }
- tcfree(rbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- inum = 0;
- if(!tcfdbiterinit(fdb)){
- eprint(fdb, __LINE__, "tcfdbiterinit");
- err = true;
- }
- for(int i = 1; (kbuf = tcfdbiternext2(fdb, &ksiz)) != NULL; i++, inum++){
- int vsiz;
- char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
- int rsiz;
- const char *rbuf = tcmapget(map, kbuf, ksiz, &rsiz);
- if(rsiz > RECBUFSIZ) rsiz = RECBUFSIZ;
- if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- tcfree(vbuf);
- tcfree(kbuf);
- break;
- }
- tcfree(vbuf);
- tcfree(kbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- tcmapdel(map);
- if(!tcfdbvanish(fdb)){
- eprint(fdb, __LINE__, "tcfdbvanish");
- err = true;
- }
- if(rnum >= 100){
- if(!tcfdbtranbegin(fdb)){
- eprint(fdb, __LINE__, "tcfdbtranbegin");
- err = true;
- }
- if(!tcfdbput3(fdb, "99", "hirabayashi")){
- eprint(fdb, __LINE__, "tcfdbput3");
- err = true;
- }
- for(int i = 0; i < 10; i++){
- char buf[RECBUFSIZ];
- int size = sprintf(buf, "%d", myrand(rnum) + 1);
- if(!tcfdbput2(fdb, buf, size, buf, size)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
- }
- }
- for(int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)){
- char vbuf[i];
- memset(vbuf, '@', i - 1);
- vbuf[i-1] = '\0';
- if(!tcfdbput3(fdb, "99", vbuf)){
- eprint(fdb, __LINE__, "tcfdbput3");
- err = true;
- }
- }
- if(!tcfdbforeach(fdb, iterfunc, NULL)){
- eprint(fdb, __LINE__, "tcfdbforeach");
- err = true;
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
-}
-
-
-/* perform wicked command */
-static int procwicked(const char *path, int rnum, bool mt, int omode){
- iprintf("<Wicked Writing Test>\n seed=%u path=%s rnum=%d mt=%d omode=%d\n\n",
- g_randseed, path, rnum, mt, omode);
- bool err = false;
- double stime = tctime();
- TCFDB *fdb = tcfdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
- if(mt && !tcfdbsetmutex(fdb)){
- eprint(fdb, __LINE__, "tcfdbsetmutex");
- err = true;
- }
- if(!tcfdbtune(fdb, RECBUFSIZ * 2, EXHEADSIZ + (RECBUFSIZ * 2 + sizeof(int)) * rnum)){
- eprint(fdb, __LINE__, "tcfdbtune");
- err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)){
- eprint(fdb, __LINE__, "tcfdbopen");
- err = true;
- }
- if(!tcfdbiterinit(fdb)){
- eprint(fdb, __LINE__, "tcfdbiterinit");
- err = true;
- }
- TCMAP *map = tcmapnew2(rnum / 5);
- for(int i = 1; i <= rnum && !err; i++){
- uint64_t id = myrand(rnum) + 1;
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%" PRIuMAX "", (uint64_t)id);
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '*', vsiz);
- vbuf[vsiz] = '\0';
- char *rbuf;
- switch(myrand(16)){
- case 0:
- iputchar('0');
- if(!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- iputchar('1');
- if(!tcfdbput3(fdb, kbuf, vbuf)){
- eprint(fdb, __LINE__, "tcfdbput3");
- err = true;
- }
- tcmapput2(map, kbuf, vbuf);
- break;
- case 2:
- iputchar('2');
- if(!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep2");
- err = true;
- }
- tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- iputchar('3');
- if(!tcfdbputkeep3(fdb, kbuf, vbuf) && tcfdbecode(fdb) != TCEKEEP){
- eprint(fdb, __LINE__, "tcfdbputkeep3");
- err = true;
- }
- tcmapputkeep2(map, kbuf, vbuf);
- break;
- case 4:
- iputchar('4');
- if(!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbputcat2");
- err = true;
- }
- tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 5:
- iputchar('5');
- if(!tcfdbputcat3(fdb, kbuf, vbuf)){
- eprint(fdb, __LINE__, "tcfdbputcat3");
- err = true;
- }
- tcmapputcat2(map, kbuf, vbuf);
- break;
- case 6:
- iputchar('6');
- if(myrand(10) == 0){
- if(!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout2");
+ break;
+ } else if (vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
err = true;
- }
- tcmapout(map, kbuf, ksiz);
- }
- break;
- case 7:
- iputchar('7');
- if(myrand(10) == 0){
- if(!tcfdbout3(fdb, kbuf) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout3");
+ tcfree(vbuf);
+ break;
+ }
+ tcfree(vbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (tcfdbrnum(fdb) != rnum) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ iprintf("random writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '*', vsiz);
+ if (!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput");
err = true;
- }
- tcmapout2(map, kbuf);
- }
- break;
- case 8:
- iputchar('8');
- if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz))){
- if(tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbget2");
+ break;
+ }
+ int rsiz;
+ char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
+ if (!rbuf) {
+ eprint(fdb, __LINE__, "tcfdbget");
err = true;
- }
- rbuf = tcsprintf("[%d]", myrand(i + 1));
- vsiz = strlen(rbuf);
+ break;
}
- vsiz += myrand(vsiz);
- rbuf = tcrealloc(rbuf, vsiz + 1);
- for(int j = 0; j < vsiz; j++){
- rbuf[j] = myrand(0x100);
+ if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(rbuf);
+ break;
}
- if(!tcfdbput2(fdb, kbuf, ksiz, rbuf, vsiz)){
- eprint(fdb, __LINE__, "tcfdbput2");
- err = true;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcmapput(map, kbuf, ksiz, rbuf, vsiz);
tcfree(rbuf);
- break;
- case 9:
- iputchar('9');
- if(!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz)) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbget2");
- err = true;
+ }
+ iprintf("random erasing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
+ if (!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout");
+ err = true;
+ break;
}
- tcfree(rbuf);
- break;
- case 10:
- iputchar('A');
- if(!(rbuf = tcfdbget3(fdb, kbuf)) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbget3");
- err = true;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcfree(rbuf);
- break;
- case 11:
- iputchar('B');
- if(myrand(1) == 0) vsiz = 1;
- if((vsiz = tcfdbget4(fdb, id, vbuf, vsiz)) < 0 && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbget4");
- err = true;
- }
- break;
- case 12:
- iputchar('C');
- if(myrand(rnum / 128) == 0){
- if(myrand(2) == 0){
- if(!tcfdbiterinit(fdb)){
- eprint(fdb, __LINE__, "tcfdbiterinit");
- err = true;
+ }
+ iprintf("writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "[%d]", i);
+ char vbuf[RECBUFSIZ];
+ int vsiz = i % RECBUFSIZ;
+ memset(vbuf, '*', vsiz);
+ if (!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep");
+ err = true;
+ break;
+ }
+ if (vsiz < 1) {
+ char tbuf[PATH_MAX];
+ for (int j = 0; j < PATH_MAX; j++) {
+ tbuf[j] = myrand(0x100);
}
- } else {
- if(!tcfdbiterinit2(fdb, myrand(rnum) + 1) && tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbiterinit2");
- err = true;
+ if (!tcfdbput2(fdb, kbuf, ksiz, tbuf, PATH_MAX)) {
+ eprint(fdb, __LINE__, "tcfdbput");
+ err = true;
+ break;
}
- }
- }
- for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
- if(tcfdbiternext(fdb) < 0){
- int ecode = tcfdbecode(fdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbiternext");
- err = true;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("erasing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ if (i % 2 == 1) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "[%d]", i);
+ if (!tcfdbout2(fdb, kbuf, ksiz)) {
+ eprint(fdb, __LINE__, "tcfdbout");
+ err = true;
+ break;
}
- }
- }
- break;
- default:
- iputchar('@');
- if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
- if(myrand(rnum / 16 + 1) == 0){
- int cnt = myrand(30);
- for(int j = 0; j < rnum && !err; j++){
- ksiz = sprintf(kbuf, "%d", i + j);
- if(tcfdbout2(fdb, kbuf, ksiz)){
- cnt--;
- } else if(tcfdbecode(fdb) != TCENOREC){
- eprint(fdb, __LINE__, "tcfdbout2");
- err = true;
+ if (tcfdbout2(fdb, kbuf, ksiz) || tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout");
+ err = true;
+ break;
}
- tcmapout(map, kbuf, ksiz);
- if(cnt < 0) break;
- }
}
- break;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
}
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- if(i == rnum / 2){
- if(!tcfdbclose(fdb)){
+ iprintf("random writing and reopening:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
+ int vsiz = myrand(RECBUFSIZ);
+ char *vbuf = tcmalloc(vsiz + 1);
+ memset(vbuf, '*', vsiz);
+ switch (myrand(3)) {
+ case 0:
+ if (!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbputcat");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout");
+ err = true;
+ }
+ break;
+ }
+ tcfree(vbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (!tcfdbclose(fdb)) {
eprint(fdb, __LINE__, "tcfdbclose");
err = true;
- }
- if(!tcfdbopen(fdb, path, FDBOWRITER | omode)){
+ }
+ if (!tcfdbopen(fdb, path, FDBOWRITER | omode)) {
eprint(fdb, __LINE__, "tcfdbopen");
err = true;
- }
- } else if(i == rnum / 4){
- char *npath = tcsprintf("%s-tmp", path);
- if(!tcfdbcopy(fdb, npath)){
- eprint(fdb, __LINE__, "tcfdbcopy");
- err = true;
- }
- TCFDB *nfdb = tcfdbnew();
- if(!tcfdbopen(nfdb, npath, FDBOREADER | omode)){
- eprint(nfdb, __LINE__, "tcfdbopen");
+ }
+ iprintf("checking:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "[%d]", i);
+ int vsiz;
+ char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ tcfree(vbuf);
+ } else if (tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbget");
+ err = true;
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", i);
+ if (!tcfdbput2(fdb, buf, len, buf, len)) {
+ eprint(fdb, __LINE__, "tcfdbput");
+ err = true;
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("reading:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", i);
+ int vsiz;
+ char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
+ eprint(fdb, __LINE__, "tcfdbget");
+ err = true;
+ break;
+ } else if (vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(vbuf);
+ break;
+ }
+ tcfree(vbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("checking iterator:\n");
+ if (!tcfdbiterinit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbiterinit");
err = true;
- }
- tcfdbdel(nfdb);
- unlink(npath);
- tcfree(npath);
- if(!tcfdboptimize(fdb, RECBUFSIZ, -1)){
- eprint(fdb, __LINE__, "tcfdboptimize");
+ }
+ char *kbuf;
+ int ksiz;
+ int inum = 0;
+ for (int i = 1; (kbuf = tcfdbiternext2(fdb, &ksiz)) != NULL; i++, inum++) {
+ int vsiz;
+ char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
+ eprint(fdb, __LINE__, "tcfdbget2");
+ err = true;
+ tcfree(kbuf);
+ break;
+ }
+ tcfree(vbuf);
+ tcfree(kbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (tcfdbecode(fdb) != TCENOREC || inum != tcfdbrnum(fdb)) {
+ eprint(fdb, __LINE__, "(validation)");
err = true;
- }
- if(!tcfdbiterinit(fdb)){
+ }
+ iprintf("iteration updating:\n");
+ if (!tcfdbiterinit(fdb)) {
eprint(fdb, __LINE__, "tcfdbiterinit");
err = true;
- }
- } else if(i == rnum / 8){
- if(!tcfdbtranbegin(fdb)){
+ }
+ inum = 0;
+ for (int i = 1; (kbuf = tcfdbiternext2(fdb, &ksiz)) != NULL; i++, inum++) {
+ if (myrand(2) == 0) {
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, "0123456789", 10)) {
+ eprint(fdb, __LINE__, "tcfdbputcat2");
+ err = true;
+ tcfree(kbuf);
+ break;
+ }
+ } else {
+ if (!tcfdbout2(fdb, kbuf, ksiz)) {
+ eprint(fdb, __LINE__, "tcfdbout");
+ err = true;
+ tcfree(kbuf);
+ break;
+ }
+ }
+ tcfree(kbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (tcfdbecode(fdb) != TCENOREC || inum < tcfdbrnum(fdb)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ if (myrand(10) == 0 && !tcfdbsync(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsync");
+ err = true;
+ }
+ if (!tcfdbvanish(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbvanish");
+ err = true;
+ }
+ TCMAP *map = tcmapnew();
+ iprintf("random writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
+ char vbuf[RECBUFSIZ];
+ int vsiz = sprintf(vbuf, "%d", myrand(rnum) + 1);
+ switch (myrand(7)) {
+ case 0:
+ if (!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ if (!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep2");
+ err = true;
+ }
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 2:
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputcat2");
+ err = true;
+ }
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ if (!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout2");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("checking transaction commit:\n");
+ if (!tcfdbtranbegin(fdb)) {
eprint(fdb, __LINE__, "tcfdbtranbegin");
err = true;
- }
- } else if(i == rnum / 8 + rnum / 16){
- if(!tcfdbtrancommit(fdb)){
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
+ char vbuf[RECBUFSIZ];
+ int vsiz = sprintf(vbuf, "[%d]", myrand(rnum) + 1);
+ switch (myrand(7)) {
+ case 0:
+ if (!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ if (!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep2");
+ err = true;
+ }
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 2:
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbputcat2");
+ err = true;
+ }
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ if (tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), 1) == INT_MIN &&
+ tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbaddint");
+ err = true;
+ }
+ tcmapaddint(map, kbuf, ksiz, 1);
+ break;
+ case 4:
+ if (isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), 1.0)) &&
+ tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbadddouble");
+ err = true;
+ }
+ tcmapadddouble(map, kbuf, ksiz, 1.0);
+ break;
+ case 5:
+ if (myrand(2) == 0) {
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), vbuf, vsiz, pdprocfunc, op) &&
+ tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputproc");
+ err = true;
+ }
+ tcmapputproc(map, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op);
+ } else {
+ vsiz = myrand(10);
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), NULL, vsiz, pdprocfunc, op) &&
+ tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbputproc");
+ err = true;
+ }
+ tcmapputproc(map, kbuf, ksiz, NULL, vsiz, pdprocfunc, op);
+ }
+ break;
+ case 6:
+ if (!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout2");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (!tcfdbtrancommit(fdb)) {
eprint(fdb, __LINE__, "tcfdbtrancommit");
err = true;
- }
- }
- }
- if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
- if(!tcfdbsync(fdb)){
- eprint(fdb, __LINE__, "tcfdbsync");
- err = true;
- }
- if(tcfdbrnum(fdb) != tcmaprnum(map)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
- for(int i = 1; i <= rnum && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", i);
- int vsiz;
- const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
- int rsiz;
- char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
- if(vbuf){
- iputchar('.');
- if(vsiz > RECBUFSIZ) vsiz = RECBUFSIZ;
- if(!rbuf){
- eprint(fdb, __LINE__, "tcfdbget2");
+ }
+ iprintf("checking transaction abort:\n");
+ uint64_t ornum = tcfdbrnum(fdb);
+ uint64_t ofsiz = tcfdbfsiz(fdb);
+ if (!tcfdbtranbegin(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbtranbegin");
+ err = true;
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum) + 1);
+ char vbuf[RECBUFSIZ];
+ int vsiz = sprintf(vbuf, "[%d]", myrand(rnum) + 1);
+ switch (myrand(7)) {
+ case 0:
+ if (!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep2");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbputcat2");
+ err = true;
+ }
+ break;
+ case 3:
+ if (tcfdbaddint(fdb, tcfdbkeytoid(kbuf, ksiz), 1) == INT_MIN &&
+ tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbaddint");
+ err = true;
+ }
+ break;
+ case 4:
+ if (isnan(tcfdbadddouble(fdb, tcfdbkeytoid(kbuf, ksiz), 1.0)) &&
+ tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbadddouble");
+ err = true;
+ }
+ break;
+ case 5:
+ if (myrand(2) == 0) {
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), vbuf, vsiz, pdprocfunc, op) &&
+ tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputproc");
+ err = true;
+ }
+ } else {
+ vsiz = myrand(10);
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tcfdbputproc(fdb, tcfdbkeytoid(kbuf, ksiz), NULL, vsiz, pdprocfunc, op) &&
+ tcfdbecode(fdb) != TCEKEEP && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbputproc");
+ err = true;
+ }
+ }
+ break;
+ case 6:
+ if (!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout2");
+ err = true;
+ }
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (!tcfdbtranabort(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbtranabort");
err = true;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
+ }
+ iprintf("checking consistency:\n");
+ if (tcfdbrnum(fdb) != ornum || tcfdbfsiz(fdb) != ofsiz || tcfdbrnum(fdb) != tcmaprnum(map)) {
eprint(fdb, __LINE__, "(validation)");
err = true;
- }
- } else {
- iputchar('*');
- if(rbuf || tcfdbecode(fdb) != TCENOREC){
+ }
+ inum = 0;
+ tcmapiterinit(map);
+ const char *tkbuf;
+ int tksiz;
+ for (int i = 1; (tkbuf = tcmapiternext(map, &tksiz)) != NULL; i++, inum++) {
+ int tvsiz;
+ const char *tvbuf = tcmapiterval(tkbuf, &tvsiz);
+ if (tvsiz > RECBUFSIZ) tvsiz = RECBUFSIZ;
+ int rsiz;
+ char *rbuf = tcfdbget2(fdb, tkbuf, tksiz, &rsiz);
+ if (!rbuf || rsiz != tvsiz || memcmp(rbuf, tvbuf, rsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(rbuf);
+ break;
+ }
+ tcfree(rbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ inum = 0;
+ if (!tcfdbiterinit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbiterinit");
+ err = true;
+ }
+ for (int i = 1; (kbuf = tcfdbiternext2(fdb, &ksiz)) != NULL; i++, inum++) {
+ int vsiz;
+ char *vbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz);
+ int rsiz;
+ const char *rbuf = tcmapget(map, kbuf, ksiz, &rsiz);
+ if (rsiz > RECBUFSIZ) rsiz = RECBUFSIZ;
+ if (!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(vbuf);
+ tcfree(kbuf);
+ break;
+ }
+ tcfree(vbuf);
+ tcfree(kbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ tcmapdel(map);
+ if (!tcfdbvanish(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbvanish");
+ err = true;
+ }
+ if (rnum >= 100) {
+ if (!tcfdbtranbegin(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbtranbegin");
+ err = true;
+ }
+ if (!tcfdbput3(fdb, "99", "hirabayashi")) {
+ eprint(fdb, __LINE__, "tcfdbput3");
+ err = true;
+ }
+ for (int i = 0; i < 10; i++) {
+ char buf[RECBUFSIZ];
+ int size = sprintf(buf, "%d", myrand(rnum) + 1);
+ if (!tcfdbput2(fdb, buf, size, buf, size)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
+ }
+ }
+ for (int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)) {
+ char vbuf[i];
+ memset(vbuf, '@', i - 1);
+ vbuf[i - 1] = '\0';
+ if (!tcfdbput3(fdb, "99", vbuf)) {
+ eprint(fdb, __LINE__, "tcfdbput3");
+ err = true;
+ }
+ }
+ if (!tcfdbforeach(fdb, iterfunc, NULL)) {
+ eprint(fdb, __LINE__, "tcfdbforeach");
+ err = true;
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
+ err = true;
+ }
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
+}
+
+/* perform wicked command */
+static int procwicked(const char *path, int rnum, bool mt, int omode) {
+ iprintf("<Wicked Writing Test>\n seed=%u path=%s rnum=%d mt=%d omode=%d\n\n",
+ g_randseed, path, rnum, mt, omode);
+ bool err = false;
+ double stime = tctime();
+ TCFDB *fdb = tcfdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tcfdbsetdbgfd(fdb, g_dbgfd);
+ if (mt && !tcfdbsetmutex(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsetmutex");
+ err = true;
+ }
+ if (!tcfdbtune(fdb, RECBUFSIZ * 2, EXHEADSIZ + (RECBUFSIZ * 2 + sizeof (int)) * rnum)) {
+ eprint(fdb, __LINE__, "tcfdbtune");
+ err = true;
+ }
+ if (!tcfdbopen(fdb, path, FDBOWRITER | FDBOCREAT | FDBOTRUNC | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
+ err = true;
+ }
+ if (!tcfdbiterinit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbiterinit");
+ err = true;
+ }
+ TCMAP *map = tcmapnew2(rnum / 5);
+ for (int i = 1; i <= rnum && !err; i++) {
+ uint64_t id = myrand(rnum) + 1;
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%" PRIuMAX "", (uint64_t) id);
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '*', vsiz);
+ vbuf[vsiz] = '\0';
+ char *rbuf;
+ switch (myrand(16)) {
+ case 0:
+ iputchar('0');
+ if (!tcfdbput2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ iputchar('1');
+ if (!tcfdbput3(fdb, kbuf, vbuf)) {
+ eprint(fdb, __LINE__, "tcfdbput3");
+ err = true;
+ }
+ tcmapput2(map, kbuf, vbuf);
+ break;
+ case 2:
+ iputchar('2');
+ if (!tcfdbputkeep2(fdb, kbuf, ksiz, vbuf, vsiz) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep2");
+ err = true;
+ }
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ iputchar('3');
+ if (!tcfdbputkeep3(fdb, kbuf, vbuf) && tcfdbecode(fdb) != TCEKEEP) {
+ eprint(fdb, __LINE__, "tcfdbputkeep3");
+ err = true;
+ }
+ tcmapputkeep2(map, kbuf, vbuf);
+ break;
+ case 4:
+ iputchar('4');
+ if (!tcfdbputcat2(fdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbputcat2");
+ err = true;
+ }
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 5:
+ iputchar('5');
+ if (!tcfdbputcat3(fdb, kbuf, vbuf)) {
+ eprint(fdb, __LINE__, "tcfdbputcat3");
+ err = true;
+ }
+ tcmapputcat2(map, kbuf, vbuf);
+ break;
+ case 6:
+ iputchar('6');
+ if (myrand(10) == 0) {
+ if (!tcfdbout2(fdb, kbuf, ksiz) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout2");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ }
+ break;
+ case 7:
+ iputchar('7');
+ if (myrand(10) == 0) {
+ if (!tcfdbout3(fdb, kbuf) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout3");
+ err = true;
+ }
+ tcmapout2(map, kbuf);
+ }
+ break;
+ case 8:
+ iputchar('8');
+ if (!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz))) {
+ if (tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbget2");
+ err = true;
+ }
+ rbuf = tcsprintf("[%d]", myrand(i + 1));
+ vsiz = strlen(rbuf);
+ }
+ vsiz += myrand(vsiz);
+ rbuf = tcrealloc(rbuf, vsiz + 1);
+ for (int j = 0; j < vsiz; j++) {
+ rbuf[j] = myrand(0x100);
+ }
+ if (!tcfdbput2(fdb, kbuf, ksiz, rbuf, vsiz)) {
+ eprint(fdb, __LINE__, "tcfdbput2");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, rbuf, vsiz);
+ tcfree(rbuf);
+ break;
+ case 9:
+ iputchar('9');
+ if (!(rbuf = tcfdbget2(fdb, kbuf, ksiz, &vsiz)) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbget2");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 10:
+ iputchar('A');
+ if (!(rbuf = tcfdbget3(fdb, kbuf)) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbget3");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 11:
+ iputchar('B');
+ if (myrand(1) == 0) vsiz = 1;
+ if ((vsiz = tcfdbget4(fdb, id, vbuf, vsiz)) < 0 && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbget4");
+ err = true;
+ }
+ break;
+ case 12:
+ iputchar('C');
+ if (myrand(rnum / 128) == 0) {
+ if (myrand(2) == 0) {
+ if (!tcfdbiterinit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbiterinit");
+ err = true;
+ }
+ } else {
+ if (!tcfdbiterinit2(fdb, myrand(rnum) + 1) && tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbiterinit2");
+ err = true;
+ }
+ }
+ }
+ for (int j = myrand(rnum) / 1000 + 1; j >= 0; j--) {
+ if (tcfdbiternext(fdb) < 0) {
+ int ecode = tcfdbecode(fdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbiternext");
+ err = true;
+ }
+ }
+ }
+ break;
+ default:
+ iputchar('@');
+ if (myrand(10000) == 0) srand((unsigned int) (tctime() * 1000) % UINT_MAX);
+ if (myrand(rnum / 16 + 1) == 0) {
+ int cnt = myrand(30);
+ for (int j = 0; j < rnum && !err; j++) {
+ ksiz = sprintf(kbuf, "%d", i + j);
+ if (tcfdbout2(fdb, kbuf, ksiz)) {
+ cnt--;
+ } else if (tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "tcfdbout2");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ if (cnt < 0) break;
+ }
+ }
+ break;
+ }
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ if (i == rnum / 2) {
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
+ err = true;
+ }
+ if (!tcfdbopen(fdb, path, FDBOWRITER | omode)) {
+ eprint(fdb, __LINE__, "tcfdbopen");
+ err = true;
+ }
+ } else if (i == rnum / 4) {
+ char *npath = tcsprintf("%s-tmp", path);
+ if (!tcfdbcopy(fdb, npath)) {
+ eprint(fdb, __LINE__, "tcfdbcopy");
+ err = true;
+ }
+ TCFDB *nfdb = tcfdbnew();
+ if (!tcfdbopen(nfdb, npath, FDBOREADER | omode)) {
+ eprint(nfdb, __LINE__, "tcfdbopen");
+ err = true;
+ }
+ tcfdbdel(nfdb);
+ unlink(npath);
+ tcfree(npath);
+ if (!tcfdboptimize(fdb, RECBUFSIZ, -1)) {
+ eprint(fdb, __LINE__, "tcfdboptimize");
+ err = true;
+ }
+ if (!tcfdbiterinit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbiterinit");
+ err = true;
+ }
+ } else if (i == rnum / 8) {
+ if (!tcfdbtranbegin(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbtranbegin");
+ err = true;
+ }
+ } else if (i == rnum / 8 + rnum / 16) {
+ if (!tcfdbtrancommit(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbtrancommit");
+ err = true;
+ }
+ }
+ }
+ if (rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
+ if (!tcfdbsync(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbsync");
+ err = true;
+ }
+ if (tcfdbrnum(fdb) != tcmaprnum(map)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ for (int i = 1; i <= rnum && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", i);
+ int vsiz;
+ const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
+ int rsiz;
+ char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
+ if (vbuf) {
+ iputchar('.');
+ if (vsiz > RECBUFSIZ) vsiz = RECBUFSIZ;
+ if (!rbuf) {
+ eprint(fdb, __LINE__, "tcfdbget2");
+ err = true;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ } else {
+ iputchar('*');
+ if (rbuf || tcfdbecode(fdb) != TCENOREC) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ tcfree(rbuf);
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ }
+ if (rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
+ tcmapiterinit(map);
+ int ksiz;
+ const char *kbuf;
+ for (int i = 1; (kbuf = tcmapiternext(map, &ksiz)) != NULL; i++) {
+ iputchar('+');
+ int vsiz;
+ const char *vbuf = tcmapiterval(kbuf, &vsiz);
+ if (vsiz > tcfdbwidth(fdb)) vsiz = tcfdbwidth(fdb);
+ int rsiz;
+ char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
+ if (!rbuf) {
+ eprint(fdb, __LINE__, "tcfdbget2");
+ err = true;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(fdb, __LINE__, "(validation)");
+ err = true;
+ }
+ tcfree(rbuf);
+ if (!tcfdbout2(fdb, kbuf, ksiz)) {
+ eprint(fdb, __LINE__, "tcfdbout2");
+ err = true;
+ }
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ }
+ int mrnum = tcmaprnum(map);
+ if (mrnum % 50 > 0) iprintf(" (%08d)\n", mrnum);
+ if (tcfdbrnum(fdb) != 0) {
eprint(fdb, __LINE__, "(validation)");
err = true;
- }
- }
- tcfree(rbuf);
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- }
- if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
- tcmapiterinit(map);
- int ksiz;
- const char *kbuf;
- for(int i = 1; (kbuf = tcmapiternext(map, &ksiz)) != NULL; i++){
- iputchar('+');
- int vsiz;
- const char *vbuf = tcmapiterval(kbuf, &vsiz);
- if(vsiz > tcfdbwidth(fdb)) vsiz = tcfdbwidth(fdb);
- int rsiz;
- char *rbuf = tcfdbget2(fdb, kbuf, ksiz, &rsiz);
- if(!rbuf){
- eprint(fdb, __LINE__, "tcfdbget2");
- err = true;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
- tcfree(rbuf);
- if(!tcfdbout2(fdb, kbuf, ksiz)){
- eprint(fdb, __LINE__, "tcfdbout2");
- err = true;
- }
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- }
- int mrnum = tcmaprnum(map);
- if(mrnum % 50 > 0) iprintf(" (%08d)\n", mrnum);
- if(tcfdbrnum(fdb) != 0){
- eprint(fdb, __LINE__, "(validation)");
- err = true;
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tcfdbrnum(fdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tcfdbfsiz(fdb));
- mprint(fdb);
- sysprint();
- tcmapdel(map);
- if(!tcfdbclose(fdb)){
- eprint(fdb, __LINE__, "tcfdbclose");
- err = true;
- }
- tcfdbdel(fdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tcfdbrnum(fdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tcfdbfsiz(fdb));
+ mprint(fdb);
+ sysprint();
+ tcmapdel(map);
+ if (!tcfdbclose(fdb)) {
+ eprint(fdb, __LINE__, "tcfdbclose");
+ err = true;
+ }
+ tcfdbdel(fdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
/* global variables */
-const char *g_progname; // program name
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
static int proccreate(const char *path, int bnum, int apow, int fpow, int opts);
static int procinform(const char *path, int omode);
static int procput(const char *path, const char *kbuf, int ksiz, const char *vbuf, int vsiz,
- int omode, int dmode);
+ int omode, int dmode);
static int procout(const char *path, const char *kbuf, int ksiz, int omode);
static int procget(const char *path, const char *kbuf, int ksiz, int omode, bool px, bool pz);
static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr);
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode,
- bool df);
+ bool df);
static int procimporttsv(const char *path, const char *file, int omode, bool sc);
static int procversion(void);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- g_dbgfd = INVALID_HANDLE_VALUE;
- const char *ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ g_dbgfd = INVALID_HANDLE_VALUE;
+ const char *ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "create")){
- rv = runcreate(argc, argv);
- } else if(!strcmp(argv[1], "inform")){
- rv = runinform(argc, argv);
- } else if(!strcmp(argv[1], "put")){
- rv = runput(argc, argv);
- } else if(!strcmp(argv[1], "out")){
- rv = runout(argc, argv);
- } else if(!strcmp(argv[1], "get")){
- rv = runget(argc, argv);
- } else if(!strcmp(argv[1], "list")){
- rv = runlist(argc, argv);
- } else if(!strcmp(argv[1], "optimize")){
- rv = runoptimize(argc, argv);
- } else if(!strcmp(argv[1], "importtsv")){
- rv = runimporttsv(argc, argv);
- } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){
- rv = runversion(argc, argv);
- } else {
- usage();
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "create")) {
+ rv = runcreate(argc, argv);
+ } else if (!strcmp(argv[1], "inform")) {
+ rv = runinform(argc, argv);
+ } else if (!strcmp(argv[1], "put")) {
+ rv = runput(argc, argv);
+ } else if (!strcmp(argv[1], "out")) {
+ rv = runout(argc, argv);
+ } else if (!strcmp(argv[1], "get")) {
+ rv = runget(argc, argv);
+ } else if (!strcmp(argv[1], "list")) {
+ rv = runlist(argc, argv);
+ } else if (!strcmp(argv[1], "optimize")) {
+ rv = runoptimize(argc, argv);
+ } else if (!strcmp(argv[1], "importtsv")) {
+ rv = runimporttsv(argc, argv);
+ } else if (!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")) {
+ rv = runversion(argc, argv);
+ } else {
+ usage();
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: the command line utility of the hash database API\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s create [-tl] [-td|-tb|-tt|-tx] path [bnum [apow [fpow]]]\n", g_progname);
- fprintf(stderr, " %s inform [-nl|-nb] path\n", g_progname);
- fprintf(stderr, " %s put [-nl|-nb] [-sx] [-dk|-dc|-dai|-dad] path key value\n", g_progname);
- fprintf(stderr, " %s out [-nl|-nb] [-sx] path key\n", g_progname);
- fprintf(stderr, " %s get [-nl|-nb] [-sx] [-px] [-pz] path key\n", g_progname);
- fprintf(stderr, " %s list [-nl|-nb] [-m num] [-pv] [-px] [-fm str] path\n", g_progname);
- fprintf(stderr, " %s optimize [-tl] [-td|-tb|-tt|-tx] [-tz] [-nl|-nb] [-df]"
- " path [bnum [apow [fpow]]]\n", g_progname);
- fprintf(stderr, " %s importtsv [-nl|-nb] [-sc] path [file]\n", g_progname);
- fprintf(stderr, " %s version\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: the command line utility of the hash database API\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s create [-tl] [-td|-tb|-tt|-tx] path [bnum [apow [fpow]]]\n", g_progname);
+ fprintf(stderr, " %s inform [-nl|-nb] path\n", g_progname);
+ fprintf(stderr, " %s put [-nl|-nb] [-sx] [-dk|-dc|-dai|-dad] path key value\n", g_progname);
+ fprintf(stderr, " %s out [-nl|-nb] [-sx] path key\n", g_progname);
+ fprintf(stderr, " %s get [-nl|-nb] [-sx] [-px] [-pz] path key\n", g_progname);
+ fprintf(stderr, " %s list [-nl|-nb] [-m num] [-pv] [-px] [-fm str] path\n", g_progname);
+ fprintf(stderr, " %s optimize [-tl] [-td|-tb|-tt|-tx] [-tz] [-nl|-nb] [-df]"
+ " path [bnum [apow [fpow]]]\n", g_progname);
+ fprintf(stderr, " %s importtsv [-nl|-nb] [-sc] path [file]\n", g_progname);
+ fprintf(stderr, " %s version\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print error information */
-static void printerr(TCHDB *hdb){
- const char *path = tchdbpath(hdb);
- int ecode = tchdbecode(hdb);
- fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tchdberrmsg(ecode));
+static void printerr(TCHDB *hdb) {
+ const char *path = tchdbpath(hdb);
+ int ecode = tchdbecode(hdb);
+ fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tchdberrmsg(ecode));
}
-
/* print record data */
-static int printdata(const char *ptr, int size, bool px){
- int len = 0;
- while(size-- > 0){
- if(px){
- if(len > 0) putchar(' ');
- len += printf("%02X", *(unsigned char *)ptr);
- } else {
- putchar(*ptr);
- len++;
+static int printdata(const char *ptr, int size, bool px) {
+ int len = 0;
+ while (size-- > 0) {
+ if (px) {
+ if (len > 0) putchar(' ');
+ len += printf("%02X", *(unsigned char *) ptr);
+ } else {
+ putchar(*ptr);
+ len++;
+ }
+ ptr++;
}
- ptr++;
- }
- return len;
+ return len;
}
-
/* read a line from a file descriptor */
-static char *mygetline(FILE *ifp){
- int len = 0;
- int blen = 1024;
- char *buf = tcmalloc(blen + 1);
- bool end = true;
- int c;
- while((c = fgetc(ifp)) != EOF){
- end = false;
- if(c == '\0') continue;
- if(blen <= len){
- blen *= 2;
- buf = tcrealloc(buf, blen + 1);
- }
- if(c == '\n' || c == '\r') c = '\0';
- buf[len++] = c;
- if(c == '\0') break;
- }
- if(end){
- tcfree(buf);
- return NULL;
- }
- buf[len] = '\0';
- return buf;
+static char *mygetline(FILE *ifp) {
+ int len = 0;
+ int blen = 1024;
+ char *buf = tcmalloc(blen + 1);
+ bool end = true;
+ int c;
+ while ((c = fgetc(ifp)) != EOF) {
+ end = false;
+ if (c == '\0') continue;
+ if (blen <= len) {
+ blen *= 2;
+ buf = tcrealloc(buf, blen + 1);
+ }
+ if (c == '\n' || c == '\r') c = '\0';
+ buf[len++] = c;
+ if (c == '\0') break;
+ }
+ if (end) {
+ tcfree(buf);
+ return NULL;
+ }
+ buf[len] = '\0';
+ return buf;
}
-
/* parse arguments of create command */
-static int runcreate(int argc, char **argv){
- char *path = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= HDBTEXCODEC;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = proccreate(path, bnum, apow, fpow, opts);
- return rv;
+static int runcreate(int argc, char **argv) {
+ char *path = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= HDBTEXCODEC;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = proccreate(path, bnum, apow, fpow, opts);
+ return rv;
}
-
/* parse arguments of inform command */
-static int runinform(int argc, char **argv){
- char *path = NULL;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runinform(int argc, char **argv) {
+ char *path = NULL;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procinform(path, omode);
- return rv;
+ if (!path) usage();
+ int rv = procinform(path, omode);
+ return rv;
}
-
/* parse arguments of put command */
-static int runput(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- char *value = NULL;
- int omode = 0;
- int dmode = 0;
- bool sx = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-dk")){
- dmode = -1;
- } else if(!strcmp(argv[i], "-dc")){
- dmode = 1;
- } else if(!strcmp(argv[i], "-dai")){
- dmode = 10;
- } else if(!strcmp(argv[i], "-dad")){
- dmode = 11;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!key){
- key = argv[i];
- } else if(!value){
- value = argv[i];
+static int runput(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ char *value = NULL;
+ int omode = 0;
+ int dmode = 0;
+ bool sx = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-dk")) {
+ dmode = -1;
+ } else if (!strcmp(argv[i], "-dc")) {
+ dmode = 1;
+ } else if (!strcmp(argv[i], "-dai")) {
+ dmode = 10;
+ } else if (!strcmp(argv[i], "-dad")) {
+ dmode = 11;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else if (!value) {
+ value = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !key || !value) usage();
+ char *kbuf, *vbuf;
+ int ksiz, vsiz;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
+ vbuf = tchexdecode(value, &vsiz);
} else {
- usage();
- }
- }
- if(!path || !key || !value) usage();
- char *kbuf, *vbuf;
- int ksiz, vsiz;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- vbuf = tchexdecode(value, &vsiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- vsiz = strlen(value);
- vbuf = tcmemdup(value, vsiz);
- }
- int rv = procput(path, kbuf, ksiz, vbuf, vsiz, omode, dmode);
- tcfree(vbuf);
- tcfree(kbuf);
- return rv;
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
+ vsiz = strlen(value);
+ vbuf = tcmemdup(value, vsiz);
+ }
+ int rv = procput(path, kbuf, ksiz, vbuf, vsiz, omode, dmode);
+ tcfree(vbuf);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of out command */
-static int runout(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- int omode = 0;
- bool sx = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!key){
- key = argv[i];
+static int runout(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ int omode = 0;
+ bool sx = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !key) usage();
+ int ksiz;
+ char *kbuf;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
} else {
- usage();
- }
- }
- if(!path || !key) usage();
- int ksiz;
- char *kbuf;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- }
- int rv = procout(path, kbuf, ksiz, omode);
- tcfree(kbuf);
- return rv;
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
+ }
+ int rv = procout(path, kbuf, ksiz, omode);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of get command */
-static int runget(int argc, char **argv){
- char *path = NULL;
- char *key = NULL;
- int omode = 0;
- bool sx = false;
- bool px = false;
- bool pz = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-pz")){
- pz = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!key){
- key = argv[i];
+static int runget(int argc, char **argv) {
+ char *path = NULL;
+ char *key = NULL;
+ int omode = 0;
+ bool sx = false;
+ bool px = false;
+ bool pz = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-pz")) {
+ pz = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!key) {
+ key = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !key) usage();
+ int ksiz;
+ char *kbuf;
+ if (sx) {
+ kbuf = tchexdecode(key, &ksiz);
} else {
- usage();
- }
- }
- if(!path || !key) usage();
- int ksiz;
- char *kbuf;
- if(sx){
- kbuf = tchexdecode(key, &ksiz);
- } else {
- ksiz = strlen(key);
- kbuf = tcmemdup(key, ksiz);
- }
- int rv = procget(path, kbuf, ksiz, omode, px, pz);
- tcfree(kbuf);
- return rv;
+ ksiz = strlen(key);
+ kbuf = tcmemdup(key, ksiz);
+ }
+ int rv = procget(path, kbuf, ksiz, omode, px, pz);
+ tcfree(kbuf);
+ return rv;
}
-
/* parse arguments of list command */
-static int runlist(int argc, char **argv){
- char *path = NULL;
- int omode = 0;
- int max = -1;
- bool pv = false;
- bool px = false;
- char *fmstr = NULL;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-m")){
- if(++i >= argc) usage();
- max = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-pv")){
- pv = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-fm")){
- if(++i >= argc) usage();
- fmstr = argv[i];
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runlist(int argc, char **argv) {
+ char *path = NULL;
+ int omode = 0;
+ int max = -1;
+ bool pv = false;
+ bool px = false;
+ char *fmstr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-m")) {
+ if (++i >= argc) usage();
+ max = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-pv")) {
+ pv = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-fm")) {
+ if (++i >= argc) usage();
+ fmstr = argv[i];
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = proclist(path, omode, max, pv, px, fmstr);
- return rv;
+ if (!path) usage();
+ int rv = proclist(path, omode, max, pv, px, fmstr);
+ return rv;
}
-
/* parse arguments of optimize command */
-static int runoptimize(int argc, char **argv){
- char *path = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = UINT8_MAX;
- int omode = 0;
- bool df = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= HDBTEXCODEC;
- } else if(!strcmp(argv[i], "-tz")){
- if(opts == UINT8_MAX) opts = 0;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-df")){
- df = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procoptimize(path, bnum, apow, fpow, opts, omode, df);
- return rv;
+static int runoptimize(int argc, char **argv) {
+ char *path = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = UINT8_MAX;
+ int omode = 0;
+ bool df = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= HDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-tz")) {
+ if (opts == UINT8_MAX) opts = 0;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-df")) {
+ df = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procoptimize(path, bnum, apow, fpow, opts, omode, df);
+ return rv;
}
-
/* parse arguments of importtsv command */
-static int runimporttsv(int argc, char **argv){
- char *path = NULL;
- char *file = NULL;
- int omode = 0;
- bool sc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-sc")){
- sc = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!file){
- file = argv[i];
- } else {
- usage();
+static int runimporttsv(int argc, char **argv) {
+ char *path = NULL;
+ char *file = NULL;
+ int omode = 0;
+ bool sc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sc")) {
+ sc = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!file) {
+ file = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procimporttsv(path, file, omode, sc);
- return rv;
+ if (!path) usage();
+ int rv = procimporttsv(path, file, omode, sc);
+ return rv;
}
-
/* parse arguments of version command */
-static int runversion(int argc, char **argv){
- int rv = procversion();
- return rv;
+static int runversion(int argc, char **argv) {
+ int rv = procversion();
+ return rv;
}
-
/* 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);
+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 1;
- }
- bool err = false;
- if(!tchdbclose(hdb)){
- printerr(hdb);
- err = true;
- }
- tchdbdel(hdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform inform command */
-static int procinform(const char *path, int omode){
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL);
- if(!tchdbopen(hdb, path, HDBOREADER | omode)){
- printerr(hdb);
+static int procinform(const char *path, int omode) {
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL);
+ if (!tchdbopen(hdb, path, HDBOREADER | omode)) {
+ printerr(hdb);
+ tchdbdel(hdb);
+ return 1;
+ }
+ bool err = false;
+ const char *npath = tchdbpath(hdb);
+ if (!npath) npath = "(unknown)";
+ printf("path: %s\n", npath);
+ const char *type = "(unknown)";
+ switch (tchdbtype(hdb)) {
+ case TCDBTHASH: type = "hash";
+ break;
+ case TCDBTBTREE: type = "btree";
+ break;
+ case TCDBTFIXED: type = "fixed";
+ break;
+ case TCDBTTABLE: type = "table";
+ break;
+ }
+ printf("database type: %s\n", type);
+ uint8_t flags = tchdbflags(hdb);
+ printf("additional flags:");
+ if (flags & HDBFOPEN) printf(" open");
+ if (flags & HDBFFATAL) printf(" fatal");
+ printf("\n");
+ printf("bucket number: %" PRIuMAX "\n", (uint64_t) tchdbbnum(hdb));
+ if (hdb->cnt_writerec >= 0)
+ printf("used bucket number: %" PRIdMAX "\n", (int64_t) tchdbbnumused(hdb));
+ printf("alignment: %u\n", tchdbalign(hdb));
+ printf("free block pool: %u\n", tchdbfbpmax(hdb));
+ printf("inode number: %" PRIdMAX "\n", (int64_t) tchdbinode(hdb));
+ char date[48];
+ tcdatestrwww(tchdbmtime(hdb), INT_MAX, date);
+ printf("modified time: %s\n", date);
+ uint8_t opts = tchdbopts(hdb);
+ printf("options:");
+ if (opts & HDBTLARGE) printf(" large");
+ if (opts & HDBTDEFLATE) printf(" deflate");
+ if (opts & HDBTBZIP) printf(" bzip");
+ if (opts & HDBTTCBS) printf(" tcbs");
+ if (opts & HDBTEXCODEC) printf(" excodec");
+ printf("\n");
+ printf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ printf("file size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ if (!tchdbclose(hdb)) {
+ if (!err) printerr(hdb);
+ err = true;
+ }
tchdbdel(hdb);
- return 1;
- }
- bool err = false;
- const char *npath = tchdbpath(hdb);
- if(!npath) npath = "(unknown)";
- printf("path: %s\n", npath);
- const char *type = "(unknown)";
- switch(tchdbtype(hdb)){
- case TCDBTHASH: type = "hash"; break;
- case TCDBTBTREE: type = "btree"; break;
- case TCDBTFIXED: type = "fixed"; break;
- case TCDBTTABLE: type = "table"; break;
- }
- printf("database type: %s\n", type);
- uint8_t flags = tchdbflags(hdb);
- printf("additional flags:");
- if(flags & HDBFOPEN) printf(" open");
- if(flags & HDBFFATAL) printf(" fatal");
- printf("\n");
- printf("bucket number: %" PRIuMAX "\n", (uint64_t)tchdbbnum(hdb));
- if(hdb->cnt_writerec >= 0)
- printf("used bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnumused(hdb));
- printf("alignment: %u\n", tchdbalign(hdb));
- printf("free block pool: %u\n", tchdbfbpmax(hdb));
- printf("inode number: %" PRIdMAX "\n", (int64_t)tchdbinode(hdb));
- char date[48];
- tcdatestrwww(tchdbmtime(hdb), INT_MAX, date);
- printf("modified time: %s\n", date);
- uint8_t opts = tchdbopts(hdb);
- printf("options:");
- if(opts & HDBTLARGE) printf(" large");
- if(opts & HDBTDEFLATE) printf(" deflate");
- if(opts & HDBTBZIP) printf(" bzip");
- if(opts & HDBTTCBS) printf(" tcbs");
- if(opts & HDBTEXCODEC) printf(" excodec");
- printf("\n");
- printf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- printf("file size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- if(!tchdbclose(hdb)){
- if(!err) printerr(hdb);
- err = true;
- }
- tchdbdel(hdb);
- return err ? 1 : 0;
+ return err ? 1 : 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)){
+ 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;
- }
- break;
- case 10:
- inum = tchdbaddint(hdb, kbuf, ksiz, tcatoi(vbuf));
- if(inum == INT_MIN){
+ }
+ tchdbdel(hdb);
+ return err ? 1 : 0;
+}
+
+/* perform out command */
+static int procout(const char *path, const char *kbuf, int ksiz, int omode) {
+ 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);
- err = true;
- } else {
- printf("%d\n", inum);
- }
- break;
- case 11:
- dnum = tchdbadddouble(hdb, kbuf, ksiz, tcatof(vbuf));
- if(isnan(dnum)){
+ tchdbdel(hdb);
+ return 1;
+ }
+ bool err = false;
+ if (!tchdbout(hdb, kbuf, ksiz)) {
printerr(hdb);
err = true;
- } else {
- printf("%.6f\n", dnum);
- }
- break;
- default:
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- printerr(hdb);
+ }
+ if (!tchdbclose(hdb)) {
+ if (!err) printerr(hdb);
err = true;
- }
- break;
- }
- if(!tchdbclose(hdb)){
- if(!err) printerr(hdb);
- err = true;
- }
- tchdbdel(hdb);
- return err ? 1 : 0;
-}
-
-
-/* perform out command */
-static int procout(const char *path, const char *kbuf, int ksiz, int omode){
- 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;
- if(!tchdbout(hdb, kbuf, ksiz)){
- printerr(hdb);
- err = true;
- }
- if(!tchdbclose(hdb)){
- if(!err) printerr(hdb);
- err = true;
- }
- tchdbdel(hdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform get command */
-static int procget(const char *path, const char *kbuf, int ksiz, int omode, bool px, bool pz){
- 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, HDBOREADER | omode)){
- printerr(hdb);
+static int procget(const char *path, const char *kbuf, int ksiz, int omode, bool px, bool pz) {
+ 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, HDBOREADER | omode)) {
+ printerr(hdb);
+ tchdbdel(hdb);
+ return 1;
+ }
+ bool err = false;
+ int vsiz;
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ printdata(vbuf, vsiz, px);
+ if (!pz) putchar('\n');
+ tcfree(vbuf);
+ } else {
+ printerr(hdb);
+ err = true;
+ }
+ if (!tchdbclose(hdb)) {
+ if (!err) printerr(hdb);
+ err = true;
+ }
tchdbdel(hdb);
- return 1;
- }
- bool err = false;
- int vsiz;
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- printdata(vbuf, vsiz, px);
- if(!pz) putchar('\n');
- tcfree(vbuf);
- } else {
- printerr(hdb);
- err = true;
- }
- if(!tchdbclose(hdb)){
- if(!err) printerr(hdb);
- err = true;
- }
- tchdbdel(hdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform list command */
-static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr){
- 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, HDBOREADER | omode)){
- printerr(hdb);
- tchdbdel(hdb);
- return 1;
- }
- bool err = false;
- if(fmstr){
- TCLIST *keys = tchdbfwmkeys2(hdb, fmstr, max);
- for(int i = 0; i < tclistnum(keys); i++){
- int ksiz;
- const char *kbuf = tclistval(keys, i, &ksiz);
- printdata(kbuf, ksiz, px);
- if(pv){
- int vsiz;
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- putchar('\t');
- printdata(vbuf, vsiz, px);
- tcfree(vbuf);
+static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr) {
+ 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, HDBOREADER | omode)) {
+ printerr(hdb);
+ tchdbdel(hdb);
+ return 1;
+ }
+ bool err = false;
+ if (fmstr) {
+ TCLIST *keys = tchdbfwmkeys2(hdb, fmstr, max);
+ for (int i = 0; i < tclistnum(keys); i++) {
+ int ksiz;
+ const char *kbuf = tclistval(keys, i, &ksiz);
+ printdata(kbuf, ksiz, px);
+ if (pv) {
+ int vsiz;
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ putchar('\t');
+ printdata(vbuf, vsiz, px);
+ tcfree(vbuf);
+ }
+ }
+ putchar('\n');
+ }
+ tclistdel(keys);
+ } else {
+ if (!tchdbiterinit(hdb)) {
+ printerr(hdb);
+ err = true;
+ }
+ TCXSTR *key = tcxstrnew();
+ TCXSTR *val = tcxstrnew();
+ int cnt = 0;
+ while (tchdbiternext3(hdb, key, val)) {
+ printdata(tcxstrptr(key), tcxstrsize(key), px);
+ if (pv) {
+ putchar('\t');
+ printdata(tcxstrptr(val), tcxstrsize(val), px);
+ }
+ putchar('\n');
+ if (max >= 0 && ++cnt >= max) break;
}
- }
- putchar('\n');
+ tcxstrdel(val);
+ tcxstrdel(key);
}
- tclistdel(keys);
- } else {
- if(!tchdbiterinit(hdb)){
- printerr(hdb);
- err = true;
+ if (!tchdbclose(hdb)) {
+ if (!err) printerr(hdb);
+ err = true;
}
- TCXSTR *key = tcxstrnew();
- TCXSTR *val = tcxstrnew();
- int cnt = 0;
- while(tchdbiternext3(hdb, key, val)){
- printdata(tcxstrptr(key), tcxstrsize(key), px);
- if(pv){
- putchar('\t');
- printdata(tcxstrptr(val), tcxstrsize(val), px);
- }
- putchar('\n');
- if(max >= 0 && ++cnt >= max) break;
- }
- tcxstrdel(val);
- tcxstrdel(key);
- }
- if(!tchdbclose(hdb)){
- if(!err) printerr(hdb);
- err = true;
- }
- tchdbdel(hdb);
- return err ? 1 : 0;
+ tchdbdel(hdb);
+ return err ? 1 : 0;
}
-
/* perform optimize command */
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode,
- bool df){
- 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);
+ bool df) {
+ 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;
+ if (df) {
+ if (!tchdbdefrag(hdb, INT64_MAX)) {
+ printerr(hdb);
+ err = true;
+ }
+ } else {
+ if (!tchdboptimize(hdb, bnum, apow, fpow, opts)) {
+ printerr(hdb);
+ err = true;
+ }
+ }
+ if (!tchdbclose(hdb)) {
+ if (!err) printerr(hdb);
+ err = true;
+ }
tchdbdel(hdb);
- return 1;
- }
- bool err = false;
- if(df){
- if(!tchdbdefrag(hdb, INT64_MAX)){
- printerr(hdb);
- err = true;
- }
- } else {
- if(!tchdboptimize(hdb, bnum, apow, fpow, opts)){
- printerr(hdb);
- err = true;
- }
- }
- if(!tchdbclose(hdb)){
- if(!err) printerr(hdb);
- err = true;
- }
- tchdbdel(hdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform importtsv command */
-static int procimporttsv(const char *path, const char *file, int omode, bool sc){
- FILE *ifp = file ? fopen(file, "rb") : stdin;
- if(!ifp){
- fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
- return 1;
- }
- 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 | HDBOCREAT | omode)){
- printerr(hdb);
+static int procimporttsv(const char *path, const char *file, int omode, bool sc) {
+ FILE *ifp = file ? fopen(file, "rb") : stdin;
+ if (!ifp) {
+ fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
+ return 1;
+ }
+ 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 | HDBOCREAT | omode)) {
+ printerr(hdb);
+ tchdbdel(hdb);
+ if (ifp != stdin) fclose(ifp);
+ return 1;
+ }
+ bool err = false;
+ char *line;
+ int cnt = 0;
+ while (!err && (line = mygetline(ifp)) != NULL) {
+ char *pv = strchr(line, '\t');
+ if (!pv) {
+ tcfree(line);
+ continue;
+ }
+ *pv = '\0';
+ if (sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
+ if (!tchdbput2(hdb, line, pv + 1)) {
+ printerr(hdb);
+ err = true;
+ }
+ tcfree(line);
+ if (cnt > 0 && cnt % 100 == 0) {
+ putchar('.');
+ fflush(stdout);
+ if (cnt % 5000 == 0) printf(" (%08d)\n", cnt);
+ }
+ cnt++;
+ }
+ printf(" (%08d)\n", cnt);
+ if (!tchdbclose(hdb)) {
+ if (!err) printerr(hdb);
+ err = true;
+ }
tchdbdel(hdb);
- if(ifp != stdin) fclose(ifp);
- return 1;
- }
- bool err = false;
- char *line;
- int cnt = 0;
- while(!err && (line = mygetline(ifp)) != NULL){
- char *pv = strchr(line, '\t');
- if(!pv){
- tcfree(line);
- continue;
- }
- *pv = '\0';
- if(sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
- if(!tchdbput2(hdb, line, pv + 1)){
- printerr(hdb);
- err = true;
- }
- tcfree(line);
- if(cnt > 0 && cnt % 100 == 0){
- putchar('.');
- fflush(stdout);
- if(cnt % 5000 == 0) printf(" (%08d)\n", cnt);
- }
- cnt++;
- }
- printf(" (%08d)\n", cnt);
- if(!tchdbclose(hdb)){
- if(!err) printerr(hdb);
- err = true;
- }
- tchdbdel(hdb);
- if(ifp != stdin) fclose(ifp);
- return err ? 1 : 0;
+ if (ifp != stdin) fclose(ifp);
+ return err ? 1 : 0;
}
-
/* perform version command */
-static int procversion(void){
- printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
- tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
- printf("Copyright (C) 2006-2012 FAL Labs\n");
- return 0;
+static int procversion(void) {
+ printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
+ tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
+ printf("Copyright (C) 2006-2012 FAL Labs\n");
+ return 0;
}
#define RECBUFSIZ 48 // buffer for records
-typedef struct { // type of structure for write thread
- TCHDB *hdb;
- int rnum;
- bool as;
- bool rnd;
- int id;
+typedef struct { // type of structure for write thread
+ TCHDB *hdb;
+ int rnum;
+ bool as;
+ bool rnd;
+ int id;
} TARGWRITE;
-typedef struct { // type of structure for read thread
- TCHDB *hdb;
- int rnum;
- bool wb;
- bool rnd;
- int id;
+typedef struct { // type of structure for read thread
+ TCHDB *hdb;
+ int rnum;
+ bool wb;
+ bool rnd;
+ int id;
} TARGREAD;
-typedef struct { // type of structure for remove thread
- TCHDB *hdb;
- int rnum;
- bool rnd;
- int id;
+typedef struct { // type of structure for remove thread
+ TCHDB *hdb;
+ int rnum;
+ bool rnd;
+ int id;
} TARGREMOVE;
-typedef struct { // type of structure for wicked thread
- TCHDB *hdb;
- int rnum;
- bool nc;
- int id;
- TCMAP *map;
+typedef struct { // type of structure for wicked thread
+ TCHDB *hdb;
+ int rnum;
+ bool nc;
+ int id;
+ TCMAP *map;
} TARGWICKED;
-typedef struct { // type of structure for typical thread
- TCHDB *hdb;
- int rnum;
- bool nc;
- int rratio;
- int id;
+typedef struct { // type of structure for typical thread
+ TCHDB *hdb;
+ int rnum;
+ bool nc;
+ int rratio;
+ int id;
} TARGTYPICAL;
-typedef struct { // type of structure for race thread
- TCHDB *hdb;
- int rnum;
- int id;
+typedef struct { // type of structure for race thread
+ TCHDB *hdb;
+ int rnum;
+ int id;
} TARGRACE;
/* global variables */
-const char *g_progname; // program name
-unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+unsigned int g_randseed; // random seed
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
static int runtypical(int argc, char **argv);
static int runrace(int argc, char **argv);
static int procwrite(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int rcnum, int xmsiz, int dfunit, int omode, bool as, bool rnd);
+ int opts, int rcnum, int xmsiz, int dfunit, int omode, bool as, bool rnd);
static int procread(const char *path, int tnum, int rcnum, int xmsiz, int dfunit, int omode,
- bool wb, bool rnd);
+ bool wb, bool rnd);
static int procremove(const char *path, int tnum, int rcnum, int xmsiz, int dfunit, int omode,
- bool rnd);
+ bool rnd);
static int procwicked(const char *path, int tnum, int rnum, int opts, int omode, bool nc);
static int proctypical(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int rcnum, int xmsiz, int dfunit, int omode,
- bool nc, int rratio);
+ int opts, int rcnum, int xmsiz, int dfunit, int omode,
+ bool nc, int rratio);
static int procrace(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int xmsiz, int dfunit, int omode);
+ int opts, int xmsiz, int dfunit, int omode);
static void *threadwrite(void *targ);
static void *threadread(void *targ);
static void *threadremove(void *targ);
static void *threadtypical(void *targ);
static void *threadrace(void *targ);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- const char *ebuf = getenv("TCRNDSEED");
- g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
- srand(g_randseed);
- ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ const char *ebuf = getenv("TCRNDSEED");
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
+ srand(g_randseed);
+ ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "remove")){
- rv = runremove(argc, argv);
- } else if(!strcmp(argv[1], "wicked")){
- rv = runwicked(argc, argv);
- } else if(!strcmp(argv[1], "typical")){
- rv = runtypical(argc, argv);
- } else if(!strcmp(argv[1], "race")){
- rv = runrace(argc, argv);
- } else {
- usage();
- }
- if(rv != 0){
- printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
- for(int i = 0; i < argc; i++){
- printf(" %s", argv[i]);
- }
- printf("\n\n");
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "write")) {
+ rv = runwrite(argc, argv);
+ } else if (!strcmp(argv[1], "read")) {
+ rv = runread(argc, argv);
+ } else if (!strcmp(argv[1], "remove")) {
+ rv = runremove(argc, argv);
+ } else if (!strcmp(argv[1], "wicked")) {
+ rv = runwicked(argc, argv);
+ } else if (!strcmp(argv[1], "typical")) {
+ rv = runtypical(argc, argv);
+ } else if (!strcmp(argv[1], "race")) {
+ rv = runrace(argc, argv);
+ } else {
+ usage();
+ }
+ if (rv != 0) {
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int) getpid());
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\n\n");
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: test cases of the hash database API of Tokyo Cabinet\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
- " [-nl|-nb] [-as] [-rnd] path tnum rnum [bnum [apow [fpow]]]\n", g_progname);
- fprintf(stderr, " %s read [-rc num] [-xm num] [-df num] [-nl|-nb] [-wb] [-rnd] path tnum\n",
- g_progname);
- fprintf(stderr, " %s remove [-rc num] [-xm num] [-df num] [-nl|-nb] [-rnd] path tnum\n",
- g_progname);
- fprintf(stderr, " %s wicked [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] [-nc]"
- " path tnum rnum\n", g_progname);
- fprintf(stderr, " %s typical [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
- " [-nl|-nb] [-nc] [-rr num] path tnum rnum [bnum [apow [fpow]]]\n", g_progname);
- fprintf(stderr, " %s race [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb]"
- " path tnum rnum [bnum [apow [fpow]]]\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: test cases of the hash database API of Tokyo Cabinet\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s write [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
+ " [-nl|-nb] [-as] [-rnd] path tnum rnum [bnum [apow [fpow]]]\n", g_progname);
+ fprintf(stderr, " %s read [-rc num] [-xm num] [-df num] [-nl|-nb] [-wb] [-rnd] path tnum\n",
+ g_progname);
+ fprintf(stderr, " %s remove [-rc num] [-xm num] [-df num] [-nl|-nb] [-rnd] path tnum\n",
+ g_progname);
+ fprintf(stderr, " %s wicked [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] [-nc]"
+ " path tnum rnum\n", g_progname);
+ fprintf(stderr, " %s typical [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
+ " [-nl|-nb] [-nc] [-rr num] path tnum rnum [bnum [apow [fpow]]]\n", g_progname);
+ fprintf(stderr, " %s race [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb]"
+ " path tnum rnum [bnum [apow [fpow]]]\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print formatted information string and flush the buffer */
-static void iprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- fflush(stdout);
- va_end(ap);
+static void iprintf(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ fflush(stdout);
+ va_end(ap);
}
-
/* print a character and flush the buffer */
-static void iputchar(int c){
- putchar(c);
- fflush(stdout);
+static void iputchar(int c) {
+ putchar(c);
+ fflush(stdout);
}
-
/* print error message of hash database */
-static void eprint(TCHDB *hdb, int line, const char *func){
- const char *path = tchdbpath(hdb);
- int ecode = tchdbecode(hdb);
- fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
- g_progname, path ? path : "-", line, func, ecode, tchdberrmsg(ecode));
+static void eprint(TCHDB *hdb, int line, const char *func) {
+ const char *path = tchdbpath(hdb);
+ int ecode = tchdbecode(hdb);
+ fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
+ g_progname, path ? path : "-", line, func, ecode, tchdberrmsg(ecode));
}
-
/* print members of hash database */
-static void mprint(TCHDB *hdb){
- iprintf("bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnum(hdb));
- iprintf("used bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnumused(hdb));
+static void mprint(TCHDB *hdb) {
+ iprintf("bucket number: %" PRIdMAX "\n", (int64_t) tchdbbnum(hdb));
+ iprintf("used bucket number: %" PRIdMAX "\n", (int64_t) tchdbbnumused(hdb));
#ifndef NDEBUG
- if(hdb->cnt_writerec < 0) return;
- iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)hdb->cnt_writerec);
- iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t)hdb->cnt_reuserec);
- iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t)hdb->cnt_moverec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)hdb->cnt_readrec);
- iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_searchfbp);
- iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_insertfbp);
- iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_splicefbp);
- iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_dividefbp);
- iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_mergefbp);
- iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_reducefbp);
- iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_appenddrp);
- iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_deferdrp);
- iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_flushdrp);
- iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t)hdb->cnt_adjrecc);
- iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t)hdb->cnt_defrag);
- iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t)hdb->cnt_shiftrec);
- iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t)hdb->cnt_trunc);
+ if (hdb->cnt_writerec < 0) return;
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t) hdb->cnt_writerec);
+ iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t) hdb->cnt_reuserec);
+ iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t) hdb->cnt_moverec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t) hdb->cnt_readrec);
+ iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_searchfbp);
+ iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_insertfbp);
+ iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_splicefbp);
+ iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_dividefbp);
+ iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_mergefbp);
+ iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_reducefbp);
+ iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t) hdb->cnt_appenddrp);
+ iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t) hdb->cnt_deferdrp);
+ iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t) hdb->cnt_flushdrp);
+ iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t) hdb->cnt_adjrecc);
+ iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t) hdb->cnt_defrag);
+ iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t) hdb->cnt_shiftrec);
+ iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t) hdb->cnt_trunc);
#endif
}
-
/* print system information */
-static void sysprint(void){
- TCMAP *info = tcsysinfo();
- if(info){
- tcmapiterinit(info);
- const char *kbuf;
- while((kbuf = tcmapiternext2(info)) != NULL){
- iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
- }
- tcmapdel(info);
- }
+static void sysprint(void) {
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ tcmapiterinit(info);
+ const char *kbuf;
+ while ((kbuf = tcmapiternext2(info)) != NULL) {
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+ }
+ tcmapdel(info);
+ }
}
-
/* get a random number */
-static int myrand(int range){
- if(range < 2) return 0;
- int high = (unsigned int)rand() >> 4;
- int low = range * (rand() / (RAND_MAX + 1.0));
- low &= (unsigned int)INT_MAX >> 4;
- return (high + low) % range;
+static int myrand(int range) {
+ if (range < 2) return 0;
+ int high = (unsigned int) rand() >> 4;
+ int low = range * (rand() / (RAND_MAX + 1.0));
+ low &= (unsigned int) INT_MAX >> 4;
+ return (high + low) % range;
}
-
/* get a random number based on normal distribution */
-static int myrandnd(int range){
- int num = (int)tcdrandnd(range >> 1, range / 10);
- return (num < 0 || num >= range) ? 0 : num;
+static int myrandnd(int range) {
+ int num = (int) tcdrandnd(range >> 1, range / 10);
+ return (num < 0 || num >= range) ? 0 : num;
}
-
/* iterator function */
-static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op){
- unsigned int sum = 0;
- while(--ksiz >= 0){
- sum += ((char *)kbuf)[ksiz];
- }
- while(--vsiz >= 0){
- sum += ((char *)vbuf)[vsiz];
- }
- return myrand(100 + (sum & 0xff)) > 0;
+static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op) {
+ unsigned int sum = 0;
+ while (--ksiz >= 0) {
+ sum += ((char *) kbuf)[ksiz];
+ }
+ while (--vsiz >= 0) {
+ sum += ((char *) vbuf)[vsiz];
+ }
+ return myrand(100 + (sum & 0xff)) > 0;
}
-
/* parse arguments of write command */
-static int runwrite(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- int rcnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool as = false;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= HDBTEXCODEC;
- } else if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-as")){
- as = true;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procwrite(path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, dfunit, omode,
- as, rnd);
- return rv;
+static int runwrite(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ int rcnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool as = false;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= HDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-as")) {
+ as = true;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procwrite(path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, dfunit, omode,
+ as, rnd);
+ return rv;
}
-
/* parse arguments of read command */
-static int runread(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- int rcnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool wb = false;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-wb")){
- wb = true;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procread(path, tnum, rcnum, xmsiz, dfunit, omode, wb, rnd);
- return rv;
+static int runread(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ int rcnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool wb = false;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-wb")) {
+ wb = true;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procread(path, tnum, rcnum, xmsiz, dfunit, omode, wb, rnd);
+ return rv;
}
-
/* parse arguments of remove command */
-static int runremove(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- int rcnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procremove(path, tnum, rcnum, xmsiz, dfunit, omode, rnd);
- return rv;
+static int runremove(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ int rcnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procremove(path, tnum, rcnum, xmsiz, dfunit, omode, rnd);
+ return rv;
}
-
/* parse arguments of wicked command */
-static int runwicked(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- int opts = 0;
- int omode = 0;
- bool nc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= HDBTEXCODEC;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-nc")){
- nc = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int rv = procwicked(path, tnum, rnum, opts, omode, nc);
- return rv;
+static int runwicked(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ int opts = 0;
+ int omode = 0;
+ bool nc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= HDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-nc")) {
+ nc = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int rv = procwicked(path, tnum, rnum, opts, omode, nc);
+ return rv;
}
-
/* parse arguments of typical command */
-static int runtypical(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- int rcnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- int rratio = -1;
- bool nc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= HDBTEXCODEC;
- } else if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-nc")){
- nc = true;
- } else if(!strcmp(argv[i], "-rr")){
- if(++i >= argc) usage();
- rratio = tcatoix(argv[i]);
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = proctypical(path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, dfunit, omode,
- nc, rratio);
- return rv;
+static int runtypical(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ int rcnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ int rratio = -1;
+ bool nc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= HDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-nc")) {
+ nc = true;
+ } else if (!strcmp(argv[i], "-rr")) {
+ if (++i >= argc) usage();
+ rratio = tcatoix(argv[i]);
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = proctypical(path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, dfunit, omode,
+ nc, rratio);
+ return rv;
}
-
/* parse arguments of race command */
-static int runrace(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= HDBTEXCODEC;
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procrace(path, tnum, rnum, bnum, apow, fpow, opts, xmsiz, dfunit, omode);
- return rv;
+static int runrace(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= HDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procrace(path, tnum, rnum, bnum, apow, fpow, opts, xmsiz, dfunit, omode);
+ return rv;
}
-
/* perform write command */
static int procwrite(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int rcnum, int xmsiz, int dfunit, int omode, bool as, bool rnd){
- iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d fpow=%d"
- " opts=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d as=%d rnd=%d\n\n",
- g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, dfunit, omode,
- as, rnd);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(!tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbtune(hdb, bnum, apow, fpow, opts)){
- eprint(hdb, __LINE__, "tchdbtune");
- err = true;
- }
- if(!tchdbsetcache(hdb, rcnum)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- TARGWRITE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].hdb = hdb;
- targs[0].rnum = rnum;
- targs[0].as = as;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadwrite(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].hdb = hdb;
- targs[i].rnum = rnum;
- targs[i].as = as;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadwrite, targs + i) != 0){
- eprint(hdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int opts, int rcnum, int xmsiz, int dfunit, int omode, bool as, bool rnd) {
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d fpow=%d"
+ " opts=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d as=%d rnd=%d\n\n",
+ g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, dfunit, omode,
+ as, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (!tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
+ err = true;
+ }
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
+ err = true;
+ }
+ if (!tchdbtune(hdb, bnum, apow, fpow, opts)) {
+ eprint(hdb, __LINE__, "tchdbtune");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(hdb, __LINE__, "pthread_join");
+ if (!tchdbsetcache(hdb, rcnum)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
err = true;
- } else if(rv){
+ }
+ if (xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
+ err = true;
+ }
+ if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ TARGWRITE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].hdb = hdb;
+ targs[0].rnum = rnum;
+ targs[0].as = as;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadwrite(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].hdb = hdb;
+ targs[i].rnum = rnum;
+ targs[i].as = as;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadwrite, targs + i) != 0) {
+ eprint(hdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(hdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform read command */
static int procread(const char *path, int tnum, int rcnum, int xmsiz, int dfunit, int omode,
- bool wb, bool rnd){
- iprintf("<Reading Test>\n seed=%u path=%s tnum=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d"
- " wb=%d rnd=%d\n\n", g_randseed, path, tnum, rcnum, xmsiz, dfunit, omode, wb, rnd);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(!tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbsetcache(hdb, rcnum)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOREADER | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- int rnum = tchdbrnum(hdb) / tnum;
- TARGREAD targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].hdb = hdb;
- targs[0].rnum = rnum;
- targs[0].wb = wb;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadread(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].hdb = hdb;
- targs[i].rnum = rnum;
- targs[i].wb = wb;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadread, targs + i) != 0){
- eprint(hdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ bool wb, bool rnd) {
+ iprintf("<Reading Test>\n seed=%u path=%s tnum=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d"
+ " wb=%d rnd=%d\n\n", g_randseed, path, tnum, rcnum, xmsiz, dfunit, omode, wb, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (!tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(hdb, __LINE__, "pthread_join");
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
err = true;
- } else if(rv){
+ }
+ if (!tchdbsetcache(hdb, rcnum)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ if (dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
+ err = true;
+ }
+ if (!tchdbopen(hdb, path, HDBOREADER | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ int rnum = tchdbrnum(hdb) / tnum;
+ TARGREAD targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].hdb = hdb;
+ targs[0].rnum = rnum;
+ targs[0].wb = wb;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadread(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].hdb = hdb;
+ targs[i].rnum = rnum;
+ targs[i].wb = wb;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadread, targs + i) != 0) {
+ eprint(hdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(hdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform remove command */
static int procremove(const char *path, int tnum, int rcnum, int xmsiz, int dfunit, int omode,
- bool rnd){
- iprintf("<Removing Test>\n seed=%u path=%s tnum=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d"
- " rnd=%d\n\n", g_randseed, path, tnum, rcnum, xmsiz, dfunit, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(!tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbsetcache(hdb, rcnum)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- int rnum = tchdbrnum(hdb) / tnum;
- TARGREMOVE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].hdb = hdb;
- targs[0].rnum = rnum;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadremove(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].hdb = hdb;
- targs[i].rnum = rnum;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){
- eprint(hdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ bool rnd) {
+ iprintf("<Removing Test>\n seed=%u path=%s tnum=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d"
+ " rnd=%d\n\n", g_randseed, path, tnum, rcnum, xmsiz, dfunit, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (!tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
+ err = true;
+ }
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
+ err = true;
+ }
+ if (!tchdbsetcache(hdb, rcnum)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(hdb, __LINE__, "pthread_join");
+ if (!tchdbopen(hdb, path, HDBOWRITER | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
err = true;
- } else if(rv){
+ }
+ int rnum = tchdbrnum(hdb) / tnum;
+ TARGREMOVE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].hdb = hdb;
+ targs[0].rnum = rnum;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadremove(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].hdb = hdb;
+ targs[i].rnum = rnum;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadremove, targs + i) != 0) {
+ eprint(hdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(hdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform wicked command */
-static int procwicked(const char *path, int tnum, int rnum, int opts, int omode, bool nc){
- iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d opts=%d omode=%d nc=%d\n\n",
- g_randseed, path, tnum, rnum, opts, omode, nc);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(!tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbtune(hdb, rnum / 50, 2, -1, opts)){
- eprint(hdb, __LINE__, "tchdbtune");
- err = true;
- }
- if(!tchdbsetcache(hdb, rnum / 2)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(!tchdbsetxmsiz(hdb, rnum * sizeof(int))){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(!tchdbsetdfunit(hdb, 8)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- if(!tchdbiterinit(hdb)){
- eprint(hdb, __LINE__, "tchdbiterinit");
- err = true;
- }
- TARGWICKED targs[tnum];
- pthread_t threads[tnum];
- TCMAP *map = tcmapnew();
- if(tnum == 1){
- targs[0].hdb = hdb;
- targs[0].rnum = rnum;
- targs[0].nc = nc;
- targs[0].id = 0;
- targs[0].map = map;
- if(threadwicked(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].hdb = hdb;
- targs[i].rnum = rnum;
- targs[i].nc = nc;
- targs[i].id = i;
- targs[i].map = map;
- if(pthread_create(threads + i, NULL, threadwicked, targs + i) != 0){
- eprint(hdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+static int procwicked(const char *path, int tnum, int rnum, int opts, int omode, bool nc) {
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d opts=%d omode=%d nc=%d\n\n",
+ g_randseed, path, tnum, rnum, opts, omode, nc);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ tchdbsetdbgfd(hdb, g_dbgfd);
+ if (!tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(hdb, __LINE__, "pthread_join");
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
err = true;
- } else if(rv){
+ }
+ if (!tchdbtune(hdb, rnum / 50, 2, -1, opts)) {
+ eprint(hdb, __LINE__, "tchdbtune");
err = true;
- }
- }
- }
- if(!nc){
- if(!tchdbsync(hdb)){
- eprint(hdb, __LINE__, "tchdbsync");
- err = true;
- }
- if(tchdbrnum(hdb) != tcmaprnum(map)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- int end = rnum * tnum;
- for(int i = 1; i <= end && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", i - 1);
- int vsiz;
- const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
- int rsiz;
- char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
- if(vbuf){
- iputchar('.');
- if(!rbuf){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
+ }
+ if (!tchdbsetcache(hdb, rnum / 2)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
+ err = true;
+ }
+ if (!tchdbsetxmsiz(hdb, rnum * sizeof (int))) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
+ err = true;
+ }
+ if (!tchdbsetdfunit(hdb, 8)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
+ err = true;
+ }
+ if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ if (!tchdbiterinit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbiterinit");
+ err = true;
+ }
+ TARGWICKED targs[tnum];
+ pthread_t threads[tnum];
+ TCMAP *map = tcmapnew();
+ if (tnum == 1) {
+ targs[0].hdb = hdb;
+ targs[0].rnum = rnum;
+ targs[0].nc = nc;
+ targs[0].id = 0;
+ targs[0].map = map;
+ if (threadwicked(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].hdb = hdb;
+ targs[i].rnum = rnum;
+ targs[i].nc = nc;
+ targs[i].id = i;
+ targs[i].map = map;
+ if (pthread_create(threads + i, NULL, threadwicked, targs + i) != 0) {
+ eprint(hdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(hdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ if (!nc) {
+ if (!tchdbsync(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsync");
+ err = true;
+ }
+ if (tchdbrnum(hdb) != tcmaprnum(map)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
}
- } else {
- iputchar('*');
- if(rbuf || tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
+ int end = rnum * tnum;
+ for (int i = 1; i <= end && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", i - 1);
+ int vsiz;
+ const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
+ int rsiz;
+ char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
+ if (vbuf) {
+ iputchar('.');
+ if (!rbuf) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ } else {
+ iputchar('*');
+ if (rbuf || tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ tcfree(rbuf);
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
}
- }
- tcfree(rbuf);
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- }
- if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
- }
- tcmapdel(map);
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ if (rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
+ }
+ tcmapdel(map);
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform typical command */
static int proctypical(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int rcnum, int xmsiz, int dfunit, int omode,
- bool nc, int rratio){
- iprintf("<Typical Access Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d"
- " fpow=%d opts=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d nc=%d rratio=%d\n\n",
- g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, dfunit, omode,
- nc, rratio);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(!tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbtune(hdb, bnum, apow, fpow, opts)){
- eprint(hdb, __LINE__, "tchdbtune");
- err = true;
- }
- if(!tchdbsetcache(hdb, rcnum)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- TARGTYPICAL targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].hdb = hdb;
- targs[0].rnum = rnum;
- targs[0].nc = nc;
- targs[0].rratio = rratio;
- targs[0].id = 0;
- if(threadtypical(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].hdb = hdb;
- targs[i].rnum = rnum;
- targs[i].nc = nc;
- targs[i].rratio= rratio;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){
- eprint(hdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int opts, int rcnum, int xmsiz, int dfunit, int omode,
+ bool nc, int rratio) {
+ iprintf("<Typical Access Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d"
+ " fpow=%d opts=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d nc=%d rratio=%d\n\n",
+ g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, rcnum, xmsiz, dfunit, omode,
+ nc, rratio);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (!tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
+ err = true;
+ }
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
+ err = true;
+ }
+ if (!tchdbtune(hdb, bnum, apow, fpow, opts)) {
+ eprint(hdb, __LINE__, "tchdbtune");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(hdb, __LINE__, "pthread_join");
+ if (!tchdbsetcache(hdb, rcnum)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
err = true;
- } else if(rv){
+ }
+ if (xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ TARGTYPICAL targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].hdb = hdb;
+ targs[0].rnum = rnum;
+ targs[0].nc = nc;
+ targs[0].rratio = rratio;
+ targs[0].id = 0;
+ if (threadtypical(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].hdb = hdb;
+ targs[i].rnum = rnum;
+ targs[i].nc = nc;
+ targs[i].rratio = rratio;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadtypical, targs + i) != 0) {
+ eprint(hdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(hdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform race command */
static int procrace(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int xmsiz, int dfunit, int omode){
- iprintf("<Race Condition Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d"
- " fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d\n\n",
- g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, xmsiz, dfunit, omode);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(!tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbtune(hdb, bnum, apow, fpow, opts)){
- eprint(hdb, __LINE__, "tchdbtune");
- err = true;
- }
- if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- TARGRACE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].hdb = hdb;
- targs[0].rnum = rnum;
- targs[0].id = 0;
- if(threadrace(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].hdb = hdb;
- targs[i].rnum = rnum;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadrace, targs + i) != 0){
- eprint(hdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int opts, int xmsiz, int dfunit, int omode) {
+ iprintf("<Race Condition Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d"
+ " fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d\n\n",
+ g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, xmsiz, dfunit, omode);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (!tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(hdb, __LINE__, "pthread_join");
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
err = true;
- } else if(rv){
- err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
-}
-
-
-/* thread the write function */
-static void *threadwrite(void *targ){
- TCHDB *hdb = ((TARGWRITE *)targ)->hdb;
- int rnum = ((TARGWRITE *)targ)->rnum;
- bool as = ((TARGWRITE *)targ)->as;
- bool rnd = ((TARGWRITE *)targ)->rnd;
- int id = ((TARGWRITE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) : i));
- if(as){
- if(!tchdbputasync(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbputasync");
+ }
+ if (!tchdbtune(hdb, bnum, apow, fpow, opts)) {
+ eprint(hdb, __LINE__, "tchdbtune");
err = true;
- break;
- }
- } else {
- if(!tchdbput(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbput");
+ }
+ if (xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
err = true;
- break;
- }
}
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ if (dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
+ err = true;
}
- }
- return err ? "error" : NULL;
-}
-
-
-/* thread the read function */
-static void *threadread(void *targ){
- TCHDB *hdb = ((TARGREAD *)targ)->hdb;
- int rnum = ((TARGREAD *)targ)->rnum;
- bool wb = ((TARGREAD *)targ)->wb;
- bool rnd = ((TARGREAD *)targ)->rnd;
- 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 + (rnd ? myrandnd(i) : i));
- int vsiz;
- if(wb){
- char vbuf[RECBUFSIZ];
- int vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, RECBUFSIZ);
- if(vsiz < 0 && (!rnd || tchdbecode(hdb) != TCENOREC)){
- eprint(hdb, __LINE__, "tchdbget3");
+ if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
err = true;
- }
+ }
+ TARGRACE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].hdb = hdb;
+ targs[0].rnum = rnum;
+ targs[0].id = 0;
+ if (threadrace(targs) != NULL) err = true;
} else {
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(!vbuf && (!rnd || tchdbecode(hdb) != TCENOREC)){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- }
- tcfree(vbuf);
+ for (int i = 0; i < tnum; i++) {
+ targs[i].hdb = hdb;
+ targs[i].rnum = rnum;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadrace, targs + i) != 0) {
+ eprint(hdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(hdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
}
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
}
- }
- return err ? "error" : NULL;
-}
-
-
-/* thread the remove function */
-static void *threadremove(void *targ){
- TCHDB *hdb = ((TARGREMOVE *)targ)->hdb;
- int rnum = ((TARGREMOVE *)targ)->rnum;
- bool rnd = ((TARGREMOVE *)targ)->rnd;
- int id = ((TARGREMOVE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i + 1) : i));
- if(!tchdbout(hdb, kbuf, ksiz) && (!rnd || tchdbecode(hdb) != TCENOREC)){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- break;
- }
- 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;
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
-/* thread the wicked function */
-static void *threadwicked(void *targ){
- TCHDB *hdb = ((TARGWICKED *)targ)->hdb;
- int rnum = ((TARGWICKED *)targ)->rnum;
- bool nc = ((TARGWICKED *)targ)->nc;
- int id = ((TARGWICKED *)targ)->id;
- TCMAP *map = ((TARGWICKED *)targ)->map;
- bool err = false;
- for(int i = 1; i <= rnum && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum * (id + 1)));
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '*', vsiz);
- vbuf[vsiz] = '\0';
- char *rbuf;
- if(!nc) tcglobalmutexlock();
- switch(myrand(16)){
- case 0:
- if(id == 0) iputchar('0');
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- if(id == 0) iputchar('1');
- if(!tchdbput2(hdb, kbuf, vbuf)){
- eprint(hdb, __LINE__, "tchdbput2");
- err = true;
- }
- if(!nc) tcmapput2(map, kbuf, vbuf);
- break;
- case 2:
- if(id == 0) iputchar('2');
- if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- }
- if(!nc) tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- if(id == 0) iputchar('3');
- if(!tchdbputkeep2(hdb, kbuf, vbuf) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep2");
- err = true;
- }
- if(!nc) tcmapputkeep2(map, kbuf, vbuf);
- break;
- case 4:
- if(id == 0) iputchar('4');
- if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
+/* thread the write function */
+static void *threadwrite(void *targ) {
+ TCHDB *hdb = ((TARGWRITE *) targ)->hdb;
+ int rnum = ((TARGWRITE *) targ)->rnum;
+ bool as = ((TARGWRITE *) targ)->as;
+ bool rnd = ((TARGWRITE *) targ)->rnd;
+ int id = ((TARGWRITE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) : i));
+ if (as) {
+ if (!tchdbputasync(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbputasync");
+ err = true;
+ break;
+ }
+ } else {
+ if (!tchdbput(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ break;
+ }
}
- if(!nc) tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 5:
- if(id == 0) iputchar('5');
- if(!tchdbputcat2(hdb, kbuf, vbuf)){
- eprint(hdb, __LINE__, "tchdbputcat2");
- err = true;
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- if(!nc) tcmapputcat2(map, kbuf, vbuf);
- break;
- case 6:
- if(id == 0) iputchar('6');
- if(i > rnum / 4 * 3){
- if(!tchdbputasync(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputasync");
- err = true;
- }
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the read function */
+static void *threadread(void *targ) {
+ TCHDB *hdb = ((TARGREAD *) targ)->hdb;
+ int rnum = ((TARGREAD *) targ)->rnum;
+ bool wb = ((TARGREAD *) targ)->wb;
+ bool rnd = ((TARGREAD *) targ)->rnd;
+ 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 + (rnd ? myrandnd(i) : i));
+ int vsiz;
+ if (wb) {
+ char vbuf[RECBUFSIZ];
+ int vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, RECBUFSIZ);
+ if (vsiz < 0 && (!rnd || tchdbecode(hdb) != TCENOREC)) {
+ eprint(hdb, __LINE__, "tchdbget3");
+ err = true;
+ }
} else {
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (!vbuf && (!rnd || tchdbecode(hdb) != TCENOREC)) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ }
+ tcfree(vbuf);
}
- if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 7:
- if(id == 0) iputchar('7');
- if(i > rnum / 4 * 3){
- if(!tchdbputasync2(hdb, kbuf, vbuf)){
- eprint(hdb, __LINE__, "tchdbputasync2");
- err = true;
- }
- } else {
- if(!tchdbput2(hdb, kbuf, vbuf)){
- eprint(hdb, __LINE__, "tchdbput2");
- err = true;
- }
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- if(!nc) tcmapput2(map, kbuf, vbuf);
- break;
- case 8:
- if(id == 0) iputchar('8');
- if(myrand(2) == 0){
- if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the remove function */
+static void *threadremove(void *targ) {
+ TCHDB *hdb = ((TARGREMOVE *) targ)->hdb;
+ int rnum = ((TARGREMOVE *) targ)->rnum;
+ bool rnd = ((TARGREMOVE *) targ)->rnd;
+ int id = ((TARGREMOVE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i + 1) : i));
+ if (!tchdbout(hdb, kbuf, ksiz) && (!rnd || tchdbecode(hdb) != TCENOREC)) {
eprint(hdb, __LINE__, "tchdbout");
err = true;
- }
- if(!nc) tcmapout(map, kbuf, ksiz);
- }
- break;
- case 9:
- if(id == 0) iputchar('9');
- if(myrand(2) == 0){
- if(!tchdbout2(hdb, kbuf) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout2");
- err = true;
- }
- if(!nc) tcmapout2(map, kbuf);
- }
- break;
- case 10:
- if(id == 0) iputchar('A');
- if(!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz))){
- if(tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- }
- rbuf = tcsprintf("[%d]", myrand(i + 1));
- vsiz = strlen(rbuf);
- }
- vsiz += myrand(vsiz);
- if(myrand(3) == 0) vsiz += PATH_MAX;
- rbuf = tcrealloc(rbuf, vsiz + 1);
- for(int j = 0; j < vsiz; j++){
- rbuf[j] = myrand(0x100);
+ break;
}
- if(!tchdbput(hdb, kbuf, ksiz, rbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- if(!nc) tcmapput(map, kbuf, ksiz, rbuf, vsiz);
- tcfree(rbuf);
- break;
- case 11:
- if(id == 0) iputchar('B');
- if(!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz)) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- }
- tcfree(rbuf);
- break;
- case 12:
- if(id == 0) iputchar('C');
- if(!(rbuf = tchdbget2(hdb, kbuf)) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbget2");
- err = true;
- }
- tcfree(rbuf);
- break;
- case 13:
- if(id == 0) iputchar('D');
- if(myrand(1) == 0) vsiz = 1;
- if((vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, vsiz)) < 0 && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbget3");
- err = true;
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the wicked function */
+static void *threadwicked(void *targ) {
+ TCHDB *hdb = ((TARGWICKED *) targ)->hdb;
+ int rnum = ((TARGWICKED *) targ)->rnum;
+ bool nc = ((TARGWICKED *) targ)->nc;
+ int id = ((TARGWICKED *) targ)->id;
+ TCMAP *map = ((TARGWICKED *) targ)->map;
+ bool err = false;
+ for (int i = 1; i <= rnum && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum * (id + 1)));
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '*', vsiz);
+ vbuf[vsiz] = '\0';
+ char *rbuf;
+ if (!nc) tcglobalmutexlock();
+ switch (myrand(16)) {
+ case 0:
+ if (id == 0) iputchar('0');
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ if (id == 0) iputchar('1');
+ if (!tchdbput2(hdb, kbuf, vbuf)) {
+ eprint(hdb, __LINE__, "tchdbput2");
+ err = true;
+ }
+ if (!nc) tcmapput2(map, kbuf, vbuf);
+ break;
+ case 2:
+ if (id == 0) iputchar('2');
+ if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
+ err = true;
+ }
+ if (!nc) tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ if (id == 0) iputchar('3');
+ if (!tchdbputkeep2(hdb, kbuf, vbuf) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep2");
+ err = true;
+ }
+ if (!nc) tcmapputkeep2(map, kbuf, vbuf);
+ break;
+ case 4:
+ if (id == 0) iputchar('4');
+ if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ if (!nc) tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 5:
+ if (id == 0) iputchar('5');
+ if (!tchdbputcat2(hdb, kbuf, vbuf)) {
+ eprint(hdb, __LINE__, "tchdbputcat2");
+ err = true;
+ }
+ if (!nc) tcmapputcat2(map, kbuf, vbuf);
+ break;
+ case 6:
+ if (id == 0) iputchar('6');
+ if (i > rnum / 4 * 3) {
+ if (!tchdbputasync(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputasync");
+ err = true;
+ }
+ } else {
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 7:
+ if (id == 0) iputchar('7');
+ if (i > rnum / 4 * 3) {
+ if (!tchdbputasync2(hdb, kbuf, vbuf)) {
+ eprint(hdb, __LINE__, "tchdbputasync2");
+ err = true;
+ }
+ } else {
+ if (!tchdbput2(hdb, kbuf, vbuf)) {
+ eprint(hdb, __LINE__, "tchdbput2");
+ err = true;
+ }
+ }
+ if (!nc) tcmapput2(map, kbuf, vbuf);
+ break;
+ case 8:
+ if (id == 0) iputchar('8');
+ if (myrand(2) == 0) {
+ if (!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ if (!nc) tcmapout(map, kbuf, ksiz);
+ }
+ break;
+ case 9:
+ if (id == 0) iputchar('9');
+ if (myrand(2) == 0) {
+ if (!tchdbout2(hdb, kbuf) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout2");
+ err = true;
+ }
+ if (!nc) tcmapout2(map, kbuf);
+ }
+ break;
+ case 10:
+ if (id == 0) iputchar('A');
+ if (!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz))) {
+ if (tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ }
+ rbuf = tcsprintf("[%d]", myrand(i + 1));
+ vsiz = strlen(rbuf);
+ }
+ vsiz += myrand(vsiz);
+ if (myrand(3) == 0) vsiz += PATH_MAX;
+ rbuf = tcrealloc(rbuf, vsiz + 1);
+ for (int j = 0; j < vsiz; j++) {
+ rbuf[j] = myrand(0x100);
+ }
+ if (!tchdbput(hdb, kbuf, ksiz, rbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, rbuf, vsiz);
+ tcfree(rbuf);
+ break;
+ case 11:
+ if (id == 0) iputchar('B');
+ if (!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz)) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 12:
+ if (id == 0) iputchar('C');
+ if (!(rbuf = tchdbget2(hdb, kbuf)) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget2");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 13:
+ if (id == 0) iputchar('D');
+ if (myrand(1) == 0) vsiz = 1;
+ if ((vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, vsiz)) < 0 && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget3");
+ err = true;
+ }
+ break;
+ case 14:
+ if (id == 0) iputchar('E');
+ if (myrand(rnum / 50) == 0) {
+ if (!tchdbiterinit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbiterinit");
+ err = true;
+ }
+ }
+ TCXSTR *ikey = tcxstrnew();
+ TCXSTR *ival = tcxstrnew();
+ for (int j = myrand(rnum) / 1000 + 1; j >= 0; j--) {
+ if (j % 3 == 0) {
+ if (!tchdbiternext3(hdb, ikey, ival)) {
+ int ecode = tchdbecode(hdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbiternext3");
+ err = true;
+ }
+ }
+ } else {
+ int iksiz;
+ char *ikbuf = tchdbiternext(hdb, &iksiz);
+ if (ikbuf) {
+ tcfree(ikbuf);
+ } else {
+ int ecode = tchdbecode(hdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbiternext");
+ err = true;
+ }
+ }
+ }
+ }
+ tcxstrdel(ival);
+ tcxstrdel(ikey);
+ break;
+ default:
+ if (id == 0) iputchar('@');
+ if (tchdbtranbegin(hdb)) {
+ if (myrand(2) == 0) {
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ if (!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ } else {
+ if (!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ if (!nc) tcmapout(map, kbuf, ksiz);
+ }
+ if (nc && myrand(2) == 0) {
+ if (!tchdbtranabort(hdb)) {
+ eprint(hdb, __LINE__, "tchdbtranabort");
+ err = true;
+ }
+ } else {
+ if (!tchdbtrancommit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbtrancommit");
+ err = true;
+ }
+ }
+ } else {
+ eprint(hdb, __LINE__, "tchdbtranbegin");
+ err = true;
+ }
+ if (myrand(1000) == 0) {
+ if (!tchdbforeach(hdb, iterfunc, NULL)) {
+ eprint(hdb, __LINE__, "tchdbforeach");
+ err = true;
+ }
+ }
+ if (myrand(10000) == 0) srand((unsigned int) (tctime() * 1000) % UINT_MAX);
+ break;
}
- break;
- case 14:
- if(id == 0) iputchar('E');
- if(myrand(rnum / 50) == 0){
- if(!tchdbiterinit(hdb)){
- eprint(hdb, __LINE__, "tchdbiterinit");
- err = true;
- }
+ if (!nc) tcglobalmutexunlock();
+ if (id == 0) {
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ if (id == 0 && i == rnum / 4) {
+ if (!tchdboptimize(hdb, rnum / 50, -1, -1, -1) && tchdbecode(hdb) != TCEINVALID) {
+ eprint(hdb, __LINE__, "tchdboptimize");
+ err = true;
+ }
+ if (!tchdbiterinit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbiterinit");
+ err = true;
+ }
+ }
}
- TCXSTR *ikey = tcxstrnew();
- TCXSTR *ival = tcxstrnew();
- for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
- if(j % 3 == 0){
- if(!tchdbiternext3(hdb, ikey, ival)){
- int ecode = tchdbecode(hdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(hdb, __LINE__, "tchdbiternext3");
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the typical function */
+static void *threadtypical(void *targ) {
+ TCHDB *hdb = ((TARGTYPICAL *) targ)->hdb;
+ int rnum = ((TARGTYPICAL *) targ)->rnum;
+ bool nc = ((TARGTYPICAL *) targ)->nc;
+ int rratio = ((TARGTYPICAL *) targ)->rratio;
+ int id = ((TARGTYPICAL *) targ)->id;
+ bool err = false;
+ TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL;
+ int base = id * rnum;
+ int mrange = tclmax(50 + rratio, 100);
+ for (int i = 1; !err && i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", base + myrandnd(i));
+ int rnd = myrand(mrange);
+ if (rnd < 10) {
+ if (!tchdbput(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbput");
err = true;
- }
}
- } else {
- int iksiz;
- char *ikbuf = tchdbiternext(hdb, &iksiz);
- if(ikbuf){
- tcfree(ikbuf);
- } else {
- int ecode = tchdbecode(hdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(hdb, __LINE__, "tchdbiternext");
+ if (map) tcmapput(map, buf, len, buf, len);
+ } else if (rnd < 15) {
+ if (!tchdbputkeep(hdb, buf, len, buf, len) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
err = true;
- }
}
- }
- }
- tcxstrdel(ival);
- tcxstrdel(ikey);
- break;
- default:
- if(id == 0) iputchar('@');
- if(tchdbtranbegin(hdb)){
- if(myrand(2) == 0){
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
+ if (map) tcmapputkeep(map, buf, len, buf, len);
+ } else if (rnd < 20) {
+ if (!tchdbputcat(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ if (map) tcmapputcat(map, buf, len, buf, len);
+ } else if (rnd < 25) {
+ if (i > rnum / 10 * 9) {
+ if (!tchdbputasync(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbputasync");
+ err = true;
+ }
+ } else {
+ if (!tchdbput(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
}
- if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- } else {
- if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
+ if (map) tcmapput(map, buf, len, buf, len);
+ } else if (rnd < 30) {
+ if (!tchdbout(hdb, buf, len) && tchdbecode(hdb) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
}
- if(!nc) tcmapout(map, kbuf, ksiz);
- }
- if(nc && myrand(2) == 0){
- if(!tchdbtranabort(hdb)){
- eprint(hdb, __LINE__, "tchdbtranabort");
- err = true;
+ if (map) tcmapout(map, buf, len);
+ } else if (rnd < 31) {
+ if (myrand(10) == 0 && !tchdbiterinit(hdb) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbiterinit");
+ err = true;
}
- } else {
- if(!tchdbtrancommit(hdb)){
- eprint(hdb, __LINE__, "tchdbtrancommit");
- err = true;
+ for (int j = 0; !err && j < 10; j++) {
+ int ksiz;
+ char *kbuf = tchdbiternext(hdb, &ksiz);
+ if (kbuf) {
+ tcfree(kbuf);
+ } else if (tchdbecode(hdb) != TCEINVALID && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbiternext");
+ err = true;
+ }
}
- }
} else {
- eprint(hdb, __LINE__, "tchdbtranbegin");
- err = true;
- }
- if(myrand(1000) == 0){
- if(!tchdbforeach(hdb, iterfunc, NULL)){
- eprint(hdb, __LINE__, "tchdbforeach");
- err = true;
- }
- }
- if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
- break;
- }
- if(!nc) tcglobalmutexunlock();
- if(id == 0){
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- if(id == 0 && i == rnum / 4){
- if(!tchdboptimize(hdb, rnum / 50, -1, -1, -1) && tchdbecode(hdb) != TCEINVALID){
- eprint(hdb, __LINE__, "tchdboptimize");
- err = true;
+ int vsiz;
+ char *vbuf = tchdbget(hdb, buf, len, &vsiz);
+ if (vbuf) {
+ if (map) {
+ int msiz;
+ const char *mbuf = tcmapget(map, buf, len, &msiz);
+ if (!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ tcfree(vbuf);
+ } else {
+ if (tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ }
+ if (map && tcmapget(map, buf, len, &vsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
}
- if(!tchdbiterinit(hdb)){
- eprint(hdb, __LINE__, "tchdbiterinit");
- err = true;
+ 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;
-}
-
-
-/* thread the typical function */
-static void *threadtypical(void *targ){
- TCHDB *hdb = ((TARGTYPICAL *)targ)->hdb;
- int rnum = ((TARGTYPICAL *)targ)->rnum;
- bool nc = ((TARGTYPICAL *)targ)->nc;
- int rratio = ((TARGTYPICAL *)targ)->rratio;
- int id = ((TARGTYPICAL *)targ)->id;
- bool err = false;
- TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL;
- int base = id * rnum;
- int mrange = tclmax(50 + rratio, 100);
- for(int i = 1; !err && i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", base + myrandnd(i));
- int rnd = myrand(mrange);
- if(rnd < 10){
- if(!tchdbput(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- if(map) tcmapput(map, buf, len, buf, len);
- } else if(rnd < 15){
- if(!tchdbputkeep(hdb, buf, len, buf, len) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- }
- if(map) tcmapputkeep(map, buf, len, buf, len);
- } else if(rnd < 20){
- if(!tchdbputcat(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
- if(map) tcmapputcat(map, buf, len, buf, len);
- } else if(rnd < 25){
- if(i > rnum / 10 * 9){
- if(!tchdbputasync(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbputasync");
- err = true;
- }
- } else {
- if(!tchdbput(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- }
- if(map) tcmapput(map, buf, len, buf, len);
- } else if(rnd < 30){
- if(!tchdbout(hdb, buf, len) && tchdbecode(hdb) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- }
- if(map) tcmapout(map, buf, len);
- } else if(rnd < 31){
- if(myrand(10) == 0 && !tchdbiterinit(hdb) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbiterinit");
- err = true;
- }
- for(int j = 0; !err && j < 10; j++){
+ if (map) {
+ tcmapiterinit(map);
int ksiz;
- char *kbuf = tchdbiternext(hdb, &ksiz);
- if(kbuf){
- tcfree(kbuf);
- } else if(tchdbecode(hdb) != TCEINVALID && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbiternext");
- err = true;
- }
- }
- } else {
- int vsiz;
- char *vbuf = tchdbget(hdb, buf, len, &vsiz);
- if(vbuf){
- if(map){
- int msiz;
- const char *mbuf = tcmapget(map, buf, len, &msiz);
- if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- }
- tcfree(vbuf);
- } else {
- if(tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- }
- if(map && tcmapget(map, buf, len, &vsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- }
- }
- if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(map){
- tcmapiterinit(map);
- int ksiz;
- const char *kbuf;
- while(!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL){
- int vsiz;
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- int msiz;
- const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz);
- if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
+ const char *kbuf;
+ while (!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL) {
+ int vsiz;
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ int msiz;
+ const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz);
+ if (!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ tcfree(vbuf);
+ } else {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
}
- tcfree(vbuf);
- } else {
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
+ tcmapdel(map);
}
- tcmapdel(map);
- }
- return err ? "error" : NULL;
+ return err ? "error" : NULL;
}
-
/* thread the race function */
-static void *threadrace(void *targ){
- TCHDB *hdb = ((TARGRACE *)targ)->hdb;
- int rnum = ((TARGRACE *)targ)->rnum;
- int id = ((TARGRACE *)targ)->id;
- bool err = false;
- int mid = rnum * 2;
- for(int i = 1; !err && i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%d", myrandnd(i));
- int rnd = myrand(100);
- if(rnd < 10){
- if(!tchdbputkeep(hdb, buf, len, buf, len) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- }
- } else if(rnd < 20){
- if(!tchdbputcat(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
- } else if(rnd < 30){
- if(!tchdbout(hdb, buf, len) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- }
- } else if(rnd < 31){
- if(!tchdbputasync(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbputasync");
- err = true;
- }
- } else {
- if(myrand(10) == 0){
- int rsiz = myrand(256);
- char *rbuf = tcmalloc(rsiz + 1);
- for(int j = 0; j < rsiz; j++){
- rbuf[j] = myrand('z' - 'a') + 'a';
- }
- if(myrand(2) == 0){
- if(!tchdbput(hdb, buf, len, rbuf, rsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
+static void *threadrace(void *targ) {
+ TCHDB *hdb = ((TARGRACE *) targ)->hdb;
+ int rnum = ((TARGRACE *) targ)->rnum;
+ int id = ((TARGRACE *) targ)->id;
+ bool err = false;
+ int mid = rnum * 2;
+ for (int i = 1; !err && i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%d", myrandnd(i));
+ int rnd = myrand(100);
+ if (rnd < 10) {
+ if (!tchdbputkeep(hdb, buf, len, buf, len) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
+ err = true;
+ }
+ } else if (rnd < 20) {
+ if (!tchdbputcat(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ } else if (rnd < 30) {
+ if (!tchdbout(hdb, buf, len) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ } else if (rnd < 31) {
+ if (!tchdbputasync(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbputasync");
+ err = true;
+ }
} else {
- if(!tchdbputcat(hdb, buf, len, rbuf, rsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
- }
- tcfree(rbuf);
- } else {
- if(!tchdbput(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- }
- }
- if(id == 0){
- if(myrand(mid) == 0){
- iprintf("[v]");
- if(!tchdbvanish(hdb)){
- eprint(hdb, __LINE__, "tchdbvanish");
- err = true;
- }
- }
- if(myrand(mid) == 0){
- iprintf("[o]");
- if(!tchdboptimize(hdb, myrand(rnum) + 1, myrand(10), myrand(10), 0)){
- eprint(hdb, __LINE__, "tchdboptimize");
- err = true;
- }
- }
- if(myrand(mid) == 0){
- iprintf("[d]");
- if(!tchdbdefrag(hdb, -1)){
- eprint(hdb, __LINE__, "tchdbdefrag");
- err = true;
- }
- }
- if(myrand(mid) == 0){
- iprintf("[i]");
- if(!tchdbiterinit(hdb)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- char *kbuf;
- int ksiz;
- while((kbuf = tchdbiternext(hdb, &ksiz)) != NULL){
- int vsiz;
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(vbuf){
- tcfree(vbuf);
- } else if(tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- }
- tcfree(kbuf);
+ if (myrand(10) == 0) {
+ int rsiz = myrand(256);
+ char *rbuf = tcmalloc(rsiz + 1);
+ for (int j = 0; j < rsiz; j++) {
+ rbuf[j] = myrand('z' - 'a') + 'a';
+ }
+ if (myrand(2) == 0) {
+ if (!tchdbput(hdb, buf, len, rbuf, rsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ } else {
+ if (!tchdbputcat(hdb, buf, len, rbuf, rsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ }
+ tcfree(rbuf);
+ } else {
+ if (!tchdbput(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ }
}
- if(tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
+ if (id == 0) {
+ if (myrand(mid) == 0) {
+ iprintf("[v]");
+ if (!tchdbvanish(hdb)) {
+ eprint(hdb, __LINE__, "tchdbvanish");
+ err = true;
+ }
+ }
+ if (myrand(mid) == 0) {
+ iprintf("[o]");
+ if (!tchdboptimize(hdb, myrand(rnum) + 1, myrand(10), myrand(10), 0)) {
+ eprint(hdb, __LINE__, "tchdboptimize");
+ err = true;
+ }
+ }
+ if (myrand(mid) == 0) {
+ iprintf("[d]");
+ if (!tchdbdefrag(hdb, -1)) {
+ eprint(hdb, __LINE__, "tchdbdefrag");
+ err = true;
+ }
+ }
+ if (myrand(mid) == 0) {
+ iprintf("[i]");
+ if (!tchdbiterinit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ char *kbuf;
+ int ksiz;
+ while ((kbuf = tchdbiternext(hdb, &ksiz)) != NULL) {
+ int vsiz;
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (vbuf) {
+ tcfree(vbuf);
+ } else if (tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ }
+ tcfree(kbuf);
+ }
+ if (tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
}
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- }
- return err ? "error" : NULL;
+ }
+ return err ? "error" : NULL;
}
/* global variables */
-const char *g_progname; // program name
-unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+unsigned int g_randseed; // random seed
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
static int runmisc(int argc, char **argv);
static int runwicked(int argc, char **argv);
static int procwrite(const char *path, int rnum, int bnum, int apow, int fpow,
- bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode,
- bool as, bool rnd);
+ bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode,
+ bool as, bool rnd);
static int procread(const char *path, bool mt, int rcnum, int xmsiz, int dfunit, int omode,
- bool wb, bool rnd);
+ bool wb, bool rnd);
static int procremove(const char *path, bool mt, int rcnum, int xmsiz, int dfunit, int omode,
- bool rnd);
+ bool rnd);
static int procrcat(const char *path, int rnum, int bnum, int apow, int fpow,
- bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode, int pnum,
- bool dai, bool dad, bool rl, bool ru);
+ bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode, int pnum,
+ bool dai, bool dad, bool rl, bool ru);
static int procmisc(const char *path, int rnum, bool mt, int opts, int omode);
static int procwicked(const char *path, int rnum, bool mt, int opts, int omode);
-
/* main routine */
-int main(int argc, char **argv){
+int main(int argc, char **argv) {
- g_progname = argv[0];
- const char *ebuf = getenv("TCRNDSEED");
- g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
- srand(g_randseed);
- g_dbgfd = INVALID_HANDLE_VALUE;
- ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+ g_progname = argv[0];
+ const char *ebuf = getenv("TCRNDSEED");
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
+ srand(g_randseed);
+ g_dbgfd = INVALID_HANDLE_VALUE;
+ ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "remove")){
- rv = runremove(argc, argv);
- } else if(!strcmp(argv[1], "rcat")){
- rv = runrcat(argc, argv);
- } else if(!strcmp(argv[1], "misc")){
- rv = runmisc(argc, argv);
- } else if(!strcmp(argv[1], "wicked")){
- rv = runwicked(argc, argv);
- } else {
- usage();
- }
- if(rv != 0){
- printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
- for(int i = 0; i < argc; i++){
- printf(" %s", argv[i]);
- }
- printf("\n\n");
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "write")) {
+ rv = runwrite(argc, argv);
+ } else if (!strcmp(argv[1], "read")) {
+ rv = runread(argc, argv);
+ } else if (!strcmp(argv[1], "remove")) {
+ rv = runremove(argc, argv);
+ } else if (!strcmp(argv[1], "rcat")) {
+ rv = runrcat(argc, argv);
+ } else if (!strcmp(argv[1], "misc")) {
+ rv = runmisc(argc, argv);
+ } else if (!strcmp(argv[1], "wicked")) {
+ rv = runwicked(argc, argv);
+ } else {
+ usage();
+ }
+ if (rv != 0) {
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int) getpid());
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\n\n");
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: test cases of the hash database API of Tokyo Cabinet\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write [-mt] [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
- " [-nl|-nb] [-as] [-rnd] path rnum [bnum [apow [fpow]]]\n", g_progname);
- fprintf(stderr, " %s read [-mt] [-rc num] [-xm num] [-df num] [-nl|-nb] [-wb] [-rnd] path\n",
- g_progname);
- fprintf(stderr, " %s remove [-mt] [-rc num] [-xm num] [-df num] [-nl|-nb] [-rnd] path\n",
- g_progname);
- fprintf(stderr, " %s rcat [-mt] [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
- " [-nl|-nb] [-pn num] [-dai|-dad|-rl|-ru] path rnum [bnum [apow [fpow]]]\n",
- g_progname);
- fprintf(stderr, " %s misc [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
- fprintf(stderr, " %s wicked [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: test cases of the hash database API of Tokyo Cabinet\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s write [-mt] [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
+ " [-nl|-nb] [-as] [-rnd] path rnum [bnum [apow [fpow]]]\n", g_progname);
+ fprintf(stderr, " %s read [-mt] [-rc num] [-xm num] [-df num] [-nl|-nb] [-wb] [-rnd] path\n",
+ g_progname);
+ fprintf(stderr, " %s remove [-mt] [-rc num] [-xm num] [-df num] [-nl|-nb] [-rnd] path\n",
+ g_progname);
+ fprintf(stderr, " %s rcat [-mt] [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
+ " [-nl|-nb] [-pn num] [-dai|-dad|-rl|-ru] path rnum [bnum [apow [fpow]]]\n",
+ g_progname);
+ fprintf(stderr, " %s misc [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
+ fprintf(stderr, " %s wicked [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print formatted information string and flush the buffer */
-static void iprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- fflush(stdout);
- va_end(ap);
+static void iprintf(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ fflush(stdout);
+ va_end(ap);
}
-
/* print a character and flush the buffer */
-static void iputchar(int c){
- putchar(c);
- fflush(stdout);
+static void iputchar(int c) {
+ putchar(c);
+ fflush(stdout);
}
-
/* print error message of hash database */
-static void eprint(TCHDB *hdb, int line, const char *func){
- const char *path = tchdbpath(hdb);
- int ecode = tchdbecode(hdb);
- fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
- g_progname, path ? path : "-", line, func, ecode, tchdberrmsg(ecode));
+static void eprint(TCHDB *hdb, int line, const char *func) {
+ const char *path = tchdbpath(hdb);
+ int ecode = tchdbecode(hdb);
+ fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
+ g_progname, path ? path : "-", line, func, ecode, tchdberrmsg(ecode));
}
-
/* print members of hash database */
-static void mprint(TCHDB *hdb){
- if(hdb->cnt_writerec < 0) return;
- iprintf("bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnum(hdb));
- iprintf("used bucket number: %" PRIdMAX "\n", (int64_t)tchdbbnumused(hdb));
- iprintf("msiz: %" PRIdMAX "\n", hdb->msiz);
- iprintf("xmsiz: %" PRIdMAX "\n", hdb->xmsiz);
- iprintf("fbpnum: %" PRIdMAX "\n", hdb->fbpnum);
- iprintf("fbpool: %p\n", hdb->fbpool);
+static void mprint(TCHDB *hdb) {
+ if (hdb->cnt_writerec < 0) return;
+ iprintf("bucket number: %" PRIdMAX "\n", (int64_t) tchdbbnum(hdb));
+ iprintf("used bucket number: %" PRIdMAX "\n", (int64_t) tchdbbnumused(hdb));
+ iprintf("msiz: %" PRIdMAX "\n", hdb->msiz);
+ iprintf("xmsiz: %" PRIdMAX "\n", hdb->xmsiz);
+ iprintf("fbpnum: %" PRIdMAX "\n", hdb->fbpnum);
+ iprintf("fbpool: %p\n", hdb->fbpool);
#ifndef NDEBUG
- iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t)hdb->cnt_writerec);
- iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t)hdb->cnt_reuserec);
- iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t)hdb->cnt_moverec);
- iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t)hdb->cnt_readrec);
- iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_searchfbp);
- iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_insertfbp);
- iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_splicefbp);
- iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_dividefbp);
- iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_mergefbp);
- iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t)hdb->cnt_reducefbp);
- iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_appenddrp);
- iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_deferdrp);
- iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t)hdb->cnt_flushdrp);
- iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t)hdb->cnt_adjrecc);
- iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t)hdb->cnt_defrag);
- iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t)hdb->cnt_shiftrec);
- iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t)hdb->cnt_trunc);
+ iprintf("cnt_writerec: %" PRIdMAX "\n", (int64_t) hdb->cnt_writerec);
+ iprintf("cnt_reuserec: %" PRIdMAX "\n", (int64_t) hdb->cnt_reuserec);
+ iprintf("cnt_moverec: %" PRIdMAX "\n", (int64_t) hdb->cnt_moverec);
+ iprintf("cnt_readrec: %" PRIdMAX "\n", (int64_t) hdb->cnt_readrec);
+ iprintf("cnt_searchfbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_searchfbp);
+ iprintf("cnt_insertfbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_insertfbp);
+ iprintf("cnt_splicefbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_splicefbp);
+ iprintf("cnt_dividefbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_dividefbp);
+ iprintf("cnt_mergefbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_mergefbp);
+ iprintf("cnt_reducefbp: %" PRIdMAX "\n", (int64_t) hdb->cnt_reducefbp);
+ iprintf("cnt_appenddrp: %" PRIdMAX "\n", (int64_t) hdb->cnt_appenddrp);
+ iprintf("cnt_deferdrp: %" PRIdMAX "\n", (int64_t) hdb->cnt_deferdrp);
+ iprintf("cnt_flushdrp: %" PRIdMAX "\n", (int64_t) hdb->cnt_flushdrp);
+ iprintf("cnt_adjrecc: %" PRIdMAX "\n", (int64_t) hdb->cnt_adjrecc);
+ iprintf("cnt_defrag: %" PRIdMAX "\n", (int64_t) hdb->cnt_defrag);
+ iprintf("cnt_shiftrec: %" PRIdMAX "\n", (int64_t) hdb->cnt_shiftrec);
+ iprintf("cnt_trunc: %" PRIdMAX "\n", (int64_t) hdb->cnt_trunc);
#endif
}
-
/* print system information */
-static void sysprint(void){
- TCMAP *info = tcsysinfo();
- if(info){
- tcmapiterinit(info);
- const char *kbuf;
- while((kbuf = tcmapiternext2(info)) != NULL){
- iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+static void sysprint(void) {
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ tcmapiterinit(info);
+ const char *kbuf;
+ while ((kbuf = tcmapiternext2(info)) != NULL) {
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+ }
+ tcmapdel(info);
}
- tcmapdel(info);
- }
}
-
/* get a random number */
-static int myrand(int range){
- if(range < 2) return 0;
- int high = (unsigned int)rand() >> 4;
- int low = range * (rand() / (RAND_MAX + 1.0));
- low &= (unsigned int)INT_MAX >> 4;
- return (high + low) % range;
+static int myrand(int range) {
+ if (range < 2) return 0;
+ int high = (unsigned int) rand() >> 4;
+ int low = range * (rand() / (RAND_MAX + 1.0));
+ low &= (unsigned int) INT_MAX >> 4;
+ return (high + low) % range;
}
-
/* duplication callback function */
-static void *pdprocfunc(const void *vbuf, int vsiz, int *sp, void *op){
- if(op){
- char *buf = NULL;
- int len = 0;
- switch((int)(intptr_t)op){
- case 1:
- len = vsiz + 1;
- buf = tcmalloc(len + 1);
- memset(buf, '*', len);
- break;
- case 2:
- buf = (void *)-1;
- break;
+static void *pdprocfunc(const void *vbuf, int vsiz, int *sp, void *op) {
+ if (op) {
+ char *buf = NULL;
+ int len = 0;
+ switch ((int) (intptr_t) op) {
+ case 1:
+ len = vsiz + 1;
+ buf = tcmalloc(len + 1);
+ memset(buf, '*', len);
+ break;
+ case 2:
+ buf = (void *) - 1;
+ break;
+ }
+ *sp = len;
+ return buf;
}
+ if (myrand(4) == 0) return (void *) - 1;
+ if (myrand(2) == 0) return NULL;
+ int len = myrand(RECBUFSIZ);
+ char buf[RECBUFSIZ];
+ memset(buf, '*', len);
*sp = len;
- return buf;
- }
- if(myrand(4) == 0) return (void *)-1;
- if(myrand(2) == 0) return NULL;
- int len = myrand(RECBUFSIZ);
- char buf[RECBUFSIZ];
- memset(buf, '*', len);
- *sp = len;
- return tcmemdup(buf, len);
+ return tcmemdup(buf, len);
}
-
/* iterator function */
-static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op){
- unsigned int sum = 0;
- while(--ksiz >= 0){
- sum += ((char *)kbuf)[ksiz];
- }
- while(--vsiz >= 0){
- sum += ((char *)vbuf)[vsiz];
- }
- return myrand(100 + (sum & 0xff)) > 0;
+static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op) {
+ unsigned int sum = 0;
+ while (--ksiz >= 0) {
+ sum += ((char *) kbuf)[ksiz];
+ }
+ while (--vsiz >= 0) {
+ sum += ((char *) vbuf)[vsiz];
+ }
+ return myrand(100 + (sum & 0xff)) > 0;
}
-
/* parse arguments of write command */
-static int runwrite(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- bool mt = false;
- int opts = 0;
- int rcnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool as = false;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= HDBTEXCODEC;
- } else if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-as")){
- as = true;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procwrite(path, rnum, bnum, apow, fpow,
- mt, opts, rcnum, xmsiz, dfunit, omode, as, rnd);
- return rv;
+static int runwrite(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ bool mt = false;
+ int opts = 0;
+ int rcnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool as = false;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= HDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-as")) {
+ as = true;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procwrite(path, rnum, bnum, apow, fpow,
+ mt, opts, rcnum, xmsiz, dfunit, omode, as, rnd);
+ return rv;
}
-
/* parse arguments of read command */
-static int runread(int argc, char **argv){
- char *path = NULL;
- bool mt = false;
- int rcnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool wb = false;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-wb")){
- wb = true;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runread(int argc, char **argv) {
+ char *path = NULL;
+ bool mt = false;
+ int rcnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool wb = false;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-wb")) {
+ wb = true;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procread(path, mt, rcnum, xmsiz, dfunit, omode, wb, rnd);
- return rv;
+ if (!path) usage();
+ int rv = procread(path, mt, rcnum, xmsiz, dfunit, omode, wb, rnd);
+ return rv;
}
-
/* parse arguments of remove command */
-static int runremove(int argc, char **argv){
- char *path = NULL;
- bool mt = false;
- int rcnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runremove(int argc, char **argv) {
+ char *path = NULL;
+ bool mt = false;
+ int rcnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procremove(path, mt, rcnum, xmsiz, dfunit, omode, rnd);
- return rv;
+ if (!path) usage();
+ int rv = procremove(path, mt, rcnum, xmsiz, dfunit, omode, rnd);
+ return rv;
}
-
/* parse arguments of rcat command */
-static int runrcat(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- bool mt = false;
- int opts = 0;
- int rcnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- int pnum = 0;
- bool dai = false;
- bool dad = false;
- bool rl = false;
- bool ru = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= HDBTEXCODEC;
- } else if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else if(!strcmp(argv[i], "-pn")){
- if(++i >= argc) usage();
- pnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-dai")){
- dai = true;
- } else if(!strcmp(argv[i], "-dad")){
- dad = true;
- } else if(!strcmp(argv[i], "-rl")){
- rl = true;
- } else if(!strcmp(argv[i], "-ru")){
- ru = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procrcat(path, rnum, bnum, apow, fpow, mt, opts, rcnum, xmsiz, dfunit, omode, pnum,
- dai, dad, rl, ru);
- return rv;
+static int runrcat(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ bool mt = false;
+ int opts = 0;
+ int rcnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ int pnum = 0;
+ bool dai = false;
+ bool dad = false;
+ bool rl = false;
+ bool ru = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= HDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else if (!strcmp(argv[i], "-pn")) {
+ if (++i >= argc) usage();
+ pnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-dai")) {
+ dai = true;
+ } else if (!strcmp(argv[i], "-dad")) {
+ dad = true;
+ } else if (!strcmp(argv[i], "-rl")) {
+ rl = true;
+ } else if (!strcmp(argv[i], "-ru")) {
+ ru = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procrcat(path, rnum, bnum, apow, fpow, mt, opts, rcnum, xmsiz, dfunit, omode, pnum,
+ dai, dad, rl, ru);
+ return rv;
}
-
/* parse arguments of misc command */
-static int runmisc(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- bool mt = false;
- int opts = 0;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= HDBTEXCODEC;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int rv = procmisc(path, rnum, mt, opts, omode);
- return rv;
+static int runmisc(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ bool mt = false;
+ int opts = 0;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= HDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int rv = procmisc(path, rnum, mt, opts, omode);
+ return rv;
}
-
/* parse arguments of wicked command */
-static int runwicked(int argc, char **argv){
- char *path = NULL;
- char *rstr = NULL;
- bool mt = false;
- int opts = 0;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-mt")){
- mt = true;
- } else if(!strcmp(argv[i], "-tl")){
- opts |= HDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= HDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= HDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= HDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= HDBTEXCODEC;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= HDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= HDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !rstr) usage();
- int rnum = tcatoix(rstr);
- if(rnum < 1) usage();
- int rv = procwicked(path, rnum, mt, opts, omode);
- return rv;
+static int runwicked(int argc, char **argv) {
+ char *path = NULL;
+ char *rstr = NULL;
+ bool mt = false;
+ int opts = 0;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-mt")) {
+ mt = true;
+ } else if (!strcmp(argv[i], "-tl")) {
+ opts |= HDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= HDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= HDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= HDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= HDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= HDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= HDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !rstr) usage();
+ int rnum = tcatoix(rstr);
+ if (rnum < 1) usage();
+ int rv = procwicked(path, rnum, mt, opts, omode);
+ return rv;
}
-
/* perform write command */
static int procwrite(const char *path, int rnum, int bnum, int apow, int fpow,
- bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode,
- bool as, bool rnd){
- iprintf("<Writing Test>\n seed=%u path=%s rnum=%d bnum=%d apow=%d fpow=%d mt=%d"
- " opts=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d as=%d rnd=%d\n\n",
- g_randseed, path, rnum, bnum, apow, fpow, mt, opts, rcnum, xmsiz, dfunit,
- omode, as, rnd);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(mt && !tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbtune(hdb, bnum, apow, fpow, opts)){
- eprint(hdb, __LINE__, "tchdbtune");
- err = true;
- }
- if(!tchdbsetcache(hdb, rcnum)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!rnd) omode |= HDBOTRUNC;
- if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", rnd ? myrand(rnum) + 1 : i);
- if(as){
- if(!tchdbputasync(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbput");
+ bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode,
+ bool as, bool rnd) {
+ iprintf("<Writing Test>\n seed=%u path=%s rnum=%d bnum=%d apow=%d fpow=%d mt=%d"
+ " opts=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d as=%d rnd=%d\n\n",
+ g_randseed, path, rnum, bnum, apow, fpow, mt, opts, rcnum, xmsiz, dfunit,
+ omode, as, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (mt && !tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
err = true;
- break;
- }
- } else {
- if(!tchdbput(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
+ err = true;
+ }
+ if (!tchdbtune(hdb, bnum, apow, fpow, opts)) {
+ eprint(hdb, __LINE__, "tchdbtune");
+ err = true;
+ }
+ if (!tchdbsetcache(hdb, rcnum)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
+ err = true;
+ }
+ if (!rnd) omode |= HDBOTRUNC;
+ if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ if (as) {
+ if (!tchdbputasync(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ break;
+ }
+ } else {
+ if (!tchdbput(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ break;
+ }
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform read command */
static int procread(const char *path, bool mt, int rcnum, int xmsiz, int dfunit, int omode,
- bool wb, bool rnd){
- iprintf("<Reading Test>\n seed=%u path=%s mt=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d"
- " wb=%d rnd=%d\n\n", g_randseed, path, mt, rcnum, xmsiz, dfunit, omode, wb, rnd);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(mt && !tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbsetcache(hdb, rcnum)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOREADER | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- int rnum = tchdbrnum(hdb);
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
- int vsiz;
- if(wb){
- char vbuf[RECBUFSIZ];
- int vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, RECBUFSIZ);
- if(vsiz < 0 && !(rnd && tchdbecode(hdb) == TCENOREC)){
- eprint(hdb, __LINE__, "tchdbget3");
- err = true;
- break;
- }
- } else {
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(!vbuf && !(rnd && tchdbecode(hdb) == TCENOREC)){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- break;
- }
- tcfree(vbuf);
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ bool wb, bool rnd) {
+ iprintf("<Reading Test>\n seed=%u path=%s mt=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d"
+ " wb=%d rnd=%d\n\n", g_randseed, path, mt, rcnum, xmsiz, dfunit, omode, wb, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (mt && !tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
+ err = true;
+ }
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
+ err = true;
+ }
+ if (!tchdbsetcache(hdb, rcnum)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
+ err = true;
+ }
+ if (!tchdbopen(hdb, path, HDBOREADER | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ int rnum = tchdbrnum(hdb);
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ int vsiz;
+ if (wb) {
+ char vbuf[RECBUFSIZ];
+ int vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, RECBUFSIZ);
+ if (vsiz < 0 && !(rnd && tchdbecode(hdb) == TCENOREC)) {
+ eprint(hdb, __LINE__, "tchdbget3");
+ err = true;
+ break;
+ }
+ } else {
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (!vbuf && !(rnd && tchdbecode(hdb) == TCENOREC)) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ break;
+ }
+ tcfree(vbuf);
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform remove command */
static int procremove(const char *path, bool mt, int rcnum, int xmsiz, int dfunit, int omode,
- bool rnd){
- iprintf("<Removing Test>\n seed=%u path=%s mt=%d rcnum=%d xmsiz=%d dfunit=%d"
- " omode=%d rnd=%d\n\n", g_randseed, path, mt, rcnum, xmsiz, dfunit, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(mt && !tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbsetcache(hdb, rcnum)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- int rnum = tchdbrnum(hdb);
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
- if(!tchdbout(hdb, kbuf, ksiz) && !(rnd && tchdbecode(hdb) == TCENOREC)){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ bool rnd) {
+ iprintf("<Removing Test>\n seed=%u path=%s mt=%d rcnum=%d xmsiz=%d dfunit=%d"
+ " omode=%d rnd=%d\n\n", g_randseed, path, mt, rcnum, xmsiz, dfunit, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (mt && !tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
+ err = true;
+ }
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
+ err = true;
+ }
+ if (!tchdbsetcache(hdb, rcnum)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
+ err = true;
+ }
+ if (!tchdbopen(hdb, path, HDBOWRITER | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ int rnum = tchdbrnum(hdb);
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
+ if (!tchdbout(hdb, kbuf, ksiz) && !(rnd && tchdbecode(hdb) == TCENOREC)) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform rcat command */
static int procrcat(const char *path, int rnum, int bnum, int apow, int fpow,
- bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode, int pnum,
- bool dai, bool dad, bool rl, bool ru){
- iprintf("<Random Concatenating Test>\n"
- " seed=%u path=%s rnum=%d bnum=%d apow=%d fpow=%d mt=%d opts=%d"
- " rcnum=%d xmsiz=%d dfunit=%d omode=%d pnum=%d dai=%d dad=%d rl=%d ru=%d\n\n",
- g_randseed, path, rnum, bnum, apow, fpow, mt, opts, rcnum, xmsiz, dfunit, omode, pnum,
- dai, dad, rl, ru);
- if(pnum < 1) pnum = rnum;
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(mt && !tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbtune(hdb, bnum, apow, fpow, opts)){
- eprint(hdb, __LINE__, "tchdbtune");
- err = true;
- }
- if(!tchdbsetcache(hdb, rcnum)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- if(ru){
- char fmt[RECBUFSIZ];
- sprintf(fmt, "%%0%dd", myrand(RECBUFSIZ));
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, fmt, myrand(pnum));
- switch(myrand(8)){
- case 0:
- if(!tchdbput(hdb, kbuf, ksiz, kbuf, ksiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- break;
- case 1:
- if(!tchdbputkeep(hdb, kbuf, ksiz, kbuf, ksiz) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- }
- break;
- case 2:
- if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- }
- break;
- case 3:
- if(tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbaddint");
- err = true;
- }
- break;
- case 4:
- if(isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbadddouble");
- err = true;
- }
- break;
- case 5:
- if(myrand(2) == 0){
- if(!tchdbputproc(hdb, kbuf, ksiz, kbuf, ksiz, pdprocfunc, NULL) &&
- tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputproc");
- err = true;
+ bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode, int pnum,
+ bool dai, bool dad, bool rl, bool ru) {
+ iprintf("<Random Concatenating Test>\n"
+ " seed=%u path=%s rnum=%d bnum=%d apow=%d fpow=%d mt=%d opts=%d"
+ " rcnum=%d xmsiz=%d dfunit=%d omode=%d pnum=%d dai=%d dad=%d rl=%d ru=%d\n\n",
+ g_randseed, path, rnum, bnum, apow, fpow, mt, opts, rcnum, xmsiz, dfunit, omode, pnum,
+ dai, dad, rl, ru);
+ if (pnum < 1) pnum = rnum;
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (mt && !tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
+ err = true;
+ }
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
+ err = true;
+ }
+ if (!tchdbtune(hdb, bnum, apow, fpow, opts)) {
+ eprint(hdb, __LINE__, "tchdbtune");
+ err = true;
+ }
+ if (!tchdbsetcache(hdb, rcnum)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
+ err = true;
+ }
+ if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ for (int i = 1; i <= rnum; i++) {
+ if (ru) {
+ char fmt[RECBUFSIZ];
+ sprintf(fmt, "%%0%dd", myrand(RECBUFSIZ));
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, fmt, myrand(pnum));
+ switch (myrand(8)) {
+ case 0:
+ if (!tchdbput(hdb, kbuf, ksiz, kbuf, ksiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tchdbputkeep(hdb, kbuf, ksiz, kbuf, ksiz) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ break;
+ case 3:
+ if (tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbaddint");
+ err = true;
+ }
+ break;
+ case 4:
+ if (isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbadddouble");
+ err = true;
+ }
+ break;
+ case 5:
+ if (myrand(2) == 0) {
+ if (!tchdbputproc(hdb, kbuf, ksiz, kbuf, ksiz, pdprocfunc, NULL) &&
+ tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputproc");
+ err = true;
+ }
+ } else {
+ if (!tchdbputproc(hdb, kbuf, ksiz, NULL, 0, pdprocfunc, NULL) &&
+ tchdbecode(hdb) != TCEKEEP && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbputproc");
+ err = true;
+ }
+ }
+ break;
+ default:
+ if (!tchdbputcat(hdb, kbuf, ksiz, kbuf, ksiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ break;
}
- } else {
- if(!tchdbputproc(hdb, kbuf, ksiz, NULL, 0, pdprocfunc, NULL) &&
- tchdbecode(hdb) != TCEKEEP && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbputproc");
- err = true;
+ if (err) break;
+ } else {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(pnum));
+ if (dai) {
+ if (tchdbaddint(hdb, kbuf, ksiz, myrand(3)) == INT_MIN) {
+ eprint(hdb, __LINE__, "tchdbaddint");
+ err = true;
+ break;
+ }
+ } else if (dad) {
+ if (isnan(tchdbadddouble(hdb, kbuf, ksiz, myrand(30) / 10.0))) {
+ eprint(hdb, __LINE__, "tchdbadddouble");
+ err = true;
+ break;
+ }
+ } else if (rl) {
+ char vbuf[PATH_MAX];
+ int vsiz = myrand(PATH_MAX);
+ for (int j = 0; j < vsiz; j++) {
+ vbuf[j] = myrand(0x100);
+ }
+ if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ break;
+ }
+ } else {
+ if (!tchdbputcat(hdb, kbuf, ksiz, kbuf, ksiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ break;
+ }
}
- }
- break;
- default:
- if(!tchdbputcat(hdb, kbuf, ksiz, kbuf, ksiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
- break;
- }
- if(err) break;
- } else {
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(pnum));
- if(dai){
- if(tchdbaddint(hdb, kbuf, ksiz, myrand(3)) == INT_MIN){
- eprint(hdb, __LINE__, "tchdbaddint");
- err = true;
- break;
- }
- } else if(dad){
- if(isnan(tchdbadddouble(hdb, kbuf, ksiz, myrand(30) / 10.0))){
- eprint(hdb, __LINE__, "tchdbadddouble");
- err = true;
- break;
- }
- } else if(rl){
- char vbuf[PATH_MAX];
- int vsiz = myrand(PATH_MAX);
- for(int j = 0; j < vsiz; j++){
- vbuf[j] = myrand(0x100);
- }
- if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- break;
- }
- } else {
- if(!tchdbputcat(hdb, kbuf, ksiz, kbuf, ksiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- break;
- }
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform misc command */
-static int procmisc(const char *path, int rnum, bool mt, int opts, int omode){
- iprintf("<Miscellaneous Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
- g_randseed, path, rnum, mt, opts, omode);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(mt && !tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbtune(hdb, rnum / 50, 2, -1, opts)){
- eprint(hdb, __LINE__, "tchdbtune");
- err = true;
- }
- if(!tchdbsetcache(hdb, rnum / 10)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(!tchdbsetxmsiz(hdb, rnum * sizeof(int))){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(!tchdbsetdfunit(hdb, 8)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- if(1){
- TCHDB *hdbdup = tchdbnew();
- if(tchdbopen(hdbdup, path, HDBOREADER)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- } else if(tchdbecode(hdbdup) != TCETHREAD){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- tchdbdel(hdbdup);
- }
- iprintf("writing:\n");
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- if(i % 3 == 0){
- if(!tchdbputkeep(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbputkeep");
+static int procmisc(const char *path, int rnum, bool mt, int opts, int omode) {
+ iprintf("<Miscellaneous Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
+ g_randseed, path, rnum, mt, opts, omode);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (mt && !tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
err = true;
- break;
- }
- } else {
- if(!tchdbputasync(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbputasync");
- err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("reading:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", i);
- int vsiz;
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- break;
- } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- tcfree(vbuf);
- break;
- }
- tcfree(vbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(tchdbrnum(hdb) != rnum){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- iprintf("random writing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '*', vsiz);
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- break;
- }
- int rsiz;
- char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
- if(!rbuf){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- break;
- }
- if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- tcfree(rbuf);
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- tcfree(rbuf);
- }
- iprintf("word writing:\n");
- const char *words[] = {
- "a", "A", "bb", "BB", "ccc", "CCC", "dddd", "DDDD", "eeeee", "EEEEEE",
- "mikio", "hirabayashi", "tokyo", "cabinet", "hyper", "estraier", "19780211", "birth day",
- "one", "first", "two", "second", "three", "third", "four", "fourth", "five", "fifth",
- "_[1]_", "uno", "_[2]_", "dos", "_[3]_", "tres", "_[4]_", "cuatro", "_[5]_", "cinco",
- "[\xe5\xb9\xb3\xe6\x9e\x97\xe5\xb9\xb9\xe9\x9b\x84]", "[\xe9\xa6\xac\xe9\xb9\xbf]", NULL
- };
- for(int i = 0; words[i] != NULL; i += 2){
- const char *kbuf = words[i];
- int ksiz = strlen(kbuf);
- const char *vbuf = words[i+1];
- int vsiz = strlen(vbuf);
- if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- break;
- }
- if(rnum > 250) iputchar('.');
- }
- if(rnum > 250) iprintf(" (%08d)\n", (int)(sizeof(words) / sizeof(*words)));
- iprintf("random erasing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("writing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "[%d]", i);
- char vbuf[RECBUFSIZ];
- int vsiz = i % RECBUFSIZ;
- memset(vbuf, '*', vsiz);
- if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- break;
- }
- if(vsiz < 1){
- char tbuf[PATH_MAX];
- for(int j = 0; j < PATH_MAX; j++){
- tbuf[j] = myrand(0x100);
- }
- if(!tchdbput(hdb, kbuf, ksiz, tbuf, PATH_MAX)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("erasing:\n");
- for(int i = 1; i <= rnum; i++){
- if(i % 2 == 1){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "[%d]", i);
- if(!tchdbout(hdb, kbuf, ksiz)){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- break;
- }
- if(tchdbout(hdb, kbuf, ksiz) || tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("random writing and reopening:\n");
- for(int i = 1; i <= rnum; i++){
- if(myrand(10) == 0){
- int ksiz, vsiz;
- char *kbuf, *vbuf;
- ksiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
- kbuf = tcmalloc(ksiz + 1);
- memset(kbuf, '@', ksiz);
- vsiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
- vbuf = tcmalloc(vsiz + 1);
- for(int j = 0; j < vsiz; j++){
- vbuf[j] = myrand(256);
- }
- switch(myrand(4)){
- case 0:
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- break;
- case 1:
- if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
- break;
- case 2:
- if(!tchdbputasync(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputasync");
- err = true;
- }
- break;
- case 3:
- if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- }
- break;
- }
- tcfree(vbuf);
- tcfree(kbuf);
- } else {
- char kbuf[RECBUFSIZ];
- int ksiz = myrand(RECBUFSIZ);
- memset(kbuf, '@', ksiz);
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '@', vsiz);
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- break;
- }
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- iprintf("checking:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "[%d]", i);
- int vsiz;
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(i % 2 == 0){
- if(!vbuf){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- break;
- }
- if(vsiz != i % RECBUFSIZ && vsiz != PATH_MAX){
- eprint(hdb, __LINE__, "(validation)");
+ }
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
err = true;
- tcfree(vbuf);
- break;
- }
- } else {
- if(vbuf || tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "(validation)");
+ }
+ if (!tchdbtune(hdb, rnum / 50, 2, -1, opts)) {
+ eprint(hdb, __LINE__, "tchdbtune");
err = true;
- tcfree(vbuf);
- break;
- }
}
- tcfree(vbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ if (!tchdbsetcache(hdb, rnum / 10)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
+ err = true;
}
- }
- iprintf("writing:\n");
- for(int i = 1; i <= rnum; i++){
- char buf[RECBUFSIZ];
- int len = sprintf(buf, "%08d", i);
- if(!tchdbput(hdb, buf, len, buf, len)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("reading:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%08d", i);
- int vsiz;
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- break;
- } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- tcfree(vbuf);
- break;
- }
- tcfree(vbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- iprintf("checking words:\n");
- for(int i = 0; words[i] != NULL; i += 2){
- const char *kbuf = words[i];
- int ksiz = strlen(kbuf);
- const char *vbuf = words[i+1];
- int vsiz = strlen(vbuf);
- int rsiz;
- char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
- if(!rbuf){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- break;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- tcfree(rbuf);
- break;
- }
- tcfree(rbuf);
- if(rnum > 250) iputchar('.');
- }
- if(rnum > 250) iprintf(" (%08d)\n", (int)(sizeof(words) / sizeof(*words)));
- iprintf("checking iterator:\n");
- int inum = 0;
- if(!tchdbiterinit(hdb)){
- eprint(hdb, __LINE__, "tchdbiterinit");
- err = true;
- }
- char *kbuf;
- int ksiz;
- for(int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++){
- int vsiz;
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- if(!vbuf){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- tcfree(kbuf);
- break;
- }
- tcfree(vbuf);
- tcfree(kbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- if(tchdbecode(hdb) != TCENOREC || inum != tchdbrnum(hdb)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- iprintf("iteration updating:\n");
- if(!tchdbiterinit(hdb)){
- eprint(hdb, __LINE__, "tchdbiterinit");
- err = true;
- }
- inum = 0;
- for(int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++){
- if(myrand(2) == 0){
- if(!tchdbputcat(hdb, kbuf, ksiz, "0123456789", 10)){
- eprint(hdb, __LINE__, "tchdbputcat");
+ if (!tchdbsetxmsiz(hdb, rnum * sizeof (int))) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
err = true;
- tcfree(kbuf);
- break;
- }
- } else {
- if(!tchdbout(hdb, kbuf, ksiz)){
- eprint(hdb, __LINE__, "tchdbout");
+ }
+ if (!tchdbsetdfunit(hdb, 8)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
err = true;
- tcfree(kbuf);
- break;
- }
- }
- tcfree(kbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- if(tchdbecode(hdb) != TCENOREC || inum < tchdbrnum(hdb)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- if(myrand(10) == 0 && !tchdbsync(hdb)){
- eprint(hdb, __LINE__, "tchdbsync");
- err = true;
- }
- if(!tchdbvanish(hdb)){
- eprint(hdb, __LINE__, "tchdbvanish");
- err = true;
- }
- TCMAP *map = tcmapnew();
- iprintf("random writing:\n");
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = sprintf(vbuf, "%d", myrand(rnum));
- switch(myrand(4)){
- case 0:
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- }
- tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 2:
- if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
- tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- }
- tcmapout(map, kbuf, ksiz);
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(myrand(4) == 0 && !tchdbdefrag(hdb, 0)){
- eprint(hdb, __LINE__, "tchdbdefrag");
- err = true;
- }
- if(myrand(4) == 0 && !tchdbcacheclear(hdb)){
- eprint(hdb, __LINE__, "tchdbcacheclear");
- err = true;
- }
- iprintf("checking transaction commit:\n");
- if(!tchdbtranbegin(hdb)){
- eprint(hdb, __LINE__, "tchdbtranbegin");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = sprintf(vbuf, "[%d]", myrand(rnum));
- switch(myrand(7)){
- case 0:
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- }
- tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 2:
- if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
- tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- if(tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbaddint");
- err = true;
- }
- tcmapaddint(map, kbuf, ksiz, 1);
- break;
- case 4:
- if(isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbadddouble");
- err = true;
- }
- tcmapadddouble(map, kbuf, ksiz, 1.0);
- break;
- case 5:
- if(myrand(2) == 0){
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tchdbputproc(hdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
- tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputproc");
- err = true;
- }
- tcmapputproc(map, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op);
- } else {
- vsiz = myrand(10);
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tchdbputproc(hdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
- tchdbecode(hdb) != TCEKEEP && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbputproc");
+ }
+ if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ if (1) {
+ TCHDB *hdbdup = tchdbnew();
+ if (tchdbopen(hdbdup, path, HDBOREADER)) {
+ eprint(hdb, __LINE__, "(validation)");
err = true;
- }
- tcmapputproc(map, kbuf, ksiz, NULL, vsiz, pdprocfunc, op);
- }
- break;
- case 6:
- if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- }
- tcmapout(map, kbuf, ksiz);
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tchdbtrancommit(hdb)){
- eprint(hdb, __LINE__, "tchdbtrancommit");
- err = true;
- }
- iprintf("checking transaction abort:\n");
- uint64_t ornum = tchdbrnum(hdb);
- uint64_t ofsiz = tchdbfsiz(hdb);
- if(!tchdbtranbegin(hdb)){
- eprint(hdb, __LINE__, "tchdbtranbegin");
- err = true;
- }
- for(int i = 1; i <= rnum; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = sprintf(vbuf, "((%d))", myrand(rnum));
- switch(myrand(7)){
- case 0:
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- break;
- case 1:
- if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- }
- break;
- case 2:
- if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
- break;
- case 3:
- if(tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbaddint");
- err = true;
- }
- break;
- case 4:
- if(isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbadddouble");
- err = true;
- }
- break;
- case 5:
- if(myrand(2) == 0){
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tchdbputproc(hdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
- tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputproc");
+ } else if (tchdbecode(hdbdup) != TCETHREAD) {
+ eprint(hdb, __LINE__, "(validation)");
err = true;
- }
+ }
+ tchdbdel(hdbdup);
+ }
+ iprintf("writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", i);
+ if (i % 3 == 0) {
+ if (!tchdbputkeep(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
+ err = true;
+ break;
+ }
} else {
- vsiz = myrand(10);
- void *op = (void *)(intptr_t)(myrand(3) + 1);
- if(!tchdbputproc(hdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
- tchdbecode(hdb) != TCEKEEP && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbputproc");
+ if (!tchdbputasync(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbputasync");
+ err = true;
+ break;
+ }
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("reading:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", i);
+ int vsiz;
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
+ eprint(hdb, __LINE__, "tchdbget");
err = true;
- }
- }
- break;
- case 6:
- if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- }
- break;
- }
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(!tchdbtranabort(hdb)){
- eprint(hdb, __LINE__, "tchdbtranabort");
- err = true;
- }
- iprintf("checking consistency: %d %d\n", (int)tchdbrnum(hdb), (int) ornum);
- if(tchdbrnum(hdb) != ornum || tchdbfsiz(hdb) != ofsiz || tchdbrnum(hdb) != tcmaprnum(map)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- inum = 0;
- tcmapiterinit(map);
- const char *tkbuf;
- int tksiz;
- for(int i = 1; (tkbuf = tcmapiternext(map, &tksiz)) != NULL; i++, inum++){
- int tvsiz;
- const char *tvbuf = tcmapiterval(tkbuf, &tvsiz);
- int rsiz;
- char *rbuf = tchdbget(hdb, tkbuf, tksiz, &rsiz);
- if(!rbuf || rsiz != tvsiz || memcmp(rbuf, tvbuf, rsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- tcfree(rbuf);
- break;
- }
- tcfree(rbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- inum = 0;
- if(!tchdbiterinit(hdb)){
- eprint(hdb, __LINE__, "tchdbiterinit");
- err = true;
- }
- for(int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++){
- int vsiz;
- char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
- int rsiz;
- const char *rbuf = tcmapget(map, kbuf, ksiz, &rsiz);
- if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- tcfree(vbuf);
- tcfree(kbuf);
- break;
- }
- tcfree(vbuf);
- tcfree(kbuf);
- if(rnum > 250 && i % (rnum / 250) == 0){
- iputchar('.');
- if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
- }
- }
- if(rnum > 250) iprintf(" (%08d)\n", inum);
- tcmapdel(map);
- if(!tchdbvanish(hdb)){
- eprint(hdb, __LINE__, "tchdbvanish");
- err = true;
- }
- for(int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)){
- char vbuf[i];
- memset(vbuf, '@', i - 1);
- vbuf[i-1] = '\0';
- if(!tchdbput2(hdb, "mikio", vbuf)){
- eprint(hdb, __LINE__, "tchdbput2");
- err = true;
- }
- }
- if(!tchdbput2(hdb, "mikio", "nanashi")){
- eprint(hdb, __LINE__, "tchdbput2");
- err = true;
- }
- if(!tchdbtranbegin(hdb)){
- eprint(hdb, __LINE__, "tchdbtranbegin");
- err = true;
- }
- if(!tchdbput2(hdb, "mikio", "hirabayashi")){
- eprint(hdb, __LINE__, "tchdbput2");
- err = true;
- }
- for(int i = 0; i < 10; i++){
- char buf[RECBUFSIZ];
- int size = sprintf(buf, "%d", myrand(rnum));
- if(!tchdbput(hdb, buf, size, buf, size)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- }
- for(int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)){
- char vbuf[i];
- memset(vbuf, '@', i - 1);
- vbuf[i-1] = '\0';
- if(!tchdbput2(hdb, "mikio", vbuf)){
- eprint(hdb, __LINE__, "tchdbput2");
- err = true;
- }
- }
- if(!tchdbforeach(hdb, iterfunc, NULL)){
- eprint(hdb, __LINE__, "tchdbforeach");
- err = true;
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
-}
-
-
-/* perform wicked command */
-static int procwicked(const char *path, int rnum, bool mt, int opts, int omode){
- iprintf("<Wicked Writing Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
- g_randseed, path, rnum, mt, opts, omode);
- bool err = false;
- double stime = tctime();
- TCHDB *hdb = tchdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
- if(mt && !tchdbsetmutex(hdb)){
- eprint(hdb, __LINE__, "tchdbsetmutex");
- err = true;
- }
- if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(hdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbtune(hdb, rnum / 50, 2, -1, opts)){
- eprint(hdb, __LINE__, "tchdbtune");
- err = true;
- }
- if(!tchdbsetcache(hdb, rnum / 10)){
- eprint(hdb, __LINE__, "tchdbsetcache");
- err = true;
- }
- if(!tchdbsetxmsiz(hdb, rnum * sizeof(int))){
- eprint(hdb, __LINE__, "tchdbsetxmsiz");
- err = true;
- }
- if(!tchdbsetdfunit(hdb, 8)){
- eprint(hdb, __LINE__, "tchdbsetdfunit");
- err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
- eprint(hdb, __LINE__, "tchdbopen");
- err = true;
- }
- if(!tchdbiterinit(hdb)){
- eprint(hdb, __LINE__, "tchdbiterinit");
- err = true;
- }
- TCMAP *map = tcmapnew2(rnum / 5);
- for(int i = 1; i <= rnum && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", myrand(rnum));
- char vbuf[RECBUFSIZ];
- int vsiz = myrand(RECBUFSIZ);
- memset(vbuf, '*', vsiz);
- vbuf[vsiz] = '\0';
- char *rbuf;
- switch(myrand(16)){
- case 0:
- iputchar('0');
- if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 1:
- iputchar('1');
- if(!tchdbput2(hdb, kbuf, vbuf)){
- eprint(hdb, __LINE__, "tchdbput2");
- err = true;
- }
- tcmapput2(map, kbuf, vbuf);
- break;
- case 2:
- iputchar('2');
- if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep");
- err = true;
- }
- tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 3:
- iputchar('3');
- if(!tchdbputkeep2(hdb, kbuf, vbuf) && tchdbecode(hdb) != TCEKEEP){
- eprint(hdb, __LINE__, "tchdbputkeep2");
- err = true;
- }
- tcmapputkeep2(map, kbuf, vbuf);
- break;
- case 4:
- iputchar('4');
- if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputcat");
- err = true;
- }
- tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 5:
- iputchar('5');
- if(!tchdbputcat2(hdb, kbuf, vbuf)){
- eprint(hdb, __LINE__, "tchdbputcat2");
- err = true;
- }
- tcmapputcat2(map, kbuf, vbuf);
- break;
- case 6:
- iputchar('6');
- if(!tchdbputasync(hdb, kbuf, ksiz, vbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbputasync");
- err = true;
- }
- tcmapput(map, kbuf, ksiz, vbuf, vsiz);
- break;
- case 7:
- iputchar('7');
- if(!tchdbputasync2(hdb, kbuf, vbuf)){
- eprint(hdb, __LINE__, "tchdbputasync2");
- err = true;
- }
- tcmapput2(map, kbuf, vbuf);
- break;
- case 8:
- iputchar('8');
- if(myrand(10) == 0){
- if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
+ break;
+ } else if (vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
err = true;
- }
- tcmapout(map, kbuf, ksiz);
- }
- break;
- case 9:
- iputchar('9');
- if(myrand(10) == 0){
- if(!tchdbout2(hdb, kbuf) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout2");
+ tcfree(vbuf);
+ break;
+ }
+ tcfree(vbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (tchdbrnum(hdb) != rnum) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ iprintf("random writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '*', vsiz);
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
err = true;
- }
- tcmapout2(map, kbuf);
- }
- break;
- case 10:
- iputchar('A');
- if(!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz))){
- if(tchdbecode(hdb) != TCENOREC){
+ break;
+ }
+ int rsiz;
+ char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
+ if (!rbuf) {
eprint(hdb, __LINE__, "tchdbget");
err = true;
- }
- rbuf = tcsprintf("[%d]", myrand(i + 1));
- vsiz = strlen(rbuf);
+ break;
}
- vsiz += myrand(vsiz);
- if(myrand(3) == 0) vsiz += PATH_MAX;
- rbuf = tcrealloc(rbuf, vsiz + 1);
- for(int j = 0; j < vsiz; j++){
- rbuf[j] = myrand(0x100);
+ if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(rbuf);
+ break;
}
- if(!tchdbput(hdb, kbuf, ksiz, rbuf, vsiz)){
- eprint(hdb, __LINE__, "tchdbput");
- err = true;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcmapput(map, kbuf, ksiz, rbuf, vsiz);
tcfree(rbuf);
- break;
- case 11:
- iputchar('B');
- if(!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz)) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
+ }
+ iprintf("word writing:\n");
+ const char *words[] = {
+ "a", "A", "bb", "BB", "ccc", "CCC", "dddd", "DDDD", "eeeee", "EEEEEE",
+ "mikio", "hirabayashi", "tokyo", "cabinet", "hyper", "estraier", "19780211", "birth day",
+ "one", "first", "two", "second", "three", "third", "four", "fourth", "five", "fifth",
+ "_[1]_", "uno", "_[2]_", "dos", "_[3]_", "tres", "_[4]_", "cuatro", "_[5]_", "cinco",
+ "[\xe5\xb9\xb3\xe6\x9e\x97\xe5\xb9\xb9\xe9\x9b\x84]", "[\xe9\xa6\xac\xe9\xb9\xbf]", NULL
+ };
+ for (int i = 0; words[i] != NULL; i += 2) {
+ const char *kbuf = words[i];
+ int ksiz = strlen(kbuf);
+ const char *vbuf = words[i + 1];
+ int vsiz = strlen(vbuf);
+ if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
+ err = true;
+ break;
}
- tcfree(rbuf);
- break;
- case 12:
- iputchar('C');
- if(!(rbuf = tchdbget2(hdb, kbuf)) && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbget2");
- err = true;
+ if (rnum > 250) iputchar('.');
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", (int) (sizeof (words) / sizeof (*words)));
+ iprintf("random erasing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ if (!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ break;
}
- tcfree(rbuf);
- break;
- case 13:
- iputchar('D');
- if(myrand(1) == 0) vsiz = 1;
- if((vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, vsiz)) < 0 && tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbget3");
- err = true;
- }
- break;
- case 14:
- iputchar('E');
- if(myrand(rnum / 50) == 0){
- if(!tchdbiterinit(hdb)){
- eprint(hdb, __LINE__, "tchdbiterinit");
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "[%d]", i);
+ char vbuf[RECBUFSIZ];
+ int vsiz = i % RECBUFSIZ;
+ memset(vbuf, '*', vsiz);
+ if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
err = true;
- }
- }
- TCXSTR *ikey = tcxstrnew();
- TCXSTR *ival = tcxstrnew();
- for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
- if(j % 3 == 0){
- if(tchdbiternext3(hdb, ikey, ival)){
- if(tcxstrsize(ival) != tchdbvsiz(hdb, tcxstrptr(ikey), tcxstrsize(ikey))){
- eprint(hdb, __LINE__, "(validation)");
+ break;
+ }
+ if (vsiz < 1) {
+ char tbuf[PATH_MAX];
+ for (int j = 0; j < PATH_MAX; j++) {
+ tbuf[j] = myrand(0x100);
+ }
+ if (!tchdbput(hdb, kbuf, ksiz, tbuf, PATH_MAX)) {
+ eprint(hdb, __LINE__, "tchdbput");
err = true;
- }
- } else {
- int ecode = tchdbecode(hdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(hdb, __LINE__, "tchdbiternext3");
+ break;
+ }
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("erasing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ if (i % 2 == 1) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "[%d]", i);
+ if (!tchdbout(hdb, kbuf, ksiz)) {
+ eprint(hdb, __LINE__, "tchdbout");
err = true;
- }
+ break;
}
- } else {
- int iksiz;
- char *ikbuf = tchdbiternext(hdb, &iksiz);
- if(ikbuf){
- tcfree(ikbuf);
- } else {
- int ecode = tchdbecode(hdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(hdb, __LINE__, "tchdbiternext");
+ if (tchdbout(hdb, kbuf, ksiz) || tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
err = true;
- }
+ break;
+ }
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("random writing and reopening:\n");
+ for (int i = 1; i <= rnum; i++) {
+ if (myrand(10) == 0) {
+ int ksiz, vsiz;
+ char *kbuf, *vbuf;
+ ksiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
+ kbuf = tcmalloc(ksiz + 1);
+ memset(kbuf, '@', ksiz);
+ vsiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
+ vbuf = tcmalloc(vsiz + 1);
+ for (int j = 0; j < vsiz; j++) {
+ vbuf[j] = myrand(256);
}
- }
- }
- tcxstrdel(ival);
- tcxstrdel(ikey);
- break;
- default:
- iputchar('@');
- if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
- if(myrand(rnum / 16 + 1) == 0){
- int cnt = myrand(30);
- for(int j = 0; j < rnum && !err; j++){
- ksiz = sprintf(kbuf, "%d", i + j);
- if(tchdbout(hdb, kbuf, ksiz)){
- cnt--;
- } else if(tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
+ switch (myrand(4)) {
+ case 0:
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tchdbputasync(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputasync");
+ err = true;
+ }
+ break;
+ case 3:
+ if (!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ break;
+ }
+ tcfree(vbuf);
+ tcfree(kbuf);
+ } else {
+ char kbuf[RECBUFSIZ];
+ int ksiz = myrand(RECBUFSIZ);
+ memset(kbuf, '@', ksiz);
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '@', vsiz);
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ break;
}
- tcmapout(map, kbuf, ksiz);
- if(cnt < 0) break;
- }
}
- break;
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
}
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- if(i == rnum / 2){
- if(!tchdbclose(hdb)){
+ if (!tchdbclose(hdb)) {
eprint(hdb, __LINE__, "tchdbclose");
err = true;
- }
- if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
+ }
+ if (!tchdbopen(hdb, path, HDBOWRITER | omode)) {
eprint(hdb, __LINE__, "tchdbopen");
err = true;
- }
- } else if(i == rnum / 4){
- char *npath = tcsprintf("%s-tmp", path);
- if(!tchdbcopy(hdb, npath)){
- eprint(hdb, __LINE__, "tchdbcopy");
- err = true;
- }
- TCHDB *nhdb = tchdbnew();
- if(!tchdbsetcodecfunc(nhdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(nhdb, __LINE__, "tchdbsetcodecfunc");
- err = true;
- }
- if(!tchdbopen(nhdb, npath, HDBOREADER | omode)){
- eprint(nhdb, __LINE__, "tchdbopen");
- err = true;
- }
- tchdbdel(nhdb);
- unlink(npath);
- tcfree(npath);
- if(!tchdboptimize(hdb, rnum / 50, -1, -1, -1)){
- eprint(hdb, __LINE__, "tchdboptimize");
- err = true;
- }
- if(!tchdbiterinit(hdb)){
+ }
+ iprintf("checking:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "[%d]", i);
+ int vsiz;
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (i % 2 == 0) {
+ if (!vbuf) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ break;
+ }
+ if (vsiz != i % RECBUFSIZ && vsiz != PATH_MAX) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(vbuf);
+ break;
+ }
+ } else {
+ if (vbuf || tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(vbuf);
+ break;
+ }
+ }
+ tcfree(vbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char buf[RECBUFSIZ];
+ int len = sprintf(buf, "%08d", i);
+ if (!tchdbput(hdb, buf, len, buf, len)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("reading:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%08d", i);
+ int vsiz;
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ break;
+ } else if (vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(vbuf);
+ break;
+ }
+ tcfree(vbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ iprintf("checking words:\n");
+ for (int i = 0; words[i] != NULL; i += 2) {
+ const char *kbuf = words[i];
+ int ksiz = strlen(kbuf);
+ const char *vbuf = words[i + 1];
+ int vsiz = strlen(vbuf);
+ int rsiz;
+ char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
+ if (!rbuf) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ break;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(rbuf);
+ break;
+ }
+ tcfree(rbuf);
+ if (rnum > 250) iputchar('.');
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", (int) (sizeof (words) / sizeof (*words)));
+ iprintf("checking iterator:\n");
+ int inum = 0;
+ if (!tchdbiterinit(hdb)) {
eprint(hdb, __LINE__, "tchdbiterinit");
err = true;
- }
- } else if(i == rnum / 8){
- if(!tchdbtranbegin(hdb)){
+ }
+ char *kbuf;
+ int ksiz;
+ for (int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++) {
+ int vsiz;
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ if (!vbuf) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ tcfree(kbuf);
+ break;
+ }
+ tcfree(vbuf);
+ tcfree(kbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ if (tchdbecode(hdb) != TCENOREC || inum != tchdbrnum(hdb)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ iprintf("iteration updating:\n");
+ if (!tchdbiterinit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbiterinit");
+ err = true;
+ }
+ inum = 0;
+ for (int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++) {
+ if (myrand(2) == 0) {
+ if (!tchdbputcat(hdb, kbuf, ksiz, "0123456789", 10)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ tcfree(kbuf);
+ break;
+ }
+ } else {
+ if (!tchdbout(hdb, kbuf, ksiz)) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ tcfree(kbuf);
+ break;
+ }
+ }
+ tcfree(kbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ if (tchdbecode(hdb) != TCENOREC || inum < tchdbrnum(hdb)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ if (myrand(10) == 0 && !tchdbsync(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsync");
+ err = true;
+ }
+ if (!tchdbvanish(hdb)) {
+ eprint(hdb, __LINE__, "tchdbvanish");
+ err = true;
+ }
+ TCMAP *map = tcmapnew();
+ iprintf("random writing:\n");
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = sprintf(vbuf, "%d", myrand(rnum));
+ switch (myrand(4)) {
+ case 0:
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
+ err = true;
+ }
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 2:
+ if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ if (!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (myrand(4) == 0 && !tchdbdefrag(hdb, 0)) {
+ eprint(hdb, __LINE__, "tchdbdefrag");
+ err = true;
+ }
+ if (myrand(4) == 0 && !tchdbcacheclear(hdb)) {
+ eprint(hdb, __LINE__, "tchdbcacheclear");
+ err = true;
+ }
+ iprintf("checking transaction commit:\n");
+ if (!tchdbtranbegin(hdb)) {
eprint(hdb, __LINE__, "tchdbtranbegin");
err = true;
- }
- } else if(i == rnum / 8 + rnum / 16){
- if(!tchdbtrancommit(hdb)){
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = sprintf(vbuf, "[%d]", myrand(rnum));
+ switch (myrand(7)) {
+ case 0:
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
+ err = true;
+ }
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 2:
+ if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ if (tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbaddint");
+ err = true;
+ }
+ tcmapaddint(map, kbuf, ksiz, 1);
+ break;
+ case 4:
+ if (isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbadddouble");
+ err = true;
+ }
+ tcmapadddouble(map, kbuf, ksiz, 1.0);
+ break;
+ case 5:
+ if (myrand(2) == 0) {
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tchdbputproc(hdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
+ tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputproc");
+ err = true;
+ }
+ tcmapputproc(map, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op);
+ } else {
+ vsiz = myrand(10);
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tchdbputproc(hdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
+ tchdbecode(hdb) != TCEKEEP && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbputproc");
+ err = true;
+ }
+ tcmapputproc(map, kbuf, ksiz, NULL, vsiz, pdprocfunc, op);
+ }
+ break;
+ case 6:
+ if (!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (!tchdbtrancommit(hdb)) {
eprint(hdb, __LINE__, "tchdbtrancommit");
err = true;
- }
- }
- }
- if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
- if(!tchdbsync(hdb)){
- eprint(hdb, __LINE__, "tchdbsync");
- err = true;
- }
- if(tchdbrnum(hdb) != tcmaprnum(map)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- for(int i = 1; i <= rnum && !err; i++){
- char kbuf[RECBUFSIZ];
- int ksiz = sprintf(kbuf, "%d", i - 1);
- int vsiz;
- const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
- int rsiz;
- char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
- if(vbuf){
- iputchar('.');
- if(!rbuf){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(hdb, __LINE__, "(validation)");
+ }
+ iprintf("checking transaction abort:\n");
+ uint64_t ornum = tchdbrnum(hdb);
+ uint64_t ofsiz = tchdbfsiz(hdb);
+ if (!tchdbtranbegin(hdb)) {
+ eprint(hdb, __LINE__, "tchdbtranbegin");
err = true;
- }
- } else {
- iputchar('*');
- if(rbuf || tchdbecode(hdb) != TCENOREC){
+ }
+ for (int i = 1; i <= rnum; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = sprintf(vbuf, "((%d))", myrand(rnum));
+ switch (myrand(7)) {
+ case 0:
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
+ err = true;
+ }
+ break;
+ case 2:
+ if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ break;
+ case 3:
+ if (tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbaddint");
+ err = true;
+ }
+ break;
+ case 4:
+ if (isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbadddouble");
+ err = true;
+ }
+ break;
+ case 5:
+ if (myrand(2) == 0) {
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tchdbputproc(hdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
+ tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputproc");
+ err = true;
+ }
+ } else {
+ vsiz = myrand(10);
+ void *op = (void *) (intptr_t) (myrand(3) + 1);
+ if (!tchdbputproc(hdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
+ tchdbecode(hdb) != TCEKEEP && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbputproc");
+ err = true;
+ }
+ }
+ break;
+ case 6:
+ if (!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ break;
+ }
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (!tchdbtranabort(hdb)) {
+ eprint(hdb, __LINE__, "tchdbtranabort");
+ err = true;
+ }
+ iprintf("checking consistency: %d %d\n", (int) tchdbrnum(hdb), (int) ornum);
+ if (tchdbrnum(hdb) != ornum || tchdbfsiz(hdb) != ofsiz || tchdbrnum(hdb) != tcmaprnum(map)) {
eprint(hdb, __LINE__, "(validation)");
err = true;
- }
- }
- tcfree(rbuf);
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- }
- if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
- int inum = 0;
- char *cbuf;
- int csiz;
- if(myrand(2) == 0){
- cbuf = tchdbgetnext(hdb, NULL, -1, &csiz);
- } else {
- const char *cvbuf;
- int cvsiz;
- cbuf = tchdbgetnext3(hdb, NULL, -1, &csiz, &cvbuf, &cvsiz);
- }
- while(cbuf){
- inum++;
- iputchar(':');
- int nsiz;
- char *nbuf;
- if(myrand(2) == 0){
- nbuf = tchdbgetnext(hdb, cbuf, csiz, &nsiz);
- } else {
- const char *cvbuf;
- int cvsiz;
- nbuf = tchdbgetnext3(hdb, cbuf, csiz, &nsiz, &cvbuf, &cvsiz);
- }
- if(myrand(10) == 0){
- if(!tchdbiterinit2(hdb, cbuf, csiz)){
- eprint(hdb, __LINE__, "tchdbiterinit2");
- err = true;
- }
- int ksiz;
- char *kbuf = tchdbiternext(hdb, &ksiz);
- if(kbuf){
+ }
+ inum = 0;
+ tcmapiterinit(map);
+ const char *tkbuf;
+ int tksiz;
+ for (int i = 1; (tkbuf = tcmapiternext(map, &tksiz)) != NULL; i++, inum++) {
+ int tvsiz;
+ const char *tvbuf = tcmapiterval(tkbuf, &tvsiz);
+ int rsiz;
+ char *rbuf = tchdbget(hdb, tkbuf, tksiz, &rsiz);
+ if (!rbuf || rsiz != tvsiz || memcmp(rbuf, tvbuf, rsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(rbuf);
+ break;
+ }
+ tcfree(rbuf);
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ inum = 0;
+ if (!tchdbiterinit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbiterinit");
+ err = true;
+ }
+ for (int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++) {
+ int vsiz;
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
+ int rsiz;
+ const char *rbuf = tcmapget(map, kbuf, ksiz, &rsiz);
+ if (!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ tcfree(vbuf);
+ tcfree(kbuf);
+ break;
+ }
+ tcfree(vbuf);
tcfree(kbuf);
- } else {
- eprint(hdb, __LINE__, "tchdbiternext");
+ if (rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
+ }
+ }
+ if (rnum > 250) iprintf(" (%08d)\n", inum);
+ tcmapdel(map);
+ if (!tchdbvanish(hdb)) {
+ eprint(hdb, __LINE__, "tchdbvanish");
+ err = true;
+ }
+ for (int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)) {
+ char vbuf[i];
+ memset(vbuf, '@', i - 1);
+ vbuf[i - 1] = '\0';
+ if (!tchdbput2(hdb, "mikio", vbuf)) {
+ eprint(hdb, __LINE__, "tchdbput2");
+ err = true;
+ }
+ }
+ if (!tchdbput2(hdb, "mikio", "nanashi")) {
+ eprint(hdb, __LINE__, "tchdbput2");
+ err = true;
+ }
+ if (!tchdbtranbegin(hdb)) {
+ eprint(hdb, __LINE__, "tchdbtranbegin");
+ err = true;
+ }
+ if (!tchdbput2(hdb, "mikio", "hirabayashi")) {
+ eprint(hdb, __LINE__, "tchdbput2");
err = true;
- }
- for(int i = 0; i < 5; i++){
- kbuf = tchdbiternext(hdb, &ksiz);
- if(kbuf){
- tcfree(kbuf);
- } else if(tchdbecode(hdb) != TCENOREC){
- eprint(hdb, __LINE__, "tchdbiternext");
- err = true;
+ }
+ for (int i = 0; i < 10; i++) {
+ char buf[RECBUFSIZ];
+ int size = sprintf(buf, "%d", myrand(rnum));
+ if (!tchdbput(hdb, buf, size, buf, size)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
}
- }
+ }
+ for (int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)) {
+ char vbuf[i];
+ memset(vbuf, '@', i - 1);
+ vbuf[i - 1] = '\0';
+ if (!tchdbput2(hdb, "mikio", vbuf)) {
+ eprint(hdb, __LINE__, "tchdbput2");
+ err = true;
+ }
+ }
+ if (!tchdbforeach(hdb, iterfunc, NULL)) {
+ eprint(hdb, __LINE__, "tchdbforeach");
+ err = true;
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
+}
+
+/* perform wicked command */
+static int procwicked(const char *path, int rnum, bool mt, int opts, int omode) {
+ iprintf("<Wicked Writing Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
+ g_randseed, path, rnum, mt, opts, omode);
+ bool err = false;
+ double stime = tctime();
+ TCHDB *hdb = tchdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tchdbsetdbgfd(hdb, g_dbgfd);
+ if (mt && !tchdbsetmutex(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsetmutex");
+ err = true;
+ }
+ if (!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
+ err = true;
+ }
+ if (!tchdbtune(hdb, rnum / 50, 2, -1, opts)) {
+ eprint(hdb, __LINE__, "tchdbtune");
+ err = true;
+ }
+ if (!tchdbsetcache(hdb, rnum / 10)) {
+ eprint(hdb, __LINE__, "tchdbsetcache");
+ err = true;
+ }
+ if (!tchdbsetxmsiz(hdb, rnum * sizeof (int))) {
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
+ err = true;
+ }
+ if (!tchdbsetdfunit(hdb, 8)) {
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
+ err = true;
+ }
+ if (!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ if (!tchdbiterinit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbiterinit");
+ err = true;
+ }
+ TCMAP *map = tcmapnew2(rnum / 5);
+ for (int i = 1; i <= rnum && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
+ char vbuf[RECBUFSIZ];
+ int vsiz = myrand(RECBUFSIZ);
+ memset(vbuf, '*', vsiz);
+ vbuf[vsiz] = '\0';
+ char *rbuf;
+ switch (myrand(16)) {
+ case 0:
+ iputchar('0');
+ if (!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 1:
+ iputchar('1');
+ if (!tchdbput2(hdb, kbuf, vbuf)) {
+ eprint(hdb, __LINE__, "tchdbput2");
+ err = true;
+ }
+ tcmapput2(map, kbuf, vbuf);
+ break;
+ case 2:
+ iputchar('2');
+ if (!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep");
+ err = true;
+ }
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 3:
+ iputchar('3');
+ if (!tchdbputkeep2(hdb, kbuf, vbuf) && tchdbecode(hdb) != TCEKEEP) {
+ eprint(hdb, __LINE__, "tchdbputkeep2");
+ err = true;
+ }
+ tcmapputkeep2(map, kbuf, vbuf);
+ break;
+ case 4:
+ iputchar('4');
+ if (!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputcat");
+ err = true;
+ }
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 5:
+ iputchar('5');
+ if (!tchdbputcat2(hdb, kbuf, vbuf)) {
+ eprint(hdb, __LINE__, "tchdbputcat2");
+ err = true;
+ }
+ tcmapputcat2(map, kbuf, vbuf);
+ break;
+ case 6:
+ iputchar('6');
+ if (!tchdbputasync(hdb, kbuf, ksiz, vbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbputasync");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
+ break;
+ case 7:
+ iputchar('7');
+ if (!tchdbputasync2(hdb, kbuf, vbuf)) {
+ eprint(hdb, __LINE__, "tchdbputasync2");
+ err = true;
+ }
+ tcmapput2(map, kbuf, vbuf);
+ break;
+ case 8:
+ iputchar('8');
+ if (myrand(10) == 0) {
+ if (!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ }
+ break;
+ case 9:
+ iputchar('9');
+ if (myrand(10) == 0) {
+ if (!tchdbout2(hdb, kbuf) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout2");
+ err = true;
+ }
+ tcmapout2(map, kbuf);
+ }
+ break;
+ case 10:
+ iputchar('A');
+ if (!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz))) {
+ if (tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ }
+ rbuf = tcsprintf("[%d]", myrand(i + 1));
+ vsiz = strlen(rbuf);
+ }
+ vsiz += myrand(vsiz);
+ if (myrand(3) == 0) vsiz += PATH_MAX;
+ rbuf = tcrealloc(rbuf, vsiz + 1);
+ for (int j = 0; j < vsiz; j++) {
+ rbuf[j] = myrand(0x100);
+ }
+ if (!tchdbput(hdb, kbuf, ksiz, rbuf, vsiz)) {
+ eprint(hdb, __LINE__, "tchdbput");
+ err = true;
+ }
+ tcmapput(map, kbuf, ksiz, rbuf, vsiz);
+ tcfree(rbuf);
+ break;
+ case 11:
+ iputchar('B');
+ if (!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz)) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 12:
+ iputchar('C');
+ if (!(rbuf = tchdbget2(hdb, kbuf)) && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget2");
+ err = true;
+ }
+ tcfree(rbuf);
+ break;
+ case 13:
+ iputchar('D');
+ if (myrand(1) == 0) vsiz = 1;
+ if ((vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, vsiz)) < 0 && tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbget3");
+ err = true;
+ }
+ break;
+ case 14:
+ iputchar('E');
+ if (myrand(rnum / 50) == 0) {
+ if (!tchdbiterinit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbiterinit");
+ err = true;
+ }
+ }
+ TCXSTR *ikey = tcxstrnew();
+ TCXSTR *ival = tcxstrnew();
+ for (int j = myrand(rnum) / 1000 + 1; j >= 0; j--) {
+ if (j % 3 == 0) {
+ if (tchdbiternext3(hdb, ikey, ival)) {
+ if (tcxstrsize(ival) != tchdbvsiz(hdb, tcxstrptr(ikey), tcxstrsize(ikey))) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ } else {
+ int ecode = tchdbecode(hdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbiternext3");
+ err = true;
+ }
+ }
+ } else {
+ int iksiz;
+ char *ikbuf = tchdbiternext(hdb, &iksiz);
+ if (ikbuf) {
+ tcfree(ikbuf);
+ } else {
+ int ecode = tchdbecode(hdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbiternext");
+ err = true;
+ }
+ }
+ }
+ }
+ tcxstrdel(ival);
+ tcxstrdel(ikey);
+ break;
+ default:
+ iputchar('@');
+ if (myrand(10000) == 0) srand((unsigned int) (tctime() * 1000) % UINT_MAX);
+ if (myrand(rnum / 16 + 1) == 0) {
+ int cnt = myrand(30);
+ for (int j = 0; j < rnum && !err; j++) {
+ ksiz = sprintf(kbuf, "%d", i + j);
+ if (tchdbout(hdb, kbuf, ksiz)) {
+ cnt--;
+ } else if (tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ tcmapout(map, kbuf, ksiz);
+ if (cnt < 0) break;
+ }
+ }
+ break;
+ }
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ if (i == rnum / 2) {
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ if (!tchdbopen(hdb, path, HDBOWRITER | omode)) {
+ eprint(hdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ } else if (i == rnum / 4) {
+ char *npath = tcsprintf("%s-tmp", path);
+ if (!tchdbcopy(hdb, npath)) {
+ eprint(hdb, __LINE__, "tchdbcopy");
+ err = true;
+ }
+ TCHDB *nhdb = tchdbnew();
+ if (!tchdbsetcodecfunc(nhdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(nhdb, __LINE__, "tchdbsetcodecfunc");
+ err = true;
+ }
+ if (!tchdbopen(nhdb, npath, HDBOREADER | omode)) {
+ eprint(nhdb, __LINE__, "tchdbopen");
+ err = true;
+ }
+ tchdbdel(nhdb);
+ unlink(npath);
+ tcfree(npath);
+ if (!tchdboptimize(hdb, rnum / 50, -1, -1, -1)) {
+ eprint(hdb, __LINE__, "tchdboptimize");
+ err = true;
+ }
+ if (!tchdbiterinit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbiterinit");
+ err = true;
+ }
+ } else if (i == rnum / 8) {
+ if (!tchdbtranbegin(hdb)) {
+ eprint(hdb, __LINE__, "tchdbtranbegin");
+ err = true;
+ }
+ } else if (i == rnum / 8 + rnum / 16) {
+ if (!tchdbtrancommit(hdb)) {
+ eprint(hdb, __LINE__, "tchdbtrancommit");
+ err = true;
+ }
+ }
+ }
+ if (rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
+ if (!tchdbsync(hdb)) {
+ eprint(hdb, __LINE__, "tchdbsync");
+ err = true;
+ }
+ if (tchdbrnum(hdb) != tcmaprnum(map)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ for (int i = 1; i <= rnum && !err; i++) {
+ char kbuf[RECBUFSIZ];
+ int ksiz = sprintf(kbuf, "%d", i - 1);
+ int vsiz;
+ const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
+ int rsiz;
+ char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
+ if (vbuf) {
+ iputchar('.');
+ if (!rbuf) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ } else {
+ iputchar('*');
+ if (rbuf || tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ }
+ tcfree(rbuf);
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ }
+ if (rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
+ int inum = 0;
+ char *cbuf;
+ int csiz;
+ if (myrand(2) == 0) {
+ cbuf = tchdbgetnext(hdb, NULL, -1, &csiz);
+ } else {
+ const char *cvbuf;
+ int cvsiz;
+ cbuf = tchdbgetnext3(hdb, NULL, -1, &csiz, &cvbuf, &cvsiz);
+ }
+ while (cbuf) {
+ inum++;
+ iputchar(':');
+ int nsiz;
+ char *nbuf;
+ if (myrand(2) == 0) {
+ nbuf = tchdbgetnext(hdb, cbuf, csiz, &nsiz);
+ } else {
+ const char *cvbuf;
+ int cvsiz;
+ nbuf = tchdbgetnext3(hdb, cbuf, csiz, &nsiz, &cvbuf, &cvsiz);
+ }
+ if (myrand(10) == 0) {
+ if (!tchdbiterinit2(hdb, cbuf, csiz)) {
+ eprint(hdb, __LINE__, "tchdbiterinit2");
+ err = true;
+ }
+ int ksiz;
+ char *kbuf = tchdbiternext(hdb, &ksiz);
+ if (kbuf) {
+ tcfree(kbuf);
+ } else {
+ eprint(hdb, __LINE__, "tchdbiternext");
+ err = true;
+ }
+ for (int i = 0; i < 5; i++) {
+ kbuf = tchdbiternext(hdb, &ksiz);
+ if (kbuf) {
+ tcfree(kbuf);
+ } else if (tchdbecode(hdb) != TCENOREC) {
+ eprint(hdb, __LINE__, "tchdbiternext");
+ err = true;
+ }
+ }
+ }
+ tcfree(cbuf);
+ cbuf = nbuf;
+ csiz = nsiz;
+ if (inum % 50 == 0) iprintf(" (%08d)\n", inum);
}
tcfree(cbuf);
- cbuf = nbuf;
- csiz = nsiz;
- if(inum % 50 == 0) iprintf(" (%08d)\n", inum);
- }
- tcfree(cbuf);
- if(inum % 50 > 0) iprintf(" (%08d)\n", inum);
- if(inum != tchdbrnum(hdb)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- tcmapiterinit(map);
- int ksiz;
- const char *kbuf;
- for(int i = 1; (kbuf = tcmapiternext(map, &ksiz)) != NULL; i++){
- iputchar('+');
- int vsiz;
- const char *vbuf = tcmapiterval(kbuf, &vsiz);
- int rsiz;
- char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
- if(!rbuf){
- eprint(hdb, __LINE__, "tchdbget");
- err = true;
- } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- tcfree(rbuf);
- if(!tchdbout(hdb, kbuf, ksiz)){
- eprint(hdb, __LINE__, "tchdbout");
- err = true;
- }
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- }
- int mrnum = tcmaprnum(map);
- if(mrnum % 50 > 0) iprintf(" (%08d)\n", mrnum);
- if(tchdbrnum(hdb) != 0){
- eprint(hdb, __LINE__, "(validation)");
- err = true;
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tchdbrnum(hdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tchdbfsiz(hdb));
- mprint(hdb);
- sysprint();
- tcmapdel(map);
- if(!tchdbclose(hdb)){
- eprint(hdb, __LINE__, "tchdbclose");
- err = true;
- }
- tchdbdel(hdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ if (inum % 50 > 0) iprintf(" (%08d)\n", inum);
+ if (inum != tchdbrnum(hdb)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ tcmapiterinit(map);
+ int ksiz;
+ const char *kbuf;
+ for (int i = 1; (kbuf = tcmapiternext(map, &ksiz)) != NULL; i++) {
+ iputchar('+');
+ int vsiz;
+ const char *vbuf = tcmapiterval(kbuf, &vsiz);
+ int rsiz;
+ char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
+ if (!rbuf) {
+ eprint(hdb, __LINE__, "tchdbget");
+ err = true;
+ } else if (rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ tcfree(rbuf);
+ if (!tchdbout(hdb, kbuf, ksiz)) {
+ eprint(hdb, __LINE__, "tchdbout");
+ err = true;
+ }
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ }
+ int mrnum = tcmaprnum(map);
+ if (mrnum % 50 > 0) iprintf(" (%08d)\n", mrnum);
+ if (tchdbrnum(hdb) != 0) {
+ eprint(hdb, __LINE__, "(validation)");
+ err = true;
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tchdbrnum(hdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tchdbfsiz(hdb));
+ mprint(hdb);
+ sysprint();
+ tcmapdel(map);
+ if (!tchdbclose(hdb)) {
+ eprint(hdb, __LINE__, "tchdbclose");
+ err = true;
+ }
+ tchdbdel(hdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
/* global variables */
-const char *g_progname; // program name
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
static int proccreate(const char *path, int bnum, int apow, int fpow, int opts);
static int procinform(const char *path, int omode);
static int procput(const char *path, const char *pkbuf, int pksiz, TCMAP *cols,
- int omode, int dmode);
+ int omode, int dmode);
static int procout(const char *path, const char *pkbuf, int pksiz, int omode);
static int procget(const char *path, const char *pkbuf, int pksiz, int omode, bool px, bool pz);
static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr);
static int procsearch(const char *path, TCLIST *conds, const char *oname, const char *otype,
- int omode, int max, int skip, bool pv, bool px, bool kw, bool ph, int bt,
- bool rm, const char *mtype);
+ int omode, int max, int skip, bool pv, bool px, bool kw, bool ph, int bt,
+ bool rm, const char *mtype);
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode,
- bool df);
+ bool df);
static int procsetindex(const char *path, const char *name, int omode, int type);
static int procimporttsv(const char *path, const char *file, int omode, bool sc);
static int procversion(void);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- g_dbgfd = INVALID_HANDLE_VALUE;
- const char *ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ g_dbgfd = INVALID_HANDLE_VALUE;
+ const char *ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "create")){
- rv = runcreate(argc, argv);
- } else if(!strcmp(argv[1], "inform")){
- rv = runinform(argc, argv);
- } else if(!strcmp(argv[1], "put")){
- rv = runput(argc, argv);
- } else if(!strcmp(argv[1], "out")){
- rv = runout(argc, argv);
- } else if(!strcmp(argv[1], "get")){
- rv = runget(argc, argv);
- } else if(!strcmp(argv[1], "list")){
- rv = runlist(argc, argv);
- } else if(!strcmp(argv[1], "search")){
- rv = runsearch(argc, argv);
- } else if(!strcmp(argv[1], "optimize")){
- rv = runoptimize(argc, argv);
- } else if(!strcmp(argv[1], "setindex")){
- rv = runsetindex(argc, argv);
- } else if(!strcmp(argv[1], "importtsv")){
- rv = runimporttsv(argc, argv);
- } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){
- rv = runversion(argc, argv);
- } else {
- usage();
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "create")) {
+ rv = runcreate(argc, argv);
+ } else if (!strcmp(argv[1], "inform")) {
+ rv = runinform(argc, argv);
+ } else if (!strcmp(argv[1], "put")) {
+ rv = runput(argc, argv);
+ } else if (!strcmp(argv[1], "out")) {
+ rv = runout(argc, argv);
+ } else if (!strcmp(argv[1], "get")) {
+ rv = runget(argc, argv);
+ } else if (!strcmp(argv[1], "list")) {
+ rv = runlist(argc, argv);
+ } else if (!strcmp(argv[1], "search")) {
+ rv = runsearch(argc, argv);
+ } else if (!strcmp(argv[1], "optimize")) {
+ rv = runoptimize(argc, argv);
+ } else if (!strcmp(argv[1], "setindex")) {
+ rv = runsetindex(argc, argv);
+ } else if (!strcmp(argv[1], "importtsv")) {
+ rv = runimporttsv(argc, argv);
+ } else if (!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")) {
+ rv = runversion(argc, argv);
+ } else {
+ usage();
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: the command line utility of the table database API\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s create [-tl] [-td|-tb|-tt|-tx] path [bnum [apow [fpow]]]\n", g_progname);
- fprintf(stderr, " %s inform [-nl|-nb] path\n", g_progname);
- fprintf(stderr, " %s put [-nl|-nb] [-sx] [-dk|-dc|-dai|-dad] path pkey [cols...]\n",
- g_progname);
- fprintf(stderr, " %s out [-nl|-nb] [-sx] path pkey\n", g_progname);
- fprintf(stderr, " %s get [-nl|-nb] [-sx] [-px] [-pz] path pkey\n", g_progname);
- fprintf(stderr, " %s list [-nl|-nb] [-m num] [-pv] [-px] [-fm str] path\n", g_progname);
- fprintf(stderr, " %s search [-nl|-nb] [-ord name type] [-m num] [-sk num] [-kw] [-pv] [-px]"
- " [-ph] [-bt num] [-rm] [-ms type] path [name op expr ...]\n", g_progname);
- fprintf(stderr, " %s optimize [-tl] [-td|-tb|-tt|-tx] [-tz] [-nl|-nb] [-df]"
- " path [bnum [apow [fpow]]]\n", g_progname);
- fprintf(stderr, " %s setindex [-nl|-nb] [-it type] path name\n", g_progname);
- fprintf(stderr, " %s importtsv [-nl|-nb] [-sc] path [file]\n", g_progname);
- fprintf(stderr, " %s version\n", g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: the command line utility of the table database API\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s create [-tl] [-td|-tb|-tt|-tx] path [bnum [apow [fpow]]]\n", g_progname);
+ fprintf(stderr, " %s inform [-nl|-nb] path\n", g_progname);
+ fprintf(stderr, " %s put [-nl|-nb] [-sx] [-dk|-dc|-dai|-dad] path pkey [cols...]\n",
+ g_progname);
+ fprintf(stderr, " %s out [-nl|-nb] [-sx] path pkey\n", g_progname);
+ fprintf(stderr, " %s get [-nl|-nb] [-sx] [-px] [-pz] path pkey\n", g_progname);
+ fprintf(stderr, " %s list [-nl|-nb] [-m num] [-pv] [-px] [-fm str] path\n", g_progname);
+ fprintf(stderr, " %s search [-nl|-nb] [-ord name type] [-m num] [-sk num] [-kw] [-pv] [-px]"
+ " [-ph] [-bt num] [-rm] [-ms type] path [name op expr ...]\n", g_progname);
+ fprintf(stderr, " %s optimize [-tl] [-td|-tb|-tt|-tx] [-tz] [-nl|-nb] [-df]"
+ " path [bnum [apow [fpow]]]\n", g_progname);
+ fprintf(stderr, " %s setindex [-nl|-nb] [-it type] path name\n", g_progname);
+ fprintf(stderr, " %s importtsv [-nl|-nb] [-sc] path [file]\n", g_progname);
+ fprintf(stderr, " %s version\n", g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print error information */
-static void printerr(TCTDB *tdb){
- const char *path = tctdbpath(tdb);
- int ecode = tctdbecode(tdb);
- fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tctdberrmsg(ecode));
+static void printerr(TCTDB *tdb) {
+ const char *path = tctdbpath(tdb);
+ int ecode = tctdbecode(tdb);
+ fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tctdberrmsg(ecode));
}
-
/* print record data */
-static int printdata(const char *ptr, int size, bool px){
- int len = 0;
- while(size-- > 0){
- if(px){
- if(len > 0) putchar(' ');
- len += printf("%02X", *(unsigned char *)ptr);
- } else {
- if(strchr("\t\r\n", *ptr)){
- putchar(' ');
- } else {
- putchar(*ptr);
- }
- len++;
+static int printdata(const char *ptr, int size, bool px) {
+ int len = 0;
+ while (size-- > 0) {
+ if (px) {
+ if (len > 0) putchar(' ');
+ len += printf("%02X", *(unsigned char *) ptr);
+ } else {
+ if (strchr("\t\r\n", *ptr)) {
+ putchar(' ');
+ } else {
+ putchar(*ptr);
+ }
+ len++;
+ }
+ ptr++;
}
- ptr++;
- }
- return len;
+ return len;
}
-
/* read a line from a file descriptor */
-static char *mygetline(FILE *ifp){
- int len = 0;
- int blen = 1024;
- char *buf = tcmalloc(blen + 1);
- bool end = true;
- int c;
- while((c = fgetc(ifp)) != EOF){
- end = false;
- if(c == '\0') continue;
- if(blen <= len){
- blen *= 2;
- buf = tcrealloc(buf, blen + 1);
+static char *mygetline(FILE *ifp) {
+ int len = 0;
+ int blen = 1024;
+ char *buf = tcmalloc(blen + 1);
+ bool end = true;
+ int c;
+ while ((c = fgetc(ifp)) != EOF) {
+ end = false;
+ if (c == '\0') continue;
+ if (blen <= len) {
+ blen *= 2;
+ buf = tcrealloc(buf, blen + 1);
+ }
+ if (c == '\n' || c == '\r') c = '\0';
+ buf[len++] = c;
+ if (c == '\0') break;
}
- if(c == '\n' || c == '\r') c = '\0';
- buf[len++] = c;
- if(c == '\0') break;
- }
- if(end){
- tcfree(buf);
- return NULL;
- }
- buf[len] = '\0';
- return buf;
+ if (end) {
+ tcfree(buf);
+ return NULL;
+ }
+ buf[len] = '\0';
+ return buf;
}
-
/* parse arguments of create command */
-static int runcreate(int argc, char **argv){
- char *path = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= TDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= TDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= TDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= TDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= TDBTEXCODEC;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
+static int runcreate(int argc, char **argv) {
+ char *path = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= TDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= TDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= TDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= TDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= TDBTEXCODEC;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = proccreate(path, bnum, apow, fpow, opts);
- return rv;
+ if (!path) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = proccreate(path, bnum, apow, fpow, opts);
+ return rv;
}
-
/* parse arguments of inform command */
-static int runinform(int argc, char **argv){
- char *path = NULL;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runinform(int argc, char **argv) {
+ char *path = NULL;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procinform(path, omode);
- return rv;
+ if (!path) usage();
+ int rv = procinform(path, omode);
+ return rv;
}
-
/* parse arguments of put command */
-static int runput(int argc, char **argv){
- char *path = NULL;
- char *pkey = NULL;
- TCLIST *vals = tcmpoollistnew(tcmpoolglobal());
- int omode = 0;
- int dmode = 0;
- bool sx = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-dk")){
- dmode = -1;
- } else if(!strcmp(argv[i], "-dc")){
- dmode = 1;
- } else if(!strcmp(argv[i], "-dai")){
- dmode = 10;
- } else if(!strcmp(argv[i], "-dad")){
- dmode = 11;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!pkey){
- pkey = argv[i];
- } else {
- tclistpush2(vals, argv[i]);
- }
- }
- if(!path || !pkey) usage();
- TCMAP *cols = tcmapnew();
- char *pkbuf;
- int pksiz;
- if(sx){
- pkbuf = tchexdecode(pkey, &pksiz);
- for(int i = 0; i < tclistnum(vals) - 1; i += 2){
- const char *name = tclistval2(vals, i);
- const char *value = tclistval2(vals, i + 1);
- int nsiz;
- char *nbuf = tchexdecode(name, &nsiz);
- int vsiz;
- char *vbuf = tchexdecode(value, &vsiz);
- tcmapput(cols, nbuf, nsiz, vbuf, vsiz);
- tcfree(vbuf);
- tcfree(nbuf);
+static int runput(int argc, char **argv) {
+ char *path = NULL;
+ char *pkey = NULL;
+ TCLIST *vals = tcmpoollistnew(tcmpoolglobal());
+ int omode = 0;
+ int dmode = 0;
+ bool sx = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-dk")) {
+ dmode = -1;
+ } else if (!strcmp(argv[i], "-dc")) {
+ dmode = 1;
+ } else if (!strcmp(argv[i], "-dai")) {
+ dmode = 10;
+ } else if (!strcmp(argv[i], "-dad")) {
+ dmode = 11;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!pkey) {
+ pkey = argv[i];
+ } else {
+ tclistpush2(vals, argv[i]);
+ }
}
- } else {
- pksiz = strlen(pkey);
- pkbuf = tcmemdup(pkey, pksiz);
- for(int i = 0; i < tclistnum(vals) - 1; i += 2){
- const char *name = tclistval2(vals, i);
- const char *value = tclistval2(vals, i + 1);
- tcmapput2(cols, name, value);
+ if (!path || !pkey) usage();
+ TCMAP *cols = tcmapnew();
+ char *pkbuf;
+ int pksiz;
+ if (sx) {
+ pkbuf = tchexdecode(pkey, &pksiz);
+ for (int i = 0; i < tclistnum(vals) - 1; i += 2) {
+ const char *name = tclistval2(vals, i);
+ const char *value = tclistval2(vals, i + 1);
+ int nsiz;
+ char *nbuf = tchexdecode(name, &nsiz);
+ int vsiz;
+ char *vbuf = tchexdecode(value, &vsiz);
+ tcmapput(cols, nbuf, nsiz, vbuf, vsiz);
+ tcfree(vbuf);
+ tcfree(nbuf);
+ }
+ } else {
+ pksiz = strlen(pkey);
+ pkbuf = tcmemdup(pkey, pksiz);
+ for (int i = 0; i < tclistnum(vals) - 1; i += 2) {
+ const char *name = tclistval2(vals, i);
+ const char *value = tclistval2(vals, i + 1);
+ tcmapput2(cols, name, value);
+ }
}
- }
- int rv = procput(path, pkbuf, pksiz, cols, omode, dmode);
- tcmapdel(cols);
- tcfree(pkbuf);
- return rv;
+ int rv = procput(path, pkbuf, pksiz, cols, omode, dmode);
+ tcmapdel(cols);
+ tcfree(pkbuf);
+ return rv;
}
-
/* parse arguments of out command */
-static int runout(int argc, char **argv){
- char *path = NULL;
- char *pkey = NULL;
- int omode = 0;
- bool sx = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!pkey){
- pkey = argv[i];
+static int runout(int argc, char **argv) {
+ char *path = NULL;
+ char *pkey = NULL;
+ int omode = 0;
+ bool sx = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!pkey) {
+ pkey = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !pkey) usage();
+ int pksiz;
+ char *pkbuf;
+ if (sx) {
+ pkbuf = tchexdecode(pkey, &pksiz);
} else {
- usage();
+ pksiz = strlen(pkey);
+ pkbuf = tcmemdup(pkey, pksiz);
}
- }
- if(!path || !pkey) usage();
- int pksiz;
- char *pkbuf;
- if(sx){
- pkbuf = tchexdecode(pkey, &pksiz);
- } else {
- pksiz = strlen(pkey);
- pkbuf = tcmemdup(pkey, pksiz);
- }
- int rv = procout(path, pkbuf, pksiz, omode);
- tcfree(pkbuf);
- return rv;
+ int rv = procout(path, pkbuf, pksiz, omode);
+ tcfree(pkbuf);
+ return rv;
}
-
/* parse arguments of get command */
-static int runget(int argc, char **argv){
- char *path = NULL;
- char *pkey = NULL;
- int omode = 0;
- bool sx = false;
- bool px = false;
- bool pz = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-sx")){
- sx = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-pz")){
- pz = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!pkey){
- pkey = argv[i];
+static int runget(int argc, char **argv) {
+ char *path = NULL;
+ char *pkey = NULL;
+ int omode = 0;
+ bool sx = false;
+ bool px = false;
+ bool pz = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sx")) {
+ sx = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-pz")) {
+ pz = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!pkey) {
+ pkey = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !pkey) usage();
+ int pksiz;
+ char *pkbuf;
+ if (sx) {
+ pkbuf = tchexdecode(pkey, &pksiz);
} else {
- usage();
+ pksiz = strlen(pkey);
+ pkbuf = tcmemdup(pkey, pksiz);
}
- }
- if(!path || !pkey) usage();
- int pksiz;
- char *pkbuf;
- if(sx){
- pkbuf = tchexdecode(pkey, &pksiz);
- } else {
- pksiz = strlen(pkey);
- pkbuf = tcmemdup(pkey, pksiz);
- }
- int rv = procget(path, pkbuf, pksiz, omode, px, pz);
- tcfree(pkbuf);
- return rv;
+ int rv = procget(path, pkbuf, pksiz, omode, px, pz);
+ tcfree(pkbuf);
+ return rv;
}
-
/* parse arguments of list command */
-static int runlist(int argc, char **argv){
- char *path = NULL;
- int omode = 0;
- int max = -1;
- bool pv = false;
- bool px = false;
- char *fmstr = NULL;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-m")){
- if(++i >= argc) usage();
- max = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-pv")){
- pv = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-fm")){
- if(++i >= argc) usage();
- fmstr = argv[i];
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- usage();
+static int runlist(int argc, char **argv) {
+ char *path = NULL;
+ int omode = 0;
+ int max = -1;
+ bool pv = false;
+ bool px = false;
+ char *fmstr = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-m")) {
+ if (++i >= argc) usage();
+ max = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-pv")) {
+ pv = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-fm")) {
+ if (++i >= argc) usage();
+ fmstr = argv[i];
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = proclist(path, omode, max, pv, px, fmstr);
- return rv;
+ if (!path) usage();
+ int rv = proclist(path, omode, max, pv, px, fmstr);
+ return rv;
}
-
/* parse arguments of search command */
-static int runsearch(int argc, char **argv){
- char *path = NULL;
- TCLIST *conds = tcmpoollistnew(tcmpoolglobal());
- char *oname = NULL;
- char *otype = NULL;
- int omode = 0;
- int max = -1;
- int skip = -1;
- bool pv = false;
- bool px = false;
- bool kw = false;
- bool ph = false;
- int bt = 0;
- bool rm = false;
- char *mtype = NULL;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-ord")){
- if(++i >= argc) usage();
- oname = argv[i];
- if(++i >= argc) usage();
- otype = argv[i];
- } else if(!strcmp(argv[i], "-m")){
- if(++i >= argc) usage();
- max = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-sk")){
- if(++i >= argc) usage();
- skip = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-kw")){
- kw = true;
- } else if(!strcmp(argv[i], "-pv")){
- pv = true;
- } else if(!strcmp(argv[i], "-px")){
- px = true;
- } else if(!strcmp(argv[i], "-ph")){
- ph = true;
- } else if(!strcmp(argv[i], "-bt")){
- if(++i >= argc) usage();
- bt = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-rm")){
- rm = true;
- } else if(!strcmp(argv[i], "-ms")){
- if(++i >= argc) usage();
- mtype = argv[i];
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else {
- tclistpush2(conds, argv[i]);
+static int runsearch(int argc, char **argv) {
+ char *path = NULL;
+ TCLIST *conds = tcmpoollistnew(tcmpoolglobal());
+ char *oname = NULL;
+ char *otype = NULL;
+ int omode = 0;
+ int max = -1;
+ int skip = -1;
+ bool pv = false;
+ bool px = false;
+ bool kw = false;
+ bool ph = false;
+ int bt = 0;
+ bool rm = false;
+ char *mtype = NULL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-ord")) {
+ if (++i >= argc) usage();
+ oname = argv[i];
+ if (++i >= argc) usage();
+ otype = argv[i];
+ } else if (!strcmp(argv[i], "-m")) {
+ if (++i >= argc) usage();
+ max = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-sk")) {
+ if (++i >= argc) usage();
+ skip = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-kw")) {
+ kw = true;
+ } else if (!strcmp(argv[i], "-pv")) {
+ pv = true;
+ } else if (!strcmp(argv[i], "-px")) {
+ px = true;
+ } else if (!strcmp(argv[i], "-ph")) {
+ ph = true;
+ } else if (!strcmp(argv[i], "-bt")) {
+ if (++i >= argc) usage();
+ bt = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-rm")) {
+ rm = true;
+ } else if (!strcmp(argv[i], "-ms")) {
+ if (++i >= argc) usage();
+ mtype = argv[i];
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else {
+ tclistpush2(conds, argv[i]);
+ }
}
- }
- if(!path || tclistnum(conds) % 3 != 0) usage();
- int rv = procsearch(path, conds, oname, otype, omode, max, skip,
- pv, px, kw, ph, bt, rm, mtype);
- return rv;
+ if (!path || tclistnum(conds) % 3 != 0) usage();
+ int rv = procsearch(path, conds, oname, otype, omode, max, skip,
+ pv, px, kw, ph, bt, rm, mtype);
+ return rv;
}
-
/* parse arguments of optimize command */
-static int runoptimize(int argc, char **argv){
- char *path = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = UINT8_MAX;
- int omode = 0;
- bool df = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= TDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= TDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= TDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= TDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- if(opts == UINT8_MAX) opts = 0;
- opts |= TDBTEXCODEC;
- } else if(!strcmp(argv[i], "-tz")){
- if(opts == UINT8_MAX) opts = 0;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-df")){
- df = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
+static int runoptimize(int argc, char **argv) {
+ char *path = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = UINT8_MAX;
+ int omode = 0;
+ bool df = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= TDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= TDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= TDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= TDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ if (opts == UINT8_MAX) opts = 0;
+ opts |= TDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-tz")) {
+ if (opts == UINT8_MAX) opts = 0;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-df")) {
+ df = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procoptimize(path, bnum, apow, fpow, opts, omode, df);
- return rv;
+ if (!path) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procoptimize(path, bnum, apow, fpow, opts, omode, df);
+ return rv;
}
-
/* parse arguments of setindex command */
-static int runsetindex(int argc, char **argv){
- char *path = NULL;
- char *name = NULL;
- int omode = 0;
- int type = TDBITLEXICAL;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-it")){
- if(++i >= argc) usage();
- type = tctdbstrtoindextype(argv[i]);
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!name){
- name = argv[i];
- } else {
- usage();
+static int runsetindex(int argc, char **argv) {
+ char *path = NULL;
+ char *name = NULL;
+ int omode = 0;
+ int type = TDBITLEXICAL;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-it")) {
+ if (++i >= argc) usage();
+ type = tctdbstrtoindextype(argv[i]);
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!name) {
+ name = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path || !name) usage();
- if(type < 0) usage();
- int rv = procsetindex(path, name, omode, type);
- return rv;
+ if (!path || !name) usage();
+ if (type < 0) usage();
+ int rv = procsetindex(path, name, omode, type);
+ return rv;
}
-
/* parse arguments of importtsv command */
-static int runimporttsv(int argc, char **argv){
- char *path = NULL;
- char *file = NULL;
- int omode = 0;
- bool sc = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-sc")){
- sc = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!file){
- file = argv[i];
- } else {
- usage();
+static int runimporttsv(int argc, char **argv) {
+ char *path = NULL;
+ char *file = NULL;
+ int omode = 0;
+ bool sc = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-sc")) {
+ sc = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!file) {
+ file = argv[i];
+ } else {
+ usage();
+ }
}
- }
- if(!path) usage();
- int rv = procimporttsv(path, file, omode, sc);
- return rv;
+ if (!path) usage();
+ int rv = procimporttsv(path, file, omode, sc);
+ return rv;
}
-
/* parse arguments of version command */
-static int runversion(int argc, char **argv){
- int rv = procversion();
- return rv;
+static int runversion(int argc, char **argv) {
+ int rv = procversion();
+ return rv;
}
-
/* perform create command */
-static int proccreate(const char *path, int bnum, int apow, int fpow, int opts){
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
- if(!tctdbtune(tdb, bnum, apow, fpow, opts)){
- printerr(tdb);
- tctdbdel(tdb);
- return 1;
- }
- if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC)){
- printerr(tdb);
+static int proccreate(const char *path, int bnum, int apow, int fpow, int opts) {
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
+ if (!tctdbtune(tdb, bnum, apow, fpow, opts)) {
+ printerr(tdb);
+ tctdbdel(tdb);
+ return 1;
+ }
+ if (!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC)) {
+ printerr(tdb);
+ tctdbdel(tdb);
+ return 1;
+ }
+ bool err = false;
+ if (!tctdbclose(tdb)) {
+ printerr(tdb);
+ err = true;
+ }
tctdbdel(tdb);
- return 1;
- }
- bool err = false;
- if(!tctdbclose(tdb)){
- printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform inform command */
-static int procinform(const char *path, int omode){
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL);
- if(!tctdbopen(tdb, path, TDBOREADER | omode)){
- printerr(tdb);
- tctdbdel(tdb);
- return 1;
- }
- bool err = false;
- const char *npath = tctdbpath(tdb);
- if(!npath) npath = "(unknown)";
- printf("path: %s\n", npath);
- printf("database type: table\n");
- uint8_t flags = tctdbflags(tdb);
- printf("additional flags:");
- if(flags & TDBFOPEN) printf(" open");
- if(flags & TDBFFATAL) printf(" fatal");
- printf("\n");
- printf("bucket number: %" PRIuMAX "\n", (uint64_t)tctdbbnum(tdb));
+static int procinform(const char *path, int omode) {
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL);
+ if (!tctdbopen(tdb, path, TDBOREADER | omode)) {
+ printerr(tdb);
+ tctdbdel(tdb);
+ return 1;
+ }
+ bool err = false;
+ const char *npath = tctdbpath(tdb);
+ if (!npath) npath = "(unknown)";
+ printf("path: %s\n", npath);
+ printf("database type: table\n");
+ uint8_t flags = tctdbflags(tdb);
+ printf("additional flags:");
+ if (flags & TDBFOPEN) printf(" open");
+ if (flags & TDBFFATAL) printf(" fatal");
+ printf("\n");
+ printf("bucket number: %" PRIuMAX "\n", (uint64_t) tctdbbnum(tdb));
#ifndef NDEBUG
- if(tdb->hdb->cnt_writerec >= 0)
- printf("used bucket number: %" PRIdMAX "\n", (int64_t)tctdbbnumused(tdb));
+ if (tdb->hdb->cnt_writerec >= 0)
+ printf("used bucket number: %" PRIdMAX "\n", (int64_t) tctdbbnumused(tdb));
#endif
- printf("alignment: %u\n", tctdbalign(tdb));
- printf("free block pool: %u\n", tctdbfbpmax(tdb));
- printf("index number: %d\n", tctdbinum(tdb));
- TDBIDX *idxs = tdb->idxs;
- int inum = tdb->inum;
- for(int i = 0; i < inum; i++){
- TDBIDX *idxp = idxs + i;
- switch(idxp->type){
- case TDBITLEXICAL:
- printf(" name=%s, type=lexical, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
- idxp->name, (int64_t)tcbdbrnum(idxp->db), (int64_t)tcbdbfsiz(idxp->db));
- break;
- case TDBITDECIMAL:
- printf(" name=%s, type=decimal, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
- idxp->name, (int64_t)tcbdbrnum(idxp->db), (int64_t)tcbdbfsiz(idxp->db));
- break;
- case TDBITTOKEN:
- printf(" name=%s, type=token, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
- idxp->name, (int64_t)tcbdbrnum(idxp->db), (int64_t)tcbdbfsiz(idxp->db));
- break;
- case TDBITQGRAM:
- printf(" name=%s, type=qgram, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
- idxp->name, (int64_t)tcbdbrnum(idxp->db), (int64_t)tcbdbfsiz(idxp->db));
- break;
+ printf("alignment: %u\n", tctdbalign(tdb));
+ printf("free block pool: %u\n", tctdbfbpmax(tdb));
+ printf("index number: %d\n", tctdbinum(tdb));
+ TDBIDX *idxs = tdb->idxs;
+ int inum = tdb->inum;
+ for (int i = 0; i < inum; i++) {
+ TDBIDX *idxp = idxs + i;
+ switch (idxp->type) {
+ case TDBITLEXICAL:
+ printf(" name=%s, type=lexical, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
+ idxp->name, (int64_t) tcbdbrnum(idxp->db), (int64_t) tcbdbfsiz(idxp->db));
+ break;
+ case TDBITDECIMAL:
+ printf(" name=%s, type=decimal, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
+ idxp->name, (int64_t) tcbdbrnum(idxp->db), (int64_t) tcbdbfsiz(idxp->db));
+ break;
+ case TDBITTOKEN:
+ printf(" name=%s, type=token, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
+ idxp->name, (int64_t) tcbdbrnum(idxp->db), (int64_t) tcbdbfsiz(idxp->db));
+ break;
+ case TDBITQGRAM:
+ printf(" name=%s, type=qgram, rnum=%" PRIdMAX ", fsiz=%" PRIdMAX "\n",
+ idxp->name, (int64_t) tcbdbrnum(idxp->db), (int64_t) tcbdbfsiz(idxp->db));
+ break;
+ }
}
- }
- printf("unique ID seed: %" PRIdMAX "\n", (int64_t)tctdbuidseed(tdb));
- printf("inode number: %" PRIdMAX "\n", (int64_t)tctdbinode(tdb));
- char date[48];
- tcdatestrwww(tctdbmtime(tdb), INT_MAX, date);
- printf("modified time: %s\n", date);
- uint8_t opts = tctdbopts(tdb);
- printf("options:");
- if(opts & TDBTLARGE) printf(" large");
- if(opts & TDBTDEFLATE) printf(" deflate");
- if(opts & TDBTBZIP) printf(" bzip");
- if(opts & TDBTTCBS) printf(" tcbs");
- if(opts & TDBTEXCODEC) printf(" excodec");
- printf("\n");
- printf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
- printf("file size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
- if(!tctdbclose(tdb)){
- if(!err) printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- return err ? 1 : 0;
+ printf("unique ID seed: %" PRIdMAX "\n", (int64_t) tctdbuidseed(tdb));
+ printf("inode number: %" PRIdMAX "\n", (int64_t) tctdbinode(tdb));
+ char date[48];
+ tcdatestrwww(tctdbmtime(tdb), INT_MAX, date);
+ printf("modified time: %s\n", date);
+ uint8_t opts = tctdbopts(tdb);
+ printf("options:");
+ if (opts & TDBTLARGE) printf(" large");
+ if (opts & TDBTDEFLATE) printf(" deflate");
+ if (opts & TDBTBZIP) printf(" bzip");
+ if (opts & TDBTTCBS) printf(" tcbs");
+ if (opts & TDBTEXCODEC) printf(" excodec");
+ printf("\n");
+ printf("record number: %" PRIuMAX "\n", (uint64_t) tctdbrnum(tdb));
+ printf("file size: %" PRIuMAX "\n", (uint64_t) tctdbfsiz(tdb));
+ if (!tctdbclose(tdb)) {
+ if (!err) printerr(tdb);
+ err = true;
+ }
+ tctdbdel(tdb);
+ return err ? 1 : 0;
}
-
/* perform put command */
static int procput(const char *path, const char *pkbuf, int pksiz, TCMAP *cols,
- int omode, int dmode){
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
- if(!tctdbopen(tdb, path, TDBOWRITER | omode)){
- printerr(tdb);
- tctdbdel(tdb);
- return 1;
- }
- bool err = false;
- char pknumbuf[TCNUMBUFSIZ];
- if(pksiz < 1){
- pksiz = sprintf(pknumbuf, "%" PRIdMAX "", (int64_t)tctdbgenuid(tdb));
- pkbuf = pknumbuf;
- }
- const char *vbuf;
- switch(dmode){
- case -1:
- if(!tctdbputkeep(tdb, pkbuf, pksiz, cols)){
- printerr(tdb);
- err = true;
- }
- break;
- case 1:
- if(!tctdbputcat(tdb, pkbuf, pksiz, cols)){
+ int omode, int dmode) {
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
+ if (!tctdbopen(tdb, path, TDBOWRITER | omode)) {
printerr(tdb);
+ tctdbdel(tdb);
+ return 1;
+ }
+ bool err = false;
+ char pknumbuf[TCNUMBUFSIZ];
+ if (pksiz < 1) {
+ pksiz = sprintf(pknumbuf, "%" PRIdMAX "", (int64_t) tctdbgenuid(tdb));
+ pkbuf = pknumbuf;
+ }
+ const char *vbuf;
+ switch (dmode) {
+ case -1:
+ if (!tctdbputkeep(tdb, pkbuf, pksiz, cols)) {
+ printerr(tdb);
+ err = true;
+ }
+ break;
+ case 1:
+ if (!tctdbputcat(tdb, pkbuf, pksiz, cols)) {
+ printerr(tdb);
+ err = true;
+ }
+ break;
+ case 10:
+ vbuf = tcmapget2(cols, "_num");
+ if (!vbuf) vbuf = "1";
+ if (tctdbaddint(tdb, pkbuf, pksiz, tcatoi(vbuf)) == INT_MIN) {
+ printerr(tdb);
+ err = true;
+ }
+ break;
+ case 11:
+ vbuf = tcmapget2(cols, "_num");
+ if (!vbuf) vbuf = "1.0";
+ if (isnan(tctdbadddouble(tdb, pkbuf, pksiz, tcatof(vbuf)))) {
+ printerr(tdb);
+ err = true;
+ }
+ break;
+ default:
+ if (!tctdbput(tdb, pkbuf, pksiz, cols)) {
+ printerr(tdb);
+ err = true;
+ }
+ break;
+ }
+ if (!tctdbclose(tdb)) {
+ if (!err) printerr(tdb);
err = true;
- }
- break;
- case 10:
- vbuf = tcmapget2(cols, "_num");
- if(!vbuf) vbuf = "1";
- if(tctdbaddint(tdb, pkbuf, pksiz, tcatoi(vbuf)) == INT_MIN){
+ }
+ tctdbdel(tdb);
+ return err ? 1 : 0;
+}
+
+/* perform out command */
+static int procout(const char *path, const char *pkbuf, int pksiz, int omode) {
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
+ if (!tctdbopen(tdb, path, TDBOWRITER | omode)) {
printerr(tdb);
- err = true;
- }
- break;
- case 11:
- vbuf = tcmapget2(cols, "_num");
- if(!vbuf) vbuf = "1.0";
- if(isnan(tctdbadddouble(tdb, pkbuf, pksiz, tcatof(vbuf)))){
+ tctdbdel(tdb);
+ return 1;
+ }
+ bool err = false;
+ if (!tctdbout(tdb, pkbuf, pksiz)) {
printerr(tdb);
err = true;
- }
- break;
- default:
- if(!tctdbput(tdb, pkbuf, pksiz, cols)){
- printerr(tdb);
+ }
+ if (!tctdbclose(tdb)) {
+ if (!err) printerr(tdb);
err = true;
- }
- break;
- }
- if(!tctdbclose(tdb)){
- if(!err) printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- return err ? 1 : 0;
-}
-
-
-/* perform out command */
-static int procout(const char *path, const char *pkbuf, int pksiz, int omode){
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
- if(!tctdbopen(tdb, path, TDBOWRITER | omode)){
- printerr(tdb);
+ }
tctdbdel(tdb);
- return 1;
- }
- bool err = false;
- if(!tctdbout(tdb, pkbuf, pksiz)){
- printerr(tdb);
- err = true;
- }
- if(!tctdbclose(tdb)){
- if(!err) printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform get command */
-static int procget(const char *path, const char *pkbuf, int pksiz, int omode, bool px, bool pz){
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
- if(!tctdbopen(tdb, path, TDBOREADER | omode)){
- printerr(tdb);
- tctdbdel(tdb);
- return 1;
- }
- bool err = false;
- TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
- if(cols){
- tcmapiterinit(cols);
- const char *kbuf;
- int ksiz;
- while((kbuf = tcmapiternext(cols, &ksiz)) != NULL){
- int vsiz;
- const char *vbuf = tcmapiterval(kbuf, &vsiz);
- printdata(kbuf, ksiz, px);
- putchar('\t');
- printdata(vbuf, vsiz, px);
- putchar(pz ? '\t' : '\n');
+static int procget(const char *path, const char *pkbuf, int pksiz, int omode, bool px, bool pz) {
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
+ if (!tctdbopen(tdb, path, TDBOREADER | omode)) {
+ printerr(tdb);
+ tctdbdel(tdb);
+ return 1;
}
- tcmapdel(cols);
- } else {
- printerr(tdb);
- err = true;
- }
- if(!tctdbclose(tdb)){
- if(!err) printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- return err ? 1 : 0;
-}
-
-
-/* perform list command */
-static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr){
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
- if(!tctdbopen(tdb, path, TDBOREADER | omode)){
- printerr(tdb);
- tctdbdel(tdb);
- return 1;
- }
- bool err = false;
- if(fmstr){
- TCLIST *pkeys = tctdbfwmkeys2(tdb, fmstr, max);
- for(int i = 0; i < tclistnum(pkeys); i++){
- int pksiz;
- const char *pkbuf = tclistval(pkeys, i, &pksiz);
- printdata(pkbuf, pksiz, px);
- if(pv){
- TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
- if(cols){
- tcmapiterinit(cols);
- const char *kbuf;
- int ksiz;
- while((kbuf = tcmapiternext(cols, &ksiz)) != NULL){
+ bool err = false;
+ TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
+ if (cols) {
+ tcmapiterinit(cols);
+ const char *kbuf;
+ int ksiz;
+ while ((kbuf = tcmapiternext(cols, &ksiz)) != NULL) {
int vsiz;
const char *vbuf = tcmapiterval(kbuf, &vsiz);
- putchar('\t');
printdata(kbuf, ksiz, px);
putchar('\t');
printdata(vbuf, vsiz, px);
- }
- tcmapdel(cols);
+ putchar(pz ? '\t' : '\n');
}
- }
- putchar('\n');
+ tcmapdel(cols);
+ } else {
+ printerr(tdb);
+ err = true;
}
- tclistdel(pkeys);
- } else {
- if(!tctdbiterinit(tdb)){
- printerr(tdb);
- err = true;
+ if (!tctdbclose(tdb)) {
+ if (!err) printerr(tdb);
+ err = true;
}
- int cnt = 0;
- TCMAP *cols;
- while((cols = tctdbiternext3(tdb)) != NULL){
- int pksiz;
- const char *pkbuf = tcmapget(cols, "", 0, &pksiz);
- if(pkbuf){
- printdata(pkbuf, pksiz, px);
- if(pv){
- tcmapiterinit(cols);
- const char *kbuf;
- int ksiz;
- while((kbuf = tcmapiternext(cols, &ksiz)) != NULL){
- if(*kbuf == '\0') continue;
- int vsiz;
- const char *vbuf = tcmapiterval(kbuf, &vsiz);
- putchar('\t');
- printdata(kbuf, ksiz, px);
- putchar('\t');
- printdata(vbuf, vsiz, px);
- }
+ tctdbdel(tdb);
+ return err ? 1 : 0;
+}
+
+/* perform list command */
+static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr) {
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
+ if (!tctdbopen(tdb, path, TDBOREADER | omode)) {
+ printerr(tdb);
+ tctdbdel(tdb);
+ return 1;
+ }
+ bool err = false;
+ if (fmstr) {
+ TCLIST *pkeys = tctdbfwmkeys2(tdb, fmstr, max);
+ for (int i = 0; i < tclistnum(pkeys); i++) {
+ int pksiz;
+ const char *pkbuf = tclistval(pkeys, i, &pksiz);
+ printdata(pkbuf, pksiz, px);
+ if (pv) {
+ TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
+ if (cols) {
+ tcmapiterinit(cols);
+ const char *kbuf;
+ int ksiz;
+ while ((kbuf = tcmapiternext(cols, &ksiz)) != NULL) {
+ int vsiz;
+ const char *vbuf = tcmapiterval(kbuf, &vsiz);
+ putchar('\t');
+ printdata(kbuf, ksiz, px);
+ putchar('\t');
+ printdata(vbuf, vsiz, px);
+ }
+ tcmapdel(cols);
+ }
+ }
+ putchar('\n');
+ }
+ tclistdel(pkeys);
+ } else {
+ if (!tctdbiterinit(tdb)) {
+ printerr(tdb);
+ err = true;
}
- }
- tcmapdel(cols);
- putchar('\n');
- if(max >= 0 && ++cnt >= max) break;
+ int cnt = 0;
+ TCMAP *cols;
+ while ((cols = tctdbiternext3(tdb)) != NULL) {
+ int pksiz;
+ const char *pkbuf = tcmapget(cols, "", 0, &pksiz);
+ if (pkbuf) {
+ printdata(pkbuf, pksiz, px);
+ if (pv) {
+ tcmapiterinit(cols);
+ const char *kbuf;
+ int ksiz;
+ while ((kbuf = tcmapiternext(cols, &ksiz)) != NULL) {
+ if (*kbuf == '\0') continue;
+ int vsiz;
+ const char *vbuf = tcmapiterval(kbuf, &vsiz);
+ putchar('\t');
+ printdata(kbuf, ksiz, px);
+ putchar('\t');
+ printdata(vbuf, vsiz, px);
+ }
+ }
+ }
+ tcmapdel(cols);
+ putchar('\n');
+ if (max >= 0 && ++cnt >= max) break;
+ }
+ }
+ if (!tctdbclose(tdb)) {
+ if (!err) printerr(tdb);
+ err = true;
}
- }
- if(!tctdbclose(tdb)){
- if(!err) printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- return err ? 1 : 0;
+ tctdbdel(tdb);
+ return err ? 1 : 0;
}
-
/* perform search command */
static int procsearch(const char *path, TCLIST *conds, const char *oname, const char *otype,
- int omode, int max, int skip, bool pv, bool px, bool kw, bool ph, int bt,
- bool rm, const char *mtype){
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
- if(!tctdbopen(tdb, path, (rm ? TDBOWRITER : TDBOREADER) | omode)){
- printerr(tdb);
- tctdbdel(tdb);
- return 1;
- }
- bool err = false;
- TDBQRY *qry = tctdbqrynew(tdb);
- int cnum = tclistnum(conds);
- for(int i = 0; i < cnum - 2; i += 3){
- const char *name = tclistval2(conds, i);
- const char *opstr = tclistval2(conds, i + 1);
- const char *expr = tclistval2(conds, i + 2);
- int op = tctdbqrystrtocondop(opstr);
- if(op >= 0) tctdbqryaddcond(qry, name, op, expr);
- }
- if(oname){
- int type = tctdbqrystrtoordertype(otype);
- if(type >= 0) tctdbqrysetorder(qry, oname, type);
- }
- tctdbqrysetlimit(qry, max, skip);
- if(rm){
- double stime = tctime();
- if(!tctdbqrysearchout(qry)){
- printerr(tdb);
- err = true;
- }
- double etime = tctime();
- if(ph){
- TCLIST *hints = tcstrsplit(tctdbqryhint(qry), "\n");
- int hnum = tclistnum(hints);
- for(int i = 0; i < hnum; i++){
- const char *hint = tclistval2(hints, i);
- if(*hint == '\0') continue;
- printf("\t:::: %s\n", hint);
- }
- tclistdel(hints);
- printf("\t:::: number of records: %d\n", tctdbqrycount(qry));
- printf("\t:::: elapsed time: %.5f\n", etime - stime);
- }
- } else if(bt > 0){
- double sum = 0;
- for(int i = 1; i <= bt; i++){
- double stime = tctime();
- TCLIST *res = tctdbqrysearch(qry);
- double etime = tctime();
- tclistdel(res);
- printf("%d: %.5f sec.\n", i, etime - stime);
- sum += etime - stime;
+ int omode, int max, int skip, bool pv, bool px, bool kw, bool ph, int bt,
+ bool rm, const char *mtype) {
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
+ if (!tctdbopen(tdb, path, (rm ? TDBOWRITER : TDBOREADER) | omode)) {
+ printerr(tdb);
+ tctdbdel(tdb);
+ return 1;
}
- printf("----\n");
- printf("total: %.5f sec. (%.5f s/q = %.5f q/s)\n", sum, sum / bt, bt / sum);
- } else {
- double stime = tctime();
- TCLIST *res;
- TCLIST *hints;
- int count;
- int mtnum = mtype ? tctdbmetastrtosettype(mtype) : -1;
- if(mtnum >= 0){
- TDBQRY *qrys[cnum/3+1];
- int qnum = 0;
- for(int i = 0; i < cnum - 2; i += 3){
+ bool err = false;
+ TDBQRY *qry = tctdbqrynew(tdb);
+ int cnum = tclistnum(conds);
+ for (int i = 0; i < cnum - 2; i += 3) {
const char *name = tclistval2(conds, i);
const char *opstr = tclistval2(conds, i + 1);
- const char *expr = tclistval2(conds, i + 2);
+ const char *expr = tclistval2(conds, i + 2);
int op = tctdbqrystrtocondop(opstr);
- if(op >= 0){
- qrys[qnum] = tctdbqrynew(tdb);
- tctdbqryaddcond(qrys[qnum], name, op, expr);
- if(oname){
- int type = tctdbqrystrtoordertype(otype);
- if(type >= 0) tctdbqrysetorder(qrys[qnum], oname, type);
- }
- tctdbqrysetlimit(qrys[qnum], max, skip);
- qnum++;
+ if (op >= 0) tctdbqryaddcond(qry, name, op, expr);
+ }
+ if (oname) {
+ int type = tctdbqrystrtoordertype(otype);
+ if (type >= 0) tctdbqrysetorder(qry, oname, type);
+ }
+ tctdbqrysetlimit(qry, max, skip);
+ if (rm) {
+ double stime = tctime();
+ if (!tctdbqrysearchout(qry)) {
+ printerr(tdb);
+ err = true;
+ }
+ double etime = tctime();
+ if (ph) {
+ TCLIST *hints = tcstrsplit(tctdbqryhint(qry), "\n");
+ int hnum = tclistnum(hints);
+ for (int i = 0; i < hnum; i++) {
+ const char *hint = tclistval2(hints, i);
+ if (*hint == '\0') continue;
+ printf("\t:::: %s\n", hint);
+ }
+ tclistdel(hints);
+ printf("\t:::: number of records: %d\n", tctdbqrycount(qry));
+ printf("\t:::: elapsed time: %.5f\n", etime - stime);
}
- }
- res = tctdbmetasearch(qrys, qnum, mtnum);
- hints = qnum > 0 ? tcstrsplit(tctdbqryhint(qrys[0]), "\n") : tclistnew2(1);
- count = qnum > 0 ? tctdbqrycount(qrys[0]) : 0;
- for(int i = 0; i < qnum; i++){
- tctdbqrydel(qrys[i]);
- }
+ } else if (bt > 0) {
+ double sum = 0;
+ for (int i = 1; i <= bt; i++) {
+ double stime = tctime();
+ TCLIST *res = tctdbqrysearch(qry);
+ double etime = tctime();
+ tclistdel(res);
+ printf("%d: %.5f sec.\n", i, etime - stime);
+ sum += etime - stime;
+ }
+ printf("----\n");
+ printf("total: %.5f sec. (%.5f s/q = %.5f q/s)\n", sum, sum / bt, bt / sum);
} else {
- res = tctdbqrysearch(qry);
- hints = tcstrsplit(tctdbqryhint(qry), "\n");
- count = tctdbqrycount(qry);
- }
- double etime = tctime();
- if(max < 0) max = INT_MAX;
- int rnum = tclistnum(res);
- for(int i = 0; i < rnum && max > 0; i++){
- int pksiz;
- const char *pkbuf = tclistval(res, i, &pksiz);
- if(kw){
- TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
- if(cols){
- TCLIST *texts = tctdbqrykwic(qry, cols, NULL, 16, TCKWMUTAB);
- int tnum = tclistnum(texts);
- for(int j = 0; j < tnum && max > 0; j++){
- int tsiz;
- const char *text = tclistval(texts, j, &tsiz);
- printdata(pkbuf, pksiz, px);
- putchar('\t');
- printdata(text, tsiz, px);
- putchar('\n');
- max--;
- }
- tclistdel(texts);
- tcmapdel(cols);
+ double stime = tctime();
+ TCLIST *res;
+ TCLIST *hints;
+ int count;
+ int mtnum = mtype ? tctdbmetastrtosettype(mtype) : -1;
+ if (mtnum >= 0) {
+ TDBQRY * qrys[cnum / 3 + 1];
+ int qnum = 0;
+ for (int i = 0; i < cnum - 2; i += 3) {
+ const char *name = tclistval2(conds, i);
+ const char *opstr = tclistval2(conds, i + 1);
+ const char *expr = tclistval2(conds, i + 2);
+ int op = tctdbqrystrtocondop(opstr);
+ if (op >= 0) {
+ qrys[qnum] = tctdbqrynew(tdb);
+ tctdbqryaddcond(qrys[qnum], name, op, expr);
+ if (oname) {
+ int type = tctdbqrystrtoordertype(otype);
+ if (type >= 0) tctdbqrysetorder(qrys[qnum], oname, type);
+ }
+ tctdbqrysetlimit(qrys[qnum], max, skip);
+ qnum++;
+ }
+ }
+ res = tctdbmetasearch(qrys, qnum, mtnum);
+ hints = qnum > 0 ? tcstrsplit(tctdbqryhint(qrys[0]), "\n") : tclistnew2(1);
+ count = qnum > 0 ? tctdbqrycount(qrys[0]) : 0;
+ for (int i = 0; i < qnum; i++) {
+ tctdbqrydel(qrys[i]);
+ }
+ } else {
+ res = tctdbqrysearch(qry);
+ hints = tcstrsplit(tctdbqryhint(qry), "\n");
+ count = tctdbqrycount(qry);
}
- } else {
- printdata(pkbuf, pksiz, px);
- if(pv){
- TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
- if(cols){
- tcmapiterinit(cols);
- const char *kbuf;
- int ksiz;
- while((kbuf = tcmapiternext(cols, &ksiz)) != NULL){
- int vsiz;
- const char *vbuf = tcmapiterval(kbuf, &vsiz);
- putchar('\t');
- printdata(kbuf, ksiz, px);
- putchar('\t');
- printdata(vbuf, vsiz, px);
+ double etime = tctime();
+ if (max < 0) max = INT_MAX;
+ int rnum = tclistnum(res);
+ for (int i = 0; i < rnum && max > 0; i++) {
+ int pksiz;
+ const char *pkbuf = tclistval(res, i, &pksiz);
+ if (kw) {
+ TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
+ if (cols) {
+ TCLIST *texts = tctdbqrykwic(qry, cols, NULL, 16, TCKWMUTAB);
+ int tnum = tclistnum(texts);
+ for (int j = 0; j < tnum && max > 0; j++) {
+ int tsiz;
+ const char *text = tclistval(texts, j, &tsiz);
+ printdata(pkbuf, pksiz, px);
+ putchar('\t');
+ printdata(text, tsiz, px);
+ putchar('\n');
+ max--;
+ }
+ tclistdel(texts);
+ tcmapdel(cols);
+ }
+ } else {
+ printdata(pkbuf, pksiz, px);
+ if (pv) {
+ TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
+ if (cols) {
+ tcmapiterinit(cols);
+ const char *kbuf;
+ int ksiz;
+ while ((kbuf = tcmapiternext(cols, &ksiz)) != NULL) {
+ int vsiz;
+ const char *vbuf = tcmapiterval(kbuf, &vsiz);
+ putchar('\t');
+ printdata(kbuf, ksiz, px);
+ putchar('\t');
+ printdata(vbuf, vsiz, px);
+ }
+ tcmapdel(cols);
+ }
+ }
+ putchar('\n');
+ max--;
}
- tcmapdel(cols);
- }
}
- putchar('\n');
- max--;
- }
+ if (ph) {
+ int hnum = tclistnum(hints);
+ for (int i = 0; i < hnum; i++) {
+ const char *hint = tclistval2(hints, i);
+ if (*hint == '\0') continue;
+ printf("\t:::: %s\n", hint);
+ }
+ printf("\t:::: number of records: %d\n", count);
+ printf("\t:::: elapsed time: %.5f\n", etime - stime);
+ }
+ tclistdel(hints);
+ tclistdel(res);
}
- if(ph){
- int hnum = tclistnum(hints);
- for(int i = 0; i < hnum; i++){
- const char *hint = tclistval2(hints, i);
- if(*hint == '\0') continue;
- printf("\t:::: %s\n", hint);
- }
- printf("\t:::: number of records: %d\n", count);
- printf("\t:::: elapsed time: %.5f\n", etime - stime);
+ tctdbqrydel(qry);
+ if (!tctdbclose(tdb)) {
+ if (!err) printerr(tdb);
+ err = true;
}
- tclistdel(hints);
- tclistdel(res);
- }
- tctdbqrydel(qry);
- if(!tctdbclose(tdb)){
- if(!err) printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- return err ? 1 : 0;
+ tctdbdel(tdb);
+ return err ? 1 : 0;
}
-
/* perform optimize command */
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode,
- bool df){
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
- int64_t msiz = 0;
- TCMAP *info = tcsysinfo();
- if(info){
- msiz = tcatoi(tcmapget4(info, "total", "0"));
- tcmapdel(info);
- }
- if(!tctdbsetinvcache(tdb, msiz >= (1 << 30) ? msiz / 4 : 0, 1.0)) printerr(tdb);
- if(!tctdbopen(tdb, path, TDBOWRITER | omode)){
- printerr(tdb);
- tctdbdel(tdb);
- return 1;
- }
- bool err = false;
- if(df){
- if(!tctdbdefrag(tdb, INT64_MAX)){
- printerr(tdb);
- err = true;
+ bool df) {
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
+ int64_t msiz = 0;
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ msiz = tcatoi(tcmapget4(info, "total", "0"));
+ tcmapdel(info);
+ }
+ if (!tctdbsetinvcache(tdb, msiz >= (1 << 30) ? msiz / 4 : 0, 1.0)) printerr(tdb);
+ if (!tctdbopen(tdb, path, TDBOWRITER | omode)) {
+ printerr(tdb);
+ tctdbdel(tdb);
+ return 1;
}
- } else {
- if(!tctdboptimize(tdb, bnum, apow, fpow, opts)){
- printerr(tdb);
- err = true;
+ bool err = false;
+ if (df) {
+ if (!tctdbdefrag(tdb, INT64_MAX)) {
+ printerr(tdb);
+ err = true;
+ }
+ } else {
+ if (!tctdboptimize(tdb, bnum, apow, fpow, opts)) {
+ printerr(tdb);
+ err = true;
+ }
}
- }
- if(!tctdbclose(tdb)){
- if(!err) printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- return err ? 1 : 0;
+ if (!tctdbclose(tdb)) {
+ if (!err) printerr(tdb);
+ err = true;
+ }
+ tctdbdel(tdb);
+ return err ? 1 : 0;
}
-
/* perform setindex command */
-static int procsetindex(const char *path, const char *name, int omode, int type){
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
- int64_t msiz = 0;
- TCMAP *info = tcsysinfo();
- if(info){
- msiz = tcatoi(tcmapget4(info, "total", "0"));
- tcmapdel(info);
- }
- if(!tctdbsetinvcache(tdb, msiz >= (1 << 30) ? msiz / 4 : 0, 1.0)) printerr(tdb);
- if(!tctdbopen(tdb, path, TDBOWRITER | omode)){
- printerr(tdb);
+static int procsetindex(const char *path, const char *name, int omode, int type) {
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
+ int64_t msiz = 0;
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ msiz = tcatoi(tcmapget4(info, "total", "0"));
+ tcmapdel(info);
+ }
+ if (!tctdbsetinvcache(tdb, msiz >= (1 << 30) ? msiz / 4 : 0, 1.0)) printerr(tdb);
+ if (!tctdbopen(tdb, path, TDBOWRITER | omode)) {
+ printerr(tdb);
+ tctdbdel(tdb);
+ return 1;
+ }
+ bool err = false;
+ if (!tctdbsetindex(tdb, name, type)) {
+ printerr(tdb);
+ err = true;
+ }
+ if (!tctdbclose(tdb)) {
+ if (!err) printerr(tdb);
+ err = true;
+ }
tctdbdel(tdb);
- return 1;
- }
- bool err = false;
- if(!tctdbsetindex(tdb, name, type)){
- printerr(tdb);
- err = true;
- }
- if(!tctdbclose(tdb)){
- if(!err) printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- return err ? 1 : 0;
+ return err ? 1 : 0;
}
-
/* perform importtsv command */
-static int procimporttsv(const char *path, const char *file, int omode, bool sc){
- FILE *ifp = file ? fopen(file, "rb") : stdin;
- if(!ifp){
- fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
- return 1;
- }
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
- int64_t msiz = 0;
- TCMAP *info = tcsysinfo();
- if(info){
- msiz = tcatoi(tcmapget4(info, "total", "0"));
- tcmapdel(info);
- }
- if(!tctdbsetinvcache(tdb, msiz >= (1 << 30) ? msiz / 4 : 0, 1.0)) printerr(tdb);
- if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | omode)){
- printerr(tdb);
- tctdbdel(tdb);
- if(ifp != stdin) fclose(ifp);
- return 1;
- }
- bool err = false;
- char *line, numbuf[TCNUMBUFSIZ];
- int cnt = 0;
- while(!err && (line = mygetline(ifp)) != NULL){
- char *pv = strchr(line, '\t');
- if(!pv){
- tcfree(line);
- continue;
+static int procimporttsv(const char *path, const char *file, int omode, bool sc) {
+ FILE *ifp = file ? fopen(file, "rb") : stdin;
+ if (!ifp) {
+ fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
+ return 1;
}
- *pv = '\0';
- if(sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
- const char *pkey;
- if(*line == '\0'){
- sprintf(numbuf, "%" PRIdMAX "", (int64_t)tctdbgenuid(tdb));
- pkey = numbuf;
- } else {
- pkey = line;
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
+ int64_t msiz = 0;
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ msiz = tcatoi(tcmapget4(info, "total", "0"));
+ tcmapdel(info);
+ }
+ if (!tctdbsetinvcache(tdb, msiz >= (1 << 30) ? msiz / 4 : 0, 1.0)) printerr(tdb);
+ if (!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | omode)) {
+ printerr(tdb);
+ tctdbdel(tdb);
+ if (ifp != stdin) fclose(ifp);
+ return 1;
}
- if(!tctdbput3(tdb, pkey, pv + 1)){
- printerr(tdb);
- err = true;
+ bool err = false;
+ char *line, numbuf[TCNUMBUFSIZ];
+ int cnt = 0;
+ while (!err && (line = mygetline(ifp)) != NULL) {
+ char *pv = strchr(line, '\t');
+ if (!pv) {
+ tcfree(line);
+ continue;
+ }
+ *pv = '\0';
+ if (sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
+ const char *pkey;
+ if (*line == '\0') {
+ sprintf(numbuf, "%" PRIdMAX "", (int64_t) tctdbgenuid(tdb));
+ pkey = numbuf;
+ } else {
+ pkey = line;
+ }
+ if (!tctdbput3(tdb, pkey, pv + 1)) {
+ printerr(tdb);
+ err = true;
+ }
+ tcfree(line);
+ if (cnt > 0 && cnt % 100 == 0) {
+ putchar('.');
+ fflush(stdout);
+ if (cnt % 5000 == 0) printf(" (%08d)\n", cnt);
+ }
+ cnt++;
}
- tcfree(line);
- if(cnt > 0 && cnt % 100 == 0){
- putchar('.');
- fflush(stdout);
- if(cnt % 5000 == 0) printf(" (%08d)\n", cnt);
+ printf(" (%08d)\n", cnt);
+ if (!tctdbclose(tdb)) {
+ if (!err) printerr(tdb);
+ err = true;
}
- cnt++;
- }
- printf(" (%08d)\n", cnt);
- if(!tctdbclose(tdb)){
- if(!err) printerr(tdb);
- err = true;
- }
- tctdbdel(tdb);
- if(ifp != stdin) fclose(ifp);
- return err ? 1 : 0;
+ tctdbdel(tdb);
+ if (ifp != stdin) fclose(ifp);
+ return err ? 1 : 0;
}
-
/* perform version command */
-static int procversion(void){
- printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
- tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
- printf("Copyright (C) 2006-2012 FAL Labs\n");
- return 0;
+static int procversion(void) {
+ printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
+ tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
+ printf("Copyright (C) 2006-2012 FAL Labs\n");
+ return 0;
}
#define RECBUFSIZ 48 // buffer for records
-typedef struct { // type of structure for write thread
- TCTDB *tdb;
- int rnum;
- bool rnd;
- int id;
+typedef struct { // type of structure for write thread
+ TCTDB *tdb;
+ int rnum;
+ bool rnd;
+ int id;
} TARGWRITE;
-typedef struct { // type of structure for read thread
- TCTDB *tdb;
- int rnum;
- bool rnd;
- int id;
+typedef struct { // type of structure for read thread
+ TCTDB *tdb;
+ int rnum;
+ bool rnd;
+ int id;
} TARGREAD;
-typedef struct { // type of structure for remove thread
- TCTDB *tdb;
- int rnum;
- bool rnd;
- int id;
+typedef struct { // type of structure for remove thread
+ TCTDB *tdb;
+ int rnum;
+ bool rnd;
+ int id;
} TARGREMOVE;
-typedef struct { // type of structure for wicked thread
- TCTDB *tdb;
- int rnum;
- int id;
+typedef struct { // type of structure for wicked thread
+ TCTDB *tdb;
+ int rnum;
+ int id;
} TARGWICKED;
-typedef struct { // type of structure for typical thread
- TCTDB *tdb;
- int rnum;
- int rratio;
- int id;
+typedef struct { // type of structure for typical thread
+ TCTDB *tdb;
+ int rnum;
+ int rratio;
+ int id;
} TARGTYPICAL;
/* global variables */
-const char *g_progname; // program name
-unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+const char *g_progname; // program name
+unsigned int g_randseed; // random seed
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */
static int runwicked(int argc, char **argv);
static int runtypical(int argc, char **argv);
static int procwrite(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int dfunit,
- int iflags, int omode, bool rnd);
+ int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int dfunit,
+ int iflags, int omode, bool rnd);
static int procread(const char *path, int tnum, int rcnum, int lcnum, int ncnum,
- int xmsiz, int dfunit, int omode, bool rnd);
+ int xmsiz, int dfunit, int omode, bool rnd);
static int procremove(const char *path, int tnum, int rcnum, int lcnum, int ncnum,
- int xmsiz, int dfunit, int omode, bool rnd);
+ int xmsiz, int dfunit, int omode, bool rnd);
static int procwicked(const char *path, int tnum, int rnum, int opts, int omode);
static int proctypical(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int dfunit,
- int omode, int rratio);
+ int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int dfunit,
+ int omode, int rratio);
static void *threadwrite(void *targ);
static void *threadread(void *targ);
static void *threadremove(void *targ);
static void *threadwicked(void *targ);
static void *threadtypical(void *targ);
-
/* main routine */
-int main(int argc, char **argv){
- g_progname = argv[0];
- const char *ebuf = getenv("TCRNDSEED");
- g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
- srand(g_randseed);
- ebuf = getenv("TCDBGFD");
- if (ebuf) {
- int debugfd = tcatoix(ebuf);
+int main(int argc, char **argv) {
+ g_progname = argv[0];
+ const char *ebuf = getenv("TCRNDSEED");
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
+ srand(g_randseed);
+ ebuf = getenv("TCDBGFD");
+ if (ebuf) {
+ int debugfd = tcatoix(ebuf);
#ifdef _WIN32
- g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
+ g_dbgfd = (HANDLE) _get_osfhandle(debugfd);
#else
- g_dbgfd = debugfd;
+ g_dbgfd = debugfd;
#endif
- }
- if(argc < 2) usage();
- int rv = 0;
- if(!strcmp(argv[1], "write")){
- rv = runwrite(argc, argv);
- } else if(!strcmp(argv[1], "read")){
- rv = runread(argc, argv);
- } else if(!strcmp(argv[1], "remove")){
- rv = runremove(argc, argv);
- } else if(!strcmp(argv[1], "wicked")){
- rv = runwicked(argc, argv);
- } else if(!strcmp(argv[1], "typical")){
- rv = runtypical(argc, argv);
- } else {
- usage();
- }
- if(rv != 0){
- printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
- for(int i = 0; i < argc; i++){
- printf(" %s", argv[i]);
- }
- printf("\n\n");
- }
- return rv;
+ }
+ if (argc < 2) usage();
+ int rv = 0;
+ if (!strcmp(argv[1], "write")) {
+ rv = runwrite(argc, argv);
+ } else if (!strcmp(argv[1], "read")) {
+ rv = runread(argc, argv);
+ } else if (!strcmp(argv[1], "remove")) {
+ rv = runremove(argc, argv);
+ } else if (!strcmp(argv[1], "wicked")) {
+ rv = runwicked(argc, argv);
+ } else if (!strcmp(argv[1], "typical")) {
+ rv = runtypical(argc, argv);
+ } else {
+ usage();
+ }
+ if (rv != 0) {
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int) getpid());
+ for (int i = 0; i < argc; i++) {
+ printf(" %s", argv[i]);
+ }
+ printf("\n\n");
+ }
+ return rv;
}
-
/* print the usage and exit */
-static void usage(void){
- fprintf(stderr, "%s: test cases of the table database API of Tokyo Cabinet\n", g_progname);
- fprintf(stderr, "\n");
- fprintf(stderr, "usage:\n");
- fprintf(stderr, " %s write [-tl] [-td|-tb|-tt|-tx] [-rc num] [-lc num] [-nc num]"
- " [-xm num] [-df num] [-ip] [-is] [-in] [-it] [-if] [-ix] [-nl|-nb] [-rnd]"
- " path tnum rnum [bnum [apow [fpow]]]\n", g_progname);
- fprintf(stderr, " %s read [-rc num] [-lc num] [-nc num] [-xm num] [-df num] [-nl|-nb] [-rnd]"
- " path tnum\n", g_progname);
- fprintf(stderr, " %s remove [-rc num] [-lc num] [-nc num] [-xm num] [-df num]"
- " [-nl|-nb] [-rnd] path tnum\n", g_progname);
- fprintf(stderr, " %s wicked [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path tnum rnum\n", g_progname);
- fprintf(stderr, " %s typical [-tl] [-td|-tb|-tt|-tx] [-rc num] [-lc num] [-nc num]"
- " [-xm num] [-df num] [-nl|-nb] [-rr num] path tnum rnum [bnum [apow [fpow]]]\n",
- g_progname);
- fprintf(stderr, "\n");
- exit(1);
+static void usage(void) {
+ fprintf(stderr, "%s: test cases of the table database API of Tokyo Cabinet\n", g_progname);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "usage:\n");
+ fprintf(stderr, " %s write [-tl] [-td|-tb|-tt|-tx] [-rc num] [-lc num] [-nc num]"
+ " [-xm num] [-df num] [-ip] [-is] [-in] [-it] [-if] [-ix] [-nl|-nb] [-rnd]"
+ " path tnum rnum [bnum [apow [fpow]]]\n", g_progname);
+ fprintf(stderr, " %s read [-rc num] [-lc num] [-nc num] [-xm num] [-df num] [-nl|-nb] [-rnd]"
+ " path tnum\n", g_progname);
+ fprintf(stderr, " %s remove [-rc num] [-lc num] [-nc num] [-xm num] [-df num]"
+ " [-nl|-nb] [-rnd] path tnum\n", g_progname);
+ fprintf(stderr, " %s wicked [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path tnum rnum\n", g_progname);
+ fprintf(stderr, " %s typical [-tl] [-td|-tb|-tt|-tx] [-rc num] [-lc num] [-nc num]"
+ " [-xm num] [-df num] [-nl|-nb] [-rr num] path tnum rnum [bnum [apow [fpow]]]\n",
+ g_progname);
+ fprintf(stderr, "\n");
+ exit(1);
}
-
/* print formatted information string and flush the buffer */
-static void iprintf(const char *format, ...){
- va_list ap;
- va_start(ap, format);
- vprintf(format, ap);
- fflush(stdout);
- va_end(ap);
+static void iprintf(const char *format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ vprintf(format, ap);
+ fflush(stdout);
+ va_end(ap);
}
-
/* print a character and flush the buffer */
-static void iputchar(int c){
- putchar(c);
- fflush(stdout);
+static void iputchar(int c) {
+ putchar(c);
+ fflush(stdout);
}
-
/* print error message of table database */
-static void eprint(TCTDB *tdb, int line, const char *func){
- const char *path = tctdbpath(tdb);
- int ecode = tctdbecode(tdb);
- fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
- g_progname, path ? path : "-", line, func, ecode, tctdberrmsg(ecode));
+static void eprint(TCTDB *tdb, int line, const char *func) {
+ const char *path = tctdbpath(tdb);
+ int ecode = tctdbecode(tdb);
+ fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
+ g_progname, path ? path : "-", line, func, ecode, tctdberrmsg(ecode));
}
-
/* print system information */
-static void sysprint(void){
- TCMAP *info = tcsysinfo();
- if(info){
- tcmapiterinit(info);
- const char *kbuf;
- while((kbuf = tcmapiternext2(info)) != NULL){
- iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
- }
- tcmapdel(info);
- }
+static void sysprint(void) {
+ TCMAP *info = tcsysinfo();
+ if (info) {
+ tcmapiterinit(info);
+ const char *kbuf;
+ while ((kbuf = tcmapiternext2(info)) != NULL) {
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
+ }
+ tcmapdel(info);
+ }
}
-
/* get a random number */
-static int myrand(int range){
- if(range < 2) return 0;
- int high = (unsigned int)rand() >> 4;
- int low = range * (rand() / (RAND_MAX + 1.0));
- low &= (unsigned int)INT_MAX >> 4;
- return (high + low) % range;
+static int myrand(int range) {
+ if (range < 2) return 0;
+ int high = (unsigned int) rand() >> 4;
+ int low = range * (rand() / (RAND_MAX + 1.0));
+ low &= (unsigned int) INT_MAX >> 4;
+ return (high + low) % range;
}
-
/* get a random number based on normal distribution */
-static int myrandnd(int range){
- int num = (int)tcdrandnd(range >> 1, range / 10);
- return (num < 0 || num >= range) ? 0 : num;
+static int myrandnd(int range) {
+ int num = (int) tcdrandnd(range >> 1, range / 10);
+ return (num < 0 || num >= range) ? 0 : num;
}
-
/* parse arguments of write command */
-static int runwrite(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- int rcnum = 0;
- int lcnum = 0;
- int ncnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int iflags = 0;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= TDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= TDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= TDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= TDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= TDBTEXCODEC;
- } else if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-lc")){
- if(++i >= argc) usage();
- lcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nc")){
- if(++i >= argc) usage();
- ncnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-ip")){
- iflags |= 1 << 0;
- } else if(!strcmp(argv[i], "-is")){
- iflags |= 1 << 1;
- } else if(!strcmp(argv[i], "-in")){
- iflags |= 1 << 2;
- } else if(!strcmp(argv[i], "-it")){
- iflags |= 1 << 3;
- } else if(!strcmp(argv[i], "-if")){
- iflags |= 1 << 4;
- } else if(!strcmp(argv[i], "-ix")){
- iflags |= 1 << 5;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = procwrite(path, tnum, rnum, bnum, apow, fpow, opts, rcnum, lcnum, ncnum,
- xmsiz, dfunit, iflags, omode, rnd);
- return rv;
+static int runwrite(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ int rcnum = 0;
+ int lcnum = 0;
+ int ncnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int iflags = 0;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= TDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= TDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= TDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= TDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= TDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-lc")) {
+ if (++i >= argc) usage();
+ lcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nc")) {
+ if (++i >= argc) usage();
+ ncnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-ip")) {
+ iflags |= 1 << 0;
+ } else if (!strcmp(argv[i], "-is")) {
+ iflags |= 1 << 1;
+ } else if (!strcmp(argv[i], "-in")) {
+ iflags |= 1 << 2;
+ } else if (!strcmp(argv[i], "-it")) {
+ iflags |= 1 << 3;
+ } else if (!strcmp(argv[i], "-if")) {
+ iflags |= 1 << 4;
+ } else if (!strcmp(argv[i], "-ix")) {
+ iflags |= 1 << 5;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = procwrite(path, tnum, rnum, bnum, apow, fpow, opts, rcnum, lcnum, ncnum,
+ xmsiz, dfunit, iflags, omode, rnd);
+ return rv;
}
-
/* parse arguments of read command */
-static int runread(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- int rcnum = 0;
- int lcnum = 0;
- int ncnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-lc")){
- if(++i >= argc) usage();
- lcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nc")){
- if(++i >= argc) usage();
- ncnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procread(path, tnum, rcnum, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
- return rv;
+static int runread(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ int rcnum = 0;
+ int lcnum = 0;
+ int ncnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-lc")) {
+ if (++i >= argc) usage();
+ lcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nc")) {
+ if (++i >= argc) usage();
+ ncnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procread(path, tnum, rcnum, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
+ return rv;
}
-
/* parse arguments of remove command */
-static int runremove(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- int rcnum = 0;
- int lcnum = 0;
- int ncnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- bool rnd = false;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-lc")){
- if(++i >= argc) usage();
- lcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nc")){
- if(++i >= argc) usage();
- ncnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-rnd")){
- rnd = true;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr) usage();
- int tnum = tcatoix(tstr);
- if(tnum < 1) usage();
- int rv = procremove(path, tnum, rcnum, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
- return rv;
+static int runremove(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ int rcnum = 0;
+ int lcnum = 0;
+ int ncnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ bool rnd = false;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-lc")) {
+ if (++i >= argc) usage();
+ lcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nc")) {
+ if (++i >= argc) usage();
+ ncnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rnd")) {
+ rnd = true;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr) usage();
+ int tnum = tcatoix(tstr);
+ if (tnum < 1) usage();
+ int rv = procremove(path, tnum, rcnum, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
+ return rv;
}
-
/* parse arguments of wicked command */
-static int runwicked(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- int opts = 0;
- int omode = 0;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= TDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= TDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= TDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= TDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= TDBTEXCODEC;
- } else if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int rv = procwicked(path, tnum, rnum, opts, omode);
- return rv;
+static int runwicked(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ int opts = 0;
+ int omode = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= TDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= TDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= TDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= TDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= TDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int rv = procwicked(path, tnum, rnum, opts, omode);
+ return rv;
}
-
/* parse arguments of typical command */
-static int runtypical(int argc, char **argv){
- char *path = NULL;
- char *tstr = NULL;
- char *rstr = NULL;
- char *bstr = NULL;
- char *astr = NULL;
- char *fstr = NULL;
- int opts = 0;
- int rcnum = 0;
- int lcnum = 0;
- int ncnum = 0;
- int xmsiz = -1;
- int dfunit = 0;
- int omode = 0;
- int rratio = -1;
- for(int i = 2; i < argc; i++){
- if(!path && argv[i][0] == '-'){
- if(!strcmp(argv[i], "-tl")){
- opts |= TDBTLARGE;
- } else if(!strcmp(argv[i], "-td")){
- opts |= TDBTDEFLATE;
- } else if(!strcmp(argv[i], "-tb")){
- opts |= TDBTBZIP;
- } else if(!strcmp(argv[i], "-tt")){
- opts |= TDBTTCBS;
- } else if(!strcmp(argv[i], "-tx")){
- opts |= TDBTEXCODEC;
- } else if(!strcmp(argv[i], "-rc")){
- if(++i >= argc) usage();
- rcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-lc")){
- if(++i >= argc) usage();
- lcnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nc")){
- if(++i >= argc) usage();
- ncnum = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-xm")){
- if(++i >= argc) usage();
- xmsiz = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-df")){
- if(++i >= argc) usage();
- dfunit = tcatoix(argv[i]);
- } else if(!strcmp(argv[i], "-nl")){
- omode |= TDBONOLCK;
- } else if(!strcmp(argv[i], "-nb")){
- omode |= TDBOLCKNB;
- } else if(!strcmp(argv[i], "-rr")){
- if(++i >= argc) usage();
- rratio = tcatoix(argv[i]);
- } else {
- usage();
- }
- } else if(!path){
- path = argv[i];
- } else if(!tstr){
- tstr = argv[i];
- } else if(!rstr){
- rstr = argv[i];
- } else if(!bstr){
- bstr = argv[i];
- } else if(!astr){
- astr = argv[i];
- } else if(!fstr){
- fstr = argv[i];
- } else {
- usage();
- }
- }
- if(!path || !tstr || !rstr) usage();
- int tnum = tcatoix(tstr);
- int rnum = tcatoix(rstr);
- if(tnum < 1 || rnum < 1) usage();
- int bnum = bstr ? tcatoix(bstr) : -1;
- int apow = astr ? tcatoix(astr) : -1;
- int fpow = fstr ? tcatoix(fstr) : -1;
- int rv = proctypical(path, tnum, rnum, bnum, apow, fpow, opts, rcnum, lcnum, ncnum,
- xmsiz, dfunit, omode, rratio);
- return rv;
+static int runtypical(int argc, char **argv) {
+ char *path = NULL;
+ char *tstr = NULL;
+ char *rstr = NULL;
+ char *bstr = NULL;
+ char *astr = NULL;
+ char *fstr = NULL;
+ int opts = 0;
+ int rcnum = 0;
+ int lcnum = 0;
+ int ncnum = 0;
+ int xmsiz = -1;
+ int dfunit = 0;
+ int omode = 0;
+ int rratio = -1;
+ for (int i = 2; i < argc; i++) {
+ if (!path && argv[i][0] == '-') {
+ if (!strcmp(argv[i], "-tl")) {
+ opts |= TDBTLARGE;
+ } else if (!strcmp(argv[i], "-td")) {
+ opts |= TDBTDEFLATE;
+ } else if (!strcmp(argv[i], "-tb")) {
+ opts |= TDBTBZIP;
+ } else if (!strcmp(argv[i], "-tt")) {
+ opts |= TDBTTCBS;
+ } else if (!strcmp(argv[i], "-tx")) {
+ opts |= TDBTEXCODEC;
+ } else if (!strcmp(argv[i], "-rc")) {
+ if (++i >= argc) usage();
+ rcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-lc")) {
+ if (++i >= argc) usage();
+ lcnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nc")) {
+ if (++i >= argc) usage();
+ ncnum = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-xm")) {
+ if (++i >= argc) usage();
+ xmsiz = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-df")) {
+ if (++i >= argc) usage();
+ dfunit = tcatoix(argv[i]);
+ } else if (!strcmp(argv[i], "-nl")) {
+ omode |= TDBONOLCK;
+ } else if (!strcmp(argv[i], "-nb")) {
+ omode |= TDBOLCKNB;
+ } else if (!strcmp(argv[i], "-rr")) {
+ if (++i >= argc) usage();
+ rratio = tcatoix(argv[i]);
+ } else {
+ usage();
+ }
+ } else if (!path) {
+ path = argv[i];
+ } else if (!tstr) {
+ tstr = argv[i];
+ } else if (!rstr) {
+ rstr = argv[i];
+ } else if (!bstr) {
+ bstr = argv[i];
+ } else if (!astr) {
+ astr = argv[i];
+ } else if (!fstr) {
+ fstr = argv[i];
+ } else {
+ usage();
+ }
+ }
+ if (!path || !tstr || !rstr) usage();
+ int tnum = tcatoix(tstr);
+ int rnum = tcatoix(rstr);
+ if (tnum < 1 || rnum < 1) usage();
+ int bnum = bstr ? tcatoix(bstr) : -1;
+ int apow = astr ? tcatoix(astr) : -1;
+ int fpow = fstr ? tcatoix(fstr) : -1;
+ int rv = proctypical(path, tnum, rnum, bnum, apow, fpow, opts, rcnum, lcnum, ncnum,
+ xmsiz, dfunit, omode, rratio);
+ return rv;
}
-
/* perform write command */
static int procwrite(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int dfunit,
- int iflags, int omode, bool rnd){
- iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d fpow=%d"
- " opts=%d rcnum=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d iflags=%d"
- " omode=%d rnd=%d\n\n",
- g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, rcnum, lcnum, ncnum,
- xmsiz, dfunit, iflags, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetmutex(tdb)){
- eprint(tdb, __LINE__, "tctdbsetmutex");
- err = true;
- }
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(tdb, __LINE__, "tctdbsetcodecfunc");
- err = true;
- }
- if(!tctdbtune(tdb, bnum, apow, fpow, opts)){
- eprint(tdb, __LINE__, "tctdbtune");
- err = true;
- }
- if(!tctdbsetcache(tdb, rcnum, lcnum, ncnum)){
- eprint(tdb, __LINE__, "tctdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)){
- eprint(tdb, __LINE__, "tctdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tctdbsetdfunit(tdb, dfunit)){
- eprint(tdb, __LINE__, "tctdbsetdfunit");
- err = true;
- }
- if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC | omode)){
- eprint(tdb, __LINE__, "tctdbopen");
- err = true;
- }
- if((iflags & (1 << 0)) && !tctdbsetindex(tdb, "", TDBITDECIMAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if((iflags & (1 << 1)) && !tctdbsetindex(tdb, "str", TDBITLEXICAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if((iflags & (1 << 2)) && !tctdbsetindex(tdb, "num", TDBITDECIMAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if((iflags & (1 << 3)) && !tctdbsetindex(tdb, "type", TDBITDECIMAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if((iflags & (1 << 4)) && !tctdbsetindex(tdb, "flag", TDBITTOKEN)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if((iflags & (1 << 5)) && !tctdbsetindex(tdb, "text", TDBITQGRAM)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- TARGWRITE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].tdb = tdb;
- targs[0].rnum = rnum;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadwrite(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].tdb = tdb;
- targs[i].rnum = rnum;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadwrite, targs + i) != 0){
- eprint(tdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int dfunit,
+ int iflags, int omode, bool rnd) {
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d fpow=%d"
+ " opts=%d rcnum=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d iflags=%d"
+ " omode=%d rnd=%d\n\n",
+ g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, rcnum, lcnum, ncnum,
+ xmsiz, dfunit, iflags, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetmutex(tdb)) {
+ eprint(tdb, __LINE__, "tctdbsetmutex");
+ err = true;
+ }
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(tdb, __LINE__, "tctdbsetcodecfunc");
+ err = true;
+ }
+ if (!tctdbtune(tdb, bnum, apow, fpow, opts)) {
+ eprint(tdb, __LINE__, "tctdbtune");
+ err = true;
+ }
+ if (!tctdbsetcache(tdb, rcnum, lcnum, ncnum)) {
+ eprint(tdb, __LINE__, "tctdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)) {
+ eprint(tdb, __LINE__, "tctdbsetxmsiz");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(tdb, __LINE__, "pthread_join");
+ if (dfunit >= 0 && !tctdbsetdfunit(tdb, dfunit)) {
+ eprint(tdb, __LINE__, "tctdbsetdfunit");
err = true;
- } else if(rv){
+ }
+ if (!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC | omode)) {
+ eprint(tdb, __LINE__, "tctdbopen");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
- sysprint();
- if(!tctdbclose(tdb)){
- eprint(tdb, __LINE__, "tctdbclose");
- err = true;
- }
- tctdbdel(tdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ if ((iflags & (1 << 0)) && !tctdbsetindex(tdb, "", TDBITDECIMAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if ((iflags & (1 << 1)) && !tctdbsetindex(tdb, "str", TDBITLEXICAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if ((iflags & (1 << 2)) && !tctdbsetindex(tdb, "num", TDBITDECIMAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if ((iflags & (1 << 3)) && !tctdbsetindex(tdb, "type", TDBITDECIMAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if ((iflags & (1 << 4)) && !tctdbsetindex(tdb, "flag", TDBITTOKEN)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if ((iflags & (1 << 5)) && !tctdbsetindex(tdb, "text", TDBITQGRAM)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ TARGWRITE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].tdb = tdb;
+ targs[0].rnum = rnum;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadwrite(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].tdb = tdb;
+ targs[i].rnum = rnum;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadwrite, targs + i) != 0) {
+ eprint(tdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(tdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tctdbfsiz(tdb));
+ sysprint();
+ if (!tctdbclose(tdb)) {
+ eprint(tdb, __LINE__, "tctdbclose");
+ err = true;
+ }
+ tctdbdel(tdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform read command */
static int procread(const char *path, int tnum, int rcnum, int lcnum, int ncnum,
- int xmsiz, int dfunit, int omode, bool rnd){
- iprintf("<Reading Test>\n seed=%u path=%s tnum=%d rcnum=%d lcnum=%d ncnum=%d"
- " xmsiz=%d dfunit=%d omode=%d rnd=%d\n\n",
- g_randseed, path, tnum, rcnum, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetmutex(tdb)){
- eprint(tdb, __LINE__, "tctdbsetmutex");
- err = true;
- }
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(tdb, __LINE__, "tctdbsetcodecfunc");
- err = true;
- }
- if(!tctdbsetcache(tdb, rcnum, lcnum, ncnum)){
- eprint(tdb, __LINE__, "tctdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)){
- eprint(tdb, __LINE__, "tctdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tctdbsetdfunit(tdb, dfunit)){
- eprint(tdb, __LINE__, "tctdbsetdfunit");
- err = true;
- }
- if(!tctdbopen(tdb, path, TDBOREADER | omode)){
- eprint(tdb, __LINE__, "tctdbopen");
- err = true;
- }
- int rnum = tctdbrnum(tdb) / tnum;
- TARGREAD targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].tdb = tdb;
- targs[0].rnum = rnum;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadread(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].tdb = tdb;
- targs[i].rnum = rnum;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadread, targs + i) != 0){
- eprint(tdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int xmsiz, int dfunit, int omode, bool rnd) {
+ iprintf("<Reading Test>\n seed=%u path=%s tnum=%d rcnum=%d lcnum=%d ncnum=%d"
+ " xmsiz=%d dfunit=%d omode=%d rnd=%d\n\n",
+ g_randseed, path, tnum, rcnum, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetmutex(tdb)) {
+ eprint(tdb, __LINE__, "tctdbsetmutex");
+ err = true;
+ }
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(tdb, __LINE__, "tctdbsetcodecfunc");
+ err = true;
+ }
+ if (!tctdbsetcache(tdb, rcnum, lcnum, ncnum)) {
+ eprint(tdb, __LINE__, "tctdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)) {
+ eprint(tdb, __LINE__, "tctdbsetxmsiz");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(tdb, __LINE__, "pthread_join");
+ if (dfunit >= 0 && !tctdbsetdfunit(tdb, dfunit)) {
+ eprint(tdb, __LINE__, "tctdbsetdfunit");
err = true;
- } else if(rv){
+ }
+ if (!tctdbopen(tdb, path, TDBOREADER | omode)) {
+ eprint(tdb, __LINE__, "tctdbopen");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
- sysprint();
- if(!tctdbclose(tdb)){
- eprint(tdb, __LINE__, "tctdbclose");
- err = true;
- }
- tctdbdel(tdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ int rnum = tctdbrnum(tdb) / tnum;
+ TARGREAD targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].tdb = tdb;
+ targs[0].rnum = rnum;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadread(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].tdb = tdb;
+ targs[i].rnum = rnum;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadread, targs + i) != 0) {
+ eprint(tdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(tdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tctdbfsiz(tdb));
+ sysprint();
+ if (!tctdbclose(tdb)) {
+ eprint(tdb, __LINE__, "tctdbclose");
+ err = true;
+ }
+ tctdbdel(tdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform remove command */
static int procremove(const char *path, int tnum, int rcnum, int lcnum, int ncnum,
- int xmsiz, int dfunit, int omode, bool rnd){
- iprintf("<Removing Test>\n seed=%u path=%s tnum=%d rcnum=%d lcnum=%d ncnum=%d"
- " xmsiz=%d dfunit=%d omode=%d rnd=%d\n\n",
- g_randseed, path, tnum, rcnum, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
- bool err = false;
- double stime = tctime();
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetmutex(tdb)){
- eprint(tdb, __LINE__, "tctdbsetmutex");
- err = true;
- }
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(tdb, __LINE__, "tctdbsetcodecfunc");
- err = true;
- }
- if(!tctdbsetcache(tdb, rcnum, lcnum, ncnum)){
- eprint(tdb, __LINE__, "tctdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)){
- eprint(tdb, __LINE__, "tctdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tctdbsetdfunit(tdb, dfunit)){
- eprint(tdb, __LINE__, "tctdbsetdfunit");
- err = true;
- }
- if(!tctdbopen(tdb, path, TDBOWRITER | omode)){
- eprint(tdb, __LINE__, "tctdbopen");
- err = true;
- }
- int rnum = tctdbrnum(tdb) / tnum;
- TARGREMOVE targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].tdb = tdb;
- targs[0].rnum = rnum;
- targs[0].rnd = rnd;
- targs[0].id = 0;
- if(threadremove(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].tdb = tdb;
- targs[i].rnum = rnum;
- targs[i].rnd = rnd;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){
- eprint(tdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int xmsiz, int dfunit, int omode, bool rnd) {
+ iprintf("<Removing Test>\n seed=%u path=%s tnum=%d rcnum=%d lcnum=%d ncnum=%d"
+ " xmsiz=%d dfunit=%d omode=%d rnd=%d\n\n",
+ g_randseed, path, tnum, rcnum, lcnum, ncnum, xmsiz, dfunit, omode, rnd);
+ bool err = false;
+ double stime = tctime();
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetmutex(tdb)) {
+ eprint(tdb, __LINE__, "tctdbsetmutex");
+ err = true;
+ }
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(tdb, __LINE__, "tctdbsetcodecfunc");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(tdb, __LINE__, "pthread_join");
+ if (!tctdbsetcache(tdb, rcnum, lcnum, ncnum)) {
+ eprint(tdb, __LINE__, "tctdbsetcache");
err = true;
- } else if(rv){
+ }
+ if (xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)) {
+ eprint(tdb, __LINE__, "tctdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tctdbsetdfunit(tdb, dfunit)) {
+ eprint(tdb, __LINE__, "tctdbsetdfunit");
+ err = true;
+ }
+ if (!tctdbopen(tdb, path, TDBOWRITER | omode)) {
+ eprint(tdb, __LINE__, "tctdbopen");
+ err = true;
+ }
+ int rnum = tctdbrnum(tdb) / tnum;
+ TARGREMOVE targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].tdb = tdb;
+ targs[0].rnum = rnum;
+ targs[0].rnd = rnd;
+ targs[0].id = 0;
+ if (threadremove(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].tdb = tdb;
+ targs[i].rnum = rnum;
+ targs[i].rnd = rnd;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadremove, targs + i) != 0) {
+ eprint(tdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(tdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tctdbfsiz(tdb));
+ sysprint();
+ if (!tctdbclose(tdb)) {
+ eprint(tdb, __LINE__, "tctdbclose");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
- sysprint();
- if(!tctdbclose(tdb)){
- eprint(tdb, __LINE__, "tctdbclose");
- err = true;
- }
- tctdbdel(tdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ tctdbdel(tdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform wicked command */
-static int procwicked(const char *path, int tnum, int rnum, int opts, int omode){
- iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d opts=%d omode=%d\n\n",
- g_randseed, path, tnum, rnum, opts, omode);
- bool err = false;
- double stime = tctime();
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetmutex(tdb)){
- eprint(tdb, __LINE__, "tctdbsetmutex");
- err = true;
- }
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(tdb, __LINE__, "tctdbsetcodecfunc");
- err = true;
- }
- if(!tctdbtune(tdb, rnum / 50, 2, -1, opts)){
- eprint(tdb, __LINE__, "tctdbtune");
- err = true;
- }
- if(!tctdbsetcache(tdb, rnum / 10, 128, 256)){
- eprint(tdb, __LINE__, "tctdbsetcache");
- err = true;
- }
- if(!tctdbsetxmsiz(tdb, rnum * sizeof(int))){
- eprint(tdb, __LINE__, "tctdbsetxmsiz");
- err = true;
- }
- if(!tctdbsetdfunit(tdb, 8)){
- eprint(tdb, __LINE__, "tctdbsetdfunit");
- err = true;
- }
- if(!tctdbsetinvcache(tdb, -1, 0.5)){
- eprint(tdb, __LINE__, "tctdbsetinvcache");
- err = true;
- }
- if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC | omode)){
- eprint(tdb, __LINE__, "tctdbopen");
- err = true;
- }
- if(!tctdbsetindex(tdb, "", TDBITDECIMAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "str", TDBITLEXICAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "num", TDBITDECIMAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "type", TDBITDECIMAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "flag", TDBITTOKEN)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "text", TDBITQGRAM)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbiterinit(tdb)){
- eprint(tdb, __LINE__, "tctdbiterinit");
- err = true;
- }
- TARGWICKED targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].tdb = tdb;
- targs[0].rnum = rnum;
- targs[0].id = 0;
- if(threadwicked(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].tdb = tdb;
- targs[i].rnum = rnum;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadwicked, targs + i) != 0){
- eprint(tdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+static int procwicked(const char *path, int tnum, int rnum, int opts, int omode) {
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d opts=%d omode=%d\n\n",
+ g_randseed, path, tnum, rnum, opts, omode);
+ bool err = false;
+ double stime = tctime();
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetmutex(tdb)) {
+ eprint(tdb, __LINE__, "tctdbsetmutex");
+ err = true;
+ }
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(tdb, __LINE__, "tctdbsetcodecfunc");
+ err = true;
+ }
+ if (!tctdbtune(tdb, rnum / 50, 2, -1, opts)) {
+ eprint(tdb, __LINE__, "tctdbtune");
+ err = true;
+ }
+ if (!tctdbsetcache(tdb, rnum / 10, 128, 256)) {
+ eprint(tdb, __LINE__, "tctdbsetcache");
+ err = true;
+ }
+ if (!tctdbsetxmsiz(tdb, rnum * sizeof (int))) {
+ eprint(tdb, __LINE__, "tctdbsetxmsiz");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(tdb, __LINE__, "pthread_join");
+ if (!tctdbsetdfunit(tdb, 8)) {
+ eprint(tdb, __LINE__, "tctdbsetdfunit");
err = true;
- } else if(rv){
+ }
+ if (!tctdbsetinvcache(tdb, -1, 0.5)) {
+ eprint(tdb, __LINE__, "tctdbsetinvcache");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
- sysprint();
- if(!tctdbclose(tdb)){
- eprint(tdb, __LINE__, "tctdbclose");
- err = true;
- }
- tctdbdel(tdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
+ }
+ if (!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC | omode)) {
+ eprint(tdb, __LINE__, "tctdbopen");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "", TDBITDECIMAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "str", TDBITLEXICAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "num", TDBITDECIMAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "type", TDBITDECIMAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "flag", TDBITTOKEN)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "text", TDBITQGRAM)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbiterinit(tdb)) {
+ eprint(tdb, __LINE__, "tctdbiterinit");
+ err = true;
+ }
+ TARGWICKED targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].tdb = tdb;
+ targs[0].rnum = rnum;
+ targs[0].id = 0;
+ if (threadwicked(targs) != NULL) err = true;
+ } else {
+ for (int i = 0; i < tnum; i++) {
+ targs[i].tdb = tdb;
+ targs[i].rnum = rnum;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadwicked, targs + i) != 0) {
+ eprint(tdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
+ }
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(tdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
+ }
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tctdbfsiz(tdb));
+ sysprint();
+ if (!tctdbclose(tdb)) {
+ eprint(tdb, __LINE__, "tctdbclose");
+ err = true;
+ }
+ tctdbdel(tdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
}
-
/* perform typical command */
static int proctypical(const char *path, int tnum, int rnum, int bnum, int apow, int fpow,
- int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int dfunit,
- int omode, int rratio){
- iprintf("<Typical Access Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d"
- " fpow=%d opts=%d rcnum=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d"
- " omode=%d rratio=%d\n\n",
- g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, rcnum, lcnum, ncnum,
- xmsiz, dfunit, omode, rratio);
- bool err = false;
- double stime = tctime();
- TCTDB *tdb = tctdbnew();
- if(!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
- if(!tctdbsetmutex(tdb)){
- eprint(tdb, __LINE__, "tctdbsetmutex");
- err = true;
- }
- if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
- eprint(tdb, __LINE__, "tctdbsetcodecfunc");
- err = true;
- }
- if(!tctdbtune(tdb, bnum, apow, fpow, opts)){
- eprint(tdb, __LINE__, "tctdbtune");
- err = true;
- }
- if(!tctdbsetcache(tdb, rcnum, lcnum, ncnum)){
- eprint(tdb, __LINE__, "tctdbsetcache");
- err = true;
- }
- if(xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)){
- eprint(tdb, __LINE__, "tctdbsetxmsiz");
- err = true;
- }
- if(dfunit >= 0 && !tctdbsetdfunit(tdb, dfunit)){
- eprint(tdb, __LINE__, "tctdbsetdfunit");
- err = true;
- }
- if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC | omode)){
- eprint(tdb, __LINE__, "tctdbopen");
- err = true;
- }
- if(!tctdbsetindex(tdb, "", TDBITDECIMAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "str", TDBITLEXICAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "num", TDBITDECIMAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "type", TDBITDECIMAL)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "flag", TDBITTOKEN)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- if(!tctdbsetindex(tdb, "text", TDBITQGRAM)){
- eprint(tdb, __LINE__, "tctdbsetindex");
- err = true;
- }
- TARGTYPICAL targs[tnum];
- pthread_t threads[tnum];
- if(tnum == 1){
- targs[0].tdb = tdb;
- targs[0].rnum = rnum;
- targs[0].rratio = rratio;
- targs[0].id = 0;
- if(threadtypical(targs) != NULL) err = true;
- } else {
- for(int i = 0; i < tnum; i++){
- targs[i].tdb = tdb;
- targs[i].rnum = rnum;
- targs[i].rratio= rratio;
- targs[i].id = i;
- if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){
- eprint(tdb, __LINE__, "pthread_create");
- targs[i].id = -1;
+ int opts, int rcnum, int lcnum, int ncnum, int xmsiz, int dfunit,
+ int omode, int rratio) {
+ iprintf("<Typical Access Test>\n seed=%u path=%s tnum=%d rnum=%d bnum=%d apow=%d"
+ " fpow=%d opts=%d rcnum=%d lcnum=%d ncnum=%d xmsiz=%d dfunit=%d"
+ " omode=%d rratio=%d\n\n",
+ g_randseed, path, tnum, rnum, bnum, apow, fpow, opts, rcnum, lcnum, ncnum,
+ xmsiz, dfunit, omode, rratio);
+ bool err = false;
+ double stime = tctime();
+ TCTDB *tdb = tctdbnew();
+ if (!INVALIDHANDLE(g_dbgfd)) tctdbsetdbgfd(tdb, g_dbgfd);
+ if (!tctdbsetmutex(tdb)) {
+ eprint(tdb, __LINE__, "tctdbsetmutex");
err = true;
- }
}
- for(int i = 0; i < tnum; i++){
- if(targs[i].id == -1) continue;
- void *rv;
- if(pthread_join(threads[i], &rv) != 0){
- eprint(tdb, __LINE__, "pthread_join");
+ if (!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) {
+ eprint(tdb, __LINE__, "tctdbsetcodecfunc");
err = true;
- } else if(rv){
+ }
+ if (!tctdbtune(tdb, bnum, apow, fpow, opts)) {
+ eprint(tdb, __LINE__, "tctdbtune");
err = true;
- }
- }
- }
- iprintf("record number: %" PRIuMAX "\n", (uint64_t)tctdbrnum(tdb));
- iprintf("size: %" PRIuMAX "\n", (uint64_t)tctdbfsiz(tdb));
- sysprint();
- if(!tctdbclose(tdb)){
- eprint(tdb, __LINE__, "tctdbclose");
- err = true;
- }
- tctdbdel(tdb);
- iprintf("time: %.3f\n", tctime() - stime);
- iprintf("%s\n\n", err ? "error" : "ok");
- return err ? 1 : 0;
-}
-
-
-/* thread the write function */
-static void *threadwrite(void *targ){
- TCTDB *tdb = ((TARGWRITE *)targ)->tdb;
- int rnum = ((TARGWRITE *)targ)->rnum;
- bool rnd = ((TARGWRITE *)targ)->rnd;
- int id = ((TARGWRITE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- int uid = rnd ? (base + myrand(i) + 1) : tctdbgenuid(tdb);
- char pkbuf[RECBUFSIZ];
- int pksiz = sprintf(pkbuf, "%d", uid);
- TCMAP *cols = tcmapnew2(7);
- char vbuf[RECBUFSIZ*5];
- int vsiz = sprintf(vbuf, "%d", uid);
- tcmapput(cols, "str", 3, vbuf, vsiz);
- if(myrand(3) == 0){
- vsiz = sprintf(vbuf, "%.2f", (myrand(i * 100) + 1) / 100.0);
- } else {
- vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
- }
- tcmapput(cols, "num", 3, vbuf, vsiz);
- vsiz = sprintf(vbuf, "%d", myrand(32) + 1);
- tcmapput(cols, "type", 4, vbuf, vsiz);
- int num = myrand(5);
- int pt = 0;
- char *wp = vbuf;
- for(int j = 0; j < num; j++){
- pt += myrand(5) + 1;
- if(wp > vbuf) *(wp++) = ',';
- wp += sprintf(wp, "%d", pt);
- }
- *wp = '\0';
- if(*vbuf != '\0'){
- tcmapput(cols, "flag", 4, vbuf, wp - vbuf);
- tcmapput(cols, "text", 4, vbuf, wp - vbuf);
- }
- if(!tctdbput(tdb, pkbuf, pksiz, cols)){
- eprint(tdb, __LINE__, "tctdbput");
- err = true;
- break;
- }
- tcmapdel(cols);
- 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;
-}
-
-
-/* thread the read function */
-static void *threadread(void *targ){
- TCTDB *tdb = ((TARGREAD *)targ)->tdb;
- int rnum = ((TARGREAD *)targ)->rnum;
- bool rnd = ((TARGREAD *)targ)->rnd;
- int id = ((TARGREAD *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum && !err; i++){
- char pkbuf[RECBUFSIZ];
- int pksiz = sprintf(pkbuf, "%d", base + (rnd ? myrandnd(i) : i));
- TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
- if(cols){
- tcmapdel(cols);
- } else if(!rnd || tctdbecode(tdb) != TCENOREC){
- eprint(tdb, __LINE__, "tctdbget");
- err = true;
- }
- 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;
-}
-
-
-/* thread the remove function */
-static void *threadremove(void *targ){
- TCTDB *tdb = ((TARGREMOVE *)targ)->tdb;
- int rnum = ((TARGREMOVE *)targ)->rnum;
- bool rnd = ((TARGREMOVE *)targ)->rnd;
- int id = ((TARGREMOVE *)targ)->id;
- bool err = false;
- int base = id * rnum;
- for(int i = 1; i <= rnum; i++){
- char pkbuf[RECBUFSIZ];
- int pksiz = sprintf(pkbuf, "%d", base + (rnd ? myrand(i + 1) : i));
- if(!tctdbout(tdb, pkbuf, pksiz) && (!rnd || tctdbecode(tdb) != TCENOREC)){
- eprint(tdb, __LINE__, "tctdbout");
- err = true;
- break;
- }
- 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;
-}
-
-
-/* thread the wicked function */
-static void *threadwicked(void *targ){
- TCTDB *tdb = ((TARGWICKED *)targ)->tdb;
- int rnum = ((TARGWICKED *)targ)->rnum;
- int id = ((TARGWICKED *)targ)->id;
- bool err = false;
- const char *names[] = { "", "str", "num", "type", "flag", "c1" };
- int ops[] = { TDBQCSTREQ, TDBQCSTRINC, TDBQCSTRBW, TDBQCSTREW, TDBQCSTRAND, TDBQCSTROR,
- TDBQCSTROREQ, TDBQCSTRRX, TDBQCNUMEQ, TDBQCNUMGT, TDBQCNUMGE, TDBQCNUMLT,
- TDBQCNUMLE, TDBQCNUMBT, TDBQCNUMOREQ };
- int ftsops[] = { TDBQCFTSPH, TDBQCFTSAND, TDBQCFTSOR, TDBQCFTSEX };
- int types[] = { TDBQOSTRASC, TDBQOSTRDESC, TDBQONUMASC, TDBQONUMDESC };
- for(int i = 1; i <= rnum && !err; i++){
- char pkbuf[RECBUFSIZ];
- int pksiz = sprintf(pkbuf, "%d", myrand(rnum * (id + 1)));
- TCMAP *cols = tcmapnew2(7);
- char vbuf[RECBUFSIZ*5];
- int vsiz = sprintf(vbuf, "%d", id);
- tcmapput(cols, "str", 3, vbuf, vsiz);
- if(myrand(3) == 0){
- vsiz = sprintf(vbuf, "%.2f", (myrand(i * 100) + 1) / 100.0);
+ }
+ if (!tctdbsetcache(tdb, rcnum, lcnum, ncnum)) {
+ eprint(tdb, __LINE__, "tctdbsetcache");
+ err = true;
+ }
+ if (xmsiz >= 0 && !tctdbsetxmsiz(tdb, xmsiz)) {
+ eprint(tdb, __LINE__, "tctdbsetxmsiz");
+ err = true;
+ }
+ if (dfunit >= 0 && !tctdbsetdfunit(tdb, dfunit)) {
+ eprint(tdb, __LINE__, "tctdbsetdfunit");
+ err = true;
+ }
+ if (!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC | omode)) {
+ eprint(tdb, __LINE__, "tctdbopen");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "", TDBITDECIMAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "str", TDBITLEXICAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "num", TDBITDECIMAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "type", TDBITDECIMAL)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "flag", TDBITTOKEN)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ if (!tctdbsetindex(tdb, "text", TDBITQGRAM)) {
+ eprint(tdb, __LINE__, "tctdbsetindex");
+ err = true;
+ }
+ TARGTYPICAL targs[tnum];
+ pthread_t threads[tnum];
+ if (tnum == 1) {
+ targs[0].tdb = tdb;
+ targs[0].rnum = rnum;
+ targs[0].rratio = rratio;
+ targs[0].id = 0;
+ if (threadtypical(targs) != NULL) err = true;
} else {
- vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
- }
- tcmapput(cols, "num", 3, vbuf, vsiz);
- vsiz = sprintf(vbuf, "%d", myrand(32) + 1);
- tcmapput(cols, "type", 4, vbuf, vsiz);
- int num = myrand(5);
- int pt = 0;
- char *wp = vbuf;
- for(int j = 0; j < num; j++){
- pt += myrand(5) + 1;
- if(wp > vbuf) *(wp++) = ',';
- wp += sprintf(wp, "%d", pt);
- }
- *wp = '\0';
- if(*vbuf != '\0'){
- tcmapput(cols, "flag", 4, vbuf, wp - vbuf);
- tcmapput(cols, "text", 4, vbuf, wp - vbuf);
- }
- char nbuf[RECBUFSIZ];
- int nsiz = sprintf(nbuf, "c%d", myrand(i) + 1);
- vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
- tcmapput(cols, nbuf, nsiz, vbuf, vsiz);
- char *cbuf;
- int csiz;
- TCMAP *ncols;
- TDBQRY *qry;
- switch(myrand(17)){
- case 0:
- if(id == 0) iputchar('0');
- if(!tctdbput(tdb, pkbuf, pksiz, cols)){
- eprint(tdb, __LINE__, "tctdbput");
- err = true;
+ for (int i = 0; i < tnum; i++) {
+ targs[i].tdb = tdb;
+ targs[i].rnum = rnum;
+ targs[i].rratio = rratio;
+ targs[i].id = i;
+ if (pthread_create(threads + i, NULL, threadtypical, targs + i) != 0) {
+ eprint(tdb, __LINE__, "pthread_create");
+ targs[i].id = -1;
+ err = true;
+ }
}
- break;
- case 1:
- if(id == 0) iputchar('1');
- cbuf = tcstrjoin4(cols, &csiz);
- if(!tctdbput2(tdb, pkbuf, pksiz, cbuf, csiz)){
- eprint(tdb, __LINE__, "tctdbput2");
- err = true;
+ for (int i = 0; i < tnum; i++) {
+ if (targs[i].id == -1) continue;
+ void *rv;
+ if (pthread_join(threads[i], &rv) != 0) {
+ eprint(tdb, __LINE__, "pthread_join");
+ err = true;
+ } else if (rv) {
+ err = true;
+ }
}
- tcfree(cbuf);
- break;
- case 2:
- if(id == 0) iputchar('2');
- cbuf = tcstrjoin3(cols, '\t');
- if(!tctdbput3(tdb, pkbuf, cbuf)){
- eprint(tdb, __LINE__, "tctdbput3");
- err = true;
+ }
+ iprintf("record number: %" PRIuMAX "\n", (uint64_t) tctdbrnum(tdb));
+ iprintf("size: %" PRIuMAX "\n", (uint64_t) tctdbfsiz(tdb));
+ sysprint();
+ if (!tctdbclose(tdb)) {
+ eprint(tdb, __LINE__, "tctdbclose");
+ err = true;
+ }
+ tctdbdel(tdb);
+ iprintf("time: %.3f\n", tctime() - stime);
+ iprintf("%s\n\n", err ? "error" : "ok");
+ return err ? 1 : 0;
+}
+
+/* thread the write function */
+static void *threadwrite(void *targ) {
+ TCTDB *tdb = ((TARGWRITE *) targ)->tdb;
+ int rnum = ((TARGWRITE *) targ)->rnum;
+ bool rnd = ((TARGWRITE *) targ)->rnd;
+ int id = ((TARGWRITE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ int uid = rnd ? (base + myrand(i) + 1) : tctdbgenuid(tdb);
+ char pkbuf[RECBUFSIZ];
+ int pksiz = sprintf(pkbuf, "%d", uid);
+ TCMAP *cols = tcmapnew2(7);
+ char vbuf[RECBUFSIZ * 5];
+ int vsiz = sprintf(vbuf, "%d", uid);
+ tcmapput(cols, "str", 3, vbuf, vsiz);
+ if (myrand(3) == 0) {
+ vsiz = sprintf(vbuf, "%.2f", (myrand(i * 100) + 1) / 100.0);
+ } else {
+ vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
}
- tcfree(cbuf);
- break;
- case 3:
- if(id == 0) iputchar('3');
- if(!tctdbputkeep(tdb, pkbuf, pksiz, cols) && tctdbecode(tdb) != TCEKEEP){
- eprint(tdb, __LINE__, "tctdbputkeep");
- err = true;
+ tcmapput(cols, "num", 3, vbuf, vsiz);
+ vsiz = sprintf(vbuf, "%d", myrand(32) + 1);
+ tcmapput(cols, "type", 4, vbuf, vsiz);
+ int num = myrand(5);
+ int pt = 0;
+ char *wp = vbuf;
+ for (int j = 0; j < num; j++) {
+ pt += myrand(5) + 1;
+ if (wp > vbuf) *(wp++) = ',';
+ wp += sprintf(wp, "%d", pt);
}
- break;
- case 4:
- if(id == 0) iputchar('4');
- cbuf = tcstrjoin4(cols, &csiz);
- if(!tctdbputkeep2(tdb, pkbuf, pksiz, cbuf, csiz) && tctdbecode(tdb) != TCEKEEP){
- eprint(tdb, __LINE__, "tctdbputkeep2");
- err = true;
+ *wp = '\0';
+ if (*vbuf != '\0') {
+ tcmapput(cols, "flag", 4, vbuf, wp - vbuf);
+ tcmapput(cols, "text", 4, vbuf, wp - vbuf);
}
- tcfree(cbuf);
- break;
- case 5:
- if(id == 0) iputchar('5');
- cbuf = tcstrjoin3(cols, '\t');
- if(!tctdbputkeep3(tdb, pkbuf, cbuf) && tctdbecode(tdb) != TCEKEEP){
- eprint(tdb, __LINE__, "tctdbputkeep3");
- err = true;
+ if (!tctdbput(tdb, pkbuf, pksiz, cols)) {
+ eprint(tdb, __LINE__, "tctdbput");
+ err = true;
+ break;
}
- tcfree(cbuf);
- break;
- case 6:
- if(id == 0) iputchar('6');
- if(!tctdbputcat(tdb, pkbuf, pksiz, cols)){
- eprint(tdb, __LINE__, "tctdbputcat");
- err = true;
+ tcmapdel(cols);
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- break;
- case 7:
- if(id == 0) iputchar('7');
- cbuf = tcstrjoin4(cols, &csiz);
- if(!tctdbputcat2(tdb, pkbuf, pksiz, cbuf, csiz)){
- eprint(tdb, __LINE__, "tctdbputcat2");
- err = true;
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the read function */
+static void *threadread(void *targ) {
+ TCTDB *tdb = ((TARGREAD *) targ)->tdb;
+ int rnum = ((TARGREAD *) targ)->rnum;
+ bool rnd = ((TARGREAD *) targ)->rnd;
+ int id = ((TARGREAD *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum && !err; i++) {
+ char pkbuf[RECBUFSIZ];
+ int pksiz = sprintf(pkbuf, "%d", base + (rnd ? myrandnd(i) : i));
+ TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
+ if (cols) {
+ tcmapdel(cols);
+ } else if (!rnd || tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbget");
+ err = true;
}
- tcfree(cbuf);
- break;
- case 8:
- if(id == 0) iputchar('8');
- cbuf = tcstrjoin3(cols, '\t');
- if(!tctdbputcat3(tdb, pkbuf, cbuf)){
- eprint(tdb, __LINE__, "tctdbputcat3");
- err = true;
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- tcfree(cbuf);
- break;
- case 9:
- if(id == 0) iputchar('9');
- if(myrand(2) == 0){
- if(!tctdbout(tdb, pkbuf, pksiz) && tctdbecode(tdb) != TCENOREC){
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the remove function */
+static void *threadremove(void *targ) {
+ TCTDB *tdb = ((TARGREMOVE *) targ)->tdb;
+ int rnum = ((TARGREMOVE *) targ)->rnum;
+ bool rnd = ((TARGREMOVE *) targ)->rnd;
+ int id = ((TARGREMOVE *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ for (int i = 1; i <= rnum; i++) {
+ char pkbuf[RECBUFSIZ];
+ int pksiz = sprintf(pkbuf, "%d", base + (rnd ? myrand(i + 1) : i));
+ if (!tctdbout(tdb, pkbuf, pksiz) && (!rnd || tctdbecode(tdb) != TCENOREC)) {
eprint(tdb, __LINE__, "tctdbout");
err = true;
- }
- }
- break;
- case 10:
- if(id == 0) iputchar('A');
- if(myrand(2) == 0){
- if(!tctdbout2(tdb, pkbuf) && tctdbecode(tdb) != TCENOREC){
- eprint(tdb, __LINE__, "tctdbout2");
- err = true;
- }
- }
- break;
- case 11:
- if(id == 0) iputchar('B');
- ncols = tctdbget(tdb, pkbuf, pksiz);
- if(ncols){
- tcmapdel(ncols);
- } else if(tctdbecode(tdb) != TCENOREC){
- eprint(tdb, __LINE__, "tctdbget");
- err = true;
+ break;
}
- break;
- case 12:
- if(id == 0) iputchar('C');
- cbuf = tctdbget2(tdb, pkbuf, pksiz, &csiz);
- if(cbuf){
- tcfree(cbuf);
- } else if(tctdbecode(tdb) != TCENOREC){
- eprint(tdb, __LINE__, "tctdbget2");
- err = true;
+ if (id == 0 && rnum > 250 && i % (rnum / 250) == 0) {
+ iputchar('.');
+ if (i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
}
- break;
- case 13:
- if(id == 0) iputchar('D');
- cbuf = tctdbget3(tdb, pkbuf);
- if(cbuf){
- tcfree(cbuf);
- } else if(tctdbecode(tdb) != TCENOREC){
- eprint(tdb, __LINE__, "tctdbget3");
- err = true;
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the wicked function */
+static void *threadwicked(void *targ) {
+ TCTDB *tdb = ((TARGWICKED *) targ)->tdb;
+ int rnum = ((TARGWICKED *) targ)->rnum;
+ int id = ((TARGWICKED *) targ)->id;
+ bool err = false;
+ const char *names[] = {"", "str", "num", "type", "flag", "c1"};
+ int ops[] = {TDBQCSTREQ, TDBQCSTRINC, TDBQCSTRBW, TDBQCSTREW, TDBQCSTRAND, TDBQCSTROR,
+ TDBQCSTROREQ, TDBQCSTRRX, TDBQCNUMEQ, TDBQCNUMGT, TDBQCNUMGE, TDBQCNUMLT,
+ TDBQCNUMLE, TDBQCNUMBT, TDBQCNUMOREQ};
+ int ftsops[] = {TDBQCFTSPH, TDBQCFTSAND, TDBQCFTSOR, TDBQCFTSEX};
+ int types[] = {TDBQOSTRASC, TDBQOSTRDESC, TDBQONUMASC, TDBQONUMDESC};
+ for (int i = 1; i <= rnum && !err; i++) {
+ char pkbuf[RECBUFSIZ];
+ int pksiz = sprintf(pkbuf, "%d", myrand(rnum * (id + 1)));
+ TCMAP *cols = tcmapnew2(7);
+ char vbuf[RECBUFSIZ * 5];
+ int vsiz = sprintf(vbuf, "%d", id);
+ tcmapput(cols, "str", 3, vbuf, vsiz);
+ if (myrand(3) == 0) {
+ vsiz = sprintf(vbuf, "%.2f", (myrand(i * 100) + 1) / 100.0);
+ } else {
+ vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
}
- break;
- case 14:
- if(id == 0) iputchar('E');
- if(myrand(rnum / 50) == 0){
- if(!tctdbiterinit(tdb)){
- eprint(tdb, __LINE__, "tctdbiterinit");
- err = true;
- }
+ tcmapput(cols, "num", 3, vbuf, vsiz);
+ vsiz = sprintf(vbuf, "%d", myrand(32) + 1);
+ tcmapput(cols, "type", 4, vbuf, vsiz);
+ int num = myrand(5);
+ int pt = 0;
+ char *wp = vbuf;
+ for (int j = 0; j < num; j++) {
+ pt += myrand(5) + 1;
+ if (wp > vbuf) *(wp++) = ',';
+ wp += sprintf(wp, "%d", pt);
}
- for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
- int iksiz;
- char *ikbuf = tctdbiternext(tdb, &iksiz);
- if(ikbuf){
- tcfree(ikbuf);
- } else {
- int ecode = tctdbecode(tdb);
- if(ecode != TCEINVALID && ecode != TCENOREC){
- eprint(tdb, __LINE__, "tctdbiternext");
- err = true;
- }
- }
+ *wp = '\0';
+ if (*vbuf != '\0') {
+ tcmapput(cols, "flag", 4, vbuf, wp - vbuf);
+ tcmapput(cols, "text", 4, vbuf, wp - vbuf);
}
- break;
- case 15:
- if(id == 0) iputchar('F');
- qry = tctdbqrynew(tdb);
- if(myrand(10) != 0){
- char expr[RECBUFSIZ];
- sprintf(expr, "%d", myrand(i) + 1);
- switch(myrand(6)){
- default:
- tctdbqryaddcond(qry, "str", TDBQCSTREQ, expr);
- break;
+ char nbuf[RECBUFSIZ];
+ int nsiz = sprintf(nbuf, "c%d", myrand(i) + 1);
+ vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
+ tcmapput(cols, nbuf, nsiz, vbuf, vsiz);
+ char *cbuf;
+ int csiz;
+ TCMAP *ncols;
+ TDBQRY *qry;
+ switch (myrand(17)) {
+ case 0:
+ if (id == 0) iputchar('0');
+ if (!tctdbput(tdb, pkbuf, pksiz, cols)) {
+ eprint(tdb, __LINE__, "tctdbput");
+ err = true;
+ }
+ break;
case 1:
- tctdbqryaddcond(qry, "str", TDBQCSTRBW, expr);
- break;
+ if (id == 0) iputchar('1');
+ cbuf = tcstrjoin4(cols, &csiz);
+ if (!tctdbput2(tdb, pkbuf, pksiz, cbuf, csiz)) {
+ eprint(tdb, __LINE__, "tctdbput2");
+ err = true;
+ }
+ tcfree(cbuf);
+ break;
case 2:
- tctdbqryaddcond(qry, "str", TDBQCSTROREQ, expr);
- break;
+ if (id == 0) iputchar('2');
+ cbuf = tcstrjoin3(cols, '\t');
+ if (!tctdbput3(tdb, pkbuf, cbuf)) {
+ eprint(tdb, __LINE__, "tctdbput3");
+ err = true;
+ }
+ tcfree(cbuf);
+ break;
case 3:
- tctdbqryaddcond(qry, "num", TDBQCNUMEQ, expr);
- break;
+ if (id == 0) iputchar('3');
+ if (!tctdbputkeep(tdb, pkbuf, pksiz, cols) && tctdbecode(tdb) != TCEKEEP) {
+ eprint(tdb, __LINE__, "tctdbputkeep");
+ err = true;
+ }
+ break;
case 4:
- tctdbqryaddcond(qry, "num", TDBQCNUMGT, expr);
- break;
+ if (id == 0) iputchar('4');
+ cbuf = tcstrjoin4(cols, &csiz);
+ if (!tctdbputkeep2(tdb, pkbuf, pksiz, cbuf, csiz) && tctdbecode(tdb) != TCEKEEP) {
+ eprint(tdb, __LINE__, "tctdbputkeep2");
+ err = true;
+ }
+ tcfree(cbuf);
+ break;
case 5:
- tctdbqryaddcond(qry, "num", TDBQCNUMLT, expr);
- break;
- }
- switch(myrand(5)){
- case 0:
- tctdbqrysetorder(qry, "str", TDBQOSTRASC);
- break;
- case 1:
- tctdbqrysetorder(qry, "str", TDBQOSTRDESC);
- break;
- case 2:
- tctdbqrysetorder(qry, "num", TDBQONUMASC);
- break;
- case 3:
- tctdbqrysetorder(qry, "num", TDBQONUMDESC);
- break;
- }
- tctdbqrysetlimit(qry, 10, myrand(10));
- } else {
- int cnum = myrand(4);
- if(cnum < 1 && myrand(5) != 0) cnum = 1;
- for(int j = 0; j < cnum; j++){
- const char *name = names[myrand(sizeof(names) / sizeof(*names))];
- int op = ops[myrand(sizeof(ops) / sizeof(*ops))];
- if(myrand(10) == 0) op = ftsops[myrand(sizeof(ftsops) / sizeof(*ftsops))];
- if(myrand(20) == 0) op |= TDBQCNEGATE;
- if(myrand(20) == 0) op |= TDBQCNOIDX;
- char expr[RECBUFSIZ*3];
- char *wp = expr;
- if(myrand(3) == 0){
- wp += sprintf(expr, "%f", myrand(i * 100) / 100.0);
- } else {
- wp += sprintf(expr, "%d", myrand(i));
- }
- if(myrand(10) == 0) wp += sprintf(wp, ",%d", myrand(i));
- if(myrand(10) == 0) wp += sprintf(wp, ",%d", myrand(i));
- tctdbqryaddcond(qry, name, op, expr);
- }
- if(myrand(3) != 0){
- const char *name = names[myrand(sizeof(names) / sizeof(*names))];
- int type = types[myrand(sizeof(types) / sizeof(*types))];
- tctdbqrysetorder(qry, name, type);
- }
- if(myrand(3) != 0) tctdbqrysetlimit(qry, myrand(i), myrand(10));
+ if (id == 0) iputchar('5');
+ cbuf = tcstrjoin3(cols, '\t');
+ if (!tctdbputkeep3(tdb, pkbuf, cbuf) && tctdbecode(tdb) != TCEKEEP) {
+ eprint(tdb, __LINE__, "tctdbputkeep3");
+ err = true;
+ }
+ tcfree(cbuf);
+ break;
+ case 6:
+ if (id == 0) iputchar('6');
+ if (!tctdbputcat(tdb, pkbuf, pksiz, cols)) {
+ eprint(tdb, __LINE__, "tctdbputcat");
+ err = true;
+ }
+ break;
+ case 7:
+ if (id == 0) iputchar('7');
+ cbuf = tcstrjoin4(cols, &csiz);
+ if (!tctdbputcat2(tdb, pkbuf, pksiz, cbuf, csiz)) {
+ eprint(tdb, __LINE__, "tctdbputcat2");
+ err = true;
+ }
+ tcfree(cbuf);
+ break;
+ case 8:
+ if (id == 0) iputchar('8');
+ cbuf = tcstrjoin3(cols, '\t');
+ if (!tctdbputcat3(tdb, pkbuf, cbuf)) {
+ eprint(tdb, __LINE__, "tctdbputcat3");
+ err = true;
+ }
+ tcfree(cbuf);
+ break;
+ case 9:
+ if (id == 0) iputchar('9');
+ if (myrand(2) == 0) {
+ if (!tctdbout(tdb, pkbuf, pksiz) && tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbout");
+ err = true;
+ }
+ }
+ break;
+ case 10:
+ if (id == 0) iputchar('A');
+ if (myrand(2) == 0) {
+ if (!tctdbout2(tdb, pkbuf) && tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbout2");
+ err = true;
+ }
+ }
+ break;
+ case 11:
+ if (id == 0) iputchar('B');
+ ncols = tctdbget(tdb, pkbuf, pksiz);
+ if (ncols) {
+ tcmapdel(ncols);
+ } else if (tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbget");
+ err = true;
+ }
+ break;
+ case 12:
+ if (id == 0) iputchar('C');
+ cbuf = tctdbget2(tdb, pkbuf, pksiz, &csiz);
+ if (cbuf) {
+ tcfree(cbuf);
+ } else if (tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbget2");
+ err = true;
+ }
+ break;
+ case 13:
+ if (id == 0) iputchar('D');
+ cbuf = tctdbget3(tdb, pkbuf);
+ if (cbuf) {
+ tcfree(cbuf);
+ } else if (tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbget3");
+ err = true;
+ }
+ break;
+ case 14:
+ if (id == 0) iputchar('E');
+ if (myrand(rnum / 50) == 0) {
+ if (!tctdbiterinit(tdb)) {
+ eprint(tdb, __LINE__, "tctdbiterinit");
+ err = true;
+ }
+ }
+ for (int j = myrand(rnum) / 1000 + 1; j >= 0; j--) {
+ int iksiz;
+ char *ikbuf = tctdbiternext(tdb, &iksiz);
+ if (ikbuf) {
+ tcfree(ikbuf);
+ } else {
+ int ecode = tctdbecode(tdb);
+ if (ecode != TCEINVALID && ecode != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbiternext");
+ err = true;
+ }
+ }
+ }
+ break;
+ case 15:
+ if (id == 0) iputchar('F');
+ qry = tctdbqrynew(tdb);
+ if (myrand(10) != 0) {
+ char expr[RECBUFSIZ];
+ sprintf(expr, "%d", myrand(i) + 1);
+ switch (myrand(6)) {
+ default:
+ tctdbqryaddcond(qry, "str", TDBQCSTREQ, expr);
+ break;
+ case 1:
+ tctdbqryaddcond(qry, "str", TDBQCSTRBW, expr);
+ break;
+ case 2:
+ tctdbqryaddcond(qry, "str", TDBQCSTROREQ, expr);
+ break;
+ case 3:
+ tctdbqryaddcond(qry, "num", TDBQCNUMEQ, expr);
+ break;
+ case 4:
+ tctdbqryaddcond(qry, "num", TDBQCNUMGT, expr);
+ break;
+ case 5:
+ tctdbqryaddcond(qry, "num", TDBQCNUMLT, expr);
+ break;
+ }
+ switch (myrand(5)) {
+ case 0:
+ tctdbqrysetorder(qry, "str", TDBQOSTRASC);
+ break;
+ case 1:
+ tctdbqrysetorder(qry, "str", TDBQOSTRDESC);
+ break;
+ case 2:
+ tctdbqrysetorder(qry, "num", TDBQONUMASC);
+ break;
+ case 3:
+ tctdbqrysetorder(qry, "num", TDBQONUMDESC);
+ break;
+ }
+ tctdbqrysetlimit(qry, 10, myrand(10));
+ } else {
+ int cnum = myrand(4);
+ if (cnum < 1 && myrand(5) != 0) cnum = 1;
+ for (int j = 0; j < cnum; j++) {
+ const char *name = names[myrand(sizeof (names) / sizeof (*names))];
+ int op = ops[myrand(sizeof (ops) / sizeof (*ops))];
+ if (myrand(10) == 0) op = ftsops[myrand(sizeof (ftsops) / sizeof (*ftsops))];
+ if (myrand(20) == 0) op |= TDBQCNEGATE;
+ if (myrand(20) == 0) op |= TDBQCNOIDX;
+ char expr[RECBUFSIZ * 3];
+ char *wp = expr;
+ if (myrand(3) == 0) {
+ wp += sprintf(expr, "%f", myrand(i * 100) / 100.0);
+ } else {
+ wp += sprintf(expr, "%d", myrand(i));
+ }
+ if (myrand(10) == 0) wp += sprintf(wp, ",%d", myrand(i));
+ if (myrand(10) == 0) wp += sprintf(wp, ",%d", myrand(i));
+ tctdbqryaddcond(qry, name, op, expr);
+ }
+ if (myrand(3) != 0) {
+ const char *name = names[myrand(sizeof (names) / sizeof (*names))];
+ int type = types[myrand(sizeof (types) / sizeof (*types))];
+ tctdbqrysetorder(qry, name, type);
+ }
+ if (myrand(3) != 0) tctdbqrysetlimit(qry, myrand(i), myrand(10));
+ }
+ if (myrand(10) == 0) {
+ TCLIST *res = tctdbqrysearch(qry);
+ tclistdel(res);
+ }
+ tctdbqrydel(qry);
+ break;
+ default:
+ if (id == 0) iputchar('@');
+ if (tctdbtranbegin(tdb)) {
+ if (myrand(2) == 0) {
+ if (!tctdbput(tdb, pkbuf, pksiz, cols)) {
+ eprint(tdb, __LINE__, "tctdbput");
+ err = true;
+ }
+ } else {
+ if (!tctdbout(tdb, pkbuf, pksiz) && tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbout");
+ err = true;
+ }
+ }
+ if (myrand(2) == 0) {
+ if (!tctdbtranabort(tdb)) {
+ eprint(tdb, __LINE__, "tctdbtranabort");
+ err = true;
+ }
+ } else {
+ if (!tctdbtrancommit(tdb)) {
+ eprint(tdb, __LINE__, "tctdbtrancommit");
+ err = true;
+ }
+ }
+ } else {
+ eprint(tdb, __LINE__, "tctdbtranbegin");
+ err = true;
+ }
+ if (myrand(10000) == 0) srand((unsigned int) (tctime() * 1000) % UINT_MAX);
+ break;
}
- if(myrand(10) == 0){
- TCLIST *res = tctdbqrysearch(qry);
- tclistdel(res);
+ tcmapdel(cols);
+ if (id == 0) {
+ if (i % 50 == 0) iprintf(" (%08d)\n", i);
+ if (id == 0 && i == rnum / 4) {
+ if (!tctdboptimize(tdb, rnum / 50, -1, -1, -1) && tctdbecode(tdb) != TCEINVALID) {
+ eprint(tdb, __LINE__, "tctdboptimize");
+ err = true;
+ }
+ if (!tctdbiterinit(tdb)) {
+ eprint(tdb, __LINE__, "tctdbiterinit");
+ err = true;
+ }
+ }
}
- tctdbqrydel(qry);
- break;
- default:
- if(id == 0) iputchar('@');
- if(tctdbtranbegin(tdb)){
- if(myrand(2) == 0){
- if(!tctdbput(tdb, pkbuf, pksiz, cols)){
- eprint(tdb, __LINE__, "tctdbput");
- err = true;
+ }
+ return err ? "error" : NULL;
+}
+
+/* thread the typical function */
+static void *threadtypical(void *targ) {
+ TCTDB *tdb = ((TARGTYPICAL *) targ)->tdb;
+ int rnum = ((TARGTYPICAL *) targ)->rnum;
+ int rratio = ((TARGTYPICAL *) targ)->rratio;
+ int id = ((TARGTYPICAL *) targ)->id;
+ bool err = false;
+ int base = id * rnum;
+ int mrange = tclmax(50 + rratio, 100);
+ for (int i = 1; !err && i <= rnum; i++) {
+ char pkbuf[RECBUFSIZ];
+ int pksiz = sprintf(pkbuf, "%08d", base + myrandnd(i));
+ int rnd = myrand(mrange);
+ if (rnd < 20) {
+ TCMAP *cols = tcmapnew2(7);
+ char vbuf[RECBUFSIZ * 5];
+ int vsiz = sprintf(vbuf, "%d", id);
+ tcmapput(cols, "str", 3, vbuf, vsiz);
+ if (myrand(3) == 0) {
+ vsiz = sprintf(vbuf, "%.2f", (myrand(i * 100) + 1) / 100.0);
+ } else {
+ vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
+ }
+ tcmapput(cols, "num", 3, vbuf, vsiz);
+ vsiz = sprintf(vbuf, "%d", myrand(32) + 1);
+ tcmapput(cols, "type", 4, vbuf, vsiz);
+ int num = myrand(5);
+ int pt = 0;
+ char *wp = vbuf;
+ for (int j = 0; j < num; j++) {
+ pt += myrand(5) + 1;
+ if (wp > vbuf) *(wp++) = ',';
+ wp += sprintf(wp, "%d", pt);
+ }
+ *wp = '\0';
+ if (*vbuf != '\0') {
+ tcmapput(cols, "flag", 4, vbuf, wp - vbuf);
+ tcmapput(cols, "text", 4, vbuf, wp - vbuf);
}
- } else {
- if(!tctdbout(tdb, pkbuf, pksiz) && tctdbecode(tdb) != TCENOREC){
- eprint(tdb, __LINE__, "tctdbout");
- err = true;
+ char nbuf[RECBUFSIZ];
+ int nsiz = sprintf(nbuf, "c%d", myrand(i) + 1);
+ vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
+ tcmapput(cols, nbuf, nsiz, vbuf, vsiz);
+ if (myrand(2) == 0) {
+ if (!tctdbput(tdb, pkbuf, pksiz, cols)) {
+ eprint(tdb, __LINE__, "tctdbput");
+ err = true;
+ }
+ } else {
+ if (!tctdbput(tdb, pkbuf, pksiz, cols) && tctdbecode(tdb) && tctdbecode(tdb) != TCEKEEP) {
+ eprint(tdb, __LINE__, "tctdbput");
+ err = true;
+ }
+ }
+ tcmapdel(cols);
+ } else if (rnd < 30) {
+ if (!tctdbout(tdb, pkbuf, pksiz) && tctdbecode(tdb) && tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbout");
+ err = true;
}
- }
- if(myrand(2) == 0){
- if(!tctdbtranabort(tdb)){
- eprint(tdb, __LINE__, "tctdbtranabort");
- err = true;
+ } else if (rnd < 31) {
+ if (myrand(10) == 0 && !tctdbiterinit(tdb) && tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbiterinit");
+ err = true;
}
- } else {
- if(!tctdbtrancommit(tdb)){
- eprint(tdb, __LINE__, "tctdbtrancommit");
- err = true;
+ for (int j = 0; !err && j < 10; j++) {
+ int ksiz;
+ char *kbuf = tctdbiternext(tdb, &ksiz);
+ if (kbuf) {
+ tcfree(kbuf);
+ } else if (tctdbecode(tdb) != TCEINVALID && tctdbecode(tdb) != TCENOREC) {
+ eprint(tdb, __LINE__, "tctdbiternext");
+ err = true;
+ }
}
- }
} else {
- eprint(tdb, __LINE__, "tctdbtranbegin");
- err = true;
- }
- if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
- break;
- }
- tcmapdel(cols);
- if(id == 0){
- if(i % 50 == 0) iprintf(" (%08d)\n", i);
- if(id == 0 && i == rnum / 4){
- if(!tctdboptimize(tdb, rnum / 50, -1, -1, -1) && tctdbecode(tdb) != TCEINVALID){
- eprint(tdb, __LINE__, "tctdboptimize");
- err = true;
+ TDBQRY *qry = tctdbqrynew(tdb);
+ char expr[RECBUFSIZ];
+ sprintf(expr, "%d", myrand(i) + 1);
+ switch (myrand(6) * 1) {
+ default:
+ tctdbqryaddcond(qry, "str", TDBQCSTREQ, expr);
+ break;
+ case 1:
+ tctdbqryaddcond(qry, "str", TDBQCSTRBW, expr);
+ break;
+ case 2:
+ tctdbqryaddcond(qry, "str", TDBQCSTROREQ, expr);
+ break;
+ case 3:
+ tctdbqryaddcond(qry, "num", TDBQCNUMEQ, expr);
+ break;
+ case 4:
+ tctdbqryaddcond(qry, "num", TDBQCNUMGT, expr);
+ break;
+ case 5:
+ tctdbqryaddcond(qry, "num", TDBQCNUMLT, expr);
+ break;
+ }
+ tctdbqrysetlimit(qry, 10, myrand(5) * 10);
+ TCLIST *res = tctdbqrysearch(qry);
+ tclistdel(res);
+ tctdbqrydel(qry);
}
- if(!tctdbiterinit(tdb)){
- eprint(tdb, __LINE__, "tctdbiterinit");
- err = true;
+ 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;
-}
-
-
-/* thread the typical function */
-static void *threadtypical(void *targ){
- TCTDB *tdb = ((TARGTYPICAL *)targ)->tdb;
- int rnum = ((TARGTYPICAL *)targ)->rnum;
- int rratio = ((TARGTYPICAL *)targ)->rratio;
- int id = ((TARGTYPICAL *)targ)->id;
- bool err = false;
- int base = id * rnum;
- int mrange = tclmax(50 + rratio, 100);
- for(int i = 1; !err && i <= rnum; i++){
- char pkbuf[RECBUFSIZ];
- int pksiz = sprintf(pkbuf, "%08d", base + myrandnd(i));
- int rnd = myrand(mrange);
- if(rnd < 20){
- TCMAP *cols = tcmapnew2(7);
- char vbuf[RECBUFSIZ*5];
- int vsiz = sprintf(vbuf, "%d", id);
- tcmapput(cols, "str", 3, vbuf, vsiz);
- if(myrand(3) == 0){
- vsiz = sprintf(vbuf, "%.2f", (myrand(i * 100) + 1) / 100.0);
- } else {
- vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
- }
- tcmapput(cols, "num", 3, vbuf, vsiz);
- vsiz = sprintf(vbuf, "%d", myrand(32) + 1);
- tcmapput(cols, "type", 4, vbuf, vsiz);
- int num = myrand(5);
- int pt = 0;
- char *wp = vbuf;
- for(int j = 0; j < num; j++){
- pt += myrand(5) + 1;
- if(wp > vbuf) *(wp++) = ',';
- wp += sprintf(wp, "%d", pt);
- }
- *wp = '\0';
- if(*vbuf != '\0'){
- tcmapput(cols, "flag", 4, vbuf, wp - vbuf);
- tcmapput(cols, "text", 4, vbuf, wp - vbuf);
- }
- char nbuf[RECBUFSIZ];
- int nsiz = sprintf(nbuf, "c%d", myrand(i) + 1);
- vsiz = sprintf(vbuf, "%d", myrand(i) + 1);
- tcmapput(cols, nbuf, nsiz, vbuf, vsiz);
- if(myrand(2) == 0){
- if(!tctdbput(tdb, pkbuf, pksiz, cols)){
- eprint(tdb, __LINE__, "tctdbput");
- err = true;
- }
- } else {
- if(!tctdbput(tdb, pkbuf, pksiz, cols) && tctdbecode(tdb) && tctdbecode(tdb) != TCEKEEP){
- eprint(tdb, __LINE__, "tctdbput");
- err = true;
- }
- }
- tcmapdel(cols);
- } else if(rnd < 30){
- if(!tctdbout(tdb, pkbuf, pksiz) && tctdbecode(tdb) && tctdbecode(tdb) != TCENOREC){
- eprint(tdb, __LINE__, "tctdbout");
- err = true;
- }
- } else if(rnd < 31){
- if(myrand(10) == 0 && !tctdbiterinit(tdb) && tctdbecode(tdb) != TCENOREC){
- eprint(tdb, __LINE__, "tctdbiterinit");
- err = true;
- }
- for(int j = 0; !err && j < 10; j++){
- int ksiz;
- char *kbuf = tctdbiternext(tdb, &ksiz);
- if(kbuf){
- tcfree(kbuf);
- } else if(tctdbecode(tdb) != TCEINVALID && tctdbecode(tdb) != TCENOREC){
- eprint(tdb, __LINE__, "tctdbiternext");
- err = true;
- }
- }
- } else {
- TDBQRY *qry = tctdbqrynew(tdb);
- char expr[RECBUFSIZ];
- sprintf(expr, "%d", myrand(i) + 1);
- switch(myrand(6) * 1){
- default:
- tctdbqryaddcond(qry, "str", TDBQCSTREQ, expr);
- break;
- case 1:
- tctdbqryaddcond(qry, "str", TDBQCSTRBW, expr);
- break;
- case 2:
- tctdbqryaddcond(qry, "str", TDBQCSTROREQ, expr);
- break;
- case 3:
- tctdbqryaddcond(qry, "num", TDBQCNUMEQ, expr);
- break;
- case 4:
- tctdbqryaddcond(qry, "num", TDBQCNUMGT, expr);
- break;
- case 5:
- tctdbqryaddcond(qry, "num", TDBQCNUMLT, expr);
- break;
- }
- tctdbqrysetlimit(qry, 10, myrand(5) * 10);
- TCLIST *res = tctdbqrysearch(qry);
- tclistdel(res);
- tctdbqrydel(qry);
- }
- 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;
+ return err ? "error" : NULL;
}
/* global variables */
const char *g_progname; // program name
unsigned int g_randseed; // random seed
-HANDLE g_dbgfd; // debugging output
+HANDLE g_dbgfd = INVALID_HANDLE_VALUE; // debugging output
/* function prototypes */