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,2129 @@
1
+ /*************************************************************************************************
2
+ * The test cases of the hash 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 <tchdb.h>
19
+ #include "myconf.h"
20
+
21
+ #define RECBUFSIZ 48 // buffer for records
22
+
23
+
24
+ /* global variables */
25
+ const char *g_progname; // program name
26
+ unsigned int g_randseed; // random seed
27
+ int g_dbgfd; // debugging output
28
+
29
+
30
+ /* function prototypes */
31
+ int main(int argc, char **argv);
32
+ static void usage(void);
33
+ static void iprintf(const char *format, ...);
34
+ static void iputchar(int c);
35
+ static void eprint(TCHDB *hdb, int line, const char *func);
36
+ static void mprint(TCHDB *hdb);
37
+ static void sysprint(void);
38
+ static int myrand(int range);
39
+ static void *pdprocfunc(const void *vbuf, int vsiz, int *sp, void *op);
40
+ static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op);
41
+ static int runwrite(int argc, char **argv);
42
+ static int runread(int argc, char **argv);
43
+ static int runremove(int argc, char **argv);
44
+ static int runrcat(int argc, char **argv);
45
+ static int runmisc(int argc, char **argv);
46
+ static int runwicked(int argc, char **argv);
47
+ static int procwrite(const char *path, int rnum, int bnum, int apow, int fpow,
48
+ bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode,
49
+ bool as, bool rnd);
50
+ static int procread(const char *path, bool mt, int rcnum, int xmsiz, int dfunit, int omode,
51
+ bool wb, bool rnd);
52
+ static int procremove(const char *path, bool mt, int rcnum, int xmsiz, int dfunit, int omode,
53
+ bool rnd);
54
+ static int procrcat(const char *path, int rnum, int bnum, int apow, int fpow,
55
+ bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode, int pnum,
56
+ bool dai, bool dad, bool rl, bool ru);
57
+ static int procmisc(const char *path, int rnum, bool mt, int opts, int omode);
58
+ static int procwicked(const char *path, int rnum, bool mt, int opts, int omode);
59
+
60
+
61
+ /* main routine */
62
+ int main(int argc, char **argv){
63
+ g_progname = argv[0];
64
+ const char *ebuf = getenv("TCRNDSEED");
65
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
66
+ srand(g_randseed);
67
+ ebuf = getenv("TCDBGFD");
68
+ g_dbgfd = ebuf ? tcatoix(ebuf) : UINT16_MAX;
69
+ if(argc < 2) usage();
70
+ int rv = 0;
71
+ if(!strcmp(argv[1], "write")){
72
+ rv = runwrite(argc, argv);
73
+ } else if(!strcmp(argv[1], "read")){
74
+ rv = runread(argc, argv);
75
+ } else if(!strcmp(argv[1], "remove")){
76
+ rv = runremove(argc, argv);
77
+ } else if(!strcmp(argv[1], "rcat")){
78
+ rv = runrcat(argc, argv);
79
+ } else if(!strcmp(argv[1], "misc")){
80
+ rv = runmisc(argc, argv);
81
+ } else if(!strcmp(argv[1], "wicked")){
82
+ rv = runwicked(argc, argv);
83
+ } else {
84
+ usage();
85
+ }
86
+ if(rv != 0){
87
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
88
+ for(int i = 0; i < argc; i++){
89
+ printf(" %s", argv[i]);
90
+ }
91
+ printf("\n\n");
92
+ }
93
+ return rv;
94
+ }
95
+
96
+
97
+ /* print the usage and exit */
98
+ static void usage(void){
99
+ fprintf(stderr, "%s: test cases of the hash database API of Tokyo Cabinet\n", g_progname);
100
+ fprintf(stderr, "\n");
101
+ fprintf(stderr, "usage:\n");
102
+ fprintf(stderr, " %s write [-mt] [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
103
+ " [-nl|-nb] [-as] [-rnd] path rnum [bnum [apow [fpow]]]\n", g_progname);
104
+ fprintf(stderr, " %s read [-mt] [-rc num] [-xm num] [-df num] [-nl|-nb] [-wb] [-rnd] path\n",
105
+ g_progname);
106
+ fprintf(stderr, " %s remove [-mt] [-rc num] [-xm num] [-df num] [-nl|-nb] [-rnd] path\n",
107
+ g_progname);
108
+ fprintf(stderr, " %s rcat [-mt] [-tl] [-td|-tb|-tt|-tx] [-rc num] [-xm num] [-df num]"
109
+ " [-nl|-nb] [-pn num] [-dai|-dad|-rl|-ru] path rnum [bnum [apow [fpow]]]\n",
110
+ g_progname);
111
+ fprintf(stderr, " %s misc [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
112
+ fprintf(stderr, " %s wicked [-mt] [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] path rnum\n", g_progname);
113
+ fprintf(stderr, "\n");
114
+ exit(1);
115
+ }
116
+
117
+
118
+ /* print formatted information string and flush the buffer */
119
+ static void iprintf(const char *format, ...){
120
+ va_list ap;
121
+ va_start(ap, format);
122
+ vprintf(format, ap);
123
+ fflush(stdout);
124
+ va_end(ap);
125
+ }
126
+
127
+
128
+ /* print a character and flush the buffer */
129
+ static void iputchar(int c){
130
+ putchar(c);
131
+ fflush(stdout);
132
+ }
133
+
134
+
135
+ /* print error message of hash database */
136
+ static void eprint(TCHDB *hdb, int line, const char *func){
137
+ const char *path = tchdbpath(hdb);
138
+ int ecode = tchdbecode(hdb);
139
+ fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
140
+ g_progname, path ? path : "-", line, func, ecode, tchdberrmsg(ecode));
141
+ }
142
+
143
+
144
+ /* print members of hash database */
145
+ static void mprint(TCHDB *hdb){
146
+ if(hdb->cnt_writerec < 0) return;
147
+ iprintf("bucket number: %lld\n", (long long)tchdbbnum(hdb));
148
+ iprintf("used bucket number: %lld\n", (long long)tchdbbnumused(hdb));
149
+ iprintf("cnt_writerec: %lld\n", (long long)hdb->cnt_writerec);
150
+ iprintf("cnt_reuserec: %lld\n", (long long)hdb->cnt_reuserec);
151
+ iprintf("cnt_moverec: %lld\n", (long long)hdb->cnt_moverec);
152
+ iprintf("cnt_readrec: %lld\n", (long long)hdb->cnt_readrec);
153
+ iprintf("cnt_searchfbp: %lld\n", (long long)hdb->cnt_searchfbp);
154
+ iprintf("cnt_insertfbp: %lld\n", (long long)hdb->cnt_insertfbp);
155
+ iprintf("cnt_splicefbp: %lld\n", (long long)hdb->cnt_splicefbp);
156
+ iprintf("cnt_dividefbp: %lld\n", (long long)hdb->cnt_dividefbp);
157
+ iprintf("cnt_mergefbp: %lld\n", (long long)hdb->cnt_mergefbp);
158
+ iprintf("cnt_reducefbp: %lld\n", (long long)hdb->cnt_reducefbp);
159
+ iprintf("cnt_appenddrp: %lld\n", (long long)hdb->cnt_appenddrp);
160
+ iprintf("cnt_deferdrp: %lld\n", (long long)hdb->cnt_deferdrp);
161
+ iprintf("cnt_flushdrp: %lld\n", (long long)hdb->cnt_flushdrp);
162
+ iprintf("cnt_adjrecc: %lld\n", (long long)hdb->cnt_adjrecc);
163
+ iprintf("cnt_defrag: %lld\n", (long long)hdb->cnt_defrag);
164
+ iprintf("cnt_shiftrec: %lld\n", (long long)hdb->cnt_shiftrec);
165
+ iprintf("cnt_trunc: %lld\n", (long long)hdb->cnt_trunc);
166
+ }
167
+
168
+
169
+ /* print system information */
170
+ static void sysprint(void){
171
+ TCMAP *info = tcsysinfo();
172
+ if(info){
173
+ tcmapiterinit(info);
174
+ const char *kbuf;
175
+ while((kbuf = tcmapiternext2(info)) != NULL){
176
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
177
+ }
178
+ tcmapdel(info);
179
+ }
180
+ }
181
+
182
+
183
+ /* get a random number */
184
+ static int myrand(int range){
185
+ if(range < 2) return 0;
186
+ int high = (unsigned int)rand() >> 4;
187
+ int low = range * (rand() / (RAND_MAX + 1.0));
188
+ low &= (unsigned int)INT_MAX >> 4;
189
+ return (high + low) % range;
190
+ }
191
+
192
+
193
+ /* duplication callback function */
194
+ static void *pdprocfunc(const void *vbuf, int vsiz, int *sp, void *op){
195
+ if(op){
196
+ char *buf = NULL;
197
+ int len = 0;
198
+ switch((int)(intptr_t)op){
199
+ case 1:
200
+ len = vsiz + 1;
201
+ buf = tcmalloc(len + 1);
202
+ memset(buf, '*', len);
203
+ break;
204
+ case 2:
205
+ buf = (void *)-1;
206
+ break;
207
+ }
208
+ *sp = len;
209
+ return buf;
210
+ }
211
+ if(myrand(4) == 0) return (void *)-1;
212
+ if(myrand(2) == 0) return NULL;
213
+ int len = myrand(RECBUFSIZ);
214
+ char buf[RECBUFSIZ];
215
+ memset(buf, '*', len);
216
+ *sp = len;
217
+ return tcmemdup(buf, len);
218
+ }
219
+
220
+
221
+ /* iterator function */
222
+ static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op){
223
+ unsigned int sum = 0;
224
+ while(--ksiz >= 0){
225
+ sum += ((char *)kbuf)[ksiz];
226
+ }
227
+ while(--vsiz >= 0){
228
+ sum += ((char *)vbuf)[vsiz];
229
+ }
230
+ return myrand(100 + (sum & 0xff)) > 0;
231
+ }
232
+
233
+
234
+ /* parse arguments of write command */
235
+ static int runwrite(int argc, char **argv){
236
+ char *path = NULL;
237
+ char *rstr = NULL;
238
+ char *bstr = NULL;
239
+ char *astr = NULL;
240
+ char *fstr = NULL;
241
+ bool mt = false;
242
+ int opts = 0;
243
+ int rcnum = 0;
244
+ int xmsiz = -1;
245
+ int dfunit = 0;
246
+ int omode = 0;
247
+ bool as = false;
248
+ bool rnd = false;
249
+ for(int i = 2; i < argc; i++){
250
+ if(!path && argv[i][0] == '-'){
251
+ if(!strcmp(argv[i], "-mt")){
252
+ mt = true;
253
+ } else if(!strcmp(argv[i], "-tl")){
254
+ opts |= HDBTLARGE;
255
+ } else if(!strcmp(argv[i], "-td")){
256
+ opts |= HDBTDEFLATE;
257
+ } else if(!strcmp(argv[i], "-tb")){
258
+ opts |= HDBTBZIP;
259
+ } else if(!strcmp(argv[i], "-tt")){
260
+ opts |= HDBTTCBS;
261
+ } else if(!strcmp(argv[i], "-tx")){
262
+ opts |= HDBTEXCODEC;
263
+ } else if(!strcmp(argv[i], "-rc")){
264
+ if(++i >= argc) usage();
265
+ rcnum = tcatoix(argv[i]);
266
+ } else if(!strcmp(argv[i], "-xm")){
267
+ if(++i >= argc) usage();
268
+ xmsiz = tcatoix(argv[i]);
269
+ } else if(!strcmp(argv[i], "-df")){
270
+ if(++i >= argc) usage();
271
+ dfunit = tcatoix(argv[i]);
272
+ } else if(!strcmp(argv[i], "-nl")){
273
+ omode |= HDBONOLCK;
274
+ } else if(!strcmp(argv[i], "-nb")){
275
+ omode |= HDBOLCKNB;
276
+ } else if(!strcmp(argv[i], "-as")){
277
+ as = true;
278
+ } else if(!strcmp(argv[i], "-rnd")){
279
+ rnd = true;
280
+ } else {
281
+ usage();
282
+ }
283
+ } else if(!path){
284
+ path = argv[i];
285
+ } else if(!rstr){
286
+ rstr = argv[i];
287
+ } else if(!bstr){
288
+ bstr = argv[i];
289
+ } else if(!astr){
290
+ astr = argv[i];
291
+ } else if(!fstr){
292
+ fstr = argv[i];
293
+ } else {
294
+ usage();
295
+ }
296
+ }
297
+ if(!path || !rstr) usage();
298
+ int rnum = tcatoix(rstr);
299
+ if(rnum < 1) usage();
300
+ int bnum = bstr ? tcatoix(bstr) : -1;
301
+ int apow = astr ? tcatoix(astr) : -1;
302
+ int fpow = fstr ? tcatoix(fstr) : -1;
303
+ int rv = procwrite(path, rnum, bnum, apow, fpow,
304
+ mt, opts, rcnum, xmsiz, dfunit, omode, as, rnd);
305
+ return rv;
306
+ }
307
+
308
+
309
+ /* parse arguments of read command */
310
+ static int runread(int argc, char **argv){
311
+ char *path = NULL;
312
+ bool mt = false;
313
+ int rcnum = 0;
314
+ int xmsiz = -1;
315
+ int dfunit = 0;
316
+ int omode = 0;
317
+ bool wb = false;
318
+ bool rnd = false;
319
+ for(int i = 2; i < argc; i++){
320
+ if(!path && argv[i][0] == '-'){
321
+ if(!strcmp(argv[i], "-mt")){
322
+ mt = true;
323
+ } else if(!strcmp(argv[i], "-rc")){
324
+ if(++i >= argc) usage();
325
+ rcnum = tcatoix(argv[i]);
326
+ } else if(!strcmp(argv[i], "-xm")){
327
+ if(++i >= argc) usage();
328
+ xmsiz = tcatoix(argv[i]);
329
+ } else if(!strcmp(argv[i], "-df")){
330
+ if(++i >= argc) usage();
331
+ dfunit = tcatoix(argv[i]);
332
+ } else if(!strcmp(argv[i], "-nl")){
333
+ omode |= HDBONOLCK;
334
+ } else if(!strcmp(argv[i], "-nb")){
335
+ omode |= HDBOLCKNB;
336
+ } else if(!strcmp(argv[i], "-wb")){
337
+ wb = true;
338
+ } else if(!strcmp(argv[i], "-rnd")){
339
+ rnd = true;
340
+ } else {
341
+ usage();
342
+ }
343
+ } else if(!path){
344
+ path = argv[i];
345
+ } else {
346
+ usage();
347
+ }
348
+ }
349
+ if(!path) usage();
350
+ int rv = procread(path, mt, rcnum, xmsiz, dfunit, omode, wb, rnd);
351
+ return rv;
352
+ }
353
+
354
+
355
+ /* parse arguments of remove command */
356
+ static int runremove(int argc, char **argv){
357
+ char *path = NULL;
358
+ bool mt = false;
359
+ int rcnum = 0;
360
+ int xmsiz = -1;
361
+ int dfunit = 0;
362
+ int omode = 0;
363
+ bool rnd = false;
364
+ for(int i = 2; i < argc; i++){
365
+ if(!path && argv[i][0] == '-'){
366
+ if(!strcmp(argv[i], "-mt")){
367
+ mt = true;
368
+ } else if(!strcmp(argv[i], "-rc")){
369
+ if(++i >= argc) usage();
370
+ rcnum = tcatoix(argv[i]);
371
+ } else if(!strcmp(argv[i], "-xm")){
372
+ if(++i >= argc) usage();
373
+ xmsiz = tcatoix(argv[i]);
374
+ } else if(!strcmp(argv[i], "-df")){
375
+ if(++i >= argc) usage();
376
+ dfunit = tcatoix(argv[i]);
377
+ } else if(!strcmp(argv[i], "-nl")){
378
+ omode |= HDBONOLCK;
379
+ } else if(!strcmp(argv[i], "-nb")){
380
+ omode |= HDBOLCKNB;
381
+ } else if(!strcmp(argv[i], "-rnd")){
382
+ rnd = true;
383
+ } else {
384
+ usage();
385
+ }
386
+ } else if(!path){
387
+ path = argv[i];
388
+ } else {
389
+ usage();
390
+ }
391
+ }
392
+ if(!path) usage();
393
+ int rv = procremove(path, mt, rcnum, xmsiz, dfunit, omode, rnd);
394
+ return rv;
395
+ }
396
+
397
+
398
+ /* parse arguments of rcat command */
399
+ static int runrcat(int argc, char **argv){
400
+ char *path = NULL;
401
+ char *rstr = NULL;
402
+ char *bstr = NULL;
403
+ char *astr = NULL;
404
+ char *fstr = NULL;
405
+ bool mt = false;
406
+ int opts = 0;
407
+ int rcnum = 0;
408
+ int xmsiz = -1;
409
+ int dfunit = 0;
410
+ int omode = 0;
411
+ int pnum = 0;
412
+ bool dai = false;
413
+ bool dad = false;
414
+ bool rl = false;
415
+ bool ru = false;
416
+ for(int i = 2; i < argc; i++){
417
+ if(!path && argv[i][0] == '-'){
418
+ if(!strcmp(argv[i], "-mt")){
419
+ mt = true;
420
+ } else if(!strcmp(argv[i], "-tl")){
421
+ opts |= HDBTLARGE;
422
+ } else if(!strcmp(argv[i], "-td")){
423
+ opts |= HDBTDEFLATE;
424
+ } else if(!strcmp(argv[i], "-tb")){
425
+ opts |= HDBTBZIP;
426
+ } else if(!strcmp(argv[i], "-tt")){
427
+ opts |= HDBTTCBS;
428
+ } else if(!strcmp(argv[i], "-tx")){
429
+ opts |= HDBTEXCODEC;
430
+ } else if(!strcmp(argv[i], "-rc")){
431
+ if(++i >= argc) usage();
432
+ rcnum = tcatoix(argv[i]);
433
+ } else if(!strcmp(argv[i], "-xm")){
434
+ if(++i >= argc) usage();
435
+ xmsiz = tcatoix(argv[i]);
436
+ } else if(!strcmp(argv[i], "-df")){
437
+ if(++i >= argc) usage();
438
+ dfunit = tcatoix(argv[i]);
439
+ } else if(!strcmp(argv[i], "-nl")){
440
+ omode |= HDBONOLCK;
441
+ } else if(!strcmp(argv[i], "-nb")){
442
+ omode |= HDBOLCKNB;
443
+ } else if(!strcmp(argv[i], "-pn")){
444
+ if(++i >= argc) usage();
445
+ pnum = tcatoix(argv[i]);
446
+ } else if(!strcmp(argv[i], "-dai")){
447
+ dai = true;
448
+ } else if(!strcmp(argv[i], "-dad")){
449
+ dad = true;
450
+ } else if(!strcmp(argv[i], "-rl")){
451
+ rl = true;
452
+ } else if(!strcmp(argv[i], "-ru")){
453
+ ru = true;
454
+ } else {
455
+ usage();
456
+ }
457
+ } else if(!path){
458
+ path = argv[i];
459
+ } else if(!rstr){
460
+ rstr = argv[i];
461
+ } else if(!bstr){
462
+ bstr = argv[i];
463
+ } else if(!astr){
464
+ astr = argv[i];
465
+ } else if(!fstr){
466
+ fstr = argv[i];
467
+ } else {
468
+ usage();
469
+ }
470
+ }
471
+ if(!path || !rstr) usage();
472
+ int rnum = tcatoix(rstr);
473
+ if(rnum < 1) usage();
474
+ int bnum = bstr ? tcatoix(bstr) : -1;
475
+ int apow = astr ? tcatoix(astr) : -1;
476
+ int fpow = fstr ? tcatoix(fstr) : -1;
477
+ int rv = procrcat(path, rnum, bnum, apow, fpow, mt, opts, rcnum, xmsiz, dfunit, omode, pnum,
478
+ dai, dad, rl, ru);
479
+ return rv;
480
+ }
481
+
482
+
483
+ /* parse arguments of misc command */
484
+ static int runmisc(int argc, char **argv){
485
+ char *path = NULL;
486
+ char *rstr = NULL;
487
+ bool mt = false;
488
+ int opts = 0;
489
+ int omode = 0;
490
+ for(int i = 2; i < argc; i++){
491
+ if(!path && argv[i][0] == '-'){
492
+ if(!strcmp(argv[i], "-mt")){
493
+ mt = true;
494
+ } else if(!strcmp(argv[i], "-tl")){
495
+ opts |= HDBTLARGE;
496
+ } else if(!strcmp(argv[i], "-td")){
497
+ opts |= HDBTDEFLATE;
498
+ } else if(!strcmp(argv[i], "-tb")){
499
+ opts |= HDBTBZIP;
500
+ } else if(!strcmp(argv[i], "-tt")){
501
+ opts |= HDBTTCBS;
502
+ } else if(!strcmp(argv[i], "-tx")){
503
+ opts |= HDBTEXCODEC;
504
+ } else if(!strcmp(argv[i], "-nl")){
505
+ omode |= HDBONOLCK;
506
+ } else if(!strcmp(argv[i], "-nb")){
507
+ omode |= HDBOLCKNB;
508
+ } else {
509
+ usage();
510
+ }
511
+ } else if(!path){
512
+ path = argv[i];
513
+ } else if(!rstr){
514
+ rstr = argv[i];
515
+ } else {
516
+ usage();
517
+ }
518
+ }
519
+ if(!path || !rstr) usage();
520
+ int rnum = tcatoix(rstr);
521
+ if(rnum < 1) usage();
522
+ int rv = procmisc(path, rnum, mt, opts, omode);
523
+ return rv;
524
+ }
525
+
526
+
527
+ /* parse arguments of wicked command */
528
+ static int runwicked(int argc, char **argv){
529
+ char *path = NULL;
530
+ char *rstr = NULL;
531
+ bool mt = false;
532
+ int opts = 0;
533
+ int omode = 0;
534
+ for(int i = 2; i < argc; i++){
535
+ if(!path && argv[i][0] == '-'){
536
+ if(!strcmp(argv[i], "-mt")){
537
+ mt = true;
538
+ } else if(!strcmp(argv[i], "-tl")){
539
+ opts |= HDBTLARGE;
540
+ } else if(!strcmp(argv[i], "-td")){
541
+ opts |= HDBTDEFLATE;
542
+ } else if(!strcmp(argv[i], "-tb")){
543
+ opts |= HDBTBZIP;
544
+ } else if(!strcmp(argv[i], "-tt")){
545
+ opts |= HDBTTCBS;
546
+ } else if(!strcmp(argv[i], "-tx")){
547
+ opts |= HDBTEXCODEC;
548
+ } else if(!strcmp(argv[i], "-nl")){
549
+ omode |= HDBONOLCK;
550
+ } else if(!strcmp(argv[i], "-nb")){
551
+ omode |= HDBOLCKNB;
552
+ } else {
553
+ usage();
554
+ }
555
+ } else if(!path){
556
+ path = argv[i];
557
+ } else if(!rstr){
558
+ rstr = argv[i];
559
+ } else {
560
+ usage();
561
+ }
562
+ }
563
+ if(!path || !rstr) usage();
564
+ int rnum = tcatoix(rstr);
565
+ if(rnum < 1) usage();
566
+ int rv = procwicked(path, rnum, mt, opts, omode);
567
+ return rv;
568
+ }
569
+
570
+
571
+ /* perform write command */
572
+ static int procwrite(const char *path, int rnum, int bnum, int apow, int fpow,
573
+ bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode,
574
+ bool as, bool rnd){
575
+ iprintf("<Writing Test>\n seed=%u path=%s rnum=%d bnum=%d apow=%d fpow=%d mt=%d"
576
+ " opts=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d as=%d rnd=%d\n\n",
577
+ g_randseed, path, rnum, bnum, apow, fpow, mt, opts, rcnum, xmsiz, dfunit,
578
+ omode, as, rnd);
579
+ bool err = false;
580
+ double stime = tctime();
581
+ TCHDB *hdb = tchdbnew();
582
+ if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
583
+ if(mt && !tchdbsetmutex(hdb)){
584
+ eprint(hdb, __LINE__, "tchdbsetmutex");
585
+ err = true;
586
+ }
587
+ if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
588
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
589
+ err = true;
590
+ }
591
+ if(!tchdbtune(hdb, bnum, apow, fpow, opts)){
592
+ eprint(hdb, __LINE__, "tchdbtune");
593
+ err = true;
594
+ }
595
+ if(!tchdbsetcache(hdb, rcnum)){
596
+ eprint(hdb, __LINE__, "tchdbsetcache");
597
+ err = true;
598
+ }
599
+ if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
600
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
601
+ err = true;
602
+ }
603
+ if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
604
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
605
+ err = true;
606
+ }
607
+ if(!rnd) omode |= HDBOTRUNC;
608
+ if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | omode)){
609
+ eprint(hdb, __LINE__, "tchdbopen");
610
+ err = true;
611
+ }
612
+ for(int i = 1; i <= rnum; i++){
613
+ char buf[RECBUFSIZ];
614
+ int len = sprintf(buf, "%08d", rnd ? myrand(rnum) + 1 : i);
615
+ if(as){
616
+ if(!tchdbputasync(hdb, buf, len, buf, len)){
617
+ eprint(hdb, __LINE__, "tchdbput");
618
+ err = true;
619
+ break;
620
+ }
621
+ } else {
622
+ if(!tchdbput(hdb, buf, len, buf, len)){
623
+ eprint(hdb, __LINE__, "tchdbput");
624
+ err = true;
625
+ break;
626
+ }
627
+ }
628
+ if(rnum > 250 && i % (rnum / 250) == 0){
629
+ iputchar('.');
630
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
631
+ }
632
+ }
633
+ iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb));
634
+ iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb));
635
+ mprint(hdb);
636
+ sysprint();
637
+ if(!tchdbclose(hdb)){
638
+ eprint(hdb, __LINE__, "tchdbclose");
639
+ err = true;
640
+ }
641
+ tchdbdel(hdb);
642
+ iprintf("time: %.3f\n", tctime() - stime);
643
+ iprintf("%s\n\n", err ? "error" : "ok");
644
+ return err ? 1 : 0;
645
+ }
646
+
647
+
648
+ /* perform read command */
649
+ static int procread(const char *path, bool mt, int rcnum, int xmsiz, int dfunit, int omode,
650
+ bool wb, bool rnd){
651
+ iprintf("<Reading Test>\n seed=%u path=%s mt=%d rcnum=%d xmsiz=%d dfunit=%d omode=%d"
652
+ " wb=%d rnd=%d\n\n", g_randseed, path, mt, rcnum, xmsiz, dfunit, omode, wb, rnd);
653
+ bool err = false;
654
+ double stime = tctime();
655
+ TCHDB *hdb = tchdbnew();
656
+ if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
657
+ if(mt && !tchdbsetmutex(hdb)){
658
+ eprint(hdb, __LINE__, "tchdbsetmutex");
659
+ err = true;
660
+ }
661
+ if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
662
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
663
+ err = true;
664
+ }
665
+ if(!tchdbsetcache(hdb, rcnum)){
666
+ eprint(hdb, __LINE__, "tchdbsetcache");
667
+ err = true;
668
+ }
669
+ if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
670
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
671
+ err = true;
672
+ }
673
+ if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
674
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
675
+ err = true;
676
+ }
677
+ if(!tchdbopen(hdb, path, HDBOREADER | omode)){
678
+ eprint(hdb, __LINE__, "tchdbopen");
679
+ err = true;
680
+ }
681
+ int rnum = tchdbrnum(hdb);
682
+ for(int i = 1; i <= rnum; i++){
683
+ char kbuf[RECBUFSIZ];
684
+ int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
685
+ int vsiz;
686
+ if(wb){
687
+ char vbuf[RECBUFSIZ];
688
+ int vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, RECBUFSIZ);
689
+ if(vsiz < 0 && !(rnd && tchdbecode(hdb) == TCENOREC)){
690
+ eprint(hdb, __LINE__, "tchdbget3");
691
+ err = true;
692
+ break;
693
+ }
694
+ } else {
695
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
696
+ if(!vbuf && !(rnd && tchdbecode(hdb) == TCENOREC)){
697
+ eprint(hdb, __LINE__, "tchdbget");
698
+ err = true;
699
+ break;
700
+ }
701
+ tcfree(vbuf);
702
+ }
703
+ if(rnum > 250 && i % (rnum / 250) == 0){
704
+ iputchar('.');
705
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
706
+ }
707
+ }
708
+ iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb));
709
+ iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb));
710
+ mprint(hdb);
711
+ sysprint();
712
+ if(!tchdbclose(hdb)){
713
+ eprint(hdb, __LINE__, "tchdbclose");
714
+ err = true;
715
+ }
716
+ tchdbdel(hdb);
717
+ iprintf("time: %.3f\n", tctime() - stime);
718
+ iprintf("%s\n\n", err ? "error" : "ok");
719
+ return err ? 1 : 0;
720
+ }
721
+
722
+
723
+ /* perform remove command */
724
+ static int procremove(const char *path, bool mt, int rcnum, int xmsiz, int dfunit, int omode,
725
+ bool rnd){
726
+ iprintf("<Removing Test>\n seed=%u path=%s mt=%d rcnum=%d xmsiz=%d dfunit=%d"
727
+ " omode=%d rnd=%d\n\n", g_randseed, path, mt, rcnum, xmsiz, dfunit, omode, rnd);
728
+ bool err = false;
729
+ double stime = tctime();
730
+ TCHDB *hdb = tchdbnew();
731
+ if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
732
+ if(mt && !tchdbsetmutex(hdb)){
733
+ eprint(hdb, __LINE__, "tchdbsetmutex");
734
+ err = true;
735
+ }
736
+ if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
737
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
738
+ err = true;
739
+ }
740
+ if(!tchdbsetcache(hdb, rcnum)){
741
+ eprint(hdb, __LINE__, "tchdbsetcache");
742
+ err = true;
743
+ }
744
+ if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
745
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
746
+ err = true;
747
+ }
748
+ if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
749
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
750
+ err = true;
751
+ }
752
+ if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
753
+ eprint(hdb, __LINE__, "tchdbopen");
754
+ err = true;
755
+ }
756
+ int rnum = tchdbrnum(hdb);
757
+ for(int i = 1; i <= rnum; i++){
758
+ char kbuf[RECBUFSIZ];
759
+ int ksiz = sprintf(kbuf, "%08d", rnd ? myrand(rnum) + 1 : i);
760
+ if(!tchdbout(hdb, kbuf, ksiz) && !(rnd && tchdbecode(hdb) == TCENOREC)){
761
+ eprint(hdb, __LINE__, "tchdbout");
762
+ err = true;
763
+ break;
764
+ }
765
+ if(rnum > 250 && i % (rnum / 250) == 0){
766
+ iputchar('.');
767
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
768
+ }
769
+ }
770
+ iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb));
771
+ iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb));
772
+ mprint(hdb);
773
+ sysprint();
774
+ if(!tchdbclose(hdb)){
775
+ eprint(hdb, __LINE__, "tchdbclose");
776
+ err = true;
777
+ }
778
+ tchdbdel(hdb);
779
+ iprintf("time: %.3f\n", tctime() - stime);
780
+ iprintf("%s\n\n", err ? "error" : "ok");
781
+ return err ? 1 : 0;
782
+ }
783
+
784
+
785
+ /* perform rcat command */
786
+ static int procrcat(const char *path, int rnum, int bnum, int apow, int fpow,
787
+ bool mt, int opts, int rcnum, int xmsiz, int dfunit, int omode, int pnum,
788
+ bool dai, bool dad, bool rl, bool ru){
789
+ iprintf("<Random Concatenating Test>\n"
790
+ " seed=%u path=%s rnum=%d bnum=%d apow=%d fpow=%d mt=%d opts=%d"
791
+ " rcnum=%d xmsiz=%d dfunit=%d omode=%d pnum=%d dai=%d dad=%d rl=%d ru=%d\n\n",
792
+ g_randseed, path, rnum, bnum, apow, fpow, mt, opts, rcnum, xmsiz, dfunit, omode, pnum,
793
+ dai, dad, rl, ru);
794
+ if(pnum < 1) pnum = rnum;
795
+ bool err = false;
796
+ double stime = tctime();
797
+ TCHDB *hdb = tchdbnew();
798
+ if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
799
+ if(mt && !tchdbsetmutex(hdb)){
800
+ eprint(hdb, __LINE__, "tchdbsetmutex");
801
+ err = true;
802
+ }
803
+ if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
804
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
805
+ err = true;
806
+ }
807
+ if(!tchdbtune(hdb, bnum, apow, fpow, opts)){
808
+ eprint(hdb, __LINE__, "tchdbtune");
809
+ err = true;
810
+ }
811
+ if(!tchdbsetcache(hdb, rcnum)){
812
+ eprint(hdb, __LINE__, "tchdbsetcache");
813
+ err = true;
814
+ }
815
+ if(xmsiz >= 0 && !tchdbsetxmsiz(hdb, xmsiz)){
816
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
817
+ err = true;
818
+ }
819
+ if(dfunit >= 0 && !tchdbsetdfunit(hdb, dfunit)){
820
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
821
+ err = true;
822
+ }
823
+ if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
824
+ eprint(hdb, __LINE__, "tchdbopen");
825
+ err = true;
826
+ }
827
+ for(int i = 1; i <= rnum; i++){
828
+ if(ru){
829
+ char fmt[RECBUFSIZ];
830
+ sprintf(fmt, "%%0%dd", myrand(RECBUFSIZ));
831
+ char kbuf[RECBUFSIZ];
832
+ int ksiz = sprintf(kbuf, fmt, myrand(pnum));
833
+ switch(myrand(8)){
834
+ case 0:
835
+ if(!tchdbput(hdb, kbuf, ksiz, kbuf, ksiz)){
836
+ eprint(hdb, __LINE__, "tchdbput");
837
+ err = true;
838
+ }
839
+ break;
840
+ case 1:
841
+ if(!tchdbputkeep(hdb, kbuf, ksiz, kbuf, ksiz) && tchdbecode(hdb) != TCEKEEP){
842
+ eprint(hdb, __LINE__, "tchdbputkeep");
843
+ err = true;
844
+ }
845
+ break;
846
+ case 2:
847
+ if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
848
+ eprint(hdb, __LINE__, "tchdbout");
849
+ err = true;
850
+ }
851
+ break;
852
+ case 3:
853
+ if(tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP){
854
+ eprint(hdb, __LINE__, "tchdbaddint");
855
+ err = true;
856
+ }
857
+ break;
858
+ case 4:
859
+ if(isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP){
860
+ eprint(hdb, __LINE__, "tchdbadddouble");
861
+ err = true;
862
+ }
863
+ break;
864
+ case 5:
865
+ if(myrand(2) == 0){
866
+ if(!tchdbputproc(hdb, kbuf, ksiz, kbuf, ksiz, pdprocfunc, NULL) &&
867
+ tchdbecode(hdb) != TCEKEEP){
868
+ eprint(hdb, __LINE__, "tchdbputproc");
869
+ err = true;
870
+ }
871
+ } else {
872
+ if(!tchdbputproc(hdb, kbuf, ksiz, NULL, 0, pdprocfunc, NULL) &&
873
+ tchdbecode(hdb) != TCEKEEP && tchdbecode(hdb) != TCENOREC){
874
+ eprint(hdb, __LINE__, "tchdbputproc");
875
+ err = true;
876
+ }
877
+ }
878
+ break;
879
+ default:
880
+ if(!tchdbputcat(hdb, kbuf, ksiz, kbuf, ksiz)){
881
+ eprint(hdb, __LINE__, "tchdbputcat");
882
+ err = true;
883
+ }
884
+ break;
885
+ }
886
+ if(err) break;
887
+ } else {
888
+ char kbuf[RECBUFSIZ];
889
+ int ksiz = sprintf(kbuf, "%d", myrand(pnum));
890
+ if(dai){
891
+ if(tchdbaddint(hdb, kbuf, ksiz, myrand(3)) == INT_MIN){
892
+ eprint(hdb, __LINE__, "tchdbaddint");
893
+ err = true;
894
+ break;
895
+ }
896
+ } else if(dad){
897
+ if(isnan(tchdbadddouble(hdb, kbuf, ksiz, myrand(30) / 10.0))){
898
+ eprint(hdb, __LINE__, "tchdbadddouble");
899
+ err = true;
900
+ break;
901
+ }
902
+ } else if(rl){
903
+ char vbuf[PATH_MAX];
904
+ int vsiz = myrand(PATH_MAX);
905
+ for(int j = 0; j < vsiz; j++){
906
+ vbuf[j] = myrand(0x100);
907
+ }
908
+ if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
909
+ eprint(hdb, __LINE__, "tchdbputcat");
910
+ err = true;
911
+ break;
912
+ }
913
+ } else {
914
+ if(!tchdbputcat(hdb, kbuf, ksiz, kbuf, ksiz)){
915
+ eprint(hdb, __LINE__, "tchdbputcat");
916
+ err = true;
917
+ break;
918
+ }
919
+ }
920
+ }
921
+ if(rnum > 250 && i % (rnum / 250) == 0){
922
+ iputchar('.');
923
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
924
+ }
925
+ }
926
+ iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb));
927
+ iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb));
928
+ mprint(hdb);
929
+ sysprint();
930
+ if(!tchdbclose(hdb)){
931
+ eprint(hdb, __LINE__, "tchdbclose");
932
+ err = true;
933
+ }
934
+ tchdbdel(hdb);
935
+ iprintf("time: %.3f\n", tctime() - stime);
936
+ iprintf("%s\n\n", err ? "error" : "ok");
937
+ return err ? 1 : 0;
938
+ }
939
+
940
+
941
+ /* perform misc command */
942
+ static int procmisc(const char *path, int rnum, bool mt, int opts, int omode){
943
+ iprintf("<Miscellaneous Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
944
+ g_randseed, path, rnum, mt, opts, omode);
945
+ bool err = false;
946
+ double stime = tctime();
947
+ TCHDB *hdb = tchdbnew();
948
+ if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
949
+ if(mt && !tchdbsetmutex(hdb)){
950
+ eprint(hdb, __LINE__, "tchdbsetmutex");
951
+ err = true;
952
+ }
953
+ if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
954
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
955
+ err = true;
956
+ }
957
+ if(!tchdbtune(hdb, rnum / 50, 2, -1, opts)){
958
+ eprint(hdb, __LINE__, "tchdbtune");
959
+ err = true;
960
+ }
961
+ if(!tchdbsetcache(hdb, rnum / 10)){
962
+ eprint(hdb, __LINE__, "tchdbsetcache");
963
+ err = true;
964
+ }
965
+ if(!tchdbsetxmsiz(hdb, rnum * sizeof(int))){
966
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
967
+ err = true;
968
+ }
969
+ if(!tchdbsetdfunit(hdb, 8)){
970
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
971
+ err = true;
972
+ }
973
+ if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
974
+ eprint(hdb, __LINE__, "tchdbopen");
975
+ err = true;
976
+ }
977
+ if(TCUSEPTHREAD){
978
+ TCHDB *hdbdup = tchdbnew();
979
+ if(tchdbopen(hdbdup, path, HDBOREADER)){
980
+ eprint(hdb, __LINE__, "(validation)");
981
+ err = true;
982
+ } else if(tchdbecode(hdbdup) != TCETHREAD){
983
+ eprint(hdb, __LINE__, "(validation)");
984
+ err = true;
985
+ }
986
+ tchdbdel(hdbdup);
987
+ }
988
+ iprintf("writing:\n");
989
+ for(int i = 1; i <= rnum; i++){
990
+ char buf[RECBUFSIZ];
991
+ int len = sprintf(buf, "%08d", i);
992
+ if(i % 3 == 0){
993
+ if(!tchdbputkeep(hdb, buf, len, buf, len)){
994
+ eprint(hdb, __LINE__, "tchdbputkeep");
995
+ err = true;
996
+ break;
997
+ }
998
+ } else {
999
+ if(!tchdbputasync(hdb, buf, len, buf, len)){
1000
+ eprint(hdb, __LINE__, "tchdbputasync");
1001
+ err = true;
1002
+ break;
1003
+ }
1004
+ }
1005
+ if(rnum > 250 && i % (rnum / 250) == 0){
1006
+ iputchar('.');
1007
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1008
+ }
1009
+ }
1010
+ iprintf("reading:\n");
1011
+ for(int i = 1; i <= rnum; i++){
1012
+ char kbuf[RECBUFSIZ];
1013
+ int ksiz = sprintf(kbuf, "%08d", i);
1014
+ int vsiz;
1015
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
1016
+ if(!vbuf){
1017
+ eprint(hdb, __LINE__, "tchdbget");
1018
+ err = true;
1019
+ break;
1020
+ } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
1021
+ eprint(hdb, __LINE__, "(validation)");
1022
+ err = true;
1023
+ tcfree(vbuf);
1024
+ break;
1025
+ }
1026
+ tcfree(vbuf);
1027
+ if(rnum > 250 && i % (rnum / 250) == 0){
1028
+ iputchar('.');
1029
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1030
+ }
1031
+ }
1032
+ if(tchdbrnum(hdb) != rnum){
1033
+ eprint(hdb, __LINE__, "(validation)");
1034
+ err = true;
1035
+ }
1036
+ iprintf("random writing:\n");
1037
+ for(int i = 1; i <= rnum; i++){
1038
+ char kbuf[RECBUFSIZ];
1039
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
1040
+ char vbuf[RECBUFSIZ];
1041
+ int vsiz = myrand(RECBUFSIZ);
1042
+ memset(vbuf, '*', vsiz);
1043
+ if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
1044
+ eprint(hdb, __LINE__, "tchdbput");
1045
+ err = true;
1046
+ break;
1047
+ }
1048
+ int rsiz;
1049
+ char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
1050
+ if(!rbuf){
1051
+ eprint(hdb, __LINE__, "tchdbget");
1052
+ err = true;
1053
+ break;
1054
+ }
1055
+ if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
1056
+ eprint(hdb, __LINE__, "(validation)");
1057
+ err = true;
1058
+ tcfree(rbuf);
1059
+ break;
1060
+ }
1061
+ if(rnum > 250 && i % (rnum / 250) == 0){
1062
+ iputchar('.');
1063
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1064
+ }
1065
+ tcfree(rbuf);
1066
+ }
1067
+ iprintf("word writing:\n");
1068
+ const char *words[] = {
1069
+ "a", "A", "bb", "BB", "ccc", "CCC", "dddd", "DDDD", "eeeee", "EEEEEE",
1070
+ "mikio", "hirabayashi", "tokyo", "cabinet", "hyper", "estraier", "19780211", "birth day",
1071
+ "one", "first", "two", "second", "three", "third", "four", "fourth", "five", "fifth",
1072
+ "_[1]_", "uno", "_[2]_", "dos", "_[3]_", "tres", "_[4]_", "cuatro", "_[5]_", "cinco",
1073
+ "[\xe5\xb9\xb3\xe6\x9e\x97\xe5\xb9\xb9\xe9\x9b\x84]", "[\xe9\xa6\xac\xe9\xb9\xbf]", NULL
1074
+ };
1075
+ for(int i = 0; words[i] != NULL; i += 2){
1076
+ const char *kbuf = words[i];
1077
+ int ksiz = strlen(kbuf);
1078
+ const char *vbuf = words[i+1];
1079
+ int vsiz = strlen(vbuf);
1080
+ if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)){
1081
+ eprint(hdb, __LINE__, "tchdbputkeep");
1082
+ err = true;
1083
+ break;
1084
+ }
1085
+ if(rnum > 250) iputchar('.');
1086
+ }
1087
+ if(rnum > 250) iprintf(" (%08d)\n", (int)(sizeof(words) / sizeof(*words)));
1088
+ iprintf("random erasing:\n");
1089
+ for(int i = 1; i <= rnum; i++){
1090
+ char kbuf[RECBUFSIZ];
1091
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
1092
+ if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
1093
+ eprint(hdb, __LINE__, "tchdbout");
1094
+ err = true;
1095
+ break;
1096
+ }
1097
+ if(rnum > 250 && i % (rnum / 250) == 0){
1098
+ iputchar('.');
1099
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1100
+ }
1101
+ }
1102
+ iprintf("writing:\n");
1103
+ for(int i = 1; i <= rnum; i++){
1104
+ char kbuf[RECBUFSIZ];
1105
+ int ksiz = sprintf(kbuf, "[%d]", i);
1106
+ char vbuf[RECBUFSIZ];
1107
+ int vsiz = i % RECBUFSIZ;
1108
+ memset(vbuf, '*', vsiz);
1109
+ if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz)){
1110
+ eprint(hdb, __LINE__, "tchdbputkeep");
1111
+ err = true;
1112
+ break;
1113
+ }
1114
+ if(vsiz < 1){
1115
+ char tbuf[PATH_MAX];
1116
+ for(int j = 0; j < PATH_MAX; j++){
1117
+ tbuf[j] = myrand(0x100);
1118
+ }
1119
+ if(!tchdbput(hdb, kbuf, ksiz, tbuf, PATH_MAX)){
1120
+ eprint(hdb, __LINE__, "tchdbput");
1121
+ err = true;
1122
+ break;
1123
+ }
1124
+ }
1125
+ if(rnum > 250 && i % (rnum / 250) == 0){
1126
+ iputchar('.');
1127
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1128
+ }
1129
+ }
1130
+ iprintf("erasing:\n");
1131
+ for(int i = 1; i <= rnum; i++){
1132
+ if(i % 2 == 1){
1133
+ char kbuf[RECBUFSIZ];
1134
+ int ksiz = sprintf(kbuf, "[%d]", i);
1135
+ if(!tchdbout(hdb, kbuf, ksiz)){
1136
+ eprint(hdb, __LINE__, "tchdbout");
1137
+ err = true;
1138
+ break;
1139
+ }
1140
+ if(tchdbout(hdb, kbuf, ksiz) || tchdbecode(hdb) != TCENOREC){
1141
+ eprint(hdb, __LINE__, "tchdbout");
1142
+ err = true;
1143
+ break;
1144
+ }
1145
+ }
1146
+ if(rnum > 250 && i % (rnum / 250) == 0){
1147
+ iputchar('.');
1148
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1149
+ }
1150
+ }
1151
+ iprintf("random writing and reopening:\n");
1152
+ for(int i = 1; i <= rnum; i++){
1153
+ if(myrand(10) == 0){
1154
+ int ksiz, vsiz;
1155
+ char *kbuf, *vbuf;
1156
+ ksiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
1157
+ kbuf = tcmalloc(ksiz + 1);
1158
+ memset(kbuf, '@', ksiz);
1159
+ vsiz = (myrand(5) == 0) ? myrand(UINT16_MAX) : myrand(RECBUFSIZ);
1160
+ vbuf = tcmalloc(vsiz + 1);
1161
+ for(int j = 0; j < vsiz; j++){
1162
+ vbuf[j] = myrand(256);
1163
+ }
1164
+ switch(myrand(4)){
1165
+ case 0:
1166
+ if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
1167
+ eprint(hdb, __LINE__, "tchdbput");
1168
+ err = true;
1169
+ }
1170
+ break;
1171
+ case 1:
1172
+ if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
1173
+ eprint(hdb, __LINE__, "tchdbputcat");
1174
+ err = true;
1175
+ }
1176
+ break;
1177
+ case 2:
1178
+ if(!tchdbputasync(hdb, kbuf, ksiz, vbuf, vsiz)){
1179
+ eprint(hdb, __LINE__, "tchdbputasync");
1180
+ err = true;
1181
+ }
1182
+ break;
1183
+ case 3:
1184
+ if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
1185
+ eprint(hdb, __LINE__, "tchdbout");
1186
+ err = true;
1187
+ }
1188
+ break;
1189
+ }
1190
+ tcfree(vbuf);
1191
+ tcfree(kbuf);
1192
+ } else {
1193
+ char kbuf[RECBUFSIZ];
1194
+ int ksiz = myrand(RECBUFSIZ);
1195
+ memset(kbuf, '@', ksiz);
1196
+ char vbuf[RECBUFSIZ];
1197
+ int vsiz = myrand(RECBUFSIZ);
1198
+ memset(vbuf, '@', vsiz);
1199
+ if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
1200
+ eprint(hdb, __LINE__, "tchdbputcat");
1201
+ err = true;
1202
+ break;
1203
+ }
1204
+ }
1205
+ if(rnum > 250 && i % (rnum / 250) == 0){
1206
+ iputchar('.');
1207
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1208
+ }
1209
+ }
1210
+ if(!tchdbclose(hdb)){
1211
+ eprint(hdb, __LINE__, "tchdbclose");
1212
+ err = true;
1213
+ }
1214
+ if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
1215
+ eprint(hdb, __LINE__, "tchdbopen");
1216
+ err = true;
1217
+ }
1218
+ iprintf("checking:\n");
1219
+ for(int i = 1; i <= rnum; i++){
1220
+ char kbuf[RECBUFSIZ];
1221
+ int ksiz = sprintf(kbuf, "[%d]", i);
1222
+ int vsiz;
1223
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
1224
+ if(i % 2 == 0){
1225
+ if(!vbuf){
1226
+ eprint(hdb, __LINE__, "tchdbget");
1227
+ err = true;
1228
+ break;
1229
+ }
1230
+ if(vsiz != i % RECBUFSIZ && vsiz != PATH_MAX){
1231
+ eprint(hdb, __LINE__, "(validation)");
1232
+ err = true;
1233
+ tcfree(vbuf);
1234
+ break;
1235
+ }
1236
+ } else {
1237
+ if(vbuf || tchdbecode(hdb) != TCENOREC){
1238
+ eprint(hdb, __LINE__, "(validation)");
1239
+ err = true;
1240
+ tcfree(vbuf);
1241
+ break;
1242
+ }
1243
+ }
1244
+ tcfree(vbuf);
1245
+ if(rnum > 250 && i % (rnum / 250) == 0){
1246
+ iputchar('.');
1247
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1248
+ }
1249
+ }
1250
+ iprintf("writing:\n");
1251
+ for(int i = 1; i <= rnum; i++){
1252
+ char buf[RECBUFSIZ];
1253
+ int len = sprintf(buf, "%08d", i);
1254
+ if(!tchdbput(hdb, buf, len, buf, len)){
1255
+ eprint(hdb, __LINE__, "tchdbput");
1256
+ err = true;
1257
+ break;
1258
+ }
1259
+ if(rnum > 250 && i % (rnum / 250) == 0){
1260
+ iputchar('.');
1261
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1262
+ }
1263
+ }
1264
+ iprintf("reading:\n");
1265
+ for(int i = 1; i <= rnum; i++){
1266
+ char kbuf[RECBUFSIZ];
1267
+ int ksiz = sprintf(kbuf, "%08d", i);
1268
+ int vsiz;
1269
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
1270
+ if(!vbuf){
1271
+ eprint(hdb, __LINE__, "tchdbget");
1272
+ err = true;
1273
+ break;
1274
+ } else if(vsiz != ksiz || memcmp(vbuf, kbuf, vsiz)){
1275
+ eprint(hdb, __LINE__, "(validation)");
1276
+ err = true;
1277
+ tcfree(vbuf);
1278
+ break;
1279
+ }
1280
+ tcfree(vbuf);
1281
+ if(rnum > 250 && i % (rnum / 250) == 0){
1282
+ iputchar('.');
1283
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1284
+ }
1285
+ }
1286
+ iprintf("checking words:\n");
1287
+ for(int i = 0; words[i] != NULL; i += 2){
1288
+ const char *kbuf = words[i];
1289
+ int ksiz = strlen(kbuf);
1290
+ const char *vbuf = words[i+1];
1291
+ int vsiz = strlen(vbuf);
1292
+ int rsiz;
1293
+ char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
1294
+ if(!rbuf){
1295
+ eprint(hdb, __LINE__, "tchdbget");
1296
+ err = true;
1297
+ break;
1298
+ } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
1299
+ eprint(hdb, __LINE__, "(validation)");
1300
+ err = true;
1301
+ tcfree(rbuf);
1302
+ break;
1303
+ }
1304
+ tcfree(rbuf);
1305
+ if(rnum > 250) iputchar('.');
1306
+ }
1307
+ if(rnum > 250) iprintf(" (%08d)\n", (int)(sizeof(words) / sizeof(*words)));
1308
+ iprintf("checking iterator:\n");
1309
+ int inum = 0;
1310
+ if(!tchdbiterinit(hdb)){
1311
+ eprint(hdb, __LINE__, "tchdbiterinit");
1312
+ err = true;
1313
+ }
1314
+ char *kbuf;
1315
+ int ksiz;
1316
+ for(int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++){
1317
+ int vsiz;
1318
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
1319
+ if(!vbuf){
1320
+ eprint(hdb, __LINE__, "tchdbget");
1321
+ err = true;
1322
+ tcfree(kbuf);
1323
+ break;
1324
+ }
1325
+ tcfree(vbuf);
1326
+ tcfree(kbuf);
1327
+ if(rnum > 250 && i % (rnum / 250) == 0){
1328
+ iputchar('.');
1329
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1330
+ }
1331
+ }
1332
+ if(rnum > 250) iprintf(" (%08d)\n", inum);
1333
+ if(tchdbecode(hdb) != TCENOREC || inum != tchdbrnum(hdb)){
1334
+ eprint(hdb, __LINE__, "(validation)");
1335
+ err = true;
1336
+ }
1337
+ iprintf("iteration updating:\n");
1338
+ if(!tchdbiterinit(hdb)){
1339
+ eprint(hdb, __LINE__, "tchdbiterinit");
1340
+ err = true;
1341
+ }
1342
+ inum = 0;
1343
+ for(int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++){
1344
+ if(myrand(2) == 0){
1345
+ if(!tchdbputcat(hdb, kbuf, ksiz, "0123456789", 10)){
1346
+ eprint(hdb, __LINE__, "tchdbputcat");
1347
+ err = true;
1348
+ tcfree(kbuf);
1349
+ break;
1350
+ }
1351
+ } else {
1352
+ if(!tchdbout(hdb, kbuf, ksiz)){
1353
+ eprint(hdb, __LINE__, "tchdbout");
1354
+ err = true;
1355
+ tcfree(kbuf);
1356
+ break;
1357
+ }
1358
+ }
1359
+ tcfree(kbuf);
1360
+ if(rnum > 250 && i % (rnum / 250) == 0){
1361
+ iputchar('.');
1362
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1363
+ }
1364
+ }
1365
+ if(rnum > 250) iprintf(" (%08d)\n", inum);
1366
+ if(tchdbecode(hdb) != TCENOREC || inum < tchdbrnum(hdb)){
1367
+ eprint(hdb, __LINE__, "(validation)");
1368
+ err = true;
1369
+ }
1370
+ if(myrand(10) == 0 && !tchdbsync(hdb)){
1371
+ eprint(hdb, __LINE__, "tchdbsync");
1372
+ err = true;
1373
+ }
1374
+ if(!tchdbvanish(hdb)){
1375
+ eprint(hdb, __LINE__, "tchdbvanish");
1376
+ err = true;
1377
+ }
1378
+ TCMAP *map = tcmapnew();
1379
+ iprintf("random writing:\n");
1380
+ for(int i = 1; i <= rnum; i++){
1381
+ char kbuf[RECBUFSIZ];
1382
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
1383
+ char vbuf[RECBUFSIZ];
1384
+ int vsiz = sprintf(vbuf, "%d", myrand(rnum));
1385
+ switch(myrand(4)){
1386
+ case 0:
1387
+ if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
1388
+ eprint(hdb, __LINE__, "tchdbput");
1389
+ err = true;
1390
+ }
1391
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
1392
+ break;
1393
+ case 1:
1394
+ if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
1395
+ eprint(hdb, __LINE__, "tchdbputkeep");
1396
+ err = true;
1397
+ }
1398
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
1399
+ break;
1400
+ case 2:
1401
+ if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
1402
+ eprint(hdb, __LINE__, "tchdbputcat");
1403
+ err = true;
1404
+ }
1405
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
1406
+ break;
1407
+ case 3:
1408
+ if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
1409
+ eprint(hdb, __LINE__, "tchdbout");
1410
+ err = true;
1411
+ }
1412
+ tcmapout(map, kbuf, ksiz);
1413
+ break;
1414
+ }
1415
+ if(rnum > 250 && i % (rnum / 250) == 0){
1416
+ iputchar('.');
1417
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1418
+ }
1419
+ }
1420
+ if(myrand(4) == 0 && !tchdbdefrag(hdb, 0)){
1421
+ eprint(hdb, __LINE__, "tchdbdefrag");
1422
+ err = true;
1423
+ }
1424
+ if(myrand(4) == 0 && !tchdbcacheclear(hdb)){
1425
+ eprint(hdb, __LINE__, "tchdbcacheclear");
1426
+ err = true;
1427
+ }
1428
+ iprintf("checking transaction commit:\n");
1429
+ if(!tchdbtranbegin(hdb)){
1430
+ eprint(hdb, __LINE__, "tchdbtranbegin");
1431
+ err = true;
1432
+ }
1433
+ for(int i = 1; i <= rnum; i++){
1434
+ char kbuf[RECBUFSIZ];
1435
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
1436
+ char vbuf[RECBUFSIZ];
1437
+ int vsiz = sprintf(vbuf, "[%d]", myrand(rnum));
1438
+ switch(myrand(7)){
1439
+ case 0:
1440
+ if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
1441
+ eprint(hdb, __LINE__, "tchdbput");
1442
+ err = true;
1443
+ }
1444
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
1445
+ break;
1446
+ case 1:
1447
+ if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
1448
+ eprint(hdb, __LINE__, "tchdbputkeep");
1449
+ err = true;
1450
+ }
1451
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
1452
+ break;
1453
+ case 2:
1454
+ if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
1455
+ eprint(hdb, __LINE__, "tchdbputcat");
1456
+ err = true;
1457
+ }
1458
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
1459
+ break;
1460
+ case 3:
1461
+ if(tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP){
1462
+ eprint(hdb, __LINE__, "tchdbaddint");
1463
+ err = true;
1464
+ }
1465
+ tcmapaddint(map, kbuf, ksiz, 1);
1466
+ break;
1467
+ case 4:
1468
+ if(isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP){
1469
+ eprint(hdb, __LINE__, "tchdbadddouble");
1470
+ err = true;
1471
+ }
1472
+ tcmapadddouble(map, kbuf, ksiz, 1.0);
1473
+ break;
1474
+ case 5:
1475
+ if(myrand(2) == 0){
1476
+ void *op = (void *)(intptr_t)(myrand(3) + 1);
1477
+ if(!tchdbputproc(hdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
1478
+ tchdbecode(hdb) != TCEKEEP){
1479
+ eprint(hdb, __LINE__, "tchdbputproc");
1480
+ err = true;
1481
+ }
1482
+ tcmapputproc(map, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op);
1483
+ } else {
1484
+ vsiz = myrand(10);
1485
+ void *op = (void *)(intptr_t)(myrand(3) + 1);
1486
+ if(!tchdbputproc(hdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
1487
+ tchdbecode(hdb) != TCEKEEP && tchdbecode(hdb) != TCENOREC){
1488
+ eprint(hdb, __LINE__, "tchdbputproc");
1489
+ err = true;
1490
+ }
1491
+ tcmapputproc(map, kbuf, ksiz, NULL, vsiz, pdprocfunc, op);
1492
+ }
1493
+ break;
1494
+ case 6:
1495
+ if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
1496
+ eprint(hdb, __LINE__, "tchdbout");
1497
+ err = true;
1498
+ }
1499
+ tcmapout(map, kbuf, ksiz);
1500
+ break;
1501
+ }
1502
+ if(rnum > 250 && i % (rnum / 250) == 0){
1503
+ iputchar('.');
1504
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1505
+ }
1506
+ }
1507
+ if(!tchdbtrancommit(hdb)){
1508
+ eprint(hdb, __LINE__, "tchdbtrancommit");
1509
+ err = true;
1510
+ }
1511
+ iprintf("checking transaction abort:\n");
1512
+ uint64_t ornum = tchdbrnum(hdb);
1513
+ uint64_t ofsiz = tchdbfsiz(hdb);
1514
+ if(!tchdbtranbegin(hdb)){
1515
+ eprint(hdb, __LINE__, "tchdbtranbegin");
1516
+ err = true;
1517
+ }
1518
+ for(int i = 1; i <= rnum; i++){
1519
+ char kbuf[RECBUFSIZ];
1520
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
1521
+ char vbuf[RECBUFSIZ];
1522
+ int vsiz = sprintf(vbuf, "((%d))", myrand(rnum));
1523
+ switch(myrand(7)){
1524
+ case 0:
1525
+ if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
1526
+ eprint(hdb, __LINE__, "tchdbput");
1527
+ err = true;
1528
+ }
1529
+ break;
1530
+ case 1:
1531
+ if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
1532
+ eprint(hdb, __LINE__, "tchdbputkeep");
1533
+ err = true;
1534
+ }
1535
+ break;
1536
+ case 2:
1537
+ if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
1538
+ eprint(hdb, __LINE__, "tchdbputcat");
1539
+ err = true;
1540
+ }
1541
+ break;
1542
+ case 3:
1543
+ if(tchdbaddint(hdb, kbuf, ksiz, 1) == INT_MIN && tchdbecode(hdb) != TCEKEEP){
1544
+ eprint(hdb, __LINE__, "tchdbaddint");
1545
+ err = true;
1546
+ }
1547
+ break;
1548
+ case 4:
1549
+ if(isnan(tchdbadddouble(hdb, kbuf, ksiz, 1.0)) && tchdbecode(hdb) != TCEKEEP){
1550
+ eprint(hdb, __LINE__, "tchdbadddouble");
1551
+ err = true;
1552
+ }
1553
+ break;
1554
+ case 5:
1555
+ if(myrand(2) == 0){
1556
+ void *op = (void *)(intptr_t)(myrand(3) + 1);
1557
+ if(!tchdbputproc(hdb, kbuf, ksiz, vbuf, vsiz, pdprocfunc, op) &&
1558
+ tchdbecode(hdb) != TCEKEEP){
1559
+ eprint(hdb, __LINE__, "tchdbputproc");
1560
+ err = true;
1561
+ }
1562
+ } else {
1563
+ vsiz = myrand(10);
1564
+ void *op = (void *)(intptr_t)(myrand(3) + 1);
1565
+ if(!tchdbputproc(hdb, kbuf, ksiz, NULL, vsiz, pdprocfunc, op) &&
1566
+ tchdbecode(hdb) != TCEKEEP && tchdbecode(hdb) != TCENOREC){
1567
+ eprint(hdb, __LINE__, "tchdbputproc");
1568
+ err = true;
1569
+ }
1570
+ }
1571
+ break;
1572
+ case 6:
1573
+ if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
1574
+ eprint(hdb, __LINE__, "tchdbout");
1575
+ err = true;
1576
+ }
1577
+ break;
1578
+ }
1579
+ if(rnum > 250 && i % (rnum / 250) == 0){
1580
+ iputchar('.');
1581
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1582
+ }
1583
+ }
1584
+ if(!tchdbtranabort(hdb)){
1585
+ eprint(hdb, __LINE__, "tchdbtranabort");
1586
+ err = true;
1587
+ }
1588
+ iprintf("checking consistency:\n");
1589
+ if(tchdbrnum(hdb) != ornum || tchdbfsiz(hdb) != ofsiz || tchdbrnum(hdb) != tcmaprnum(map)){
1590
+ eprint(hdb, __LINE__, "(validation)");
1591
+ err = true;
1592
+ }
1593
+ inum = 0;
1594
+ tcmapiterinit(map);
1595
+ const char *tkbuf;
1596
+ int tksiz;
1597
+ for(int i = 1; (tkbuf = tcmapiternext(map, &tksiz)) != NULL; i++, inum++){
1598
+ int tvsiz;
1599
+ const char *tvbuf = tcmapiterval(tkbuf, &tvsiz);
1600
+ int rsiz;
1601
+ char *rbuf = tchdbget(hdb, tkbuf, tksiz, &rsiz);
1602
+ if(!rbuf || rsiz != tvsiz || memcmp(rbuf, tvbuf, rsiz)){
1603
+ eprint(hdb, __LINE__, "(validation)");
1604
+ err = true;
1605
+ tcfree(rbuf);
1606
+ break;
1607
+ }
1608
+ tcfree(rbuf);
1609
+ if(rnum > 250 && i % (rnum / 250) == 0){
1610
+ iputchar('.');
1611
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1612
+ }
1613
+ }
1614
+ if(rnum > 250) iprintf(" (%08d)\n", inum);
1615
+ inum = 0;
1616
+ if(!tchdbiterinit(hdb)){
1617
+ eprint(hdb, __LINE__, "tchdbiterinit");
1618
+ err = true;
1619
+ }
1620
+ for(int i = 1; (kbuf = tchdbiternext(hdb, &ksiz)) != NULL; i++, inum++){
1621
+ int vsiz;
1622
+ char *vbuf = tchdbget(hdb, kbuf, ksiz, &vsiz);
1623
+ int rsiz;
1624
+ const char *rbuf = tcmapget(map, kbuf, ksiz, &rsiz);
1625
+ if(!rbuf || rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
1626
+ eprint(hdb, __LINE__, "(validation)");
1627
+ err = true;
1628
+ tcfree(vbuf);
1629
+ tcfree(kbuf);
1630
+ break;
1631
+ }
1632
+ tcfree(vbuf);
1633
+ tcfree(kbuf);
1634
+ if(rnum > 250 && i % (rnum / 250) == 0){
1635
+ iputchar('.');
1636
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1637
+ }
1638
+ }
1639
+ if(rnum > 250) iprintf(" (%08d)\n", inum);
1640
+ tcmapdel(map);
1641
+ if(!tchdbvanish(hdb)){
1642
+ eprint(hdb, __LINE__, "tchdbvanish");
1643
+ err = true;
1644
+ }
1645
+ for(int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)){
1646
+ char vbuf[i];
1647
+ memset(vbuf, '@', i - 1);
1648
+ vbuf[i-1] = '\0';
1649
+ if(!tchdbput2(hdb, "mikio", vbuf)){
1650
+ eprint(hdb, __LINE__, "tchdbput2");
1651
+ err = true;
1652
+ }
1653
+ }
1654
+ if(!tchdbput2(hdb, "mikio", "nanashi")){
1655
+ eprint(hdb, __LINE__, "tchdbput2");
1656
+ err = true;
1657
+ }
1658
+ if(!tchdbtranbegin(hdb)){
1659
+ eprint(hdb, __LINE__, "tchdbtranbegin");
1660
+ err = true;
1661
+ }
1662
+ if(!tchdbput2(hdb, "mikio", "hirabayashi")){
1663
+ eprint(hdb, __LINE__, "tchdbput2");
1664
+ err = true;
1665
+ }
1666
+ for(int i = 0; i < 10; i++){
1667
+ char buf[RECBUFSIZ];
1668
+ int size = sprintf(buf, "%d", myrand(rnum));
1669
+ if(!tchdbput(hdb, buf, size, buf, size)){
1670
+ eprint(hdb, __LINE__, "tchdbput");
1671
+ err = true;
1672
+ }
1673
+ }
1674
+ for(int i = myrand(3) + 1; i < PATH_MAX; i = i * 2 + myrand(3)){
1675
+ char vbuf[i];
1676
+ memset(vbuf, '@', i - 1);
1677
+ vbuf[i-1] = '\0';
1678
+ if(!tchdbput2(hdb, "mikio", vbuf)){
1679
+ eprint(hdb, __LINE__, "tchdbput2");
1680
+ err = true;
1681
+ }
1682
+ }
1683
+ if(!tchdbforeach(hdb, iterfunc, NULL)){
1684
+ eprint(hdb, __LINE__, "tchdbforeach");
1685
+ err = true;
1686
+ }
1687
+ iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb));
1688
+ iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb));
1689
+ mprint(hdb);
1690
+ sysprint();
1691
+ if(!tchdbclose(hdb)){
1692
+ eprint(hdb, __LINE__, "tchdbclose");
1693
+ err = true;
1694
+ }
1695
+ tchdbdel(hdb);
1696
+ iprintf("time: %.3f\n", tctime() - stime);
1697
+ iprintf("%s\n\n", err ? "error" : "ok");
1698
+ return err ? 1 : 0;
1699
+ }
1700
+
1701
+
1702
+ /* perform wicked command */
1703
+ static int procwicked(const char *path, int rnum, bool mt, int opts, int omode){
1704
+ iprintf("<Wicked Writing Test>\n seed=%u path=%s rnum=%d mt=%d opts=%d omode=%d\n\n",
1705
+ g_randseed, path, rnum, mt, opts, omode);
1706
+ bool err = false;
1707
+ double stime = tctime();
1708
+ TCHDB *hdb = tchdbnew();
1709
+ if(g_dbgfd >= 0) tchdbsetdbgfd(hdb, g_dbgfd);
1710
+ if(mt && !tchdbsetmutex(hdb)){
1711
+ eprint(hdb, __LINE__, "tchdbsetmutex");
1712
+ err = true;
1713
+ }
1714
+ if(!tchdbsetcodecfunc(hdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
1715
+ eprint(hdb, __LINE__, "tchdbsetcodecfunc");
1716
+ err = true;
1717
+ }
1718
+ if(!tchdbtune(hdb, rnum / 50, 2, -1, opts)){
1719
+ eprint(hdb, __LINE__, "tchdbtune");
1720
+ err = true;
1721
+ }
1722
+ if(!tchdbsetcache(hdb, rnum / 10)){
1723
+ eprint(hdb, __LINE__, "tchdbsetcache");
1724
+ err = true;
1725
+ }
1726
+ if(!tchdbsetxmsiz(hdb, rnum * sizeof(int))){
1727
+ eprint(hdb, __LINE__, "tchdbsetxmsiz");
1728
+ err = true;
1729
+ }
1730
+ if(!tchdbsetdfunit(hdb, 8)){
1731
+ eprint(hdb, __LINE__, "tchdbsetdfunit");
1732
+ err = true;
1733
+ }
1734
+ if(!tchdbopen(hdb, path, HDBOWRITER | HDBOCREAT | HDBOTRUNC | omode)){
1735
+ eprint(hdb, __LINE__, "tchdbopen");
1736
+ err = true;
1737
+ }
1738
+ if(!tchdbiterinit(hdb)){
1739
+ eprint(hdb, __LINE__, "tchdbiterinit");
1740
+ err = true;
1741
+ }
1742
+ TCMAP *map = tcmapnew2(rnum / 5);
1743
+ for(int i = 1; i <= rnum && !err; i++){
1744
+ char kbuf[RECBUFSIZ];
1745
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum));
1746
+ char vbuf[RECBUFSIZ];
1747
+ int vsiz = myrand(RECBUFSIZ);
1748
+ memset(vbuf, '*', vsiz);
1749
+ vbuf[vsiz] = '\0';
1750
+ char *rbuf;
1751
+ switch(myrand(16)){
1752
+ case 0:
1753
+ iputchar('0');
1754
+ if(!tchdbput(hdb, kbuf, ksiz, vbuf, vsiz)){
1755
+ eprint(hdb, __LINE__, "tchdbput");
1756
+ err = true;
1757
+ }
1758
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
1759
+ break;
1760
+ case 1:
1761
+ iputchar('1');
1762
+ if(!tchdbput2(hdb, kbuf, vbuf)){
1763
+ eprint(hdb, __LINE__, "tchdbput2");
1764
+ err = true;
1765
+ }
1766
+ tcmapput2(map, kbuf, vbuf);
1767
+ break;
1768
+ case 2:
1769
+ iputchar('2');
1770
+ if(!tchdbputkeep(hdb, kbuf, ksiz, vbuf, vsiz) && tchdbecode(hdb) != TCEKEEP){
1771
+ eprint(hdb, __LINE__, "tchdbputkeep");
1772
+ err = true;
1773
+ }
1774
+ tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
1775
+ break;
1776
+ case 3:
1777
+ iputchar('3');
1778
+ if(!tchdbputkeep2(hdb, kbuf, vbuf) && tchdbecode(hdb) != TCEKEEP){
1779
+ eprint(hdb, __LINE__, "tchdbputkeep2");
1780
+ err = true;
1781
+ }
1782
+ tcmapputkeep2(map, kbuf, vbuf);
1783
+ break;
1784
+ case 4:
1785
+ iputchar('4');
1786
+ if(!tchdbputcat(hdb, kbuf, ksiz, vbuf, vsiz)){
1787
+ eprint(hdb, __LINE__, "tchdbputcat");
1788
+ err = true;
1789
+ }
1790
+ tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
1791
+ break;
1792
+ case 5:
1793
+ iputchar('5');
1794
+ if(!tchdbputcat2(hdb, kbuf, vbuf)){
1795
+ eprint(hdb, __LINE__, "tchdbputcat2");
1796
+ err = true;
1797
+ }
1798
+ tcmapputcat2(map, kbuf, vbuf);
1799
+ break;
1800
+ case 6:
1801
+ iputchar('6');
1802
+ if(!tchdbputasync(hdb, kbuf, ksiz, vbuf, vsiz)){
1803
+ eprint(hdb, __LINE__, "tchdbputasync");
1804
+ err = true;
1805
+ }
1806
+ tcmapput(map, kbuf, ksiz, vbuf, vsiz);
1807
+ break;
1808
+ case 7:
1809
+ iputchar('7');
1810
+ if(!tchdbputasync2(hdb, kbuf, vbuf)){
1811
+ eprint(hdb, __LINE__, "tchdbputasync2");
1812
+ err = true;
1813
+ }
1814
+ tcmapput2(map, kbuf, vbuf);
1815
+ break;
1816
+ case 8:
1817
+ iputchar('8');
1818
+ if(myrand(10) == 0){
1819
+ if(!tchdbout(hdb, kbuf, ksiz) && tchdbecode(hdb) != TCENOREC){
1820
+ eprint(hdb, __LINE__, "tchdbout");
1821
+ err = true;
1822
+ }
1823
+ tcmapout(map, kbuf, ksiz);
1824
+ }
1825
+ break;
1826
+ case 9:
1827
+ iputchar('9');
1828
+ if(myrand(10) == 0){
1829
+ if(!tchdbout2(hdb, kbuf) && tchdbecode(hdb) != TCENOREC){
1830
+ eprint(hdb, __LINE__, "tchdbout2");
1831
+ err = true;
1832
+ }
1833
+ tcmapout2(map, kbuf);
1834
+ }
1835
+ break;
1836
+ case 10:
1837
+ iputchar('A');
1838
+ if(!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz))){
1839
+ if(tchdbecode(hdb) != TCENOREC){
1840
+ eprint(hdb, __LINE__, "tchdbget");
1841
+ err = true;
1842
+ }
1843
+ rbuf = tcsprintf("[%d]", myrand(i + 1));
1844
+ vsiz = strlen(rbuf);
1845
+ }
1846
+ vsiz += myrand(vsiz);
1847
+ if(myrand(3) == 0) vsiz += PATH_MAX;
1848
+ rbuf = tcrealloc(rbuf, vsiz + 1);
1849
+ for(int j = 0; j < vsiz; j++){
1850
+ rbuf[j] = myrand(0x100);
1851
+ }
1852
+ if(!tchdbput(hdb, kbuf, ksiz, rbuf, vsiz)){
1853
+ eprint(hdb, __LINE__, "tchdbput");
1854
+ err = true;
1855
+ }
1856
+ tcmapput(map, kbuf, ksiz, rbuf, vsiz);
1857
+ tcfree(rbuf);
1858
+ break;
1859
+ case 11:
1860
+ iputchar('B');
1861
+ if(!(rbuf = tchdbget(hdb, kbuf, ksiz, &vsiz)) && tchdbecode(hdb) != TCENOREC){
1862
+ eprint(hdb, __LINE__, "tchdbget");
1863
+ err = true;
1864
+ }
1865
+ tcfree(rbuf);
1866
+ break;
1867
+ case 12:
1868
+ iputchar('C');
1869
+ if(!(rbuf = tchdbget2(hdb, kbuf)) && tchdbecode(hdb) != TCENOREC){
1870
+ eprint(hdb, __LINE__, "tchdbget2");
1871
+ err = true;
1872
+ }
1873
+ tcfree(rbuf);
1874
+ break;
1875
+ case 13:
1876
+ iputchar('D');
1877
+ if(myrand(1) == 0) vsiz = 1;
1878
+ if((vsiz = tchdbget3(hdb, kbuf, ksiz, vbuf, vsiz)) < 0 && tchdbecode(hdb) != TCENOREC){
1879
+ eprint(hdb, __LINE__, "tchdbget3");
1880
+ err = true;
1881
+ }
1882
+ break;
1883
+ case 14:
1884
+ iputchar('E');
1885
+ if(myrand(rnum / 50) == 0){
1886
+ if(!tchdbiterinit(hdb)){
1887
+ eprint(hdb, __LINE__, "tchdbiterinit");
1888
+ err = true;
1889
+ }
1890
+ }
1891
+ TCXSTR *ikey = tcxstrnew();
1892
+ TCXSTR *ival = tcxstrnew();
1893
+ for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
1894
+ if(j % 3 == 0){
1895
+ if(tchdbiternext3(hdb, ikey, ival)){
1896
+ if(tcxstrsize(ival) != tchdbvsiz(hdb, tcxstrptr(ikey), tcxstrsize(ikey))){
1897
+ eprint(hdb, __LINE__, "(validation)");
1898
+ err = true;
1899
+ }
1900
+ } else {
1901
+ int ecode = tchdbecode(hdb);
1902
+ if(ecode != TCEINVALID && ecode != TCENOREC){
1903
+ eprint(hdb, __LINE__, "tchdbiternext3");
1904
+ err = true;
1905
+ }
1906
+ }
1907
+ } else {
1908
+ int iksiz;
1909
+ char *ikbuf = tchdbiternext(hdb, &iksiz);
1910
+ if(ikbuf){
1911
+ tcfree(ikbuf);
1912
+ } else {
1913
+ int ecode = tchdbecode(hdb);
1914
+ if(ecode != TCEINVALID && ecode != TCENOREC){
1915
+ eprint(hdb, __LINE__, "tchdbiternext");
1916
+ err = true;
1917
+ }
1918
+ }
1919
+ }
1920
+ }
1921
+ tcxstrdel(ival);
1922
+ tcxstrdel(ikey);
1923
+ break;
1924
+ default:
1925
+ iputchar('@');
1926
+ if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
1927
+ if(myrand(rnum / 16 + 1) == 0){
1928
+ int cnt = myrand(30);
1929
+ for(int j = 0; j < rnum && !err; j++){
1930
+ ksiz = sprintf(kbuf, "%d", i + j);
1931
+ if(tchdbout(hdb, kbuf, ksiz)){
1932
+ cnt--;
1933
+ } else if(tchdbecode(hdb) != TCENOREC){
1934
+ eprint(hdb, __LINE__, "tchdbout");
1935
+ err = true;
1936
+ }
1937
+ tcmapout(map, kbuf, ksiz);
1938
+ if(cnt < 0) break;
1939
+ }
1940
+ }
1941
+ break;
1942
+ }
1943
+ if(i % 50 == 0) iprintf(" (%08d)\n", i);
1944
+ if(i == rnum / 2){
1945
+ if(!tchdbclose(hdb)){
1946
+ eprint(hdb, __LINE__, "tchdbclose");
1947
+ err = true;
1948
+ }
1949
+ if(!tchdbopen(hdb, path, HDBOWRITER | omode)){
1950
+ eprint(hdb, __LINE__, "tchdbopen");
1951
+ err = true;
1952
+ }
1953
+ } else if(i == rnum / 4){
1954
+ char *npath = tcsprintf("%s-tmp", path);
1955
+ if(!tchdbcopy(hdb, npath)){
1956
+ eprint(hdb, __LINE__, "tchdbcopy");
1957
+ err = true;
1958
+ }
1959
+ TCHDB *nhdb = tchdbnew();
1960
+ if(!tchdbsetcodecfunc(nhdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
1961
+ eprint(nhdb, __LINE__, "tchdbsetcodecfunc");
1962
+ err = true;
1963
+ }
1964
+ if(!tchdbopen(nhdb, npath, HDBOREADER | omode)){
1965
+ eprint(nhdb, __LINE__, "tchdbopen");
1966
+ err = true;
1967
+ }
1968
+ tchdbdel(nhdb);
1969
+ unlink(npath);
1970
+ tcfree(npath);
1971
+ if(!tchdboptimize(hdb, rnum / 50, -1, -1, -1)){
1972
+ eprint(hdb, __LINE__, "tchdboptimize");
1973
+ err = true;
1974
+ }
1975
+ if(!tchdbiterinit(hdb)){
1976
+ eprint(hdb, __LINE__, "tchdbiterinit");
1977
+ err = true;
1978
+ }
1979
+ } else if(i == rnum / 8){
1980
+ if(!tchdbtranbegin(hdb)){
1981
+ eprint(hdb, __LINE__, "tchdbtranbegin");
1982
+ err = true;
1983
+ }
1984
+ } else if(i == rnum / 8 + rnum / 16){
1985
+ if(!tchdbtrancommit(hdb)){
1986
+ eprint(hdb, __LINE__, "tchdbtrancommit");
1987
+ err = true;
1988
+ }
1989
+ }
1990
+ }
1991
+ if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
1992
+ if(!tchdbsync(hdb)){
1993
+ eprint(hdb, __LINE__, "tchdbsync");
1994
+ err = true;
1995
+ }
1996
+ if(tchdbrnum(hdb) != tcmaprnum(map)){
1997
+ eprint(hdb, __LINE__, "(validation)");
1998
+ err = true;
1999
+ }
2000
+ for(int i = 1; i <= rnum && !err; i++){
2001
+ char kbuf[RECBUFSIZ];
2002
+ int ksiz = sprintf(kbuf, "%d", i - 1);
2003
+ int vsiz;
2004
+ const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
2005
+ int rsiz;
2006
+ char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
2007
+ if(vbuf){
2008
+ iputchar('.');
2009
+ if(!rbuf){
2010
+ eprint(hdb, __LINE__, "tchdbget");
2011
+ err = true;
2012
+ } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
2013
+ eprint(hdb, __LINE__, "(validation)");
2014
+ err = true;
2015
+ }
2016
+ } else {
2017
+ iputchar('*');
2018
+ if(rbuf || tchdbecode(hdb) != TCENOREC){
2019
+ eprint(hdb, __LINE__, "(validation)");
2020
+ err = true;
2021
+ }
2022
+ }
2023
+ tcfree(rbuf);
2024
+ if(i % 50 == 0) iprintf(" (%08d)\n", i);
2025
+ }
2026
+ if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
2027
+ int inum = 0;
2028
+ char *cbuf;
2029
+ int csiz;
2030
+ if(myrand(2) == 0){
2031
+ cbuf = tchdbgetnext(hdb, NULL, -1, &csiz);
2032
+ } else {
2033
+ const char *cvbuf;
2034
+ int cvsiz;
2035
+ cbuf = tchdbgetnext3(hdb, NULL, -1, &csiz, &cvbuf, &cvsiz);
2036
+ }
2037
+ while(cbuf){
2038
+ inum++;
2039
+ iputchar(':');
2040
+ int nsiz;
2041
+ char *nbuf;
2042
+ if(myrand(2) == 0){
2043
+ nbuf = tchdbgetnext(hdb, cbuf, csiz, &nsiz);
2044
+ } else {
2045
+ const char *cvbuf;
2046
+ int cvsiz;
2047
+ nbuf = tchdbgetnext3(hdb, cbuf, csiz, &nsiz, &cvbuf, &cvsiz);
2048
+ }
2049
+ if(myrand(10) == 0){
2050
+ if(!tchdbiterinit2(hdb, cbuf, csiz)){
2051
+ eprint(hdb, __LINE__, "tchdbiterinit2");
2052
+ err = true;
2053
+ }
2054
+ int ksiz;
2055
+ char *kbuf = tchdbiternext(hdb, &ksiz);
2056
+ if(kbuf){
2057
+ tcfree(kbuf);
2058
+ } else {
2059
+ eprint(hdb, __LINE__, "tchdbiternext");
2060
+ err = true;
2061
+ }
2062
+ for(int i = 0; i < 5; i++){
2063
+ kbuf = tchdbiternext(hdb, &ksiz);
2064
+ if(kbuf){
2065
+ tcfree(kbuf);
2066
+ } else if(tchdbecode(hdb) != TCENOREC){
2067
+ eprint(hdb, __LINE__, "tchdbiternext");
2068
+ err = true;
2069
+ }
2070
+ }
2071
+ }
2072
+ tcfree(cbuf);
2073
+ cbuf = nbuf;
2074
+ csiz = nsiz;
2075
+ if(inum % 50 == 0) iprintf(" (%08d)\n", inum);
2076
+ }
2077
+ tcfree(cbuf);
2078
+ if(inum % 50 > 0) iprintf(" (%08d)\n", inum);
2079
+ if(inum != tchdbrnum(hdb)){
2080
+ eprint(hdb, __LINE__, "(validation)");
2081
+ err = true;
2082
+ }
2083
+ tcmapiterinit(map);
2084
+ int ksiz;
2085
+ const char *kbuf;
2086
+ for(int i = 1; (kbuf = tcmapiternext(map, &ksiz)) != NULL; i++){
2087
+ iputchar('+');
2088
+ int vsiz;
2089
+ const char *vbuf = tcmapiterval(kbuf, &vsiz);
2090
+ int rsiz;
2091
+ char *rbuf = tchdbget(hdb, kbuf, ksiz, &rsiz);
2092
+ if(!rbuf){
2093
+ eprint(hdb, __LINE__, "tchdbget");
2094
+ err = true;
2095
+ } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
2096
+ eprint(hdb, __LINE__, "(validation)");
2097
+ err = true;
2098
+ }
2099
+ tcfree(rbuf);
2100
+ if(!tchdbout(hdb, kbuf, ksiz)){
2101
+ eprint(hdb, __LINE__, "tchdbout");
2102
+ err = true;
2103
+ }
2104
+ if(i % 50 == 0) iprintf(" (%08d)\n", i);
2105
+ }
2106
+ int mrnum = tcmaprnum(map);
2107
+ if(mrnum % 50 > 0) iprintf(" (%08d)\n", mrnum);
2108
+ if(tchdbrnum(hdb) != 0){
2109
+ eprint(hdb, __LINE__, "(validation)");
2110
+ err = true;
2111
+ }
2112
+ iprintf("record number: %llu\n", (unsigned long long)tchdbrnum(hdb));
2113
+ iprintf("size: %llu\n", (unsigned long long)tchdbfsiz(hdb));
2114
+ mprint(hdb);
2115
+ sysprint();
2116
+ tcmapdel(map);
2117
+ if(!tchdbclose(hdb)){
2118
+ eprint(hdb, __LINE__, "tchdbclose");
2119
+ err = true;
2120
+ }
2121
+ tchdbdel(hdb);
2122
+ iprintf("time: %.3f\n", tctime() - stime);
2123
+ iprintf("%s\n\n", err ? "error" : "ok");
2124
+ return err ? 1 : 0;
2125
+ }
2126
+
2127
+
2128
+
2129
+ // END OF FILE