heroku-tokyotyrant 0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +504 -0
- data/README.rdoc +231 -0
- data/Rakefile +72 -0
- data/benchmarks/balancer.rb +101 -0
- data/benchmarks/bulk_db.rb +74 -0
- data/benchmarks/bulk_table.rb +87 -0
- data/benchmarks/db.rb +114 -0
- data/benchmarks/table.rb +161 -0
- data/ext/extconf.rb +43 -0
- data/ext/tokyo/bin/tcamgr +0 -0
- data/ext/tokyo/bin/tcamttest +0 -0
- data/ext/tokyo/bin/tcatest +0 -0
- data/ext/tokyo/bin/tcbmgr +0 -0
- data/ext/tokyo/bin/tcbmttest +0 -0
- data/ext/tokyo/bin/tcbtest +0 -0
- data/ext/tokyo/bin/tcfmgr +0 -0
- data/ext/tokyo/bin/tcfmttest +0 -0
- data/ext/tokyo/bin/tcftest +0 -0
- data/ext/tokyo/bin/tchmgr +0 -0
- data/ext/tokyo/bin/tchmttest +0 -0
- data/ext/tokyo/bin/tchtest +0 -0
- data/ext/tokyo/bin/tcrmgr +0 -0
- data/ext/tokyo/bin/tcrmttest +0 -0
- data/ext/tokyo/bin/tcrtest +0 -0
- data/ext/tokyo/bin/tctmgr +0 -0
- data/ext/tokyo/bin/tctmttest +0 -0
- data/ext/tokyo/bin/tcttest +0 -0
- data/ext/tokyo/bin/tcucodec +0 -0
- data/ext/tokyo/bin/tcumttest +0 -0
- data/ext/tokyo/bin/tcutest +0 -0
- data/ext/tokyo/bin/ttserver +0 -0
- data/ext/tokyo/bin/ttulmgr +0 -0
- data/ext/tokyo/bin/ttultest +0 -0
- data/ext/tokyo/include/tcadb.h +548 -0
- data/ext/tokyo/include/tcbdb.h +1101 -0
- data/ext/tokyo/include/tcfdb.h +858 -0
- data/ext/tokyo/include/tchdb.h +871 -0
- data/ext/tokyo/include/tcrdb.h +801 -0
- data/ext/tokyo/include/tctdb.h +1086 -0
- data/ext/tokyo/include/tculog.h +392 -0
- data/ext/tokyo/include/tcutil.h +4184 -0
- data/ext/tokyo/include/ttutil.h +494 -0
- data/ext/tokyo/lib/libtokyocabinet.9.4.0.dylib +0 -0
- data/ext/tokyo/lib/libtokyocabinet.9.dylib +0 -0
- data/ext/tokyo/lib/libtokyocabinet.a +0 -0
- data/ext/tokyo/lib/libtokyocabinet.dylib +0 -0
- data/ext/tokyo/lib/libtokyotyrant.3.22.0.dylib +0 -0
- data/ext/tokyo/lib/libtokyotyrant.3.dylib +0 -0
- data/ext/tokyo/lib/libtokyotyrant.a +0 -0
- data/ext/tokyo/lib/libtokyotyrant.dylib +0 -0
- data/ext/tokyo/lib/pkgconfig/tokyocabinet.pc +14 -0
- data/ext/tokyo/lib/pkgconfig/tokyotyrant.pc +14 -0
- data/ext/tokyo/lib/ttskeldir.bundle +0 -0
- data/ext/tokyo/lib/ttskelmock.bundle +0 -0
- data/ext/tokyo/lib/ttskelnull.bundle +0 -0
- data/ext/tokyo/lib/ttskelproxy.bundle +0 -0
- data/ext/tokyo/libexec/tcawmgr.cgi +0 -0
- data/ext/tokyo/sbin/ttservctl +163 -0
- data/ext/tokyo/share/man/man1/tcamgr.1 +97 -0
- data/ext/tokyo/share/man/man1/tcamttest.1 +35 -0
- data/ext/tokyo/share/man/man1/tcatest.1 +55 -0
- data/ext/tokyo/share/man/man1/tcbmgr.1 +125 -0
- data/ext/tokyo/share/man/man1/tcbmttest.1 +81 -0
- data/ext/tokyo/share/man/man1/tcbtest.1 +107 -0
- data/ext/tokyo/share/man/man1/tcfmgr.1 +98 -0
- data/ext/tokyo/share/man/man1/tcfmttest.1 +62 -0
- data/ext/tokyo/share/man/man1/tcftest.1 +73 -0
- data/ext/tokyo/share/man/man1/tchmgr.1 +110 -0
- data/ext/tokyo/share/man/man1/tchmttest.1 +85 -0
- data/ext/tokyo/share/man/man1/tchtest.1 +95 -0
- data/ext/tokyo/share/man/man1/tcrmgr.1 +164 -0
- data/ext/tokyo/share/man/man1/tcrmttest.1 +55 -0
- data/ext/tokyo/share/man/man1/tcrtest.1 +89 -0
- data/ext/tokyo/share/man/man1/tctmgr.1 +140 -0
- data/ext/tokyo/share/man/man1/tctmttest.1 +92 -0
- data/ext/tokyo/share/man/man1/tcttest.1 +105 -0
- data/ext/tokyo/share/man/man1/tcucodec.1 +162 -0
- data/ext/tokyo/share/man/man1/tcumttest.1 +41 -0
- data/ext/tokyo/share/man/man1/tcutest.1 +81 -0
- data/ext/tokyo/share/man/man1/ttserver.1 +84 -0
- data/ext/tokyo/share/man/man1/ttulmgr.1 +40 -0
- data/ext/tokyo/share/man/man1/ttultest.1 +16 -0
- data/ext/tokyo/share/man/man3/tcadb.3 +676 -0
- data/ext/tokyo/share/man/man3/tcbdb.3 +1355 -0
- data/ext/tokyo/share/man/man3/tcfdb.3 +975 -0
- data/ext/tokyo/share/man/man3/tchdb.3 +898 -0
- data/ext/tokyo/share/man/man3/tclist.3 +1 -0
- data/ext/tokyo/share/man/man3/tcmap.3 +1 -0
- data/ext/tokyo/share/man/man3/tcmdb.3 +1 -0
- data/ext/tokyo/share/man/man3/tcmpool.3 +1 -0
- data/ext/tokyo/share/man/man3/tcrdb.3 +1309 -0
- data/ext/tokyo/share/man/man3/tctdb.3 +1110 -0
- data/ext/tokyo/share/man/man3/tctree.3 +1 -0
- data/ext/tokyo/share/man/man3/tculog.3 +15 -0
- data/ext/tokyo/share/man/man3/tcutil.3 +4518 -0
- data/ext/tokyo/share/man/man3/tcxstr.3 +1 -0
- data/ext/tokyo/share/man/man3/tokyocabinet.3 +132 -0
- data/ext/tokyo/share/man/man3/ttutil.3 +14 -0
- data/ext/tokyo/share/man/man8/ttservctl.8 +37 -0
- data/ext/tokyo/share/tokyocabinet/COPYING +504 -0
- data/ext/tokyo/share/tokyocabinet/ChangeLog +1252 -0
- data/ext/tokyo/share/tokyocabinet/THANKS +12 -0
- data/ext/tokyo/share/tokyocabinet/doc/benchmark.pdf +0 -0
- data/ext/tokyo/share/tokyocabinet/doc/common.css +211 -0
- data/ext/tokyo/share/tokyocabinet/doc/icon16.png +0 -0
- data/ext/tokyo/share/tokyocabinet/doc/index.html +156 -0
- data/ext/tokyo/share/tokyocabinet/doc/index.ja.html +197 -0
- data/ext/tokyo/share/tokyocabinet/doc/logo-ja.png +0 -0
- data/ext/tokyo/share/tokyocabinet/doc/logo.png +0 -0
- data/ext/tokyo/share/tokyocabinet/doc/spex-en.html +7145 -0
- data/ext/tokyo/share/tokyocabinet/doc/spex-ja.html +7476 -0
- data/ext/tokyo/share/tokyocabinet/doc/tokyoproducts.pdf +0 -0
- data/ext/tokyo/share/tokyocabinet/doc/tokyoproducts.ppt +0 -0
- data/ext/tokyo/share/tokyotyrant/COPYING +504 -0
- data/ext/tokyo/share/tokyotyrant/ChangeLog +578 -0
- data/ext/tokyo/share/tokyotyrant/THANKS +15 -0
- data/ext/tokyo/share/tokyotyrant/doc/common.css +211 -0
- data/ext/tokyo/share/tokyotyrant/doc/index.html +79 -0
- data/ext/tokyo/share/tokyotyrant/doc/spex.html +2264 -0
- data/ext/tokyo/share/tokyotyrant/ext/mapreduce.lua +57 -0
- data/ext/tokyo/share/tokyotyrant/ext/queue.lua +55 -0
- data/ext/tokyo/share/tokyotyrant/ext/senatus.lua +532 -0
- data/ext/tokyo/share/tokyotyrant/ext/usherette.lua +438 -0
- data/ext/tokyo_tyrant.c +147 -0
- data/ext/tokyo_tyrant.h +48 -0
- data/ext/tokyo_tyrant_db.c +227 -0
- data/ext/tokyo_tyrant_db.h +8 -0
- data/ext/tokyo_tyrant_module.c +453 -0
- data/ext/tokyo_tyrant_module.h +10 -0
- data/ext/tokyo_tyrant_query.c +226 -0
- data/ext/tokyo_tyrant_query.h +9 -0
- data/ext/tokyo_tyrant_table.c +319 -0
- data/ext/tokyo_tyrant_table.h +8 -0
- data/ext/tokyocabinet-1.4.41/COPYING +504 -0
- data/ext/tokyocabinet-1.4.41/ChangeLog +1252 -0
- data/ext/tokyocabinet-1.4.41/Makefile.in +825 -0
- data/ext/tokyocabinet-1.4.41/README +38 -0
- data/ext/tokyocabinet-1.4.41/THANKS +12 -0
- data/ext/tokyocabinet-1.4.41/bros/Makefile +133 -0
- data/ext/tokyocabinet-1.4.41/bros/bdbtest.c +438 -0
- data/ext/tokyocabinet-1.4.41/bros/cdbtest.c +219 -0
- data/ext/tokyocabinet-1.4.41/bros/cmpsqltctest.c +186 -0
- data/ext/tokyocabinet-1.4.41/bros/gdbmtest.c +216 -0
- data/ext/tokyocabinet-1.4.41/bros/mapreporter +72 -0
- data/ext/tokyocabinet-1.4.41/bros/maptest.cc +677 -0
- data/ext/tokyocabinet-1.4.41/bros/ndbmtest.c +204 -0
- data/ext/tokyocabinet-1.4.41/bros/qdbmtest.c +375 -0
- data/ext/tokyocabinet-1.4.41/bros/reporter +141 -0
- data/ext/tokyocabinet-1.4.41/bros/result.xls +0 -0
- data/ext/tokyocabinet-1.4.41/bros/sdbmtest.c +204 -0
- data/ext/tokyocabinet-1.4.41/bros/sqltest.c +404 -0
- data/ext/tokyocabinet-1.4.41/bros/tctest.c +748 -0
- data/ext/tokyocabinet-1.4.41/bros/tdbtest.c +205 -0
- data/ext/tokyocabinet-1.4.41/configure +7402 -0
- data/ext/tokyocabinet-1.4.41/configure.in +362 -0
- data/ext/tokyocabinet-1.4.41/doc/benchmark.pdf +0 -0
- data/ext/tokyocabinet-1.4.41/doc/common.css +211 -0
- data/ext/tokyocabinet-1.4.41/doc/icon16.png +0 -0
- data/ext/tokyocabinet-1.4.41/doc/index.html +156 -0
- data/ext/tokyocabinet-1.4.41/doc/index.ja.html +197 -0
- data/ext/tokyocabinet-1.4.41/doc/logo-ja.png +0 -0
- data/ext/tokyocabinet-1.4.41/doc/logo.png +0 -0
- data/ext/tokyocabinet-1.4.41/doc/spex-en.html +7145 -0
- data/ext/tokyocabinet-1.4.41/doc/spex-ja.html +7476 -0
- data/ext/tokyocabinet-1.4.41/doc/tokyoproducts.pdf +0 -0
- data/ext/tokyocabinet-1.4.41/doc/tokyoproducts.ppt +0 -0
- data/ext/tokyocabinet-1.4.41/example/Makefile +113 -0
- data/ext/tokyocabinet-1.4.41/example/tcadbex.c +55 -0
- data/ext/tokyocabinet-1.4.41/example/tcbdbex.c +64 -0
- data/ext/tokyocabinet-1.4.41/example/tcfdbex.c +60 -0
- data/ext/tokyocabinet-1.4.41/example/tchdbex.c +60 -0
- data/ext/tokyocabinet-1.4.41/example/tctchat.c +97 -0
- data/ext/tokyocabinet-1.4.41/example/tctchat.tmpl +141 -0
- data/ext/tokyocabinet-1.4.41/example/tctdbex.c +85 -0
- data/ext/tokyocabinet-1.4.41/example/tctsearch.c +95 -0
- data/ext/tokyocabinet-1.4.41/example/tctsearch.tmpl +122 -0
- data/ext/tokyocabinet-1.4.41/example/tcutilex.c +77 -0
- data/ext/tokyocabinet-1.4.41/f.tsv +2 -0
- data/ext/tokyocabinet-1.4.41/lab/calccomp +118 -0
- data/ext/tokyocabinet-1.4.41/lab/datechange +56 -0
- data/ext/tokyocabinet-1.4.41/lab/diffcheck +45 -0
- data/ext/tokyocabinet-1.4.41/lab/htmltotsv +102 -0
- data/ext/tokyocabinet-1.4.41/lab/magic +19 -0
- data/ext/tokyocabinet-1.4.41/lab/printenv.cgi +27 -0
- data/ext/tokyocabinet-1.4.41/lab/stepcount +26 -0
- data/ext/tokyocabinet-1.4.41/lab/stopwatch +61 -0
- data/ext/tokyocabinet-1.4.41/lab/tabcheck +43 -0
- data/ext/tokyocabinet-1.4.41/lab/wgettsv +239 -0
- data/ext/tokyocabinet-1.4.41/lab/widthcheck +57 -0
- data/ext/tokyocabinet-1.4.41/man/htmltoman +104 -0
- data/ext/tokyocabinet-1.4.41/man/tcadb.3 +676 -0
- data/ext/tokyocabinet-1.4.41/man/tcamgr.1 +97 -0
- data/ext/tokyocabinet-1.4.41/man/tcamttest.1 +35 -0
- data/ext/tokyocabinet-1.4.41/man/tcatest.1 +55 -0
- data/ext/tokyocabinet-1.4.41/man/tcbdb.3 +1355 -0
- data/ext/tokyocabinet-1.4.41/man/tcbmgr.1 +125 -0
- data/ext/tokyocabinet-1.4.41/man/tcbmttest.1 +81 -0
- data/ext/tokyocabinet-1.4.41/man/tcbtest.1 +107 -0
- data/ext/tokyocabinet-1.4.41/man/tcfdb.3 +975 -0
- data/ext/tokyocabinet-1.4.41/man/tcfmgr.1 +98 -0
- data/ext/tokyocabinet-1.4.41/man/tcfmttest.1 +62 -0
- data/ext/tokyocabinet-1.4.41/man/tcftest.1 +73 -0
- data/ext/tokyocabinet-1.4.41/man/tchdb.3 +898 -0
- data/ext/tokyocabinet-1.4.41/man/tchmgr.1 +110 -0
- data/ext/tokyocabinet-1.4.41/man/tchmttest.1 +85 -0
- data/ext/tokyocabinet-1.4.41/man/tchtest.1 +95 -0
- data/ext/tokyocabinet-1.4.41/man/tclist.3 +1 -0
- data/ext/tokyocabinet-1.4.41/man/tcmap.3 +1 -0
- data/ext/tokyocabinet-1.4.41/man/tcmdb.3 +1 -0
- data/ext/tokyocabinet-1.4.41/man/tcmpool.3 +1 -0
- data/ext/tokyocabinet-1.4.41/man/tctdb.3 +1110 -0
- data/ext/tokyocabinet-1.4.41/man/tctmgr.1 +140 -0
- data/ext/tokyocabinet-1.4.41/man/tctmttest.1 +92 -0
- data/ext/tokyocabinet-1.4.41/man/tctree.3 +1 -0
- data/ext/tokyocabinet-1.4.41/man/tcttest.1 +105 -0
- data/ext/tokyocabinet-1.4.41/man/tcucodec.1 +162 -0
- data/ext/tokyocabinet-1.4.41/man/tcumttest.1 +41 -0
- data/ext/tokyocabinet-1.4.41/man/tcutest.1 +81 -0
- data/ext/tokyocabinet-1.4.41/man/tcutil.3 +4518 -0
- data/ext/tokyocabinet-1.4.41/man/tcxstr.3 +1 -0
- data/ext/tokyocabinet-1.4.41/man/tokyocabinet.3 +132 -0
- data/ext/tokyocabinet-1.4.41/md5.c +381 -0
- data/ext/tokyocabinet-1.4.41/md5.h +101 -0
- data/ext/tokyocabinet-1.4.41/myconf.c +493 -0
- data/ext/tokyocabinet-1.4.41/myconf.h +549 -0
- data/ext/tokyocabinet-1.4.41/tcadb.c +4339 -0
- data/ext/tokyocabinet-1.4.41/tcadb.h +548 -0
- data/ext/tokyocabinet-1.4.41/tcamgr.c +1019 -0
- data/ext/tokyocabinet-1.4.41/tcamttest.c +542 -0
- data/ext/tokyocabinet-1.4.41/tcatest.c +1845 -0
- data/ext/tokyocabinet-1.4.41/tcawmgr.c +482 -0
- data/ext/tokyocabinet-1.4.41/tcbdb.c +4180 -0
- data/ext/tokyocabinet-1.4.41/tcbdb.h +1101 -0
- data/ext/tokyocabinet-1.4.41/tcbmgr.c +1012 -0
- data/ext/tokyocabinet-1.4.41/tcbmttest.c +1810 -0
- data/ext/tokyocabinet-1.4.41/tcbtest.c +2586 -0
- data/ext/tokyocabinet-1.4.41/tcfdb.c +2746 -0
- data/ext/tokyocabinet-1.4.41/tcfdb.h +858 -0
- data/ext/tokyocabinet-1.4.41/tcfmgr.c +786 -0
- data/ext/tokyocabinet-1.4.41/tcfmttest.c +1220 -0
- data/ext/tokyocabinet-1.4.41/tcftest.c +1695 -0
- data/ext/tokyocabinet-1.4.41/tchdb.c +5153 -0
- data/ext/tokyocabinet-1.4.41/tchdb.h +871 -0
- data/ext/tokyocabinet-1.4.41/tchmgr.c +842 -0
- data/ext/tokyocabinet-1.4.41/tchmttest.c +1757 -0
- data/ext/tokyocabinet-1.4.41/tchtest.c +2129 -0
- data/ext/tokyocabinet-1.4.41/tctdb.c +6199 -0
- data/ext/tokyocabinet-1.4.41/tctdb.h +1086 -0
- data/ext/tokyocabinet-1.4.41/tctmgr.c +1241 -0
- data/ext/tokyocabinet-1.4.41/tctmttest.c +1563 -0
- data/ext/tokyocabinet-1.4.41/tcttest.c +2062 -0
- data/ext/tokyocabinet-1.4.41/tcucodec.c +1357 -0
- data/ext/tokyocabinet-1.4.41/tcumttest.c +578 -0
- data/ext/tokyocabinet-1.4.41/tcutest.c +1875 -0
- data/ext/tokyocabinet-1.4.41/tcutil.c +10528 -0
- data/ext/tokyocabinet-1.4.41/tcutil.h +4184 -0
- data/ext/tokyocabinet-1.4.41/tokyocabinet.idl +336 -0
- data/ext/tokyocabinet-1.4.41/tokyocabinet.pc.in +14 -0
- data/ext/tokyotyrant-1.1.39/COPYING +504 -0
- data/ext/tokyotyrant-1.1.39/ChangeLog +578 -0
- data/ext/tokyotyrant-1.1.39/Makefile.in +365 -0
- data/ext/tokyotyrant-1.1.39/README +38 -0
- data/ext/tokyotyrant-1.1.39/THANKS +15 -0
- data/ext/tokyotyrant-1.1.39/configure +6979 -0
- data/ext/tokyotyrant-1.1.39/configure.in +300 -0
- data/ext/tokyotyrant-1.1.39/doc/common.css +211 -0
- data/ext/tokyotyrant-1.1.39/doc/index.html +79 -0
- data/ext/tokyotyrant-1.1.39/doc/spex.html +2264 -0
- data/ext/tokyotyrant-1.1.39/example/Makefile +68 -0
- data/ext/tokyotyrant-1.1.39/example/httptest.pl +88 -0
- data/ext/tokyotyrant-1.1.39/example/mcftest.pl +39 -0
- data/ext/tokyotyrant-1.1.39/example/mctest.pl +43 -0
- data/ext/tokyotyrant-1.1.39/example/tcrdbex +0 -0
- data/ext/tokyotyrant-1.1.39/example/tcrdbex.c +49 -0
- data/ext/tokyotyrant-1.1.39/example/tcrdbex.o +0 -0
- data/ext/tokyotyrant-1.1.39/example/tcrdbtblex +0 -0
- data/ext/tokyotyrant-1.1.39/example/tcrdbtblex.c +79 -0
- data/ext/tokyotyrant-1.1.39/example/tcrdbtblex.o +0 -0
- data/ext/tokyotyrant-1.1.39/ext/mapreduce.lua +57 -0
- data/ext/tokyotyrant-1.1.39/ext/queue.lua +55 -0
- data/ext/tokyotyrant-1.1.39/ext/senatus.lua +532 -0
- data/ext/tokyotyrant-1.1.39/ext/usherette.lua +438 -0
- data/ext/tokyotyrant-1.1.39/lab/datechange +56 -0
- data/ext/tokyotyrant-1.1.39/lab/diffcheck +45 -0
- data/ext/tokyotyrant-1.1.39/lab/fibonacci.lua +20 -0
- data/ext/tokyotyrant-1.1.39/lab/footprint.lua +67 -0
- data/ext/tokyotyrant-1.1.39/lab/highlow.lua +88 -0
- data/ext/tokyotyrant-1.1.39/lab/killdualmaster +12 -0
- data/ext/tokyotyrant-1.1.39/lab/rundualmaster +38 -0
- data/ext/tokyotyrant-1.1.39/lab/stepcount +26 -0
- data/ext/tokyotyrant-1.1.39/lab/tabcheck +43 -0
- data/ext/tokyotyrant-1.1.39/lab/ushrtregister.pl +55 -0
- data/ext/tokyotyrant-1.1.39/lab/widthcheck +57 -0
- data/ext/tokyotyrant-1.1.39/man/htmltoman +100 -0
- data/ext/tokyotyrant-1.1.39/man/tcrdb.3 +1309 -0
- data/ext/tokyotyrant-1.1.39/man/tcrmgr.1 +164 -0
- data/ext/tokyotyrant-1.1.39/man/tcrmttest.1 +55 -0
- data/ext/tokyotyrant-1.1.39/man/tcrtest.1 +89 -0
- data/ext/tokyotyrant-1.1.39/man/tculog.3 +15 -0
- data/ext/tokyotyrant-1.1.39/man/ttservctl.8 +37 -0
- data/ext/tokyotyrant-1.1.39/man/ttserver.1 +84 -0
- data/ext/tokyotyrant-1.1.39/man/ttulmgr.1 +40 -0
- data/ext/tokyotyrant-1.1.39/man/ttultest.1 +16 -0
- data/ext/tokyotyrant-1.1.39/man/ttutil.3 +14 -0
- data/ext/tokyotyrant-1.1.39/myconf.c +169 -0
- data/ext/tokyotyrant-1.1.39/myconf.h +408 -0
- data/ext/tokyotyrant-1.1.39/scrext.c +2394 -0
- data/ext/tokyotyrant-1.1.39/scrext.h +96 -0
- data/ext/tokyotyrant-1.1.39/tcrdb.c +2637 -0
- data/ext/tokyotyrant-1.1.39/tcrdb.h +801 -0
- data/ext/tokyotyrant-1.1.39/tcrmgr.c +1559 -0
- data/ext/tokyotyrant-1.1.39/tcrmttest.c +915 -0
- data/ext/tokyotyrant-1.1.39/tcrtest.c +1542 -0
- data/ext/tokyotyrant-1.1.39/tculog.c +1211 -0
- data/ext/tokyotyrant-1.1.39/tculog.h +392 -0
- data/ext/tokyotyrant-1.1.39/tokyotyrant.idl +143 -0
- data/ext/tokyotyrant-1.1.39/tokyotyrant.pc.in +14 -0
- data/ext/tokyotyrant-1.1.39/ttservctl +163 -0
- data/ext/tokyotyrant-1.1.39/ttserver.c +3583 -0
- data/ext/tokyotyrant-1.1.39/ttskeldir.c +141 -0
- data/ext/tokyotyrant-1.1.39/ttskelmock.c +64 -0
- data/ext/tokyotyrant-1.1.39/ttskelnull.c +79 -0
- data/ext/tokyotyrant-1.1.39/ttskelproxy.c +74 -0
- data/ext/tokyotyrant-1.1.39/ttulmgr.c +266 -0
- data/ext/tokyotyrant-1.1.39/ttultest.c +371 -0
- data/ext/tokyotyrant-1.1.39/ttutil.c +1510 -0
- data/ext/tokyotyrant-1.1.39/ttutil.h +494 -0
- data/lib/tokyo_tyrant/balancer.rb +189 -0
- data/spec/ext.lua +4 -0
- data/spec/plu_db.rb +538 -0
- data/spec/spec.rb +1 -0
- data/spec/spec_base.rb +17 -0
- data/spec/start_tyrants.sh +36 -0
- data/spec/stop_tyrants.sh +9 -0
- data/spec/tokyo_tyrant_balancer_db_spec.rb +160 -0
- data/spec/tokyo_tyrant_balancer_table_spec.rb +177 -0
- data/spec/tokyo_tyrant_query_spec.rb +159 -0
- data/spec/tokyo_tyrant_spec.rb +254 -0
- data/spec/tokyo_tyrant_table_spec.rb +301 -0
- metadata +402 -0
@@ -0,0 +1,1241 @@
|
|
1
|
+
/*************************************************************************************************
|
2
|
+
* The command line utility of the table database API
|
3
|
+
* Copyright (C) 2006-2009 Mikio Hirabayashi
|
4
|
+
* This file is part of Tokyo Cabinet.
|
5
|
+
* Tokyo Cabinet is free software; you can redistribute it and/or modify it under the terms of
|
6
|
+
* the GNU Lesser General Public License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License or any later version. Tokyo Cabinet is distributed in the hope
|
8
|
+
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
9
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
10
|
+
* License for more details.
|
11
|
+
* You should have received a copy of the GNU Lesser General Public License along with Tokyo
|
12
|
+
* Cabinet; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
13
|
+
* Boston, MA 02111-1307 USA.
|
14
|
+
*************************************************************************************************/
|
15
|
+
|
16
|
+
|
17
|
+
#include <tcutil.h>
|
18
|
+
#include <tctdb.h>
|
19
|
+
#include "myconf.h"
|
20
|
+
|
21
|
+
|
22
|
+
/* global variables */
|
23
|
+
const char *g_progname; // program name
|
24
|
+
int g_dbgfd; // debugging output
|
25
|
+
|
26
|
+
|
27
|
+
/* function prototypes */
|
28
|
+
int main(int argc, char **argv);
|
29
|
+
static void usage(void);
|
30
|
+
static void printerr(TCTDB *tdb);
|
31
|
+
static int printdata(const char *ptr, int size, bool px);
|
32
|
+
static char *mygetline(FILE *ifp);
|
33
|
+
static int runcreate(int argc, char **argv);
|
34
|
+
static int runinform(int argc, char **argv);
|
35
|
+
static int runput(int argc, char **argv);
|
36
|
+
static int runout(int argc, char **argv);
|
37
|
+
static int runget(int argc, char **argv);
|
38
|
+
static int runlist(int argc, char **argv);
|
39
|
+
static int runsearch(int argc, char **argv);
|
40
|
+
static int runoptimize(int argc, char **argv);
|
41
|
+
static int runsetindex(int argc, char **argv);
|
42
|
+
static int runimporttsv(int argc, char **argv);
|
43
|
+
static int runversion(int argc, char **argv);
|
44
|
+
static int proccreate(const char *path, int bnum, int apow, int fpow, int opts);
|
45
|
+
static int procinform(const char *path, int omode);
|
46
|
+
static int procput(const char *path, const char *pkbuf, int pksiz, TCMAP *cols,
|
47
|
+
int omode, int dmode);
|
48
|
+
static int procout(const char *path, const char *pkbuf, int pksiz, int omode);
|
49
|
+
static int procget(const char *path, const char *pkbuf, int pksiz, int omode, bool px, bool pz);
|
50
|
+
static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr);
|
51
|
+
static int procsearch(const char *path, TCLIST *conds, const char *oname, const char *otype,
|
52
|
+
int omode, int max, int skip, bool pv, bool px, bool kw, bool ph, int bt,
|
53
|
+
bool rm, const char *mtype);
|
54
|
+
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode,
|
55
|
+
bool df);
|
56
|
+
static int procsetindex(const char *path, const char *name, int omode, int type);
|
57
|
+
static int procimporttsv(const char *path, const char *file, int omode, bool sc);
|
58
|
+
static int procversion(void);
|
59
|
+
|
60
|
+
|
61
|
+
/* main routine */
|
62
|
+
int main(int argc, char **argv){
|
63
|
+
g_progname = argv[0];
|
64
|
+
g_dbgfd = -1;
|
65
|
+
const char *ebuf = getenv("TCDBGFD");
|
66
|
+
if(ebuf) g_dbgfd = tcatoix(ebuf);
|
67
|
+
if(argc < 2) usage();
|
68
|
+
int rv = 0;
|
69
|
+
if(!strcmp(argv[1], "create")){
|
70
|
+
rv = runcreate(argc, argv);
|
71
|
+
} else if(!strcmp(argv[1], "inform")){
|
72
|
+
rv = runinform(argc, argv);
|
73
|
+
} else if(!strcmp(argv[1], "put")){
|
74
|
+
rv = runput(argc, argv);
|
75
|
+
} else if(!strcmp(argv[1], "out")){
|
76
|
+
rv = runout(argc, argv);
|
77
|
+
} else if(!strcmp(argv[1], "get")){
|
78
|
+
rv = runget(argc, argv);
|
79
|
+
} else if(!strcmp(argv[1], "list")){
|
80
|
+
rv = runlist(argc, argv);
|
81
|
+
} else if(!strcmp(argv[1], "search")){
|
82
|
+
rv = runsearch(argc, argv);
|
83
|
+
} else if(!strcmp(argv[1], "optimize")){
|
84
|
+
rv = runoptimize(argc, argv);
|
85
|
+
} else if(!strcmp(argv[1], "setindex")){
|
86
|
+
rv = runsetindex(argc, argv);
|
87
|
+
} else if(!strcmp(argv[1], "importtsv")){
|
88
|
+
rv = runimporttsv(argc, argv);
|
89
|
+
} else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){
|
90
|
+
rv = runversion(argc, argv);
|
91
|
+
} else {
|
92
|
+
usage();
|
93
|
+
}
|
94
|
+
return rv;
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
/* print the usage and exit */
|
99
|
+
static void usage(void){
|
100
|
+
fprintf(stderr, "%s: the command line utility of the table database API\n", g_progname);
|
101
|
+
fprintf(stderr, "\n");
|
102
|
+
fprintf(stderr, "usage:\n");
|
103
|
+
fprintf(stderr, " %s create [-tl] [-td|-tb|-tt|-tx] path [bnum [apow [fpow]]]\n", g_progname);
|
104
|
+
fprintf(stderr, " %s inform [-nl|-nb] path\n", g_progname);
|
105
|
+
fprintf(stderr, " %s put [-nl|-nb] [-sx] [-dk|-dc|-dai|-dad] path pkey [cols...]\n",
|
106
|
+
g_progname);
|
107
|
+
fprintf(stderr, " %s out [-nl|-nb] [-sx] path pkey\n", g_progname);
|
108
|
+
fprintf(stderr, " %s get [-nl|-nb] [-sx] [-px] [-pz] path pkey\n", g_progname);
|
109
|
+
fprintf(stderr, " %s list [-nl|-nb] [-m num] [-pv] [-px] [-fm str] path\n", g_progname);
|
110
|
+
fprintf(stderr, " %s search [-nl|-nb] [-ord name type] [-m num] [-sk num] [-kw] [-pv] [-px]"
|
111
|
+
" [-ph] [-bt num] [-rm] [-ms type] path [name op expr ...]\n", g_progname);
|
112
|
+
fprintf(stderr, " %s optimize [-tl] [-td|-tb|-tt|-tx] [-tz] [-nl|-nb] [-df]"
|
113
|
+
" path [bnum [apow [fpow]]]\n", g_progname);
|
114
|
+
fprintf(stderr, " %s setindex [-nl|-nb] [-it type] path name\n", g_progname);
|
115
|
+
fprintf(stderr, " %s importtsv [-nl|-nb] [-sc] path [file]\n", g_progname);
|
116
|
+
fprintf(stderr, " %s version\n", g_progname);
|
117
|
+
fprintf(stderr, "\n");
|
118
|
+
exit(1);
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
/* print error information */
|
123
|
+
static void printerr(TCTDB *tdb){
|
124
|
+
const char *path = tctdbpath(tdb);
|
125
|
+
int ecode = tctdbecode(tdb);
|
126
|
+
fprintf(stderr, "%s: %s: %d: %s\n", g_progname, path ? path : "-", ecode, tctdberrmsg(ecode));
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
/* print record data */
|
131
|
+
static int printdata(const char *ptr, int size, bool px){
|
132
|
+
int len = 0;
|
133
|
+
while(size-- > 0){
|
134
|
+
if(px){
|
135
|
+
if(len > 0) putchar(' ');
|
136
|
+
len += printf("%02X", *(unsigned char *)ptr);
|
137
|
+
} else {
|
138
|
+
if(strchr("\t\r\n", *ptr)){
|
139
|
+
putchar(' ');
|
140
|
+
} else {
|
141
|
+
putchar(*ptr);
|
142
|
+
}
|
143
|
+
len++;
|
144
|
+
}
|
145
|
+
ptr++;
|
146
|
+
}
|
147
|
+
return len;
|
148
|
+
}
|
149
|
+
|
150
|
+
|
151
|
+
/* read a line from a file descriptor */
|
152
|
+
static char *mygetline(FILE *ifp){
|
153
|
+
int len = 0;
|
154
|
+
int blen = 1024;
|
155
|
+
char *buf = tcmalloc(blen);
|
156
|
+
bool end = true;
|
157
|
+
int c;
|
158
|
+
while((c = fgetc(ifp)) != EOF){
|
159
|
+
end = false;
|
160
|
+
if(c == '\0') continue;
|
161
|
+
if(blen <= len){
|
162
|
+
blen *= 2;
|
163
|
+
buf = tcrealloc(buf, blen + 1);
|
164
|
+
}
|
165
|
+
if(c == '\n' || c == '\r') c = '\0';
|
166
|
+
buf[len++] = c;
|
167
|
+
if(c == '\0') break;
|
168
|
+
}
|
169
|
+
if(end){
|
170
|
+
tcfree(buf);
|
171
|
+
return NULL;
|
172
|
+
}
|
173
|
+
buf[len] = '\0';
|
174
|
+
return buf;
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
/* parse arguments of create command */
|
179
|
+
static int runcreate(int argc, char **argv){
|
180
|
+
char *path = NULL;
|
181
|
+
char *bstr = NULL;
|
182
|
+
char *astr = NULL;
|
183
|
+
char *fstr = NULL;
|
184
|
+
int opts = 0;
|
185
|
+
for(int i = 2; i < argc; i++){
|
186
|
+
if(!path && argv[i][0] == '-'){
|
187
|
+
if(!strcmp(argv[i], "-tl")){
|
188
|
+
opts |= TDBTLARGE;
|
189
|
+
} else if(!strcmp(argv[i], "-td")){
|
190
|
+
opts |= TDBTDEFLATE;
|
191
|
+
} else if(!strcmp(argv[i], "-tb")){
|
192
|
+
opts |= TDBTBZIP;
|
193
|
+
} else if(!strcmp(argv[i], "-tt")){
|
194
|
+
opts |= TDBTTCBS;
|
195
|
+
} else if(!strcmp(argv[i], "-tx")){
|
196
|
+
opts |= TDBTEXCODEC;
|
197
|
+
} else {
|
198
|
+
usage();
|
199
|
+
}
|
200
|
+
} else if(!path){
|
201
|
+
path = argv[i];
|
202
|
+
} else if(!bstr){
|
203
|
+
bstr = argv[i];
|
204
|
+
} else if(!astr){
|
205
|
+
astr = argv[i];
|
206
|
+
} else if(!fstr){
|
207
|
+
fstr = argv[i];
|
208
|
+
} else {
|
209
|
+
usage();
|
210
|
+
}
|
211
|
+
}
|
212
|
+
if(!path) usage();
|
213
|
+
int bnum = bstr ? tcatoix(bstr) : -1;
|
214
|
+
int apow = astr ? tcatoix(astr) : -1;
|
215
|
+
int fpow = fstr ? tcatoix(fstr) : -1;
|
216
|
+
int rv = proccreate(path, bnum, apow, fpow, opts);
|
217
|
+
return rv;
|
218
|
+
}
|
219
|
+
|
220
|
+
|
221
|
+
/* parse arguments of inform command */
|
222
|
+
static int runinform(int argc, char **argv){
|
223
|
+
char *path = NULL;
|
224
|
+
int omode = 0;
|
225
|
+
for(int i = 2; i < argc; i++){
|
226
|
+
if(!path && argv[i][0] == '-'){
|
227
|
+
if(!strcmp(argv[i], "-nl")){
|
228
|
+
omode |= TDBONOLCK;
|
229
|
+
} else if(!strcmp(argv[i], "-nb")){
|
230
|
+
omode |= TDBOLCKNB;
|
231
|
+
} else {
|
232
|
+
usage();
|
233
|
+
}
|
234
|
+
} else if(!path){
|
235
|
+
path = argv[i];
|
236
|
+
} else {
|
237
|
+
usage();
|
238
|
+
}
|
239
|
+
}
|
240
|
+
if(!path) usage();
|
241
|
+
int rv = procinform(path, omode);
|
242
|
+
return rv;
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
/* parse arguments of put command */
|
247
|
+
static int runput(int argc, char **argv){
|
248
|
+
char *path = NULL;
|
249
|
+
char *pkey = NULL;
|
250
|
+
TCLIST *vals = tcmpoollistnew(tcmpoolglobal());
|
251
|
+
int omode = 0;
|
252
|
+
int dmode = 0;
|
253
|
+
bool sx = false;
|
254
|
+
for(int i = 2; i < argc; i++){
|
255
|
+
if(!path && argv[i][0] == '-'){
|
256
|
+
if(!strcmp(argv[i], "-nl")){
|
257
|
+
omode |= TDBONOLCK;
|
258
|
+
} else if(!strcmp(argv[i], "-nb")){
|
259
|
+
omode |= TDBOLCKNB;
|
260
|
+
} else if(!strcmp(argv[i], "-dk")){
|
261
|
+
dmode = -1;
|
262
|
+
} else if(!strcmp(argv[i], "-dc")){
|
263
|
+
dmode = 1;
|
264
|
+
} else if(!strcmp(argv[i], "-dai")){
|
265
|
+
dmode = 10;
|
266
|
+
} else if(!strcmp(argv[i], "-dad")){
|
267
|
+
dmode = 11;
|
268
|
+
} else if(!strcmp(argv[i], "-sx")){
|
269
|
+
sx = true;
|
270
|
+
} else {
|
271
|
+
usage();
|
272
|
+
}
|
273
|
+
} else if(!path){
|
274
|
+
path = argv[i];
|
275
|
+
} else if(!pkey){
|
276
|
+
pkey = argv[i];
|
277
|
+
} else {
|
278
|
+
tclistpush2(vals, argv[i]);
|
279
|
+
}
|
280
|
+
}
|
281
|
+
if(!path || !pkey) usage();
|
282
|
+
TCMAP *cols = tcmapnew();
|
283
|
+
char *pkbuf;
|
284
|
+
int pksiz;
|
285
|
+
if(sx){
|
286
|
+
pkbuf = tchexdecode(pkey, &pksiz);
|
287
|
+
for(int i = 0; i < tclistnum(vals) - 1; i += 2){
|
288
|
+
const char *name = tclistval2(vals, i);
|
289
|
+
const char *value = tclistval2(vals, i + 1);
|
290
|
+
int nsiz;
|
291
|
+
char *nbuf = tchexdecode(name, &nsiz);
|
292
|
+
int vsiz;
|
293
|
+
char *vbuf = tchexdecode(value, &vsiz);
|
294
|
+
tcmapput(cols, nbuf, nsiz, vbuf, vsiz);
|
295
|
+
tcfree(vbuf);
|
296
|
+
tcfree(nbuf);
|
297
|
+
}
|
298
|
+
} else {
|
299
|
+
pksiz = strlen(pkey);
|
300
|
+
pkbuf = tcmemdup(pkey, pksiz);
|
301
|
+
for(int i = 0; i < tclistnum(vals) - 1; i += 2){
|
302
|
+
const char *name = tclistval2(vals, i);
|
303
|
+
const char *value = tclistval2(vals, i + 1);
|
304
|
+
tcmapput2(cols, name, value);
|
305
|
+
}
|
306
|
+
}
|
307
|
+
int rv = procput(path, pkbuf, pksiz, cols, omode, dmode);
|
308
|
+
tcmapdel(cols);
|
309
|
+
tcfree(pkbuf);
|
310
|
+
return rv;
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
/* parse arguments of out command */
|
315
|
+
static int runout(int argc, char **argv){
|
316
|
+
char *path = NULL;
|
317
|
+
char *pkey = NULL;
|
318
|
+
int omode = 0;
|
319
|
+
bool sx = false;
|
320
|
+
for(int i = 2; i < argc; i++){
|
321
|
+
if(!path && argv[i][0] == '-'){
|
322
|
+
if(!strcmp(argv[i], "-nl")){
|
323
|
+
omode |= TDBONOLCK;
|
324
|
+
} else if(!strcmp(argv[i], "-nb")){
|
325
|
+
omode |= TDBOLCKNB;
|
326
|
+
} else if(!strcmp(argv[i], "-sx")){
|
327
|
+
sx = true;
|
328
|
+
} else {
|
329
|
+
usage();
|
330
|
+
}
|
331
|
+
} else if(!path){
|
332
|
+
path = argv[i];
|
333
|
+
} else if(!pkey){
|
334
|
+
pkey = argv[i];
|
335
|
+
} else {
|
336
|
+
usage();
|
337
|
+
}
|
338
|
+
}
|
339
|
+
if(!path || !pkey) usage();
|
340
|
+
int pksiz;
|
341
|
+
char *pkbuf;
|
342
|
+
if(sx){
|
343
|
+
pkbuf = tchexdecode(pkey, &pksiz);
|
344
|
+
} else {
|
345
|
+
pksiz = strlen(pkey);
|
346
|
+
pkbuf = tcmemdup(pkey, pksiz);
|
347
|
+
}
|
348
|
+
int rv = procout(path, pkbuf, pksiz, omode);
|
349
|
+
tcfree(pkbuf);
|
350
|
+
return rv;
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
/* parse arguments of get command */
|
355
|
+
static int runget(int argc, char **argv){
|
356
|
+
char *path = NULL;
|
357
|
+
char *pkey = NULL;
|
358
|
+
int omode = 0;
|
359
|
+
bool sx = false;
|
360
|
+
bool px = false;
|
361
|
+
bool pz = false;
|
362
|
+
for(int i = 2; i < argc; i++){
|
363
|
+
if(!path && argv[i][0] == '-'){
|
364
|
+
if(!strcmp(argv[i], "-nl")){
|
365
|
+
omode |= TDBONOLCK;
|
366
|
+
} else if(!strcmp(argv[i], "-nb")){
|
367
|
+
omode |= TDBOLCKNB;
|
368
|
+
} else if(!strcmp(argv[i], "-sx")){
|
369
|
+
sx = true;
|
370
|
+
} else if(!strcmp(argv[i], "-px")){
|
371
|
+
px = true;
|
372
|
+
} else if(!strcmp(argv[i], "-pz")){
|
373
|
+
pz = true;
|
374
|
+
} else {
|
375
|
+
usage();
|
376
|
+
}
|
377
|
+
} else if(!path){
|
378
|
+
path = argv[i];
|
379
|
+
} else if(!pkey){
|
380
|
+
pkey = argv[i];
|
381
|
+
} else {
|
382
|
+
usage();
|
383
|
+
}
|
384
|
+
}
|
385
|
+
if(!path || !pkey) usage();
|
386
|
+
int pksiz;
|
387
|
+
char *pkbuf;
|
388
|
+
if(sx){
|
389
|
+
pkbuf = tchexdecode(pkey, &pksiz);
|
390
|
+
} else {
|
391
|
+
pksiz = strlen(pkey);
|
392
|
+
pkbuf = tcmemdup(pkey, pksiz);
|
393
|
+
}
|
394
|
+
int rv = procget(path, pkbuf, pksiz, omode, px, pz);
|
395
|
+
tcfree(pkbuf);
|
396
|
+
return rv;
|
397
|
+
}
|
398
|
+
|
399
|
+
|
400
|
+
/* parse arguments of list command */
|
401
|
+
static int runlist(int argc, char **argv){
|
402
|
+
char *path = NULL;
|
403
|
+
int omode = 0;
|
404
|
+
int max = -1;
|
405
|
+
bool pv = false;
|
406
|
+
bool px = false;
|
407
|
+
char *fmstr = NULL;
|
408
|
+
for(int i = 2; i < argc; i++){
|
409
|
+
if(!path && argv[i][0] == '-'){
|
410
|
+
if(!strcmp(argv[i], "-nl")){
|
411
|
+
omode |= TDBONOLCK;
|
412
|
+
} else if(!strcmp(argv[i], "-nb")){
|
413
|
+
omode |= TDBOLCKNB;
|
414
|
+
} else if(!strcmp(argv[i], "-m")){
|
415
|
+
if(++i >= argc) usage();
|
416
|
+
max = tcatoix(argv[i]);
|
417
|
+
} else if(!strcmp(argv[i], "-pv")){
|
418
|
+
pv = true;
|
419
|
+
} else if(!strcmp(argv[i], "-px")){
|
420
|
+
px = true;
|
421
|
+
} else if(!strcmp(argv[i], "-fm")){
|
422
|
+
if(++i >= argc) usage();
|
423
|
+
fmstr = argv[i];
|
424
|
+
} else {
|
425
|
+
usage();
|
426
|
+
}
|
427
|
+
} else if(!path){
|
428
|
+
path = argv[i];
|
429
|
+
} else {
|
430
|
+
usage();
|
431
|
+
}
|
432
|
+
}
|
433
|
+
if(!path) usage();
|
434
|
+
int rv = proclist(path, omode, max, pv, px, fmstr);
|
435
|
+
return rv;
|
436
|
+
}
|
437
|
+
|
438
|
+
|
439
|
+
/* parse arguments of search command */
|
440
|
+
static int runsearch(int argc, char **argv){
|
441
|
+
char *path = NULL;
|
442
|
+
TCLIST *conds = tcmpoollistnew(tcmpoolglobal());
|
443
|
+
char *oname = NULL;
|
444
|
+
char *otype = NULL;
|
445
|
+
int omode = 0;
|
446
|
+
int max = -1;
|
447
|
+
int skip = -1;
|
448
|
+
bool pv = false;
|
449
|
+
bool px = false;
|
450
|
+
bool kw = false;
|
451
|
+
bool ph = false;
|
452
|
+
int bt = 0;
|
453
|
+
bool rm = false;
|
454
|
+
char *mtype = NULL;
|
455
|
+
for(int i = 2; i < argc; i++){
|
456
|
+
if(!path && argv[i][0] == '-'){
|
457
|
+
if(!strcmp(argv[i], "-nl")){
|
458
|
+
omode |= TDBONOLCK;
|
459
|
+
} else if(!strcmp(argv[i], "-nb")){
|
460
|
+
omode |= TDBOLCKNB;
|
461
|
+
} else if(!strcmp(argv[i], "-ord")){
|
462
|
+
if(++i >= argc) usage();
|
463
|
+
oname = argv[i];
|
464
|
+
if(++i >= argc) usage();
|
465
|
+
otype = argv[i];
|
466
|
+
} else if(!strcmp(argv[i], "-m")){
|
467
|
+
if(++i >= argc) usage();
|
468
|
+
max = tcatoix(argv[i]);
|
469
|
+
} else if(!strcmp(argv[i], "-sk")){
|
470
|
+
if(++i >= argc) usage();
|
471
|
+
skip = tcatoix(argv[i]);
|
472
|
+
} else if(!strcmp(argv[i], "-kw")){
|
473
|
+
kw = true;
|
474
|
+
} else if(!strcmp(argv[i], "-pv")){
|
475
|
+
pv = true;
|
476
|
+
} else if(!strcmp(argv[i], "-px")){
|
477
|
+
px = true;
|
478
|
+
} else if(!strcmp(argv[i], "-ph")){
|
479
|
+
ph = true;
|
480
|
+
} else if(!strcmp(argv[i], "-bt")){
|
481
|
+
if(++i >= argc) usage();
|
482
|
+
bt = tcatoix(argv[i]);
|
483
|
+
} else if(!strcmp(argv[i], "-rm")){
|
484
|
+
rm = true;
|
485
|
+
} else if(!strcmp(argv[i], "-ms")){
|
486
|
+
if(++i >= argc) usage();
|
487
|
+
mtype = argv[i];
|
488
|
+
} else {
|
489
|
+
usage();
|
490
|
+
}
|
491
|
+
} else if(!path){
|
492
|
+
path = argv[i];
|
493
|
+
} else {
|
494
|
+
tclistpush2(conds, argv[i]);
|
495
|
+
}
|
496
|
+
}
|
497
|
+
if(!path || tclistnum(conds) % 3 != 0) usage();
|
498
|
+
int rv = procsearch(path, conds, oname, otype, omode, max, skip,
|
499
|
+
pv, px, kw, ph, bt, rm, mtype);
|
500
|
+
return rv;
|
501
|
+
}
|
502
|
+
|
503
|
+
|
504
|
+
/* parse arguments of optimize command */
|
505
|
+
static int runoptimize(int argc, char **argv){
|
506
|
+
char *path = NULL;
|
507
|
+
char *bstr = NULL;
|
508
|
+
char *astr = NULL;
|
509
|
+
char *fstr = NULL;
|
510
|
+
int opts = UINT8_MAX;
|
511
|
+
int omode = 0;
|
512
|
+
bool df = false;
|
513
|
+
for(int i = 2; i < argc; i++){
|
514
|
+
if(!path && argv[i][0] == '-'){
|
515
|
+
if(!strcmp(argv[i], "-tl")){
|
516
|
+
if(opts == UINT8_MAX) opts = 0;
|
517
|
+
opts |= TDBTLARGE;
|
518
|
+
} else if(!strcmp(argv[i], "-td")){
|
519
|
+
if(opts == UINT8_MAX) opts = 0;
|
520
|
+
opts |= TDBTDEFLATE;
|
521
|
+
} else if(!strcmp(argv[i], "-tb")){
|
522
|
+
if(opts == UINT8_MAX) opts = 0;
|
523
|
+
opts |= TDBTBZIP;
|
524
|
+
} else if(!strcmp(argv[i], "-tt")){
|
525
|
+
if(opts == UINT8_MAX) opts = 0;
|
526
|
+
opts |= TDBTTCBS;
|
527
|
+
} else if(!strcmp(argv[i], "-tx")){
|
528
|
+
if(opts == UINT8_MAX) opts = 0;
|
529
|
+
opts |= TDBTEXCODEC;
|
530
|
+
} else if(!strcmp(argv[i], "-tz")){
|
531
|
+
if(opts == UINT8_MAX) opts = 0;
|
532
|
+
} else if(!strcmp(argv[i], "-nl")){
|
533
|
+
omode |= TDBONOLCK;
|
534
|
+
} else if(!strcmp(argv[i], "-nb")){
|
535
|
+
omode |= TDBOLCKNB;
|
536
|
+
} else if(!strcmp(argv[i], "-df")){
|
537
|
+
df = true;
|
538
|
+
} else {
|
539
|
+
usage();
|
540
|
+
}
|
541
|
+
} else if(!path){
|
542
|
+
path = argv[i];
|
543
|
+
} else if(!bstr){
|
544
|
+
bstr = argv[i];
|
545
|
+
} else if(!astr){
|
546
|
+
astr = argv[i];
|
547
|
+
} else if(!fstr){
|
548
|
+
fstr = argv[i];
|
549
|
+
} else {
|
550
|
+
usage();
|
551
|
+
}
|
552
|
+
}
|
553
|
+
if(!path) usage();
|
554
|
+
int bnum = bstr ? tcatoix(bstr) : -1;
|
555
|
+
int apow = astr ? tcatoix(astr) : -1;
|
556
|
+
int fpow = fstr ? tcatoix(fstr) : -1;
|
557
|
+
int rv = procoptimize(path, bnum, apow, fpow, opts, omode, df);
|
558
|
+
return rv;
|
559
|
+
}
|
560
|
+
|
561
|
+
|
562
|
+
/* parse arguments of setindex command */
|
563
|
+
static int runsetindex(int argc, char **argv){
|
564
|
+
char *path = NULL;
|
565
|
+
char *name = NULL;
|
566
|
+
int omode = 0;
|
567
|
+
int type = TDBITLEXICAL;
|
568
|
+
for(int i = 2; i < argc; i++){
|
569
|
+
if(!path && argv[i][0] == '-'){
|
570
|
+
if(!strcmp(argv[i], "-nl")){
|
571
|
+
omode |= TDBONOLCK;
|
572
|
+
} else if(!strcmp(argv[i], "-nb")){
|
573
|
+
omode |= TDBOLCKNB;
|
574
|
+
} else if(!strcmp(argv[i], "-it")){
|
575
|
+
if(++i >= argc) usage();
|
576
|
+
type = tctdbstrtoindextype(argv[i]);
|
577
|
+
} else {
|
578
|
+
usage();
|
579
|
+
}
|
580
|
+
} else if(!path){
|
581
|
+
path = argv[i];
|
582
|
+
} else if(!name){
|
583
|
+
name = argv[i];
|
584
|
+
} else {
|
585
|
+
usage();
|
586
|
+
}
|
587
|
+
}
|
588
|
+
if(!path || !name) usage();
|
589
|
+
if(type < 0) usage();
|
590
|
+
int rv = procsetindex(path, name, omode, type);
|
591
|
+
return rv;
|
592
|
+
}
|
593
|
+
|
594
|
+
|
595
|
+
/* parse arguments of importtsv command */
|
596
|
+
static int runimporttsv(int argc, char **argv){
|
597
|
+
char *path = NULL;
|
598
|
+
char *file = NULL;
|
599
|
+
int omode = 0;
|
600
|
+
bool sc = false;
|
601
|
+
for(int i = 2; i < argc; i++){
|
602
|
+
if(!path && argv[i][0] == '-'){
|
603
|
+
if(!strcmp(argv[i], "-nl")){
|
604
|
+
omode |= TDBONOLCK;
|
605
|
+
} else if(!strcmp(argv[i], "-nb")){
|
606
|
+
omode |= TDBOLCKNB;
|
607
|
+
} else if(!strcmp(argv[i], "-sc")){
|
608
|
+
sc = true;
|
609
|
+
} else {
|
610
|
+
usage();
|
611
|
+
}
|
612
|
+
} else if(!path){
|
613
|
+
path = argv[i];
|
614
|
+
} else if(!file){
|
615
|
+
file = argv[i];
|
616
|
+
} else {
|
617
|
+
usage();
|
618
|
+
}
|
619
|
+
}
|
620
|
+
if(!path) usage();
|
621
|
+
int rv = procimporttsv(path, file, omode, sc);
|
622
|
+
return rv;
|
623
|
+
}
|
624
|
+
|
625
|
+
|
626
|
+
/* parse arguments of version command */
|
627
|
+
static int runversion(int argc, char **argv){
|
628
|
+
int rv = procversion();
|
629
|
+
return rv;
|
630
|
+
}
|
631
|
+
|
632
|
+
|
633
|
+
/* perform create command */
|
634
|
+
static int proccreate(const char *path, int bnum, int apow, int fpow, int opts){
|
635
|
+
TCTDB *tdb = tctdbnew();
|
636
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
637
|
+
if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
|
638
|
+
if(!tctdbtune(tdb, bnum, apow, fpow, opts)){
|
639
|
+
printerr(tdb);
|
640
|
+
tctdbdel(tdb);
|
641
|
+
return 1;
|
642
|
+
}
|
643
|
+
if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | TDBOTRUNC)){
|
644
|
+
printerr(tdb);
|
645
|
+
tctdbdel(tdb);
|
646
|
+
return 1;
|
647
|
+
}
|
648
|
+
bool err = false;
|
649
|
+
if(!tctdbclose(tdb)){
|
650
|
+
printerr(tdb);
|
651
|
+
err = true;
|
652
|
+
}
|
653
|
+
tctdbdel(tdb);
|
654
|
+
return err ? 1 : 0;
|
655
|
+
}
|
656
|
+
|
657
|
+
|
658
|
+
/* perform inform command */
|
659
|
+
static int procinform(const char *path, int omode){
|
660
|
+
TCTDB *tdb = tctdbnew();
|
661
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
662
|
+
tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL);
|
663
|
+
if(!tctdbopen(tdb, path, TDBOREADER | omode)){
|
664
|
+
printerr(tdb);
|
665
|
+
tctdbdel(tdb);
|
666
|
+
return 1;
|
667
|
+
}
|
668
|
+
bool err = false;
|
669
|
+
const char *npath = tctdbpath(tdb);
|
670
|
+
if(!npath) npath = "(unknown)";
|
671
|
+
printf("path: %s\n", npath);
|
672
|
+
printf("database type: table\n");
|
673
|
+
uint8_t flags = tctdbflags(tdb);
|
674
|
+
printf("additional flags:");
|
675
|
+
if(flags & TDBFOPEN) printf(" open");
|
676
|
+
if(flags & TDBFFATAL) printf(" fatal");
|
677
|
+
printf("\n");
|
678
|
+
printf("bucket number: %llu\n", (unsigned long long)tctdbbnum(tdb));
|
679
|
+
if(tdb->hdb->cnt_writerec >= 0)
|
680
|
+
printf("used bucket number: %lld\n", (long long)tctdbbnumused(tdb));
|
681
|
+
printf("alignment: %u\n", tctdbalign(tdb));
|
682
|
+
printf("free block pool: %u\n", tctdbfbpmax(tdb));
|
683
|
+
printf("index number: %d\n", tctdbinum(tdb));
|
684
|
+
TDBIDX *idxs = tdb->idxs;
|
685
|
+
int inum = tdb->inum;
|
686
|
+
for(int i = 0; i < inum; i++){
|
687
|
+
TDBIDX *idxp = idxs + i;
|
688
|
+
switch(idxp->type){
|
689
|
+
case TDBITLEXICAL:
|
690
|
+
printf(" name=%s, type=lexical, rnum=%lld, fsiz=%lld\n",
|
691
|
+
idxp->name, (long long)tcbdbrnum(idxp->db), (long long)tcbdbfsiz(idxp->db));
|
692
|
+
break;
|
693
|
+
case TDBITDECIMAL:
|
694
|
+
printf(" name=%s, type=decimal, rnum=%lld, fsiz=%lld\n",
|
695
|
+
idxp->name, (long long)tcbdbrnum(idxp->db), (long long)tcbdbfsiz(idxp->db));
|
696
|
+
break;
|
697
|
+
case TDBITTOKEN:
|
698
|
+
printf(" name=%s, type=token, rnum=%lld, fsiz=%lld\n",
|
699
|
+
idxp->name, (long long)tcbdbrnum(idxp->db), (long long)tcbdbfsiz(idxp->db));
|
700
|
+
break;
|
701
|
+
case TDBITQGRAM:
|
702
|
+
printf(" name=%s, type=qgram, rnum=%lld, fsiz=%lld\n",
|
703
|
+
idxp->name, (long long)tcbdbrnum(idxp->db), (long long)tcbdbfsiz(idxp->db));
|
704
|
+
break;
|
705
|
+
}
|
706
|
+
}
|
707
|
+
printf("unique ID seed: %lld\n", (long long)tctdbuidseed(tdb));
|
708
|
+
printf("inode number: %lld\n", (long long)tctdbinode(tdb));
|
709
|
+
char date[48];
|
710
|
+
tcdatestrwww(tctdbmtime(tdb), INT_MAX, date);
|
711
|
+
printf("modified time: %s\n", date);
|
712
|
+
uint8_t opts = tctdbopts(tdb);
|
713
|
+
printf("options:");
|
714
|
+
if(opts & TDBTLARGE) printf(" large");
|
715
|
+
if(opts & TDBTDEFLATE) printf(" deflate");
|
716
|
+
if(opts & TDBTBZIP) printf(" bzip");
|
717
|
+
if(opts & TDBTTCBS) printf(" tcbs");
|
718
|
+
if(opts & TDBTEXCODEC) printf(" excodec");
|
719
|
+
printf("\n");
|
720
|
+
printf("record number: %llu\n", (unsigned long long)tctdbrnum(tdb));
|
721
|
+
printf("file size: %llu\n", (unsigned long long)tctdbfsiz(tdb));
|
722
|
+
if(!tctdbclose(tdb)){
|
723
|
+
if(!err) printerr(tdb);
|
724
|
+
err = true;
|
725
|
+
}
|
726
|
+
tctdbdel(tdb);
|
727
|
+
return err ? 1 : 0;
|
728
|
+
}
|
729
|
+
|
730
|
+
|
731
|
+
/* perform put command */
|
732
|
+
static int procput(const char *path, const char *pkbuf, int pksiz, TCMAP *cols,
|
733
|
+
int omode, int dmode){
|
734
|
+
TCTDB *tdb = tctdbnew();
|
735
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
736
|
+
if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
|
737
|
+
if(!tctdbopen(tdb, path, TDBOWRITER | omode)){
|
738
|
+
printerr(tdb);
|
739
|
+
tctdbdel(tdb);
|
740
|
+
return 1;
|
741
|
+
}
|
742
|
+
bool err = false;
|
743
|
+
char pknumbuf[TCNUMBUFSIZ];
|
744
|
+
if(pksiz < 1){
|
745
|
+
pksiz = sprintf(pknumbuf, "%lld", (long long)tctdbgenuid(tdb));
|
746
|
+
pkbuf = pknumbuf;
|
747
|
+
}
|
748
|
+
const char *vbuf;
|
749
|
+
switch(dmode){
|
750
|
+
case -1:
|
751
|
+
if(!tctdbputkeep(tdb, pkbuf, pksiz, cols)){
|
752
|
+
printerr(tdb);
|
753
|
+
err = true;
|
754
|
+
}
|
755
|
+
break;
|
756
|
+
case 1:
|
757
|
+
if(!tctdbputcat(tdb, pkbuf, pksiz, cols)){
|
758
|
+
printerr(tdb);
|
759
|
+
err = true;
|
760
|
+
}
|
761
|
+
break;
|
762
|
+
case 10:
|
763
|
+
vbuf = tcmapget2(cols, "_num");
|
764
|
+
if(!vbuf) vbuf = "1";
|
765
|
+
if(tctdbaddint(tdb, pkbuf, pksiz, tcatoi(vbuf)) == INT_MIN){
|
766
|
+
printerr(tdb);
|
767
|
+
err = true;
|
768
|
+
}
|
769
|
+
break;
|
770
|
+
case 11:
|
771
|
+
vbuf = tcmapget2(cols, "_num");
|
772
|
+
if(!vbuf) vbuf = "1.0";
|
773
|
+
if(isnan(tctdbadddouble(tdb, pkbuf, pksiz, tcatof(vbuf)))){
|
774
|
+
printerr(tdb);
|
775
|
+
err = true;
|
776
|
+
}
|
777
|
+
break;
|
778
|
+
default:
|
779
|
+
if(!tctdbput(tdb, pkbuf, pksiz, cols)){
|
780
|
+
printerr(tdb);
|
781
|
+
err = true;
|
782
|
+
}
|
783
|
+
break;
|
784
|
+
}
|
785
|
+
if(!tctdbclose(tdb)){
|
786
|
+
if(!err) printerr(tdb);
|
787
|
+
err = true;
|
788
|
+
}
|
789
|
+
tctdbdel(tdb);
|
790
|
+
return err ? 1 : 0;
|
791
|
+
}
|
792
|
+
|
793
|
+
|
794
|
+
/* perform out command */
|
795
|
+
static int procout(const char *path, const char *pkbuf, int pksiz, int omode){
|
796
|
+
TCTDB *tdb = tctdbnew();
|
797
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
798
|
+
if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
|
799
|
+
if(!tctdbopen(tdb, path, TDBOWRITER | omode)){
|
800
|
+
printerr(tdb);
|
801
|
+
tctdbdel(tdb);
|
802
|
+
return 1;
|
803
|
+
}
|
804
|
+
bool err = false;
|
805
|
+
if(!tctdbout(tdb, pkbuf, pksiz)){
|
806
|
+
printerr(tdb);
|
807
|
+
err = true;
|
808
|
+
}
|
809
|
+
if(!tctdbclose(tdb)){
|
810
|
+
if(!err) printerr(tdb);
|
811
|
+
err = true;
|
812
|
+
}
|
813
|
+
tctdbdel(tdb);
|
814
|
+
return err ? 1 : 0;
|
815
|
+
}
|
816
|
+
|
817
|
+
|
818
|
+
/* perform get command */
|
819
|
+
static int procget(const char *path, const char *pkbuf, int pksiz, int omode, bool px, bool pz){
|
820
|
+
TCTDB *tdb = tctdbnew();
|
821
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
822
|
+
if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
|
823
|
+
if(!tctdbopen(tdb, path, TDBOREADER | omode)){
|
824
|
+
printerr(tdb);
|
825
|
+
tctdbdel(tdb);
|
826
|
+
return 1;
|
827
|
+
}
|
828
|
+
bool err = false;
|
829
|
+
TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
|
830
|
+
if(cols){
|
831
|
+
tcmapiterinit(cols);
|
832
|
+
const char *kbuf;
|
833
|
+
int ksiz;
|
834
|
+
while((kbuf = tcmapiternext(cols, &ksiz)) != NULL){
|
835
|
+
int vsiz;
|
836
|
+
const char *vbuf = tcmapiterval(kbuf, &vsiz);
|
837
|
+
printdata(kbuf, ksiz, px);
|
838
|
+
putchar('\t');
|
839
|
+
printdata(vbuf, vsiz, px);
|
840
|
+
putchar(pz ? '\t' : '\n');
|
841
|
+
}
|
842
|
+
tcmapdel(cols);
|
843
|
+
} else {
|
844
|
+
printerr(tdb);
|
845
|
+
err = true;
|
846
|
+
}
|
847
|
+
if(!tctdbclose(tdb)){
|
848
|
+
if(!err) printerr(tdb);
|
849
|
+
err = true;
|
850
|
+
}
|
851
|
+
tctdbdel(tdb);
|
852
|
+
return err ? 1 : 0;
|
853
|
+
}
|
854
|
+
|
855
|
+
|
856
|
+
/* perform list command */
|
857
|
+
static int proclist(const char *path, int omode, int max, bool pv, bool px, const char *fmstr){
|
858
|
+
TCTDB *tdb = tctdbnew();
|
859
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
860
|
+
if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
|
861
|
+
if(!tctdbopen(tdb, path, TDBOREADER | omode)){
|
862
|
+
printerr(tdb);
|
863
|
+
tctdbdel(tdb);
|
864
|
+
return 1;
|
865
|
+
}
|
866
|
+
bool err = false;
|
867
|
+
if(fmstr){
|
868
|
+
TCLIST *pkeys = tctdbfwmkeys2(tdb, fmstr, max);
|
869
|
+
for(int i = 0; i < tclistnum(pkeys); i++){
|
870
|
+
int pksiz;
|
871
|
+
const char *pkbuf = tclistval(pkeys, i, &pksiz);
|
872
|
+
printdata(pkbuf, pksiz, px);
|
873
|
+
if(pv){
|
874
|
+
TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
|
875
|
+
if(cols){
|
876
|
+
tcmapiterinit(cols);
|
877
|
+
const char *kbuf;
|
878
|
+
int ksiz;
|
879
|
+
while((kbuf = tcmapiternext(cols, &ksiz)) != NULL){
|
880
|
+
int vsiz;
|
881
|
+
const char *vbuf = tcmapiterval(kbuf, &vsiz);
|
882
|
+
putchar('\t');
|
883
|
+
printdata(kbuf, ksiz, px);
|
884
|
+
putchar('\t');
|
885
|
+
printdata(vbuf, vsiz, px);
|
886
|
+
}
|
887
|
+
tcmapdel(cols);
|
888
|
+
}
|
889
|
+
}
|
890
|
+
putchar('\n');
|
891
|
+
}
|
892
|
+
tclistdel(pkeys);
|
893
|
+
} else {
|
894
|
+
if(!tctdbiterinit(tdb)){
|
895
|
+
printerr(tdb);
|
896
|
+
err = true;
|
897
|
+
}
|
898
|
+
int cnt = 0;
|
899
|
+
TCMAP *cols;
|
900
|
+
while((cols = tctdbiternext3(tdb)) != NULL){
|
901
|
+
int pksiz;
|
902
|
+
const char *pkbuf = tcmapget(cols, "", 0, &pksiz);
|
903
|
+
if(pkbuf){
|
904
|
+
printdata(pkbuf, pksiz, px);
|
905
|
+
if(pv){
|
906
|
+
tcmapiterinit(cols);
|
907
|
+
const char *kbuf;
|
908
|
+
int ksiz;
|
909
|
+
while((kbuf = tcmapiternext(cols, &ksiz)) != NULL){
|
910
|
+
if(*kbuf == '\0') continue;
|
911
|
+
int vsiz;
|
912
|
+
const char *vbuf = tcmapiterval(kbuf, &vsiz);
|
913
|
+
putchar('\t');
|
914
|
+
printdata(kbuf, ksiz, px);
|
915
|
+
putchar('\t');
|
916
|
+
printdata(vbuf, vsiz, px);
|
917
|
+
}
|
918
|
+
}
|
919
|
+
}
|
920
|
+
tcmapdel(cols);
|
921
|
+
putchar('\n');
|
922
|
+
if(max >= 0 && ++cnt >= max) break;
|
923
|
+
}
|
924
|
+
}
|
925
|
+
if(!tctdbclose(tdb)){
|
926
|
+
if(!err) printerr(tdb);
|
927
|
+
err = true;
|
928
|
+
}
|
929
|
+
tctdbdel(tdb);
|
930
|
+
return err ? 1 : 0;
|
931
|
+
}
|
932
|
+
|
933
|
+
|
934
|
+
/* perform search command */
|
935
|
+
static int procsearch(const char *path, TCLIST *conds, const char *oname, const char *otype,
|
936
|
+
int omode, int max, int skip, bool pv, bool px, bool kw, bool ph, int bt,
|
937
|
+
bool rm, const char *mtype){
|
938
|
+
TCTDB *tdb = tctdbnew();
|
939
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
940
|
+
if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
|
941
|
+
if(!tctdbopen(tdb, path, (rm ? TDBOWRITER : TDBOREADER) | omode)){
|
942
|
+
printerr(tdb);
|
943
|
+
tctdbdel(tdb);
|
944
|
+
return 1;
|
945
|
+
}
|
946
|
+
bool err = false;
|
947
|
+
TDBQRY *qry = tctdbqrynew(tdb);
|
948
|
+
int cnum = tclistnum(conds);
|
949
|
+
for(int i = 0; i < cnum - 2; i += 3){
|
950
|
+
const char *name = tclistval2(conds, i);
|
951
|
+
const char *opstr = tclistval2(conds, i + 1);
|
952
|
+
const char *expr = tclistval2(conds, i + 2);
|
953
|
+
int op = tctdbqrystrtocondop(opstr);
|
954
|
+
if(op >= 0) tctdbqryaddcond(qry, name, op, expr);
|
955
|
+
}
|
956
|
+
if(oname){
|
957
|
+
int type = tctdbqrystrtoordertype(otype);
|
958
|
+
if(type >= 0) tctdbqrysetorder(qry, oname, type);
|
959
|
+
}
|
960
|
+
tctdbqrysetlimit(qry, max, skip);
|
961
|
+
if(rm){
|
962
|
+
double stime = tctime();
|
963
|
+
if(!tctdbqrysearchout(qry)){
|
964
|
+
printerr(tdb);
|
965
|
+
err = true;
|
966
|
+
}
|
967
|
+
double etime = tctime();
|
968
|
+
if(ph){
|
969
|
+
TCLIST *hints = tcstrsplit(tctdbqryhint(qry), "\n");
|
970
|
+
int hnum = tclistnum(hints);
|
971
|
+
for(int i = 0; i < hnum; i++){
|
972
|
+
const char *hint = tclistval2(hints, i);
|
973
|
+
if(*hint == '\0') continue;
|
974
|
+
printf("\t:::: %s\n", hint);
|
975
|
+
}
|
976
|
+
tclistdel(hints);
|
977
|
+
printf("\t:::: number of records: %d\n", tctdbqrycount(qry));
|
978
|
+
printf("\t:::: elapsed time: %.5f\n", etime - stime);
|
979
|
+
}
|
980
|
+
} else if(bt > 0){
|
981
|
+
double sum = 0;
|
982
|
+
for(int i = 1; i <= bt; i++){
|
983
|
+
double stime = tctime();
|
984
|
+
TCLIST *res = tctdbqrysearch(qry);
|
985
|
+
double etime = tctime();
|
986
|
+
tclistdel(res);
|
987
|
+
printf("%d: %.5f sec.\n", i, etime - stime);
|
988
|
+
sum += etime - stime;
|
989
|
+
}
|
990
|
+
printf("----\n");
|
991
|
+
printf("total: %.5f sec. (%.5f s/q = %.5f q/s)\n", sum, sum / bt, bt / sum);
|
992
|
+
} else {
|
993
|
+
double stime = tctime();
|
994
|
+
TCLIST *res;
|
995
|
+
TCLIST *hints;
|
996
|
+
int count;
|
997
|
+
int mtnum = mtype ? tctdbmetastrtosettype(mtype) : -1;
|
998
|
+
if(mtnum >= 0){
|
999
|
+
TDBQRY *qrys[cnum/3+1];
|
1000
|
+
int qnum = 0;
|
1001
|
+
for(int i = 0; i < cnum - 2; i += 3){
|
1002
|
+
const char *name = tclistval2(conds, i);
|
1003
|
+
const char *opstr = tclistval2(conds, i + 1);
|
1004
|
+
const char *expr = tclistval2(conds, i + 2);
|
1005
|
+
int op = tctdbqrystrtocondop(opstr);
|
1006
|
+
if(op >= 0){
|
1007
|
+
qrys[qnum] = tctdbqrynew(tdb);
|
1008
|
+
tctdbqryaddcond(qrys[qnum], name, op, expr);
|
1009
|
+
if(oname){
|
1010
|
+
int type = tctdbqrystrtoordertype(otype);
|
1011
|
+
if(type >= 0) tctdbqrysetorder(qrys[qnum], oname, type);
|
1012
|
+
}
|
1013
|
+
tctdbqrysetlimit(qrys[qnum], max, skip);
|
1014
|
+
qnum++;
|
1015
|
+
}
|
1016
|
+
}
|
1017
|
+
res = tctdbmetasearch(qrys, qnum, mtnum);
|
1018
|
+
hints = qnum > 0 ? tcstrsplit(tctdbqryhint(qrys[0]), "\n") : tclistnew2(1);
|
1019
|
+
count = qnum > 0 ? tctdbqrycount(qrys[0]) : 0;
|
1020
|
+
for(int i = 0; i < qnum; i++){
|
1021
|
+
tctdbqrydel(qrys[i]);
|
1022
|
+
}
|
1023
|
+
} else {
|
1024
|
+
res = tctdbqrysearch(qry);
|
1025
|
+
hints = tcstrsplit(tctdbqryhint(qry), "\n");
|
1026
|
+
count = tctdbqrycount(qry);
|
1027
|
+
}
|
1028
|
+
double etime = tctime();
|
1029
|
+
if(max < 0) max = INT_MAX;
|
1030
|
+
int rnum = tclistnum(res);
|
1031
|
+
for(int i = 0; i < rnum && max > 0; i++){
|
1032
|
+
int pksiz;
|
1033
|
+
const char *pkbuf = tclistval(res, i, &pksiz);
|
1034
|
+
if(kw){
|
1035
|
+
TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
|
1036
|
+
if(cols){
|
1037
|
+
TCLIST *texts = tctdbqrykwic(qry, cols, NULL, 16, TCKWMUTAB);
|
1038
|
+
int tnum = tclistnum(texts);
|
1039
|
+
for(int j = 0; j < tnum && max > 0; j++){
|
1040
|
+
int tsiz;
|
1041
|
+
const char *text = tclistval(texts, j, &tsiz);
|
1042
|
+
printdata(pkbuf, pksiz, px);
|
1043
|
+
putchar('\t');
|
1044
|
+
printdata(text, tsiz, px);
|
1045
|
+
putchar('\n');
|
1046
|
+
max--;
|
1047
|
+
}
|
1048
|
+
tclistdel(texts);
|
1049
|
+
tcmapdel(cols);
|
1050
|
+
}
|
1051
|
+
} else {
|
1052
|
+
printdata(pkbuf, pksiz, px);
|
1053
|
+
if(pv){
|
1054
|
+
TCMAP *cols = tctdbget(tdb, pkbuf, pksiz);
|
1055
|
+
if(cols){
|
1056
|
+
tcmapiterinit(cols);
|
1057
|
+
const char *kbuf;
|
1058
|
+
int ksiz;
|
1059
|
+
while((kbuf = tcmapiternext(cols, &ksiz)) != NULL){
|
1060
|
+
int vsiz;
|
1061
|
+
const char *vbuf = tcmapiterval(kbuf, &vsiz);
|
1062
|
+
putchar('\t');
|
1063
|
+
printdata(kbuf, ksiz, px);
|
1064
|
+
putchar('\t');
|
1065
|
+
printdata(vbuf, vsiz, px);
|
1066
|
+
}
|
1067
|
+
tcmapdel(cols);
|
1068
|
+
}
|
1069
|
+
}
|
1070
|
+
putchar('\n');
|
1071
|
+
max--;
|
1072
|
+
}
|
1073
|
+
}
|
1074
|
+
if(ph){
|
1075
|
+
int hnum = tclistnum(hints);
|
1076
|
+
for(int i = 0; i < hnum; i++){
|
1077
|
+
const char *hint = tclistval2(hints, i);
|
1078
|
+
if(*hint == '\0') continue;
|
1079
|
+
printf("\t:::: %s\n", hint);
|
1080
|
+
}
|
1081
|
+
printf("\t:::: number of records: %d\n", count);
|
1082
|
+
printf("\t:::: elapsed time: %.5f\n", etime - stime);
|
1083
|
+
}
|
1084
|
+
tclistdel(hints);
|
1085
|
+
tclistdel(res);
|
1086
|
+
}
|
1087
|
+
tctdbqrydel(qry);
|
1088
|
+
if(!tctdbclose(tdb)){
|
1089
|
+
if(!err) printerr(tdb);
|
1090
|
+
err = true;
|
1091
|
+
}
|
1092
|
+
tctdbdel(tdb);
|
1093
|
+
return err ? 1 : 0;
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
|
1097
|
+
/* perform optimize command */
|
1098
|
+
static int procoptimize(const char *path, int bnum, int apow, int fpow, int opts, int omode,
|
1099
|
+
bool df){
|
1100
|
+
TCTDB *tdb = tctdbnew();
|
1101
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
1102
|
+
if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
|
1103
|
+
int64_t msiz = 0;
|
1104
|
+
TCMAP *info = tcsysinfo();
|
1105
|
+
if(info){
|
1106
|
+
msiz = tcatoi(tcmapget4(info, "total", "0"));
|
1107
|
+
tcmapdel(info);
|
1108
|
+
}
|
1109
|
+
if(!tctdbsetinvcache(tdb, msiz >= (1 << 30) ? msiz / 4 : 0, 1.0)) printerr(tdb);
|
1110
|
+
if(!tctdbopen(tdb, path, TDBOWRITER | omode)){
|
1111
|
+
printerr(tdb);
|
1112
|
+
tctdbdel(tdb);
|
1113
|
+
return 1;
|
1114
|
+
}
|
1115
|
+
bool err = false;
|
1116
|
+
if(df){
|
1117
|
+
if(!tctdbdefrag(tdb, INT64_MAX)){
|
1118
|
+
printerr(tdb);
|
1119
|
+
err = true;
|
1120
|
+
}
|
1121
|
+
} else {
|
1122
|
+
if(!tctdboptimize(tdb, bnum, apow, fpow, opts)){
|
1123
|
+
printerr(tdb);
|
1124
|
+
err = true;
|
1125
|
+
}
|
1126
|
+
}
|
1127
|
+
if(!tctdbclose(tdb)){
|
1128
|
+
if(!err) printerr(tdb);
|
1129
|
+
err = true;
|
1130
|
+
}
|
1131
|
+
tctdbdel(tdb);
|
1132
|
+
return err ? 1 : 0;
|
1133
|
+
}
|
1134
|
+
|
1135
|
+
|
1136
|
+
/* perform setindex command */
|
1137
|
+
static int procsetindex(const char *path, const char *name, int omode, int type){
|
1138
|
+
TCTDB *tdb = tctdbnew();
|
1139
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
1140
|
+
if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
|
1141
|
+
int64_t msiz = 0;
|
1142
|
+
TCMAP *info = tcsysinfo();
|
1143
|
+
if(info){
|
1144
|
+
msiz = tcatoi(tcmapget4(info, "total", "0"));
|
1145
|
+
tcmapdel(info);
|
1146
|
+
}
|
1147
|
+
if(!tctdbsetinvcache(tdb, msiz >= (1 << 30) ? msiz / 4 : 0, 1.0)) printerr(tdb);
|
1148
|
+
if(!tctdbopen(tdb, path, TDBOWRITER | omode)){
|
1149
|
+
printerr(tdb);
|
1150
|
+
tctdbdel(tdb);
|
1151
|
+
return 1;
|
1152
|
+
}
|
1153
|
+
bool err = false;
|
1154
|
+
if(!tctdbsetindex(tdb, name, type)){
|
1155
|
+
printerr(tdb);
|
1156
|
+
err = true;
|
1157
|
+
}
|
1158
|
+
if(!tctdbclose(tdb)){
|
1159
|
+
if(!err) printerr(tdb);
|
1160
|
+
err = true;
|
1161
|
+
}
|
1162
|
+
tctdbdel(tdb);
|
1163
|
+
return err ? 1 : 0;
|
1164
|
+
}
|
1165
|
+
|
1166
|
+
|
1167
|
+
/* perform importtsv command */
|
1168
|
+
static int procimporttsv(const char *path, const char *file, int omode, bool sc){
|
1169
|
+
FILE *ifp = file ? fopen(file, "rb") : stdin;
|
1170
|
+
if(!ifp){
|
1171
|
+
fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
|
1172
|
+
return 1;
|
1173
|
+
}
|
1174
|
+
TCTDB *tdb = tctdbnew();
|
1175
|
+
if(g_dbgfd >= 0) tctdbsetdbgfd(tdb, g_dbgfd);
|
1176
|
+
if(!tctdbsetcodecfunc(tdb, _tc_recencode, NULL, _tc_recdecode, NULL)) printerr(tdb);
|
1177
|
+
int64_t msiz = 0;
|
1178
|
+
TCMAP *info = tcsysinfo();
|
1179
|
+
if(info){
|
1180
|
+
msiz = tcatoi(tcmapget4(info, "total", "0"));
|
1181
|
+
tcmapdel(info);
|
1182
|
+
}
|
1183
|
+
if(!tctdbsetinvcache(tdb, msiz >= (1 << 30) ? msiz / 4 : 0, 1.0)) printerr(tdb);
|
1184
|
+
if(!tctdbopen(tdb, path, TDBOWRITER | TDBOCREAT | omode)){
|
1185
|
+
printerr(tdb);
|
1186
|
+
tctdbdel(tdb);
|
1187
|
+
if(ifp != stdin) fclose(ifp);
|
1188
|
+
return 1;
|
1189
|
+
}
|
1190
|
+
bool err = false;
|
1191
|
+
char *line, numbuf[TCNUMBUFSIZ];
|
1192
|
+
int cnt = 0;
|
1193
|
+
while(!err && (line = mygetline(ifp)) != NULL){
|
1194
|
+
char *pv = strchr(line, '\t');
|
1195
|
+
if(!pv){
|
1196
|
+
tcfree(line);
|
1197
|
+
continue;
|
1198
|
+
}
|
1199
|
+
*pv = '\0';
|
1200
|
+
if(sc) tcstrutfnorm(line, TCUNSPACE | TCUNLOWER | TCUNNOACC | TCUNWIDTH);
|
1201
|
+
const char *pkey;
|
1202
|
+
if(*line == '\0'){
|
1203
|
+
sprintf(numbuf, "%lld", (long long)tctdbgenuid(tdb));
|
1204
|
+
pkey = numbuf;
|
1205
|
+
} else {
|
1206
|
+
pkey = line;
|
1207
|
+
}
|
1208
|
+
if(!tctdbput3(tdb, pkey, pv + 1)){
|
1209
|
+
printerr(tdb);
|
1210
|
+
err = true;
|
1211
|
+
}
|
1212
|
+
tcfree(line);
|
1213
|
+
if(cnt > 0 && cnt % 100 == 0){
|
1214
|
+
putchar('.');
|
1215
|
+
fflush(stdout);
|
1216
|
+
if(cnt % 5000 == 0) printf(" (%08d)\n", cnt);
|
1217
|
+
}
|
1218
|
+
cnt++;
|
1219
|
+
}
|
1220
|
+
printf(" (%08d)\n", cnt);
|
1221
|
+
if(!tctdbclose(tdb)){
|
1222
|
+
if(!err) printerr(tdb);
|
1223
|
+
err = true;
|
1224
|
+
}
|
1225
|
+
tctdbdel(tdb);
|
1226
|
+
if(ifp != stdin) fclose(ifp);
|
1227
|
+
return err ? 1 : 0;
|
1228
|
+
}
|
1229
|
+
|
1230
|
+
|
1231
|
+
/* perform version command */
|
1232
|
+
static int procversion(void){
|
1233
|
+
printf("Tokyo Cabinet version %s (%d:%s) for %s\n",
|
1234
|
+
tcversion, _TC_LIBVER, _TC_FORMATVER, TCSYSNAME);
|
1235
|
+
printf("Copyright (C) 2006-2009 Mikio Hirabayashi\n");
|
1236
|
+
return 0;
|
1237
|
+
}
|
1238
|
+
|
1239
|
+
|
1240
|
+
|
1241
|
+
// END OF FILE
|