heroku-tokyotyrant 0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (340) hide show
  1. data/COPYING +504 -0
  2. data/README.rdoc +231 -0
  3. data/Rakefile +72 -0
  4. data/benchmarks/balancer.rb +101 -0
  5. data/benchmarks/bulk_db.rb +74 -0
  6. data/benchmarks/bulk_table.rb +87 -0
  7. data/benchmarks/db.rb +114 -0
  8. data/benchmarks/table.rb +161 -0
  9. data/ext/extconf.rb +43 -0
  10. data/ext/tokyo/bin/tcamgr +0 -0
  11. data/ext/tokyo/bin/tcamttest +0 -0
  12. data/ext/tokyo/bin/tcatest +0 -0
  13. data/ext/tokyo/bin/tcbmgr +0 -0
  14. data/ext/tokyo/bin/tcbmttest +0 -0
  15. data/ext/tokyo/bin/tcbtest +0 -0
  16. data/ext/tokyo/bin/tcfmgr +0 -0
  17. data/ext/tokyo/bin/tcfmttest +0 -0
  18. data/ext/tokyo/bin/tcftest +0 -0
  19. data/ext/tokyo/bin/tchmgr +0 -0
  20. data/ext/tokyo/bin/tchmttest +0 -0
  21. data/ext/tokyo/bin/tchtest +0 -0
  22. data/ext/tokyo/bin/tcrmgr +0 -0
  23. data/ext/tokyo/bin/tcrmttest +0 -0
  24. data/ext/tokyo/bin/tcrtest +0 -0
  25. data/ext/tokyo/bin/tctmgr +0 -0
  26. data/ext/tokyo/bin/tctmttest +0 -0
  27. data/ext/tokyo/bin/tcttest +0 -0
  28. data/ext/tokyo/bin/tcucodec +0 -0
  29. data/ext/tokyo/bin/tcumttest +0 -0
  30. data/ext/tokyo/bin/tcutest +0 -0
  31. data/ext/tokyo/bin/ttserver +0 -0
  32. data/ext/tokyo/bin/ttulmgr +0 -0
  33. data/ext/tokyo/bin/ttultest +0 -0
  34. data/ext/tokyo/include/tcadb.h +548 -0
  35. data/ext/tokyo/include/tcbdb.h +1101 -0
  36. data/ext/tokyo/include/tcfdb.h +858 -0
  37. data/ext/tokyo/include/tchdb.h +871 -0
  38. data/ext/tokyo/include/tcrdb.h +801 -0
  39. data/ext/tokyo/include/tctdb.h +1086 -0
  40. data/ext/tokyo/include/tculog.h +392 -0
  41. data/ext/tokyo/include/tcutil.h +4184 -0
  42. data/ext/tokyo/include/ttutil.h +494 -0
  43. data/ext/tokyo/lib/libtokyocabinet.9.4.0.dylib +0 -0
  44. data/ext/tokyo/lib/libtokyocabinet.9.dylib +0 -0
  45. data/ext/tokyo/lib/libtokyocabinet.a +0 -0
  46. data/ext/tokyo/lib/libtokyocabinet.dylib +0 -0
  47. data/ext/tokyo/lib/libtokyotyrant.3.22.0.dylib +0 -0
  48. data/ext/tokyo/lib/libtokyotyrant.3.dylib +0 -0
  49. data/ext/tokyo/lib/libtokyotyrant.a +0 -0
  50. data/ext/tokyo/lib/libtokyotyrant.dylib +0 -0
  51. data/ext/tokyo/lib/pkgconfig/tokyocabinet.pc +14 -0
  52. data/ext/tokyo/lib/pkgconfig/tokyotyrant.pc +14 -0
  53. data/ext/tokyo/lib/ttskeldir.bundle +0 -0
  54. data/ext/tokyo/lib/ttskelmock.bundle +0 -0
  55. data/ext/tokyo/lib/ttskelnull.bundle +0 -0
  56. data/ext/tokyo/lib/ttskelproxy.bundle +0 -0
  57. data/ext/tokyo/libexec/tcawmgr.cgi +0 -0
  58. data/ext/tokyo/sbin/ttservctl +163 -0
  59. data/ext/tokyo/share/man/man1/tcamgr.1 +97 -0
  60. data/ext/tokyo/share/man/man1/tcamttest.1 +35 -0
  61. data/ext/tokyo/share/man/man1/tcatest.1 +55 -0
  62. data/ext/tokyo/share/man/man1/tcbmgr.1 +125 -0
  63. data/ext/tokyo/share/man/man1/tcbmttest.1 +81 -0
  64. data/ext/tokyo/share/man/man1/tcbtest.1 +107 -0
  65. data/ext/tokyo/share/man/man1/tcfmgr.1 +98 -0
  66. data/ext/tokyo/share/man/man1/tcfmttest.1 +62 -0
  67. data/ext/tokyo/share/man/man1/tcftest.1 +73 -0
  68. data/ext/tokyo/share/man/man1/tchmgr.1 +110 -0
  69. data/ext/tokyo/share/man/man1/tchmttest.1 +85 -0
  70. data/ext/tokyo/share/man/man1/tchtest.1 +95 -0
  71. data/ext/tokyo/share/man/man1/tcrmgr.1 +164 -0
  72. data/ext/tokyo/share/man/man1/tcrmttest.1 +55 -0
  73. data/ext/tokyo/share/man/man1/tcrtest.1 +89 -0
  74. data/ext/tokyo/share/man/man1/tctmgr.1 +140 -0
  75. data/ext/tokyo/share/man/man1/tctmttest.1 +92 -0
  76. data/ext/tokyo/share/man/man1/tcttest.1 +105 -0
  77. data/ext/tokyo/share/man/man1/tcucodec.1 +162 -0
  78. data/ext/tokyo/share/man/man1/tcumttest.1 +41 -0
  79. data/ext/tokyo/share/man/man1/tcutest.1 +81 -0
  80. data/ext/tokyo/share/man/man1/ttserver.1 +84 -0
  81. data/ext/tokyo/share/man/man1/ttulmgr.1 +40 -0
  82. data/ext/tokyo/share/man/man1/ttultest.1 +16 -0
  83. data/ext/tokyo/share/man/man3/tcadb.3 +676 -0
  84. data/ext/tokyo/share/man/man3/tcbdb.3 +1355 -0
  85. data/ext/tokyo/share/man/man3/tcfdb.3 +975 -0
  86. data/ext/tokyo/share/man/man3/tchdb.3 +898 -0
  87. data/ext/tokyo/share/man/man3/tclist.3 +1 -0
  88. data/ext/tokyo/share/man/man3/tcmap.3 +1 -0
  89. data/ext/tokyo/share/man/man3/tcmdb.3 +1 -0
  90. data/ext/tokyo/share/man/man3/tcmpool.3 +1 -0
  91. data/ext/tokyo/share/man/man3/tcrdb.3 +1309 -0
  92. data/ext/tokyo/share/man/man3/tctdb.3 +1110 -0
  93. data/ext/tokyo/share/man/man3/tctree.3 +1 -0
  94. data/ext/tokyo/share/man/man3/tculog.3 +15 -0
  95. data/ext/tokyo/share/man/man3/tcutil.3 +4518 -0
  96. data/ext/tokyo/share/man/man3/tcxstr.3 +1 -0
  97. data/ext/tokyo/share/man/man3/tokyocabinet.3 +132 -0
  98. data/ext/tokyo/share/man/man3/ttutil.3 +14 -0
  99. data/ext/tokyo/share/man/man8/ttservctl.8 +37 -0
  100. data/ext/tokyo/share/tokyocabinet/COPYING +504 -0
  101. data/ext/tokyo/share/tokyocabinet/ChangeLog +1252 -0
  102. data/ext/tokyo/share/tokyocabinet/THANKS +12 -0
  103. data/ext/tokyo/share/tokyocabinet/doc/benchmark.pdf +0 -0
  104. data/ext/tokyo/share/tokyocabinet/doc/common.css +211 -0
  105. data/ext/tokyo/share/tokyocabinet/doc/icon16.png +0 -0
  106. data/ext/tokyo/share/tokyocabinet/doc/index.html +156 -0
  107. data/ext/tokyo/share/tokyocabinet/doc/index.ja.html +197 -0
  108. data/ext/tokyo/share/tokyocabinet/doc/logo-ja.png +0 -0
  109. data/ext/tokyo/share/tokyocabinet/doc/logo.png +0 -0
  110. data/ext/tokyo/share/tokyocabinet/doc/spex-en.html +7145 -0
  111. data/ext/tokyo/share/tokyocabinet/doc/spex-ja.html +7476 -0
  112. data/ext/tokyo/share/tokyocabinet/doc/tokyoproducts.pdf +0 -0
  113. data/ext/tokyo/share/tokyocabinet/doc/tokyoproducts.ppt +0 -0
  114. data/ext/tokyo/share/tokyotyrant/COPYING +504 -0
  115. data/ext/tokyo/share/tokyotyrant/ChangeLog +578 -0
  116. data/ext/tokyo/share/tokyotyrant/THANKS +15 -0
  117. data/ext/tokyo/share/tokyotyrant/doc/common.css +211 -0
  118. data/ext/tokyo/share/tokyotyrant/doc/index.html +79 -0
  119. data/ext/tokyo/share/tokyotyrant/doc/spex.html +2264 -0
  120. data/ext/tokyo/share/tokyotyrant/ext/mapreduce.lua +57 -0
  121. data/ext/tokyo/share/tokyotyrant/ext/queue.lua +55 -0
  122. data/ext/tokyo/share/tokyotyrant/ext/senatus.lua +532 -0
  123. data/ext/tokyo/share/tokyotyrant/ext/usherette.lua +438 -0
  124. data/ext/tokyo_tyrant.c +147 -0
  125. data/ext/tokyo_tyrant.h +48 -0
  126. data/ext/tokyo_tyrant_db.c +227 -0
  127. data/ext/tokyo_tyrant_db.h +8 -0
  128. data/ext/tokyo_tyrant_module.c +453 -0
  129. data/ext/tokyo_tyrant_module.h +10 -0
  130. data/ext/tokyo_tyrant_query.c +226 -0
  131. data/ext/tokyo_tyrant_query.h +9 -0
  132. data/ext/tokyo_tyrant_table.c +319 -0
  133. data/ext/tokyo_tyrant_table.h +8 -0
  134. data/ext/tokyocabinet-1.4.41/COPYING +504 -0
  135. data/ext/tokyocabinet-1.4.41/ChangeLog +1252 -0
  136. data/ext/tokyocabinet-1.4.41/Makefile.in +825 -0
  137. data/ext/tokyocabinet-1.4.41/README +38 -0
  138. data/ext/tokyocabinet-1.4.41/THANKS +12 -0
  139. data/ext/tokyocabinet-1.4.41/bros/Makefile +133 -0
  140. data/ext/tokyocabinet-1.4.41/bros/bdbtest.c +438 -0
  141. data/ext/tokyocabinet-1.4.41/bros/cdbtest.c +219 -0
  142. data/ext/tokyocabinet-1.4.41/bros/cmpsqltctest.c +186 -0
  143. data/ext/tokyocabinet-1.4.41/bros/gdbmtest.c +216 -0
  144. data/ext/tokyocabinet-1.4.41/bros/mapreporter +72 -0
  145. data/ext/tokyocabinet-1.4.41/bros/maptest.cc +677 -0
  146. data/ext/tokyocabinet-1.4.41/bros/ndbmtest.c +204 -0
  147. data/ext/tokyocabinet-1.4.41/bros/qdbmtest.c +375 -0
  148. data/ext/tokyocabinet-1.4.41/bros/reporter +141 -0
  149. data/ext/tokyocabinet-1.4.41/bros/result.xls +0 -0
  150. data/ext/tokyocabinet-1.4.41/bros/sdbmtest.c +204 -0
  151. data/ext/tokyocabinet-1.4.41/bros/sqltest.c +404 -0
  152. data/ext/tokyocabinet-1.4.41/bros/tctest.c +748 -0
  153. data/ext/tokyocabinet-1.4.41/bros/tdbtest.c +205 -0
  154. data/ext/tokyocabinet-1.4.41/configure +7402 -0
  155. data/ext/tokyocabinet-1.4.41/configure.in +362 -0
  156. data/ext/tokyocabinet-1.4.41/doc/benchmark.pdf +0 -0
  157. data/ext/tokyocabinet-1.4.41/doc/common.css +211 -0
  158. data/ext/tokyocabinet-1.4.41/doc/icon16.png +0 -0
  159. data/ext/tokyocabinet-1.4.41/doc/index.html +156 -0
  160. data/ext/tokyocabinet-1.4.41/doc/index.ja.html +197 -0
  161. data/ext/tokyocabinet-1.4.41/doc/logo-ja.png +0 -0
  162. data/ext/tokyocabinet-1.4.41/doc/logo.png +0 -0
  163. data/ext/tokyocabinet-1.4.41/doc/spex-en.html +7145 -0
  164. data/ext/tokyocabinet-1.4.41/doc/spex-ja.html +7476 -0
  165. data/ext/tokyocabinet-1.4.41/doc/tokyoproducts.pdf +0 -0
  166. data/ext/tokyocabinet-1.4.41/doc/tokyoproducts.ppt +0 -0
  167. data/ext/tokyocabinet-1.4.41/example/Makefile +113 -0
  168. data/ext/tokyocabinet-1.4.41/example/tcadbex.c +55 -0
  169. data/ext/tokyocabinet-1.4.41/example/tcbdbex.c +64 -0
  170. data/ext/tokyocabinet-1.4.41/example/tcfdbex.c +60 -0
  171. data/ext/tokyocabinet-1.4.41/example/tchdbex.c +60 -0
  172. data/ext/tokyocabinet-1.4.41/example/tctchat.c +97 -0
  173. data/ext/tokyocabinet-1.4.41/example/tctchat.tmpl +141 -0
  174. data/ext/tokyocabinet-1.4.41/example/tctdbex.c +85 -0
  175. data/ext/tokyocabinet-1.4.41/example/tctsearch.c +95 -0
  176. data/ext/tokyocabinet-1.4.41/example/tctsearch.tmpl +122 -0
  177. data/ext/tokyocabinet-1.4.41/example/tcutilex.c +77 -0
  178. data/ext/tokyocabinet-1.4.41/f.tsv +2 -0
  179. data/ext/tokyocabinet-1.4.41/lab/calccomp +118 -0
  180. data/ext/tokyocabinet-1.4.41/lab/datechange +56 -0
  181. data/ext/tokyocabinet-1.4.41/lab/diffcheck +45 -0
  182. data/ext/tokyocabinet-1.4.41/lab/htmltotsv +102 -0
  183. data/ext/tokyocabinet-1.4.41/lab/magic +19 -0
  184. data/ext/tokyocabinet-1.4.41/lab/printenv.cgi +27 -0
  185. data/ext/tokyocabinet-1.4.41/lab/stepcount +26 -0
  186. data/ext/tokyocabinet-1.4.41/lab/stopwatch +61 -0
  187. data/ext/tokyocabinet-1.4.41/lab/tabcheck +43 -0
  188. data/ext/tokyocabinet-1.4.41/lab/wgettsv +239 -0
  189. data/ext/tokyocabinet-1.4.41/lab/widthcheck +57 -0
  190. data/ext/tokyocabinet-1.4.41/man/htmltoman +104 -0
  191. data/ext/tokyocabinet-1.4.41/man/tcadb.3 +676 -0
  192. data/ext/tokyocabinet-1.4.41/man/tcamgr.1 +97 -0
  193. data/ext/tokyocabinet-1.4.41/man/tcamttest.1 +35 -0
  194. data/ext/tokyocabinet-1.4.41/man/tcatest.1 +55 -0
  195. data/ext/tokyocabinet-1.4.41/man/tcbdb.3 +1355 -0
  196. data/ext/tokyocabinet-1.4.41/man/tcbmgr.1 +125 -0
  197. data/ext/tokyocabinet-1.4.41/man/tcbmttest.1 +81 -0
  198. data/ext/tokyocabinet-1.4.41/man/tcbtest.1 +107 -0
  199. data/ext/tokyocabinet-1.4.41/man/tcfdb.3 +975 -0
  200. data/ext/tokyocabinet-1.4.41/man/tcfmgr.1 +98 -0
  201. data/ext/tokyocabinet-1.4.41/man/tcfmttest.1 +62 -0
  202. data/ext/tokyocabinet-1.4.41/man/tcftest.1 +73 -0
  203. data/ext/tokyocabinet-1.4.41/man/tchdb.3 +898 -0
  204. data/ext/tokyocabinet-1.4.41/man/tchmgr.1 +110 -0
  205. data/ext/tokyocabinet-1.4.41/man/tchmttest.1 +85 -0
  206. data/ext/tokyocabinet-1.4.41/man/tchtest.1 +95 -0
  207. data/ext/tokyocabinet-1.4.41/man/tclist.3 +1 -0
  208. data/ext/tokyocabinet-1.4.41/man/tcmap.3 +1 -0
  209. data/ext/tokyocabinet-1.4.41/man/tcmdb.3 +1 -0
  210. data/ext/tokyocabinet-1.4.41/man/tcmpool.3 +1 -0
  211. data/ext/tokyocabinet-1.4.41/man/tctdb.3 +1110 -0
  212. data/ext/tokyocabinet-1.4.41/man/tctmgr.1 +140 -0
  213. data/ext/tokyocabinet-1.4.41/man/tctmttest.1 +92 -0
  214. data/ext/tokyocabinet-1.4.41/man/tctree.3 +1 -0
  215. data/ext/tokyocabinet-1.4.41/man/tcttest.1 +105 -0
  216. data/ext/tokyocabinet-1.4.41/man/tcucodec.1 +162 -0
  217. data/ext/tokyocabinet-1.4.41/man/tcumttest.1 +41 -0
  218. data/ext/tokyocabinet-1.4.41/man/tcutest.1 +81 -0
  219. data/ext/tokyocabinet-1.4.41/man/tcutil.3 +4518 -0
  220. data/ext/tokyocabinet-1.4.41/man/tcxstr.3 +1 -0
  221. data/ext/tokyocabinet-1.4.41/man/tokyocabinet.3 +132 -0
  222. data/ext/tokyocabinet-1.4.41/md5.c +381 -0
  223. data/ext/tokyocabinet-1.4.41/md5.h +101 -0
  224. data/ext/tokyocabinet-1.4.41/myconf.c +493 -0
  225. data/ext/tokyocabinet-1.4.41/myconf.h +549 -0
  226. data/ext/tokyocabinet-1.4.41/tcadb.c +4339 -0
  227. data/ext/tokyocabinet-1.4.41/tcadb.h +548 -0
  228. data/ext/tokyocabinet-1.4.41/tcamgr.c +1019 -0
  229. data/ext/tokyocabinet-1.4.41/tcamttest.c +542 -0
  230. data/ext/tokyocabinet-1.4.41/tcatest.c +1845 -0
  231. data/ext/tokyocabinet-1.4.41/tcawmgr.c +482 -0
  232. data/ext/tokyocabinet-1.4.41/tcbdb.c +4180 -0
  233. data/ext/tokyocabinet-1.4.41/tcbdb.h +1101 -0
  234. data/ext/tokyocabinet-1.4.41/tcbmgr.c +1012 -0
  235. data/ext/tokyocabinet-1.4.41/tcbmttest.c +1810 -0
  236. data/ext/tokyocabinet-1.4.41/tcbtest.c +2586 -0
  237. data/ext/tokyocabinet-1.4.41/tcfdb.c +2746 -0
  238. data/ext/tokyocabinet-1.4.41/tcfdb.h +858 -0
  239. data/ext/tokyocabinet-1.4.41/tcfmgr.c +786 -0
  240. data/ext/tokyocabinet-1.4.41/tcfmttest.c +1220 -0
  241. data/ext/tokyocabinet-1.4.41/tcftest.c +1695 -0
  242. data/ext/tokyocabinet-1.4.41/tchdb.c +5153 -0
  243. data/ext/tokyocabinet-1.4.41/tchdb.h +871 -0
  244. data/ext/tokyocabinet-1.4.41/tchmgr.c +842 -0
  245. data/ext/tokyocabinet-1.4.41/tchmttest.c +1757 -0
  246. data/ext/tokyocabinet-1.4.41/tchtest.c +2129 -0
  247. data/ext/tokyocabinet-1.4.41/tctdb.c +6199 -0
  248. data/ext/tokyocabinet-1.4.41/tctdb.h +1086 -0
  249. data/ext/tokyocabinet-1.4.41/tctmgr.c +1241 -0
  250. data/ext/tokyocabinet-1.4.41/tctmttest.c +1563 -0
  251. data/ext/tokyocabinet-1.4.41/tcttest.c +2062 -0
  252. data/ext/tokyocabinet-1.4.41/tcucodec.c +1357 -0
  253. data/ext/tokyocabinet-1.4.41/tcumttest.c +578 -0
  254. data/ext/tokyocabinet-1.4.41/tcutest.c +1875 -0
  255. data/ext/tokyocabinet-1.4.41/tcutil.c +10528 -0
  256. data/ext/tokyocabinet-1.4.41/tcutil.h +4184 -0
  257. data/ext/tokyocabinet-1.4.41/tokyocabinet.idl +336 -0
  258. data/ext/tokyocabinet-1.4.41/tokyocabinet.pc.in +14 -0
  259. data/ext/tokyotyrant-1.1.39/COPYING +504 -0
  260. data/ext/tokyotyrant-1.1.39/ChangeLog +578 -0
  261. data/ext/tokyotyrant-1.1.39/Makefile.in +365 -0
  262. data/ext/tokyotyrant-1.1.39/README +38 -0
  263. data/ext/tokyotyrant-1.1.39/THANKS +15 -0
  264. data/ext/tokyotyrant-1.1.39/configure +6979 -0
  265. data/ext/tokyotyrant-1.1.39/configure.in +300 -0
  266. data/ext/tokyotyrant-1.1.39/doc/common.css +211 -0
  267. data/ext/tokyotyrant-1.1.39/doc/index.html +79 -0
  268. data/ext/tokyotyrant-1.1.39/doc/spex.html +2264 -0
  269. data/ext/tokyotyrant-1.1.39/example/Makefile +68 -0
  270. data/ext/tokyotyrant-1.1.39/example/httptest.pl +88 -0
  271. data/ext/tokyotyrant-1.1.39/example/mcftest.pl +39 -0
  272. data/ext/tokyotyrant-1.1.39/example/mctest.pl +43 -0
  273. data/ext/tokyotyrant-1.1.39/example/tcrdbex +0 -0
  274. data/ext/tokyotyrant-1.1.39/example/tcrdbex.c +49 -0
  275. data/ext/tokyotyrant-1.1.39/example/tcrdbex.o +0 -0
  276. data/ext/tokyotyrant-1.1.39/example/tcrdbtblex +0 -0
  277. data/ext/tokyotyrant-1.1.39/example/tcrdbtblex.c +79 -0
  278. data/ext/tokyotyrant-1.1.39/example/tcrdbtblex.o +0 -0
  279. data/ext/tokyotyrant-1.1.39/ext/mapreduce.lua +57 -0
  280. data/ext/tokyotyrant-1.1.39/ext/queue.lua +55 -0
  281. data/ext/tokyotyrant-1.1.39/ext/senatus.lua +532 -0
  282. data/ext/tokyotyrant-1.1.39/ext/usherette.lua +438 -0
  283. data/ext/tokyotyrant-1.1.39/lab/datechange +56 -0
  284. data/ext/tokyotyrant-1.1.39/lab/diffcheck +45 -0
  285. data/ext/tokyotyrant-1.1.39/lab/fibonacci.lua +20 -0
  286. data/ext/tokyotyrant-1.1.39/lab/footprint.lua +67 -0
  287. data/ext/tokyotyrant-1.1.39/lab/highlow.lua +88 -0
  288. data/ext/tokyotyrant-1.1.39/lab/killdualmaster +12 -0
  289. data/ext/tokyotyrant-1.1.39/lab/rundualmaster +38 -0
  290. data/ext/tokyotyrant-1.1.39/lab/stepcount +26 -0
  291. data/ext/tokyotyrant-1.1.39/lab/tabcheck +43 -0
  292. data/ext/tokyotyrant-1.1.39/lab/ushrtregister.pl +55 -0
  293. data/ext/tokyotyrant-1.1.39/lab/widthcheck +57 -0
  294. data/ext/tokyotyrant-1.1.39/man/htmltoman +100 -0
  295. data/ext/tokyotyrant-1.1.39/man/tcrdb.3 +1309 -0
  296. data/ext/tokyotyrant-1.1.39/man/tcrmgr.1 +164 -0
  297. data/ext/tokyotyrant-1.1.39/man/tcrmttest.1 +55 -0
  298. data/ext/tokyotyrant-1.1.39/man/tcrtest.1 +89 -0
  299. data/ext/tokyotyrant-1.1.39/man/tculog.3 +15 -0
  300. data/ext/tokyotyrant-1.1.39/man/ttservctl.8 +37 -0
  301. data/ext/tokyotyrant-1.1.39/man/ttserver.1 +84 -0
  302. data/ext/tokyotyrant-1.1.39/man/ttulmgr.1 +40 -0
  303. data/ext/tokyotyrant-1.1.39/man/ttultest.1 +16 -0
  304. data/ext/tokyotyrant-1.1.39/man/ttutil.3 +14 -0
  305. data/ext/tokyotyrant-1.1.39/myconf.c +169 -0
  306. data/ext/tokyotyrant-1.1.39/myconf.h +408 -0
  307. data/ext/tokyotyrant-1.1.39/scrext.c +2394 -0
  308. data/ext/tokyotyrant-1.1.39/scrext.h +96 -0
  309. data/ext/tokyotyrant-1.1.39/tcrdb.c +2637 -0
  310. data/ext/tokyotyrant-1.1.39/tcrdb.h +801 -0
  311. data/ext/tokyotyrant-1.1.39/tcrmgr.c +1559 -0
  312. data/ext/tokyotyrant-1.1.39/tcrmttest.c +915 -0
  313. data/ext/tokyotyrant-1.1.39/tcrtest.c +1542 -0
  314. data/ext/tokyotyrant-1.1.39/tculog.c +1211 -0
  315. data/ext/tokyotyrant-1.1.39/tculog.h +392 -0
  316. data/ext/tokyotyrant-1.1.39/tokyotyrant.idl +143 -0
  317. data/ext/tokyotyrant-1.1.39/tokyotyrant.pc.in +14 -0
  318. data/ext/tokyotyrant-1.1.39/ttservctl +163 -0
  319. data/ext/tokyotyrant-1.1.39/ttserver.c +3583 -0
  320. data/ext/tokyotyrant-1.1.39/ttskeldir.c +141 -0
  321. data/ext/tokyotyrant-1.1.39/ttskelmock.c +64 -0
  322. data/ext/tokyotyrant-1.1.39/ttskelnull.c +79 -0
  323. data/ext/tokyotyrant-1.1.39/ttskelproxy.c +74 -0
  324. data/ext/tokyotyrant-1.1.39/ttulmgr.c +266 -0
  325. data/ext/tokyotyrant-1.1.39/ttultest.c +371 -0
  326. data/ext/tokyotyrant-1.1.39/ttutil.c +1510 -0
  327. data/ext/tokyotyrant-1.1.39/ttutil.h +494 -0
  328. data/lib/tokyo_tyrant/balancer.rb +189 -0
  329. data/spec/ext.lua +4 -0
  330. data/spec/plu_db.rb +538 -0
  331. data/spec/spec.rb +1 -0
  332. data/spec/spec_base.rb +17 -0
  333. data/spec/start_tyrants.sh +36 -0
  334. data/spec/stop_tyrants.sh +9 -0
  335. data/spec/tokyo_tyrant_balancer_db_spec.rb +160 -0
  336. data/spec/tokyo_tyrant_balancer_table_spec.rb +177 -0
  337. data/spec/tokyo_tyrant_query_spec.rb +159 -0
  338. data/spec/tokyo_tyrant_spec.rb +254 -0
  339. data/spec/tokyo_tyrant_table_spec.rb +301 -0
  340. metadata +402 -0
