From a01d700adf636747af18958fc3d8f03c16a7e47d Mon Sep 17 00:00:00 2001 From: "Bradley C. Kuszmaul" Date: Wed, 14 Nov 2007 18:00:48 +0000 Subject: [PATCH] Update git-svn-id: file:///svn/tokudb@521 c7de825b-a66e-492c-adef-691d508d4ae1 --- utils/Makefile | 44 +++++++++++++++++--------- utils/outputbyte.c | 75 +++++++++++++++++++++++++++++++++++++++++++++ utils/tokudb_dump.c | 2 +- 3 files changed, 106 insertions(+), 15 deletions(-) create mode 100644 utils/outputbyte.c diff --git a/utils/Makefile b/utils/Makefile index 5df126ce3d1..a20957fc7c3 100755 --- a/utils/Makefile +++ b/utils/Makefile @@ -1,27 +1,34 @@ -CFLAGS = -std=gnu89 -W -Wall -Wno-unused -g -fPIC -ldb -LFLAGS = -l CPPFLAGS = +BDB=/usr/local/BerkeleyDB.4.1 +BDB_DUMP=$(BDB)/bin/db_dump +BDB_LOAD=$(BDB)/bin/db_load -BDB_DUMP=/usr/local/Berkeleydb.4.1/bin/db_dump -BDB_LOAD=/usr/local/Berkeleydb.4.1/bin/db_load +CPPFLAGS = -I$(BDB)/include +CFLAGS = -std=gnu89 -W -Wall -Wno-unused -g +LDFLAGS = -L$(BDB)/lib -ldb -lpthread -Wl,-rpath,$(BDB)/lib +# LDFLAGS = -L$(BDB)/lib -ldb -lpthread +STATIC_LDFLAGS = -static -L../lib -ldb -lz UTILS= \ tokudb_gen \ tokudb_load \ tokudb_dump \ #End +STATIC_UTILS=$(patsubst %,%_static,$(UTILS)) .PHONY: all clean test test_gen test_gen_hex test_load test_dump -all: $(UTILS) +all: $(UTILS) $(STATIC_UTILS) -test: test_gen test_load test_dump +%: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LDFLAGS) + +%_static: %.c + $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(STATIC_LDFLAGS) + +test: test_gen test_load test_dump test_bdb_tokudb test_gen: test_gen_hex -BDB=/usr/local/BerkeleyDB.4.6 -BDB_DUMP=$(BDB)/bin/db_dump -BDB_LOAD=$(BDB)/bin/db_load - TEST_GEN_HEX_NUMKEYS=10000 TEST_GEN_HEX_LENGTHMIN=0 TEST_GEN_HEX_LENGTHLIMIT=1024 @@ -35,7 +42,7 @@ test_gen_hex: $(BDB_LOAD) $@.db.temp < $@.gen.temp $(BDB_DUMP) $@.db.temp > $@.load_dump.temp ./tokudb_gen -Hf > $@.gen_sorted.temp - ./tokudb_gen -hf $(TEST_GEN_HEX_FLAGS) -d "\t" -s "\n" | sort -k 1,1 | tr -d "\n" | tr "\t" "\n" >> $@.gen_sorted.temp + export LC_ALL=C;./tokudb_gen -hf $(TEST_GEN_HEX_FLAGS) -d "\t" -s "\n" | sort -k 1,1 | tr -d "\n" | tr "\t" "\n" >> $@.gen_sorted.temp ./tokudb_gen -Fh >> $@.gen_sorted.temp if ! diff -q $@.load_dump.temp $@.gen_sorted.temp; then echo "Test Failed!"; exit 1; fi rm $@.*.temp @@ -50,7 +57,7 @@ test_load: $(BDB_DUMP) $@.bdb.temp > $@.dump.bdb.temp $(BDB_DUMP) $@.tokudb.temp > $@.dump.tokudb.temp if ! diff -q $@.dump.bdb.temp $@.dump.tokudb.temp; then echo "Test Failed!"; exit 1; fi - + test_dump: #Generating $(TEST_GEN_HEX_NUMKEYS) keys. [$(TEST_GEN_HEX_LENGTHMIN),$(TEST_GEN_HEX_LENGTHLIMIT)) bytes + identifier overhead echo "Generating text input > db > text" @@ -60,8 +67,17 @@ test_dump: $(BDB_DUMP) $@.bdb.temp > $@.dump.bdb.temp ./tokudb_dump $@.bdb.temp > $@.dump.tokudb.temp if ! diff -q $@.dump.bdb.temp $@.dump.tokudb.temp; then echo "Test Failed!"; exit 1; fi - + +test_bdb_tokudb: + rm -rf $@.*.temp + ./tokudb_gen $(TEST_GEN_HEX_FLAGS) >$@.gen.temp + $(BDB_LOAD) $@.bdb.temp <$@.gen.temp + $(BDB_DUMP) $@.bdb.temp >$@.dump.bdb.temp + ./tokudb_load_static $@.tdb.temp <$@.gen.temp + ./tokudb_dump_static $@.tdb.temp >$@.dump.tdb.temp + if ! diff -q $@.dump.bdb.temp $@.dump.tdb.temp; then echo "$@ failed"; exit 1; fi + #if diff -q <(echo "foo") <(echo "foo") > /dev/null; then echo yes; else echo no; fi clean: - rm -rf *.so *.o $(UTILS) *.temp + rm -rf *.so *.o $(UTILS) $(STATIC_UTILS) *.temp diff --git a/utils/outputbyte.c b/utils/outputbyte.c new file mode 100644 index 00000000000..abf862581cf --- /dev/null +++ b/utils/outputbyte.c @@ -0,0 +1,75 @@ +void outputbyte(unsigned char ch, bool plaintext) +{ + if (plaintext) { + if (ch != '\n' && isprint(ch)) { + switch (ch) { + case ('\\'): { + printf("\\\\"); + break; + } + default: + { + printf("%c", ch); + break; + } + } + } + else { + printf( + "\\%c%c", + "0123456789abcdef"[(ch & 0xf0) >> 4], + "0123456789abcdef"[ch & 0x0f] + ); + } + } + else { + printf( + "%c%c", + "0123456789abcdef"[(ch & 0xf0) >> 4], + "0123456789abcdef"[ch & 0x0f] + ); + } +} +/* +The above code is too long, since printf isn't being used effectively. +*/ +void outputbyte(unsigned char ch, bool plaintext) +{ + if (plaintext) { + if (ch != '\n' && isprint(ch)) { + switch (ch) { + case ('\\'): { + printf("\\\\"); + break; + } + default: + { + printf("%c", ch); + break; + } + } + } + else { + printf("%02x", ch); + } + } + else { + printf("%02x", ch); + } +} +/* +I don't understand the control flow for the plaintext case, since \n isn't a printable character. +Also using a switch for a two-way branch seems overkill. +Switch is quite dangerous because one can forget the break, and control falls through. +For one-liner conditionsals, there is no need to put in { } +*/ +void outputbyte(unsigned char ch, bool plaintext) +{ + if (plaintext) { + if (ch == '\\') printf("\\\\"); + else if (isprint(ch)) printf("%c", ch); + else printf("%02x", ch); + } else { + printf("%02x", ch); + } +} diff --git a/utils/tokudb_dump.c b/utils/tokudb_dump.c index f40e9eb6862..1ae2cb24900 100644 --- a/utils/tokudb_dump.c +++ b/utils/tokudb_dump.c @@ -266,7 +266,7 @@ int create_init_env() REMOVE_BITS(flags, DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN); SET_BITS(flags, DB_CREATE | DB_PRIVATE); - retval = dbenv->open(dbenv, g.homedir, flags, 0); + retval = dbenv->open(dbenv, g.homedir ? g.homedir : ".", flags, 0); if (retval) { ERROR(retval, "DB_ENV->open"); goto error;