@@ -0,0 +1,1559 @@
1
+ /*************************************************************************************************
2
+ * The command line utility of the remote database API
3
+ * Copyright (C) 2007-2009 Mikio Hirabayashi
4
+ * This file is part of Tokyo Tyrant.
5
+ * Tokyo Tyrant 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 Tyrant 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
+ * Tyrant; 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 <tculog.h>
18
+ #include <tcrdb.h>
19
+ #include "myconf.h"
20
+
21
+ #define REQHEADMAX 32 // maximum number of request headers of HTTP
22
+ #define MINIBNUM 31 // bucket number of map for trivial use
23
+
24
+
25
+ /* global variables */
26
+ const char *g_progname; // program name
27
+
28
+
29
+ /* function prototypes */
30
+ int main(int argc, char **argv);
31
+ static void usage(void);
32
+ static void printerr(TCRDB *rdb);
33
+ static int sepstrtochr(const char *str);
34
+ static char *strtozsv(const char *str, int sep, int *sp);
35
+ static int printdata(const char *ptr, int size, bool px, int sep);
36
+ static char *mygetline(FILE *ifp);
37
+ static bool myopen(TCRDB *rdb, const char *host, int port);
38
+ static bool mysetmst(TCRDB *rdb, const char *host, int port, uint64_t ts, int opts);
39
+ static int runinform(int argc, char **argv);
40
+ static int runput(int argc, char **argv);
41
+ static int runout(int argc, char **argv);
42
+ static int runget(int argc, char **argv);
43
+ static int runmget(int argc, char **argv);
44
+ static int runlist(int argc, char **argv);
45
+ static int runext(int argc, char **argv);
46
+ static int runsync(int argc, char **argv);
47
+ static int runoptimize(int argc, char **argv);
48
+ static int runvanish(int argc, char **argv);
49
+ static int runcopy(int argc, char **argv);
50
+ static int runmisc(int argc, char **argv);
51
+ static int runimporttsv(int argc, char **argv);
52
+ static int runrestore(int argc, char **argv);
53
+ static int runsetmst(int argc, char **argv);
54
+ static int runrepl(int argc, char **argv);
55
+ static int runhttp(int argc, char **argv);
56
+ static int runversion(int argc, char **argv);
57
+ static int procinform(const char *host, int port, bool st);
58
+ static int procput(const char *host, int port, const char *kbuf, int ksiz,
59
+ const char *vbuf, int vsiz, int dmode, int shlw);
60
+ static int procout(const char *host, int port, const char *kbuf, int ksiz);
61
+ static int procget(const char *host, int port, const char *kbuf, int ksiz, int sep,
62
+ bool px, bool pz);
63
+ static int procmget(const char *host, int port, const TCLIST *keys, int sep, bool px);
64
+ static int proclist(const char *host, int port, int sep, int max, bool pv, bool px,
65
+ const char *fmstr);
66
+ static int procext(const char *host, int port, const char *func, int opts,
67
+ const char *kbuf, int ksiz, const char *vbuf, int vsiz, int sep,
68
+ bool px, bool pz);
69
+ static int procsync(const char *host, int port);
70
+ static int procoptimize(const char *host, int port, const char *params);
71
+ static int procvanish(const char *host, int port);
72
+ static int proccopy(const char *host, int port, const char *dpath);
73
+ static int procmisc(const char *host, int port, const char *func, int opts,
74
+ const TCLIST *args, int sep, bool px);
75
+ static int procimporttsv(const char *host, int port, const char *file, bool nr,
76
+ bool sc, int sep);
77
+ static int procrestore(const char *host, int port, const char *upath, uint64_t ts, int opts);
78
+ static int procsetmst(const char *host, int port, const char *mhost, int mport,
79
+ uint64_t ts, int opts);
80
+ static int procrepl(const char *host, int port, uint64_t ts, uint32_t sid, bool ph);
81
+ static int prochttp(const char *url, TCMAP *hmap, bool ih);
82
+ static int procversion(void);
83
+
84
+
85
+ /* main routine */
86
+ int main(int argc, char **argv){
87
+ g_progname = argv[0];
88
+ signal(SIGPIPE, SIG_IGN);
89
+ if(argc < 2) usage();
90
+ int rv = 0;
91
+ if(!strcmp(argv[1], "inform")){
92
+ rv = runinform(argc, argv);
93
+ } else if(!strcmp(argv[1], "put")){
94
+ rv = runput(argc, argv);
95
+ } else if(!strcmp(argv[1], "out")){
96
+ rv = runout(argc, argv);
97
+ } else if(!strcmp(argv[1], "get")){
98
+ rv = runget(argc, argv);
99
+ } else if(!strcmp(argv[1], "mget")){
100
+ rv = runmget(argc, argv);
101
+ } else if(!strcmp(argv[1], "list")){
102
+ rv = runlist(argc, argv);
103
+ } else if(!strcmp(argv[1], "ext")){
104
+ rv = runext(argc, argv);
105
+ } else if(!strcmp(argv[1], "sync")){
106
+ rv = runsync(argc, argv);
107
+ } else if(!strcmp(argv[1], "optimize")){
108
+ rv = runoptimize(argc, argv);
109
+ } else if(!strcmp(argv[1], "vanish")){
110
+ rv = runvanish(argc, argv);
111
+ } else if(!strcmp(argv[1], "copy")){
112
+ rv = runcopy(argc, argv);
113
+ } else if(!strcmp(argv[1], "misc")){
114
+ rv = runmisc(argc, argv);
115
+ } else if(!strcmp(argv[1], "importtsv")){
116
+ rv = runimporttsv(argc, argv);
117
+ } else if(!strcmp(argv[1], "restore")){
118
+ rv = runrestore(argc, argv);
119
+ } else if(!strcmp(argv[1], "setmst")){
120
+ rv = runsetmst(argc, argv);
121
+ } else if(!strcmp(argv[1], "repl")){
122
+ rv = runrepl(argc, argv);
123
+ } else if(!strcmp(argv[1], "http")){
124
+ rv = runhttp(argc, argv);
125
+ } else if(!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")){
126
+ rv = runversion(argc, argv);
127
+ } else {
128
+ usage();
129
+ }
130
+ return rv;
131
+ }
132
+
133
+
134
+ /* print the usage and exit */
135
+ static void usage(void){
136
+ fprintf(stderr, "%s: the command line utility of the remote database API\n", g_progname);
137
+ fprintf(stderr, "\n");
138
+ fprintf(stderr, "usage:\n");
139
+ fprintf(stderr, " %s inform [-port num] [-st] host\n", g_progname);
140
+ fprintf(stderr, " %s put [-port num] [-sx] [-sep chr] [-dk|-dc] [-ds num] host key value\n",
141
+ g_progname);
142
+ fprintf(stderr, " %s out [-port num] [-sx] [-sep chr] host key\n", g_progname);
143
+ fprintf(stderr, " %s get [-port num] [-sx] [-sep chr] [-px] [-pz] host key\n", g_progname);
144
+ fprintf(stderr, " %s mget [-port num] [-sx] [-sep chr] [-px] host [key...]\n", g_progname);
145
+ fprintf(stderr, " %s list [-port num] [-sep chr] [-m num] [-pv] [-px] [-fm str] host\n",
146
+ g_progname);
147
+ fprintf(stderr, " %s ext [-port num] [-xlr|-xlg] [-sx] [-sep chr] [-px] host func"
148
+ " [key [value]]\n", g_progname);
149
+ fprintf(stderr, " %s sync [-port num] host\n", g_progname);
150
+ fprintf(stderr, " %s optimize [-port num] host [params]\n", g_progname);
151
+ fprintf(stderr, " %s vanish [-port num] host\n", g_progname);
152
+ fprintf(stderr, " %s copy [-port num] host dpath\n", g_progname);
153
+ fprintf(stderr, " %s misc [-port num] [-mnu] [-sx] [-sep chr] [-px] host func [arg...]\n",
154
+ g_progname);
155
+ fprintf(stderr, " %s importtsv [-port num] [-nr] [-sc] [-sep chr] host [file]\n", g_progname);
156
+ fprintf(stderr, " %s restore [-port num] [-ts num] [-rcc] host upath\n", g_progname);
157
+ fprintf(stderr, " %s setmst [-port num] [-mport num] [-ts num] [-rcc] host [mhost]\n",
158
+ g_progname);
159
+ fprintf(stderr, " %s repl [-port num] [-ts num] [-sid num] [-ph] host\n", g_progname);
160
+ fprintf(stderr, " %s http [-ah name value] [-ih] url\n", g_progname);
161
+ fprintf(stderr, " %s version\n", g_progname);
162
+ fprintf(stderr, "\n");
163
+ exit(1);
164
+ }
165
+
166
+
167
+ /* print error information */
168
+ static void printerr(TCRDB *rdb){
169
+ int ecode = tcrdbecode(rdb);
170
+ fprintf(stderr, "%s: error: %d: %s\n", g_progname, ecode, tcrdberrmsg(ecode));
171
+ }
172
+
173
+
174
+ /* get the character of separation string */
175
+ static int sepstrtochr(const char *str){
176
+ if(!strcmp(str, "\\t")) return '\t';
177
+ if(!strcmp(str, "\\r")) return '\r';
178
+ if(!strcmp(str, "\\n")) return '\n';
179
+ return *(unsigned char *)str;
180
+ }
181
+
182
+
183
+ /* encode a string as a zero separaterd string */
184
+ static char *strtozsv(const char *str, int sep, int *sp){
185
+ int size = strlen(str);
186
+ char *buf = tcmemdup(str, size);
187
+ for(int i = 0; i < size; i++){
188
+ if(buf[i] == sep) buf[i] = '\0';
189
+ }
190
+ *sp = size;
191
+ return buf;
192
+ }
193
+
194
+
195
+ /* print record data */
196
+ static int printdata(const char *ptr, int size, bool px, int sep){
197
+ int len = 0;
198
+ while(size-- > 0){
199
+ if(px){
200
+ if(len > 0) putchar(' ');
201
+ len += printf("%02X", *(unsigned char *)ptr);
202
+ } else if(sep > 0){
203
+ if(*ptr == '\0'){
204
+ putchar(sep);
205
+ } else {
206
+ putchar(*ptr);
207
+ }
208
+ len++;
209
+ } else {
210
+ putchar(*ptr);
211
+ len++;
212
+ }
213
+ ptr++;
214
+ }
215
+ return len;
216
+ }
217
+
218
+
219
+ /* read a line from a file descriptor */
220
+ static char *mygetline(FILE *ifp){
221
+ int len = 0;
222
+ int blen = 1024;
223
+ char *buf = tcmalloc(blen);
224
+ bool end = true;
225
+ int c;
226
+ while((c = fgetc(ifp)) != EOF){
227
+ end = false;
228
+ if(c == '\0') continue;
229
+ if(blen <= len){
230
+ blen *= 2;
231
+ buf = tcrealloc(buf, blen + 1);
232
+ }
233
+ if(c == '\n' || c == '\r') c = '\0';
234
+ buf[len++] = c;
235
+ if(c == '\0') break;
236
+ }
237
+ if(end){
238
+ tcfree(buf);
239
+ return NULL;
240
+ }
241
+ buf[len] = '\0';
242
+ return buf;
243
+ }
244
+
245
+
246
+ /* open the remote database */
247
+ static bool myopen(TCRDB *rdb, const char *host, int port){
248
+ bool err = false;
249
+ if(strchr(host, ':') || strchr(host, '#')){
250
+ if(!tcrdbopen2(rdb, host)) err = true;
251
+ } else {
252
+ if(!tcrdbopen(rdb, host, port)) err = true;
253
+ }
254
+ return !err;
255
+ }
256
+
257
+
258
+ /* set the replication master */
259
+ static bool mysetmst(TCRDB *rdb, const char *host, int port, uint64_t ts, int opts){
260
+ bool err = false;
261
+ if(strchr(host, ':')){
262
+ if(!tcrdbsetmst2(rdb, host, ts, opts)) err = true;
263
+ } else {
264
+ if(!tcrdbsetmst(rdb, host, port, ts, opts)) err = true;
265
+ }
266
+ return !err;
267
+ }
268
+
269
+
270
+ /* parse arguments of inform command */
271
+ static int runinform(int argc, char **argv){
272
+ char *host = NULL;
273
+ int port = TTDEFPORT;
274
+ bool st = false;
275
+ for(int i = 2; i < argc; i++){
276
+ if(!host && argv[i][0] == '-'){
277
+ if(!strcmp(argv[i], "-port")){
278
+ if(++i >= argc) usage();
279
+ port = tcatoi(argv[i]);
280
+ } else if(!strcmp(argv[i], "-st")){
281
+ st = true;
282
+ } else {
283
+ usage();
284
+ }
285
+ } else if(!host){
286
+ host = argv[i];
287
+ } else {
288
+ usage();
289
+ }
290
+ }
291
+ if(!host) usage();
292
+ int rv = procinform(host, port, st);
293
+ return rv;
294
+ }
295
+
296
+
297
+ /* parse arguments of put command */
298
+ static int runput(int argc, char **argv){
299
+ char *host = NULL;
300
+ char *key = NULL;
301
+ char *value = NULL;
302
+ int port = TTDEFPORT;
303
+ int dmode = 0;
304
+ int shlw = -1;
305
+ bool sx = false;
306
+ int sep = -1;
307
+ for(int i = 2; i < argc; i++){
308
+ if(!host && argv[i][0] == '-'){
309
+ if(!strcmp(argv[i], "-port")){
310
+ if(++i >= argc) usage();
311
+ port = tcatoi(argv[i]);
312
+ } else if(!strcmp(argv[i], "-dk")){
313
+ dmode = -1;
314
+ } else if(!strcmp(argv[i], "-dc")){
315
+ dmode = 1;
316
+ } else if(!strcmp(argv[i], "-ds")){
317
+ if(++i >= argc) usage();
318
+ shlw = tcatoi(argv[i]);
319
+ } else if(!strcmp(argv[i], "-sx")){
320
+ sx = true;
321
+ } else if(!strcmp(argv[i], "-sep")){
322
+ if(++i >= argc) usage();
323
+ sep = sepstrtochr(argv[i]);
324
+ } else {
325
+ usage();
326
+ }
327
+ } else if(!host){
328
+ host = argv[i];
329
+ } else if(!key){
330
+ key = argv[i];
331
+ } else if(!value){
332
+ value = argv[i];
333
+ } else {
334
+ usage();
335
+ }
336
+ }
337
+ if(!host || !key || !value) usage();
338
+ int ksiz, vsiz;
339
+ char *kbuf, *vbuf;
340
+ if(sx){
341
+ kbuf = tchexdecode(key, &ksiz);
342
+ vbuf = tchexdecode(value, &vsiz);
343
+ } else if(sep > 0){
344
+ kbuf = strtozsv(key, sep, &ksiz);
345
+ vbuf = strtozsv(value, sep, &vsiz);
346
+ } else {
347
+ ksiz = strlen(key);
348
+ kbuf = tcmemdup(key, ksiz);
349
+ vsiz = strlen(value);
350
+ vbuf = tcmemdup(value, vsiz);
351
+ }
352
+ int rv = procput(host, port, kbuf, ksiz, vbuf, vsiz, dmode, shlw);
353
+ tcfree(vbuf);
354
+ tcfree(kbuf);
355
+ return rv;
356
+ }
357
+
358
+
359
+ /* parse arguments of out command */
360
+ static int runout(int argc, char **argv){
361
+ char *host = NULL;
362
+ char *key = NULL;
363
+ int port = TTDEFPORT;
364
+ bool sx = false;
365
+ int sep = -1;
366
+ for(int i = 2; i < argc; i++){
367
+ if(!host && argv[i][0] == '-'){
368
+ if(!strcmp(argv[i], "-port")){
369
+ if(++i >= argc) usage();
370
+ port = tcatoi(argv[i]);
371
+ } else if(!strcmp(argv[i], "-sx")){
372
+ sx = true;
373
+ } else if(!strcmp(argv[i], "-sep")){
374
+ if(++i >= argc) usage();
375
+ sep = sepstrtochr(argv[i]);
376
+ } else {
377
+ usage();
378
+ }
379
+ } else if(!host){
380
+ host = argv[i];
381
+ } else if(!key){
382
+ key = argv[i];
383
+ } else {
384
+ usage();
385
+ }
386
+ }
387
+ if(!host || !key) usage();
388
+ int ksiz;
389
+ char *kbuf;
390
+ if(sx){
391
+ kbuf = tchexdecode(key, &ksiz);
392
+ } else if(sep > 0){
393
+ kbuf = strtozsv(key, sep, &ksiz);
394
+ } else {
395
+ ksiz = strlen(key);
396
+ kbuf = tcmemdup(key, ksiz);
397
+ }
398
+ int rv = procout(host, port, kbuf, ksiz);
399
+ tcfree(kbuf);
400
+ return rv;
401
+ }
402
+
403
+
404
+ /* parse arguments of get command */
405
+ static int runget(int argc, char **argv){
406
+ char *host = NULL;
407
+ char *key = NULL;
408
+ int port = TTDEFPORT;
409
+ bool sx = false;
410
+ int sep = -1;
411
+ bool px = false;
412
+ bool pz = false;
413
+ for(int i = 2; i < argc; i++){
414
+ if(!host && argv[i][0] == '-'){
415
+ if(!strcmp(argv[i], "-port")){
416
+ if(++i >= argc) usage();
417
+ port = tcatoi(argv[i]);
418
+ } else if(!strcmp(argv[i], "-sx")){
419
+ sx = true;
420
+ } else if(!strcmp(argv[i], "-sep")){
421
+ if(++i >= argc) usage();
422
+ sep = sepstrtochr(argv[i]);
423
+ } else if(!strcmp(argv[i], "-px")){
424
+ px = true;
425
+ } else if(!strcmp(argv[i], "-pz")){
426
+ pz = true;
427
+ } else {
428
+ usage();
429
+ }
430
+ } else if(!host){
431
+ host = argv[i];
432
+ } else if(!key){
433
+ key = argv[i];
434
+ } else {
435
+ usage();
436
+ }
437
+ }
438
+ if(!host || !key) usage();
439
+ int ksiz;
440
+ char *kbuf;
441
+ if(sx){
442
+ kbuf = tchexdecode(key, &ksiz);
443
+ } else if(sep > 0){
444
+ kbuf = strtozsv(key, sep, &ksiz);
445
+ } else {
446
+ ksiz = strlen(key);
447
+ kbuf = tcmemdup(key, ksiz);
448
+ }
449
+ int rv = procget(host, port, kbuf, ksiz, sep, px, pz);
450
+ tcfree(kbuf);
451
+ return rv;
452
+ }
453
+
454
+
455
+ /* parse arguments of mget command */
456
+ static int runmget(int argc, char **argv){
457
+ char *host = NULL;
458
+ TCLIST *keys = tcmpoollistnew(tcmpoolglobal());
459
+ int port = TTDEFPORT;
460
+ bool sx = false;
461
+ int sep = -1;
462
+ bool px = false;
463
+ for(int i = 2; i < argc; i++){
464
+ if(!host && argv[i][0] == '-'){
465
+ if(!strcmp(argv[i], "-port")){
466
+ if(++i >= argc) usage();
467
+ port = tcatoi(argv[i]);
468
+ } else if(!strcmp(argv[i], "-sx")){
469
+ sx = true;
470
+ } else if(!strcmp(argv[i], "-sep")){
471
+ if(++i >= argc) usage();
472
+ sep = sepstrtochr(argv[i]);
473
+ } else if(!strcmp(argv[i], "-px")){
474
+ px = true;
475
+ } else {
476
+ usage();
477
+ }
478
+ } else if(!host){
479
+ host = argv[i];
480
+ } else {
481
+ tclistpush2(keys, argv[i]);
482
+ }
483
+ }
484
+ if(!host) usage();
485
+ if(sx){
486
+ for(int i = 0; i < tclistnum(keys); i++){
487
+ int ksiz;
488
+ char *kbuf = tchexdecode(tclistval2(keys, i), &ksiz);
489
+ tclistover(keys, i, kbuf, ksiz);
490
+ tcfree(kbuf);
491
+ }
492
+ } else if(sep > 0){
493
+ for(int i = 0; i < tclistnum(keys); i++){
494
+ int ksiz;
495
+ char *kbuf = strtozsv(tclistval2(keys, i), sep, &ksiz);
496
+ tclistover(keys, i, kbuf, ksiz);
497
+ tcfree(kbuf);
498
+ }
499
+ }
500
+ int rv = procmget(host, port, keys, sep, px);
501
+ return rv;
502
+ }
503
+
504
+
505
+ /* parse arguments of list command */
506
+ static int runlist(int argc, char **argv){
507
+ char *host = NULL;
508
+ int port = TTDEFPORT;
509
+ int sep = -1;
510
+ int max = -1;
511
+ bool pv = false;
512
+ bool px = false;
513
+ char *fmstr = NULL;
514
+ for(int i = 2; i < argc; i++){
515
+ if(!host && argv[i][0] == '-'){
516
+ if(!strcmp(argv[i], "-port")){
517
+ if(++i >= argc) usage();
518
+ port = tcatoi(argv[i]);
519
+ } else if(!strcmp(argv[i], "-sep")){
520
+ if(++i >= argc) usage();
521
+ sep = sepstrtochr(argv[i]);
522
+ } else if(!strcmp(argv[i], "-m")){
523
+ if(++i >= argc) usage();
524
+ max = tcatoi(argv[i]);
525
+ } else if(!strcmp(argv[i], "-pv")){
526
+ pv = true;
527
+ } else if(!strcmp(argv[i], "-px")){
528
+ px = true;
529
+ } else if(!strcmp(argv[i], "-fm")){
530
+ if(++i >= argc) usage();
531
+ fmstr = argv[i];
532
+ } else {
533
+ usage();
534
+ }
535
+ } else if(!host){
536
+ host = argv[i];
537
+ } else {
538
+ usage();
539
+ }
540
+ }
541
+ if(!host) usage();
542
+ int rv = proclist(host, port, sep, max, pv, px, fmstr);
543
+ return rv;
544
+ }
545
+
546
+
547
+ /* parse arguments of ext command */
548
+ static int runext(int argc, char **argv){
549
+ char *host = NULL;
550
+ char *func = NULL;
551
+ char *key = NULL;
552
+ char *value = NULL;
553
+ int port = TTDEFPORT;
554
+ int opts = 0;
555
+ bool sx = false;
556
+ int sep = -1;
557
+ bool px = false;
558
+ bool pz = false;
559
+ for(int i = 2; i < argc; i++){
560
+ if(!host && argv[i][0] == '-'){
561
+ if(!strcmp(argv[i], "-port")){
562
+ if(++i >= argc) usage();
563
+ port = tcatoi(argv[i]);
564
+ } else if(!strcmp(argv[i], "-xlr")){
565
+ opts |= RDBXOLCKREC;
566
+ } else if(!strcmp(argv[i], "-xlg")){
567
+ opts |= RDBXOLCKGLB;
568
+ } else if(!strcmp(argv[i], "-sx")){
569
+ sx = true;
570
+ } else if(!strcmp(argv[i], "-sep")){
571
+ if(++i >= argc) usage();
572
+ sep = sepstrtochr(argv[i]);
573
+ } else if(!strcmp(argv[i], "-px")){
574
+ px = true;
575
+ } else if(!strcmp(argv[i], "-pz")){
576
+ pz = true;
577
+ } else {
578
+ usage();
579
+ }
580
+ } else if(!host){
581
+ host = argv[i];
582
+ } else if(!func){
583
+ func = argv[i];
584
+ } else if(!key){
585
+ key = argv[i];
586
+ } else if(!value){
587
+ value = argv[i];
588
+ } else {
589
+ usage();
590
+ }
591
+ }
592
+ if(!host || !func) usage();
593
+ if(!key) key = "";
594
+ if(!value) value = "";
595
+ int ksiz, vsiz;
596
+ char *kbuf, *vbuf;
597
+ if(sx){
598
+ kbuf = tchexdecode(key, &ksiz);
599
+ vbuf = tchexdecode(value, &vsiz);
600
+ } else if(sep > 0){
601
+ kbuf = strtozsv(key, sep, &ksiz);
602
+ vbuf = strtozsv(value, sep, &vsiz);
603
+ } else {
604
+ ksiz = strlen(key);
605
+ kbuf = tcmemdup(key, ksiz);
606
+ vsiz = strlen(value);
607
+ vbuf = tcmemdup(value, vsiz);
608
+ }
609
+ int rv = procext(host, port, func, opts, kbuf, ksiz, vbuf, vsiz, sep, px, pz);
610
+ tcfree(vbuf);
611
+ tcfree(kbuf);
612
+ return rv;
613
+ }
614
+
615
+
616
+ /* parse arguments of sync command */
617
+ static int runsync(int argc, char **argv){
618
+ char *host = NULL;
619
+ int port = TTDEFPORT;
620
+ for(int i = 2; i < argc; i++){
621
+ if(!host && argv[i][0] == '-'){
622
+ if(!strcmp(argv[i], "-port")){
623
+ if(++i >= argc) usage();
624
+ port = tcatoi(argv[i]);
625
+ } else {
626
+ usage();
627
+ }
628
+ } else if(!host){
629
+ host = argv[i];
630
+ } else {
631
+ usage();
632
+ }
633
+ }
634
+ if(!host) usage();
635
+ int rv = procsync(host, port);
636
+ return rv;
637
+ }
638
+
639
+
640
+ /* parse arguments of optimize command */
641
+ static int runoptimize(int argc, char **argv){
642
+ char *host = NULL;
643
+ char *params = NULL;
644
+ int port = TTDEFPORT;
645
+ for(int i = 2; i < argc; i++){
646
+ if(!host && argv[i][0] == '-'){
647
+ if(!strcmp(argv[i], "-port")){
648
+ if(++i >= argc) usage();
649
+ port = tcatoi(argv[i]);
650
+ } else {
651
+ usage();
652
+ }
653
+ } else if(!host){
654
+ host = argv[i];
655
+ } else if(!params){
656
+ params = argv[i];
657
+ } else {
658
+ usage();
659
+ }
660
+ }
661
+ if(!host) usage();
662
+ int rv = procoptimize(host, port, params);
663
+ return rv;
664
+ }
665
+
666
+
667
+ /* parse arguments of vanish command */
668
+ static int runvanish(int argc, char **argv){
669
+ char *host = NULL;
670
+ int port = TTDEFPORT;
671
+ for(int i = 2; i < argc; i++){
672
+ if(!host && argv[i][0] == '-'){
673
+ if(!strcmp(argv[i], "-port")){
674
+ if(++i >= argc) usage();
675
+ port = tcatoi(argv[i]);
676
+ } else {
677
+ usage();
678
+ }
679
+ } else if(!host){
680
+ host = argv[i];
681
+ } else {
682
+ usage();
683
+ }
684
+ }
685
+ if(!host) usage();
686
+ int rv = procvanish(host, port);
687
+ return rv;
688
+ }
689
+
690
+
691
+ /* parse arguments of copy command */
692
+ static int runcopy(int argc, char **argv){
693
+ char *host = NULL;
694
+ char *dpath = NULL;
695
+ int port = TTDEFPORT;
696
+ for(int i = 2; i < argc; i++){
697
+ if(!host && argv[i][0] == '-'){
698
+ if(!strcmp(argv[i], "-port")){
699
+ if(++i >= argc) usage();
700
+ port = tcatoi(argv[i]);
701
+ } else {
702
+ usage();
703
+ }
704
+ } else if(!host){
705
+ host = argv[i];
706
+ } else if(!dpath){
707
+ dpath = argv[i];
708
+ } else {
709
+ usage();
710
+ }
711
+ }
712
+ if(!host || !dpath) usage();
713
+ int rv = proccopy(host, port, dpath);
714
+ return rv;
715
+ }
716
+
717
+
718
+ /* parse arguments of misc command */
719
+ static int runmisc(int argc, char **argv){
720
+ char *host = NULL;
721
+ char *func = NULL;
722
+ TCLIST *args = tcmpoollistnew(tcmpoolglobal());
723
+ int port = TTDEFPORT;
724
+ int opts = 0;
725
+ bool sx = false;
726
+ int sep = -1;
727
+ bool px = false;
728
+ for(int i = 2; i < argc; i++){
729
+ if(!host && argv[i][0] == '-'){
730
+ if(!strcmp(argv[i], "-port")){
731
+ if(++i >= argc) usage();
732
+ port = tcatoi(argv[i]);
733
+ } else if(!strcmp(argv[i], "-mnu")){
734
+ opts |= RDBMONOULOG;
735
+ } else if(!strcmp(argv[i], "-sx")){
736
+ sx = true;
737
+ } else if(!strcmp(argv[i], "-sep")){
738
+ if(++i >= argc) usage();
739
+ sep = sepstrtochr(argv[i]);
740
+ } else if(!strcmp(argv[i], "-px")){
741
+ px = true;
742
+ } else {
743
+ usage();
744
+ }
745
+ } else if(!host){
746
+ host = argv[i];
747
+ } else if(!func){
748
+ func = argv[i];
749
+ } else {
750
+ if(sx){
751
+ int size;
752
+ char *buf = tchexdecode(argv[i], &size);
753
+ tclistpush(args, buf, size);
754
+ tcfree(buf);
755
+ } else if(sep > 0){
756
+ int size;
757
+ char *buf = strtozsv(argv[i], sep, &size);
758
+ tclistpush(args, buf, size);
759
+ tcfree(buf);
760
+ } else {
761
+ tclistpush2(args, argv[i]);
762
+ }
763
+ }
764
+ }
765
+ if(!host || !func) usage();
766
+ int rv = procmisc(host, port, func, opts, args, sep, px);
767
+ return rv;
768
+ }
769
+
770
+
771
+ /* parse arguments of importtsv command */
772
+ static int runimporttsv(int argc, char **argv){
773
+ char *host = NULL;
774
+ char *file = NULL;
775
+ int port = TTDEFPORT;
776
+ bool nr = false;
777
+ bool sc = false;
778
+ int sep = -1;
779
+ for(int i = 2; i < argc; i++){
780
+ if(!host && argv[i][0] == '-'){
781
+ if(!strcmp(argv[i], "-port")){
782
+ if(++i >= argc) usage();
783
+ port = tcatoi(argv[i]);
784
+ } else if(!strcmp(argv[i], "-nr")){
785
+ nr = true;
786
+ } else if(!strcmp(argv[i], "-sc")){
787
+ sc = true;
788
+ } else if(!strcmp(argv[i], "-sep")){
789
+ if(++i >= argc) usage();
790
+ sep = sepstrtochr(argv[i]);
791
+ } else {
792
+ usage();
793
+ }
794
+ } else if(!host){
795
+ host = argv[i];
796
+ } else if(!file){
797
+ file = argv[i];
798
+ } else {
799
+ usage();
800
+ }
801
+ }
802
+ if(!host) usage();
803
+ int rv = procimporttsv(host, port, file, nr, sc, sep);
804
+ return rv;
805
+ }
806
+
807
+
808
+ /* parse arguments of restore command */
809
+ static int runrestore(int argc, char **argv){
810
+ char *host = NULL;
811
+ char *upath = NULL;
812
+ int port = TTDEFPORT;
813
+ uint64_t ts = 0;
814
+ int opts = 0;
815
+ for(int i = 2; i < argc; i++){
816
+ if(!host && argv[i][0] == '-'){
817
+ if(!strcmp(argv[i], "-port")){
818
+ if(++i >= argc) usage();
819
+ port = tcatoi(argv[i]);
820
+ } else if(!strcmp(argv[i], "-ts")){
821
+ if(++i >= argc) usage();
822
+ ts = ttstrtots(argv[i]);
823
+ } else if(!strcmp(argv[i], "-rcc")){
824
+ opts |= RDBROCHKCON;
825
+ } else {
826
+ usage();
827
+ }
828
+ } else if(!host){
829
+ host = argv[i];
830
+ } else if(!upath){
831
+ upath = argv[i];
832
+ } else {
833
+ usage();
834
+ }
835
+ }
836
+ if(!host || !upath) usage();
837
+ int rv = procrestore(host, port, upath, ts, opts);
838
+ return rv;
839
+ }
840
+
841
+
842
+ /* parse arguments of setmst command */
843
+ static int runsetmst(int argc, char **argv){
844
+ char *host = NULL;
845
+ char *mhost = NULL;
846
+ int port = TTDEFPORT;
847
+ int mport = TTDEFPORT;
848
+ uint64_t ts = 0;
849
+ int opts = 0;
850
+ for(int i = 2; i < argc; i++){
851
+ if(!host && argv[i][0] == '-'){
852
+ if(!strcmp(argv[i], "-port")){
853
+ if(++i >= argc) usage();
854
+ port = tcatoi(argv[i]);
855
+ } else if(!strcmp(argv[i], "-mport")){
856
+ if(++i >= argc) usage();
857
+ mport = tcatoi(argv[i]);
858
+ } else if(!strcmp(argv[i], "-ts")){
859
+ if(++i >= argc) usage();
860
+ ts = ttstrtots(argv[i]);
861
+ } else if(!strcmp(argv[i], "-rcc")){
862
+ opts |= RDBROCHKCON;
863
+ } else {
864
+ usage();
865
+ }
866
+ } else if(!host){
867
+ host = argv[i];
868
+ } else if(!mhost){
869
+ mhost = argv[i];
870
+ } else {
871
+ usage();
872
+ }
873
+ }
874
+ if(!host) usage();
875
+ int rv = procsetmst(host, port, mhost, mport, ts, opts);
876
+ return rv;
877
+ }
878
+
879
+
880
+ /* parse arguments of repl command */
881
+ static int runrepl(int argc, char **argv){
882
+ char *host = NULL;
883
+ int port = TTDEFPORT;
884
+ uint64_t ts = 0;
885
+ uint32_t sid = 0;
886
+ bool ph = false;
887
+ for(int i = 2; i < argc; i++){
888
+ if(!host && argv[i][0] == '-'){
889
+ if(!strcmp(argv[i], "-port")){
890
+ if(++i >= argc) usage();
891
+ port = tcatoi(argv[i]);
892
+ } else if(!strcmp(argv[i], "-ts")){
893
+ if(++i >= argc) usage();
894
+ ts = ttstrtots(argv[i]);
895
+ } else if(!strcmp(argv[i], "-sid")){
896
+ if(++i >= argc) usage();
897
+ sid = tcatoi(argv[i]);
898
+ } else if(!strcmp(argv[i], "-ph")){
899
+ ph = true;
900
+ } else {
901
+ usage();
902
+ }
903
+ } else if(!host){
904
+ host = argv[i];
905
+ } else {
906
+ usage();
907
+ }
908
+ }
909
+ if(!host) usage();
910
+ int rv = procrepl(host, port, ts, sid, ph);
911
+ return rv;
912
+ }
913
+
914
+
915
+ /* parse arguments of http command */
916
+ static int runhttp(int argc, char **argv){
917
+ char *url = NULL;
918
+ struct {
919
+ char *name;
920
+ char *value;
921
+ } heads[REQHEADMAX];
922
+ int hnum = 0;
923
+ bool ih = false;
924
+ for(int i = 2; i < argc; i++){
925
+ if(!url && argv[i][0] == '-'){
926
+ if(!strcmp(argv[i], "-ah")){
927
+ if(++i >= argc) usage();
928
+ char *name = argv[i];
929
+ if(++i >= argc) usage();
930
+ char *value = argv[i];
931
+ if(hnum < REQHEADMAX){
932
+ heads[hnum].name = name;
933
+ heads[hnum].value = value;
934
+ hnum++;
935
+ }
936
+ } else if(!strcmp(argv[i], "-ih")){
937
+ ih = true;
938
+ } else {
939
+ usage();
940
+ }
941
+ } else if(!url){
942
+ url = argv[i];
943
+ } else {
944
+ usage();
945
+ }
946
+ }
947
+ if(!url) usage();
948
+ TCMAP *hmap = tcmapnew2(hnum + 1);
949
+ for(int i = 0; i < hnum; i++){
950
+ tcmapput2(hmap, heads[i].name, heads[i].value);
951
+ }
952
+ int rv = prochttp(url, hmap, ih);
953
+ tcmapdel(hmap);
954
+ return rv;
955
+ }
956
+
957
+
958
+ /* parse arguments of version command */
959
+ static int runversion(int argc, char **argv){
960
+ int rv = procversion();
961
+ return rv;
962
+ }
963
+
964
+
965
+ /* perform inform command */
966
+ static int procinform(const char *host, int port, bool st){
967
+ TCRDB *rdb = tcrdbnew();
968
+ if(!myopen(rdb, host, port)){
969
+ printerr(rdb);
970
+ tcrdbdel(rdb);
971
+ return 1;
972
+ }
973
+ bool err = false;
974
+ if(st){
975
+ char *status = tcrdbstat(rdb);
976
+ if(status){
977
+ printf("%s", status);
978
+ tcfree(status);
979
+ } else {
980
+ printerr(rdb);
981
+ err = true;
982
+ }
983
+ } else {
984
+ printf("record number: %llu\n", (unsigned long long)tcrdbrnum(rdb));
985
+ printf("file size: %llu\n", (unsigned long long)tcrdbsize(rdb));
986
+ }
987
+ if(!tcrdbclose(rdb)){
988
+ if(!err) printerr(rdb);
989
+ err = true;
990
+ }
991
+ tcrdbdel(rdb);
992
+ return err ? 1 : 0;
993
+ }
994
+
995
+
996
+ /* perform put command */
997
+ static int procput(const char *host, int port, const char *kbuf, int ksiz,
998
+ const char *vbuf, int vsiz, int dmode, int shlw){
999
+ TCRDB *rdb = tcrdbnew();
1000
+ if(!myopen(rdb, host, port)){
1001
+ printerr(rdb);
1002
+ tcrdbdel(rdb);
1003
+ return 1;
1004
+ }
1005
+ bool err = false;
1006
+ switch(dmode){
1007
+ case -1:
1008
+ if(!tcrdbputkeep(rdb, kbuf, ksiz, vbuf, vsiz)){
1009
+ printerr(rdb);
1010
+ err = true;
1011
+ }
1012
+ break;
1013
+ case 1:
1014
+ if(!tcrdbputcat(rdb, kbuf, ksiz, vbuf, vsiz)){
1015
+ printerr(rdb);
1016
+ err = true;
1017
+ }
1018
+ break;
1019
+ default:
1020
+ if(shlw >= 0){
1021
+ if(!tcrdbputshl(rdb, kbuf, ksiz, vbuf, vsiz, shlw)){
1022
+ printerr(rdb);
1023
+ err = true;
1024
+ }
1025
+ } else {
1026
+ if(!tcrdbput(rdb, kbuf, ksiz, vbuf, vsiz)){
1027
+ printerr(rdb);
1028
+ err = true;
1029
+ }
1030
+ }
1031
+ break;
1032
+ }
1033
+ if(!tcrdbclose(rdb)){
1034
+ if(!err) printerr(rdb);
1035
+ err = true;
1036
+ }
1037
+ tcrdbdel(rdb);
1038
+ return err ? 1 : 0;
1039
+ }
1040
+
1041
+
1042
+ /* perform out command */
1043
+ static int procout(const char *host, int port, const char *kbuf, int ksiz){
1044
+ TCRDB *rdb = tcrdbnew();
1045
+ if(!myopen(rdb, host, port)){
1046
+ printerr(rdb);
1047
+ tcrdbdel(rdb);
1048
+ return 1;
1049
+ }
1050
+ bool err = false;
1051
+ if(!tcrdbout(rdb, kbuf, ksiz)){
1052
+ printerr(rdb);
1053
+ err = true;
1054
+ }
1055
+ if(!tcrdbclose(rdb)){
1056
+ if(!err) printerr(rdb);
1057
+ err = true;
1058
+ }
1059
+ tcrdbdel(rdb);
1060
+ return err ? 1 : 0;
1061
+ }
1062
+
1063
+
1064
+ /* perform get command */
1065
+ static int procget(const char *host, int port, const char *kbuf, int ksiz, int sep,
1066
+ bool px, bool pz){
1067
+ TCRDB *rdb = tcrdbnew();
1068
+ if(!myopen(rdb, host, port)){
1069
+ printerr(rdb);
1070
+ tcrdbdel(rdb);
1071
+ return 1;
1072
+ }
1073
+ bool err = false;
1074
+ int vsiz;
1075
+ char *vbuf = tcrdbget(rdb, kbuf, ksiz, &vsiz);
1076
+ if(vbuf){
1077
+ printdata(vbuf, vsiz, px, sep);
1078
+ if(!pz) putchar('\n');
1079
+ tcfree(vbuf);
1080
+ } else {
1081
+ printerr(rdb);
1082
+ err = true;
1083
+ }
1084
+ if(!tcrdbclose(rdb)){
1085
+ if(!err) printerr(rdb);
1086
+ err = true;
1087
+ }
1088
+ tcrdbdel(rdb);
1089
+ return err ? 1 : 0;
1090
+ }
1091
+
1092
+
1093
+ /* perform mget command */
1094
+ static int procmget(const char *host, int port, const TCLIST *keys, int sep, bool px){
1095
+ TCRDB *rdb = tcrdbnew();
1096
+ if(!myopen(rdb, host, port)){
1097
+ printerr(rdb);
1098
+ tcrdbdel(rdb);
1099
+ return 1;
1100
+ }
1101
+ bool err = false;
1102
+ TCMAP *recs = tcmapnew();
1103
+ for(int i = 0; i < tclistnum(keys); i++){
1104
+ int ksiz;
1105
+ const char *kbuf = tclistval(keys, i, &ksiz);
1106
+ tcmapput(recs, kbuf, ksiz, "", 0);
1107
+ }
1108
+ if(tcrdbget3(rdb, recs)){
1109
+ tcmapiterinit(recs);
1110
+ const char *kbuf;
1111
+ int ksiz;
1112
+ while((kbuf = tcmapiternext(recs, &ksiz)) != NULL){
1113
+ int vsiz;
1114
+ const char *vbuf = tcmapiterval(kbuf, &vsiz);
1115
+ printdata(kbuf, ksiz, px, sep);
1116
+ putchar('\t');
1117
+ printdata(vbuf, vsiz, px, sep);
1118
+ putchar('\n');
1119
+ }
1120
+ } else {
1121
+ printerr(rdb);
1122
+ err = true;
1123
+ }
1124
+ tcmapdel(recs);
1125
+ if(!tcrdbclose(rdb)){
1126
+ if(!err) printerr(rdb);
1127
+ err = true;
1128
+ }
1129
+ tcrdbdel(rdb);
1130
+ return err ? 1 : 0;
1131
+ }
1132
+
1133
+
1134
+ /* perform list command */
1135
+ static int proclist(const char *host, int port, int sep, int max, bool pv, bool px,
1136
+ const char *fmstr){
1137
+ TCRDB *rdb = tcrdbnew();
1138
+ if(!myopen(rdb, host, port)){
1139
+ printerr(rdb);
1140
+ tcrdbdel(rdb);
1141
+ return 1;
1142
+ }
1143
+ bool err = false;
1144
+ if(fmstr){
1145
+ TCLIST *keys = tcrdbfwmkeys2(rdb, fmstr, max);
1146
+ for(int i = 0; i < tclistnum(keys); i++){
1147
+ int ksiz;
1148
+ const char *kbuf = tclistval(keys, i, &ksiz);
1149
+ printdata(kbuf, ksiz, px, sep);
1150
+ if(pv){
1151
+ int vsiz;
1152
+ char *vbuf = tcrdbget(rdb, kbuf, ksiz, &vsiz);
1153
+ if(vbuf){
1154
+ putchar('\t');
1155
+ printdata(vbuf, vsiz, px, sep);
1156
+ tcfree(vbuf);
1157
+ }
1158
+ }
1159
+ putchar('\n');
1160
+ }
1161
+ tclistdel(keys);
1162
+ } else {
1163
+ if(!tcrdbiterinit(rdb)){
1164
+ printerr(rdb);
1165
+ err = true;
1166
+ }
1167
+ int ksiz;
1168
+ char *kbuf;
1169
+ int cnt = 0;
1170
+ while((kbuf = tcrdbiternext(rdb, &ksiz)) != NULL){
1171
+ printdata(kbuf, ksiz, px, sep);
1172
+ if(pv){
1173
+ int vsiz;
1174
+ char *vbuf = tcrdbget(rdb, kbuf, ksiz, &vsiz);
1175
+ if(vbuf){
1176
+ putchar('\t');
1177
+ printdata(vbuf, vsiz, px, sep);
1178
+ tcfree(vbuf);
1179
+ }
1180
+ }
1181
+ putchar('\n');
1182
+ tcfree(kbuf);
1183
+ if(max >= 0 && ++cnt >= max) break;
1184
+ }
1185
+ }
1186
+ if(!tcrdbclose(rdb)){
1187
+ if(!err) printerr(rdb);
1188
+ err = true;
1189
+ }
1190
+ tcrdbdel(rdb);
1191
+ return err ? 1 : 0;
1192
+ }
1193
+
1194
+
1195
+ /* perform ext command */
1196
+ static int procext(const char *host, int port, const char *name, int opts,
1197
+ const char *kbuf, int ksiz, const char *vbuf, int vsiz, int sep,
1198
+ bool px, bool pz){
1199
+ TCRDB *rdb = tcrdbnew();
1200
+ if(!myopen(rdb, host, port)){
1201
+ printerr(rdb);
1202
+ tcrdbdel(rdb);
1203
+ return 1;
1204
+ }
1205
+ bool err = false;
1206
+ int xsiz;
1207
+ char *xbuf = tcrdbext(rdb, name, opts, kbuf, ksiz, vbuf, vsiz, &xsiz);
1208
+ if(xbuf){
1209
+ printdata(xbuf, xsiz, px, sep);
1210
+ if(!pz) putchar('\n');
1211
+ tcfree(xbuf);
1212
+ } else {
1213
+ printerr(rdb);
1214
+ err = true;
1215
+ }
1216
+ if(!tcrdbclose(rdb)){
1217
+ if(!err) printerr(rdb);
1218
+ err = true;
1219
+ }
1220
+ tcrdbdel(rdb);
1221
+ return err ? 1 : 0;
1222
+ }
1223
+
1224
+
1225
+ /* perform sync command */
1226
+ static int procsync(const char *host, int port){
1227
+ TCRDB *rdb = tcrdbnew();
1228
+ if(!myopen(rdb, host, port)){
1229
+ printerr(rdb);
1230
+ tcrdbdel(rdb);
1231
+ return 1;
1232
+ }
1233
+ bool err = false;
1234
+ if(!tcrdbsync(rdb)){
1235
+ printerr(rdb);
1236
+ err = true;
1237
+ }
1238
+ if(!tcrdbclose(rdb)){
1239
+ if(!err) printerr(rdb);
1240
+ err = true;
1241
+ }
1242
+ tcrdbdel(rdb);
1243
+ return err ? 1 : 0;
1244
+ }
1245
+
1246
+
1247
+ /* perform optimize command */
1248
+ static int procoptimize(const char *host, int port, const char *param){
1249
+ TCRDB *rdb = tcrdbnew();
1250
+ if(!myopen(rdb, host, port)){
1251
+ printerr(rdb);
1252
+ tcrdbdel(rdb);
1253
+ return 1;
1254
+ }
1255
+ bool err = false;
1256
+ if(!tcrdboptimize(rdb, param)){
1257
+ printerr(rdb);
1258
+ err = true;
1259
+ }
1260
+ if(!tcrdbclose(rdb)){
1261
+ if(!err) printerr(rdb);
1262
+ err = true;
1263
+ }
1264
+ tcrdbdel(rdb);
1265
+ return err ? 1 : 0;
1266
+ }
1267
+
1268
+
1269
+ /* perform vanish command */
1270
+ static int procvanish(const char *host, int port){
1271
+ TCRDB *rdb = tcrdbnew();
1272
+ if(!myopen(rdb, host, port)){
1273
+ printerr(rdb);
1274
+ tcrdbdel(rdb);
1275
+ return 1;
1276
+ }
1277
+ bool err = false;
1278
+ if(!tcrdbvanish(rdb)){
1279
+ printerr(rdb);
1280
+ err = true;
1281
+ }
1282
+ if(!tcrdbclose(rdb)){
1283
+ if(!err) printerr(rdb);
1284
+ err = true;
1285
+ }
1286
+ tcrdbdel(rdb);
1287
+ return err ? 1 : 0;
1288
+ }
1289
+
1290
+
1291
+ /* perform copy command */
1292
+ static int proccopy(const char *host, int port, const char *dpath){
1293
+ TCRDB *rdb = tcrdbnew();
1294
+ if(!myopen(rdb, host, port)){
1295
+ printerr(rdb);
1296
+ tcrdbdel(rdb);
1297
+ return 1;
1298
+ }
1299
+ bool err = false;
1300
+ if(!tcrdbcopy(rdb, dpath)){
1301
+ printerr(rdb);
1302
+ err = true;
1303
+ }
1304
+ if(!tcrdbclose(rdb)){
1305
+ if(!err) printerr(rdb);
1306
+ err = true;
1307
+ }
1308
+ tcrdbdel(rdb);
1309
+ return err ? 1 : 0;
1310
+ }
1311
+
1312
+
1313
+ /* perform misc command */
1314
+ static int procmisc(const char *host, int port, const char *func, int opts,
1315
+ const TCLIST *args, int sep, bool px){
1316
+ TCRDB *rdb = tcrdbnew();
1317
+ if(!myopen(rdb, host, port)){
1318
+ printerr(rdb);
1319
+ tcrdbdel(rdb);
1320
+ return 1;
1321
+ }
1322
+ bool err = false;
1323
+ TCLIST *res = tcrdbmisc(rdb, func, opts, args);
1324
+ if(res){
1325
+ for(int i = 0; i < tclistnum(res); i++){
1326
+ int rsiz;
1327
+ const char *rbuf = tclistval(res, i, &rsiz);
1328
+ printdata(rbuf, rsiz, px, sep);
1329
+ printf("\n");
1330
+ }
1331
+ tclistdel(res);
1332
+ } else {
1333
+ printerr(rdb);
1334
+ err = true;
1335
+ }
1336
+ if(!tcrdbclose(rdb)){
1337
+ if(!err) printerr(rdb);
1338
+ err = true;
1339
+ }
1340
+ tcrdbdel(rdb);
1341
+ return err ? 1 : 0;
1342
+ }
1343
+
1344
+
1345
+ /* perform importtsv command */
1346
+ static int procimporttsv(const char *host, int port, const char *file, bool nr,
1347
+ bool sc, int sep){
1348
+ FILE *ifp = file ? fopen(file, "rb") : stdin;
1349
+ if(!ifp){
1350
+ fprintf(stderr, "%s: could not open\n", file ? file : "(stdin)");
1351
+ return 1;
1352
+ }
1353
+ TCRDB *rdb = tcrdbnew();
1354
+ if(!myopen(rdb, host, port)){
1355
+ printerr(rdb);
1356
+ tcrdbdel(rdb);
1357
+ if(ifp != stdin) fclose(ifp);
1358
+ return 1;
1359
+ }
1360
+ bool err = false;
1361
+ char *line;
1362
+ int cnt = 0;
1363
+ while(!err && (line = mygetline(ifp)) != NULL){
1364
+ char *pv = strchr(line, '\t');
1365
+ if(!pv){
1366
+ tcfree(line);
1367
+ continue;
1368
+ }
1369
+ *pv = '\0';
1370
+ if(sc) tcstrtolower(line);
1371
+ char *vbuf;
1372
+ int vsiz;
1373
+ if(sep > 0){
1374
+ vbuf = strtozsv(pv + 1, sep, &vsiz);
1375
+ } else {
1376
+ vsiz = strlen(pv + 1);
1377
+ vbuf = tcmemdup(pv + 1, vsiz);
1378
+ }
1379
+ if(nr){
1380
+ if(!tcrdbputnr(rdb, line, pv - line, vbuf, vsiz)){
1381
+ printerr(rdb);
1382
+ err = true;
1383
+ }
1384
+ } else {
1385
+ if(!tcrdbput(rdb, line, pv - line, vbuf, vsiz)){
1386
+ printerr(rdb);
1387
+ err = true;
1388
+ }
1389
+ }
1390
+ tcfree(vbuf);
1391
+ tcfree(line);
1392
+ if(cnt > 0 && cnt % 100 == 0){
1393
+ putchar('.');
1394
+ fflush(stdout);
1395
+ if(cnt % 5000 == 0) printf(" (%08d)\n", cnt);
1396
+ }
1397
+ cnt++;
1398
+ }
1399
+ printf(" (%08d)\n", cnt);
1400
+ if(!tcrdbclose(rdb)){
1401
+ if(!err) printerr(rdb);
1402
+ err = true;
1403
+ }
1404
+ tcrdbdel(rdb);
1405
+ if(ifp != stdin) fclose(ifp);
1406
+ return err ? 1 : 0;
1407
+ }
1408
+
1409
+
1410
+ /* perform restore command */
1411
+ static int procrestore(const char *host, int port, const char *upath, uint64_t ts, int opts){
1412
+ TCRDB *rdb = tcrdbnew();
1413
+ if(!myopen(rdb, host, port)){
1414
+ printerr(rdb);
1415
+ tcrdbdel(rdb);
1416
+ return 1;
1417
+ }
1418
+ bool err = false;
1419
+ if(!tcrdbrestore(rdb, upath, ts, opts)){
1420
+ printerr(rdb);
1421
+ err = true;
1422
+ }
1423
+ if(!tcrdbclose(rdb)){
1424
+ if(!err) printerr(rdb);
1425
+ err = true;
1426
+ }
1427
+ tcrdbdel(rdb);
1428
+ return err ? 1 : 0;
1429
+ }
1430
+
1431
+
1432
+ /* perform setmst command */
1433
+ static int procsetmst(const char *host, int port, const char *mhost, int mport,
1434
+ uint64_t ts, int opts){
1435
+ TCRDB *rdb = tcrdbnew();
1436
+ if(!myopen(rdb, host, port)){
1437
+ printerr(rdb);
1438
+ tcrdbdel(rdb);
1439
+ return 1;
1440
+ }
1441
+ bool err = false;
1442
+ if(!mysetmst(rdb, mhost, mport, ts, opts)){
1443
+ printerr(rdb);
1444
+ err = true;
1445
+ }
1446
+ if(!tcrdbclose(rdb)){
1447
+ if(!err) printerr(rdb);
1448
+ err = true;
1449
+ }
1450
+ tcrdbdel(rdb);
1451
+ return err ? 1 : 0;
1452
+ }
1453
+
1454
+
1455
+ /* perform repl command */
1456
+ static int procrepl(const char *host, int port, uint64_t ts, uint32_t sid, bool ph){
1457
+ bool err = false;
1458
+ TCREPL *repl = tcreplnew();
1459
+ if(tcreplopen(repl, host, port, ts, sid)){
1460
+ const char *rbuf;
1461
+ int rsiz;
1462
+ uint64_t rts;
1463
+ uint32_t rsid;
1464
+ char stack[TTIOBUFSIZ];
1465
+ while((rbuf = tcreplread(repl, &rsiz, &rts, &rsid)) != NULL){
1466
+ if(rsiz < 1) continue;
1467
+ if(ph){
1468
+ printf("%llu\t%u:%u\t",
1469
+ (unsigned long long)rts, (unsigned int)rsid, (unsigned int)repl->mid);
1470
+ if(rsiz >= 2){
1471
+ printf("%s\t", ttcmdidtostr(((unsigned char *)rbuf)[1]));
1472
+ printdata(rbuf, rsiz, true, -1);
1473
+ putchar('\n');
1474
+ } else {
1475
+ printf("[broken entry]\n");
1476
+ }
1477
+ fflush(stdout);
1478
+ } else {
1479
+ int msiz = sizeof(uint8_t) + sizeof(uint64_t) + sizeof(uint32_t) * 2 + rsiz;
1480
+ char *mbuf = (msiz < TTIOBUFSIZ) ? stack : tcmalloc(msiz);
1481
+ unsigned char *wp = (unsigned char *)mbuf;
1482
+ *(wp++) = TCULMAGICNUM;
1483
+ uint64_t llnum = TTHTONLL(rts);
1484
+ memcpy(wp, &llnum, sizeof(llnum));
1485
+ wp += sizeof(llnum);
1486
+ uint16_t snum = TTHTONS(rsid);
1487
+ memcpy(wp, &snum, sizeof(snum));
1488
+ wp += sizeof(snum);
1489
+ snum = TTHTONS(repl->mid);
1490
+ memcpy(wp, &snum, sizeof(snum));
1491
+ wp += sizeof(snum);
1492
+ uint32_t lnum = TTHTONL(rsiz);
1493
+ memcpy(wp, &lnum, sizeof(lnum));
1494
+ wp += sizeof(lnum);
1495
+ memcpy(wp, rbuf, rsiz);
1496
+ fwrite(mbuf, 1, msiz, stdout);
1497
+ fflush(stdout);
1498
+ if(mbuf != stack) tcfree(mbuf);
1499
+ }
1500
+ }
1501
+ tcreplclose(repl);
1502
+ } else {
1503
+ fprintf(stderr, "%s: %s:%d could not be connected\n", g_progname, host, port);
1504
+ err = true;
1505
+ }
1506
+ tcrepldel(repl);
1507
+ return err ? 1 : 0;
1508
+ }
1509
+
1510
+
1511
+ /* perform http command */
1512
+ static int prochttp(const char *url, TCMAP *hmap, bool ih){
1513
+ bool err = false;
1514
+ TCMAP *resheads = ih ? tcmapnew2(MINIBNUM) : NULL;
1515
+ TCXSTR *body = tcxstrnew();
1516
+ int code = tthttpfetch(url, hmap, resheads, body);
1517
+ if(code > 0){
1518
+ if(resheads){
1519
+ printf("%s\n", tcmapget2(resheads, "STATUS"));
1520
+ tcmapiterinit(resheads);
1521
+ const char *name;
1522
+ while((name = tcmapiternext2(resheads)) != NULL){
1523
+ if(*name >= 'A' && *name <= 'Z') continue;
1524
+ char *cap = tcstrdup(name);
1525
+ tcstrtolower(cap);
1526
+ char *wp = cap;
1527
+ bool head = true;
1528
+ while(*wp != '\0'){
1529
+ if(head && *wp >= 'a' && *wp <= 'z') *wp -= 'a' - 'A';
1530
+ head = *wp == '-' || *wp == ' ';
1531
+ wp++;
1532
+ }
1533
+ printf("%s: %s\n", cap, tcmapiterval2(name));
1534
+ tcfree(cap);
1535
+ }
1536
+ printf("\n");
1537
+ }
1538
+ fwrite(tcxstrptr(body), 1, tcxstrsize(body), stdout);
1539
+ } else {
1540
+ fprintf(stderr, "%s: %s: could not be connected\n", g_progname, url);
1541
+ err = true;
1542
+ }
1543
+ tcxstrdel(body);
1544
+ if(resheads) tcmapdel(resheads);
1545
+ return err ? 1 : 0;
1546
+ }
1547
+
1548
+
1549
+ /* perform version command */
1550
+ static int procversion(void){
1551
+ printf("Tokyo Tyrant version %s (%d:%s) for %s\n",
1552
+ ttversion, _TT_LIBVER, _TT_PROTVER, TTSYSNAME);
1553
+ printf("Copyright (C) 2007-2009 Mikio Hirabayashi\n");
1554
+ return 0;
1555
+ }
1556
+
1557
+
1558
+
1559
+ // END OF FILE