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,1810 @@
1
+ /*************************************************************************************************
2
+ * The test cases of the B+ tree 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 <tcbdb.h>
19
+ #include "myconf.h"
20
+
21
+ #define RECBUFSIZ 48 // buffer for records
22
+
23
+ typedef struct { // type of structure for write thread
24
+ TCBDB *bdb;
25
+ int rnum;
26
+ bool rnd;
27
+ int id;
28
+ } TARGWRITE;
29
+
30
+ typedef struct { // type of structure for read thread
31
+ TCBDB *bdb;
32
+ int rnum;
33
+ bool wb;
34
+ bool rnd;
35
+ int id;
36
+ } TARGREAD;
37
+
38
+ typedef struct { // type of structure for remove thread
39
+ TCBDB *bdb;
40
+ int rnum;
41
+ bool rnd;
42
+ int id;
43
+ } TARGREMOVE;
44
+
45
+ typedef struct { // type of structure for wicked thread
46
+ TCBDB *bdb;
47
+ int rnum;
48
+ bool nc;
49
+ int id;
50
+ TCMAP *map;
51
+ } TARGWICKED;
52
+
53
+ typedef struct { // type of structure for typical thread
54
+ TCBDB *bdb;
55
+ int rnum;
56
+ bool nc;
57
+ int rratio;
58
+ int id;
59
+ } TARGTYPICAL;
60
+
61
+ typedef struct { // type of structure for race thread
62
+ TCBDB *bdb;
63
+ int rnum;
64
+ int id;
65
+ } TARGRACE;
66
+
67
+
68
+ /* global variables */
69
+ const char *g_progname; // program name
70
+ unsigned int g_randseed; // random seed
71
+ int g_dbgfd; // debugging output
72
+
73
+
74
+ /* function prototypes */
75
+ int main(int argc, char **argv);
76
+ static void usage(void);
77
+ static void iprintf(const char *format, ...);
78
+ static void iputchar(int c);
79
+ static void eprint(TCBDB *bdb, int line, const char *func);
80
+ static void mprint(TCBDB *bdb);
81
+ static void sysprint(void);
82
+ static int myrand(int range);
83
+ static int myrandnd(int range);
84
+ static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op);
85
+ static int runwrite(int argc, char **argv);
86
+ static int runread(int argc, char **argv);
87
+ static int runremove(int argc, char **argv);
88
+ static int runwicked(int argc, char **argv);
89
+ static int runtypical(int argc, char **argv);
90
+ static int runrace(int argc, char **argv);
91
+ static int procwrite(const char *path, int tnum, int rnum, int lmemb, int nmemb,
92
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
93
+ bool rnd);
94
+ static int procread(const char *path, int tnum, int xmsiz, int dfunit, int omode,
95
+ bool wb, bool rnd);
96
+ static int procremove(const char *path, int tnum, int xmsiz, int dfunit, int omode, bool rnd);
97
+ static int procwicked(const char *path, int tnum, int rnum, int opts, int omode, bool nc);
98
+ static int proctypical(const char *path, int tnum, int rnum, int lmemb, int nmemb,
99
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
100
+ bool nc, int rratio);
101
+ static int procrace(const char *path, int tnum, int rnum, int lmemb, int nmemb,
102
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode);
103
+ static void *threadwrite(void *targ);
104
+ static void *threadread(void *targ);
105
+ static void *threadremove(void *targ);
106
+ static void *threadwicked(void *targ);
107
+ static void *threadtypical(void *targ);
108
+ static void *threadrace(void *targ);
109
+
110
+
111
+ /* main routine */
112
+ int main(int argc, char **argv){
113
+ g_progname = argv[0];
114
+ const char *ebuf = getenv("TCRNDSEED");
115
+ g_randseed = ebuf ? tcatoix(ebuf) : tctime() * 1000;
116
+ srand(g_randseed);
117
+ ebuf = getenv("TCDBGFD");
118
+ g_dbgfd = ebuf ? tcatoix(ebuf) : UINT16_MAX;
119
+ if(argc < 2) usage();
120
+ int rv = 0;
121
+ if(!strcmp(argv[1], "write")){
122
+ rv = runwrite(argc, argv);
123
+ } else if(!strcmp(argv[1], "read")){
124
+ rv = runread(argc, argv);
125
+ } else if(!strcmp(argv[1], "remove")){
126
+ rv = runremove(argc, argv);
127
+ } else if(!strcmp(argv[1], "wicked")){
128
+ rv = runwicked(argc, argv);
129
+ } else if(!strcmp(argv[1], "typical")){
130
+ rv = runtypical(argc, argv);
131
+ } else if(!strcmp(argv[1], "race")){
132
+ rv = runrace(argc, argv);
133
+ } else {
134
+ usage();
135
+ }
136
+ if(rv != 0){
137
+ printf("FAILED: TCRNDSEED=%u PID=%d", g_randseed, (int)getpid());
138
+ for(int i = 0; i < argc; i++){
139
+ printf(" %s", argv[i]);
140
+ }
141
+ printf("\n\n");
142
+ }
143
+ return rv;
144
+ }
145
+
146
+
147
+ /* print the usage and exit */
148
+ static void usage(void){
149
+ fprintf(stderr, "%s: test cases of the B+ tree database API of Tokyo Cabinet\n", g_progname);
150
+ fprintf(stderr, "\n");
151
+ fprintf(stderr, "usage:\n");
152
+ fprintf(stderr, " %s write [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb] [-rnd]"
153
+ " path tnum rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
154
+ fprintf(stderr, " %s read [-xm num] [-df num] [-nl|-nb] [-wb] [-rnd] path tnum\n",
155
+ g_progname);
156
+ fprintf(stderr, " %s remove [-xm num] [-df num] [-nl|-nb] [-rnd] path tnum\n", g_progname);
157
+ fprintf(stderr, " %s wicked [-tl] [-td|-tb|-tt|-tx] [-nl|-nb] [-nc] path tnum rnum\n",
158
+ g_progname);
159
+ fprintf(stderr, " %s typical [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb]"
160
+ " [-nc] [-rr num] path tnum rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
161
+ fprintf(stderr, " %s race [-tl] [-td|-tb|-tt|-tx] [-xm num] [-df num] [-nl|-nb]"
162
+ " path tnum rnum [lmemb [nmemb [bnum [apow [fpow]]]]]\n", g_progname);
163
+ fprintf(stderr, "\n");
164
+ exit(1);
165
+ }
166
+
167
+
168
+ /* print formatted information string and flush the buffer */
169
+ static void iprintf(const char *format, ...){
170
+ va_list ap;
171
+ va_start(ap, format);
172
+ vprintf(format, ap);
173
+ fflush(stdout);
174
+ va_end(ap);
175
+ }
176
+
177
+
178
+ /* print a character and flush the buffer */
179
+ static void iputchar(int c){
180
+ putchar(c);
181
+ fflush(stdout);
182
+ }
183
+
184
+
185
+ /* print error message of hash database */
186
+ static void eprint(TCBDB *bdb, int line, const char *func){
187
+ const char *path = tcbdbpath(bdb);
188
+ int ecode = tcbdbecode(bdb);
189
+ fprintf(stderr, "%s: %s: %d: %s: error: %d: %s\n",
190
+ g_progname, path ? path : "-", line, func, ecode, tcbdberrmsg(ecode));
191
+ }
192
+
193
+
194
+ /* print members of hash database */
195
+ static void mprint(TCBDB *bdb){
196
+ if(bdb->hdb->cnt_writerec < 0) return;
197
+ iprintf("max leaf member: %d\n", tcbdblmemb(bdb));
198
+ iprintf("max node member: %d\n", tcbdbnmemb(bdb));
199
+ iprintf("leaf number: %lld\n", (long long)tcbdblnum(bdb));
200
+ iprintf("node number: %lld\n", (long long)tcbdbnnum(bdb));
201
+ iprintf("bucket number: %lld\n", (long long)tcbdbbnum(bdb));
202
+ iprintf("used bucket number: %lld\n", (long long)tcbdbbnumused(bdb));
203
+ iprintf("cnt_saveleaf: %lld\n", (long long)bdb->cnt_saveleaf);
204
+ iprintf("cnt_loadleaf: %lld\n", (long long)bdb->cnt_loadleaf);
205
+ iprintf("cnt_killleaf: %lld\n", (long long)bdb->cnt_killleaf);
206
+ iprintf("cnt_adjleafc: %lld\n", (long long)bdb->cnt_adjleafc);
207
+ iprintf("cnt_savenode: %lld\n", (long long)bdb->cnt_savenode);
208
+ iprintf("cnt_loadnode: %lld\n", (long long)bdb->cnt_loadnode);
209
+ iprintf("cnt_adjnodec: %lld\n", (long long)bdb->cnt_adjnodec);
210
+ iprintf("cnt_writerec: %lld\n", (long long)bdb->hdb->cnt_writerec);
211
+ iprintf("cnt_reuserec: %lld\n", (long long)bdb->hdb->cnt_reuserec);
212
+ iprintf("cnt_moverec: %lld\n", (long long)bdb->hdb->cnt_moverec);
213
+ iprintf("cnt_readrec: %lld\n", (long long)bdb->hdb->cnt_readrec);
214
+ iprintf("cnt_searchfbp: %lld\n", (long long)bdb->hdb->cnt_searchfbp);
215
+ iprintf("cnt_insertfbp: %lld\n", (long long)bdb->hdb->cnt_insertfbp);
216
+ iprintf("cnt_splicefbp: %lld\n", (long long)bdb->hdb->cnt_splicefbp);
217
+ iprintf("cnt_dividefbp: %lld\n", (long long)bdb->hdb->cnt_dividefbp);
218
+ iprintf("cnt_mergefbp: %lld\n", (long long)bdb->hdb->cnt_mergefbp);
219
+ iprintf("cnt_reducefbp: %lld\n", (long long)bdb->hdb->cnt_reducefbp);
220
+ iprintf("cnt_appenddrp: %lld\n", (long long)bdb->hdb->cnt_appenddrp);
221
+ iprintf("cnt_deferdrp: %lld\n", (long long)bdb->hdb->cnt_deferdrp);
222
+ iprintf("cnt_flushdrp: %lld\n", (long long)bdb->hdb->cnt_flushdrp);
223
+ iprintf("cnt_adjrecc: %lld\n", (long long)bdb->hdb->cnt_adjrecc);
224
+ iprintf("cnt_defrag: %lld\n", (long long)bdb->hdb->cnt_defrag);
225
+ iprintf("cnt_shiftrec: %lld\n", (long long)bdb->hdb->cnt_shiftrec);
226
+ iprintf("cnt_trunc: %lld\n", (long long)bdb->hdb->cnt_trunc);
227
+ }
228
+
229
+
230
+ /* print system information */
231
+ static void sysprint(void){
232
+ TCMAP *info = tcsysinfo();
233
+ if(info){
234
+ tcmapiterinit(info);
235
+ const char *kbuf;
236
+ while((kbuf = tcmapiternext2(info)) != NULL){
237
+ iprintf("sys_%s: %s\n", kbuf, tcmapiterval2(kbuf));
238
+ }
239
+ tcmapdel(info);
240
+ }
241
+ }
242
+
243
+
244
+ /* get a random number */
245
+ static int myrand(int range){
246
+ if(range < 2) return 0;
247
+ int high = (unsigned int)rand() >> 4;
248
+ int low = range * (rand() / (RAND_MAX + 1.0));
249
+ low &= (unsigned int)INT_MAX >> 4;
250
+ return (high + low) % range;
251
+ }
252
+
253
+
254
+ /* get a random number based on normal distribution */
255
+ static int myrandnd(int range){
256
+ int num = (int)tcdrandnd(range >> 1, range / 10);
257
+ return (num < 0 || num >= range) ? 0 : num;
258
+ }
259
+
260
+
261
+ /* iterator function */
262
+ static bool iterfunc(const void *kbuf, int ksiz, const void *vbuf, int vsiz, void *op){
263
+ unsigned int sum = 0;
264
+ while(--ksiz >= 0){
265
+ sum += ((char *)kbuf)[ksiz];
266
+ }
267
+ while(--vsiz >= 0){
268
+ sum += ((char *)vbuf)[vsiz];
269
+ }
270
+ return myrand(100 + (sum & 0xff)) > 0;
271
+ }
272
+
273
+
274
+ /* parse arguments of write command */
275
+ static int runwrite(int argc, char **argv){
276
+ char *path = NULL;
277
+ char *tstr = NULL;
278
+ char *rstr = NULL;
279
+ char *lmstr = NULL;
280
+ char *nmstr = NULL;
281
+ char *bstr = NULL;
282
+ char *astr = NULL;
283
+ char *fstr = NULL;
284
+ int opts = 0;
285
+ int xmsiz = -1;
286
+ int dfunit = 0;
287
+ int omode = 0;
288
+ bool rnd = false;
289
+ for(int i = 2; i < argc; i++){
290
+ if(!path && argv[i][0] == '-'){
291
+ if(!strcmp(argv[i], "-tl")){
292
+ opts |= BDBTLARGE;
293
+ } else if(!strcmp(argv[i], "-td")){
294
+ opts |= BDBTDEFLATE;
295
+ } else if(!strcmp(argv[i], "-tb")){
296
+ opts |= BDBTBZIP;
297
+ } else if(!strcmp(argv[i], "-tt")){
298
+ opts |= BDBTTCBS;
299
+ } else if(!strcmp(argv[i], "-tx")){
300
+ opts |= BDBTEXCODEC;
301
+ } else if(!strcmp(argv[i], "-xm")){
302
+ if(++i >= argc) usage();
303
+ xmsiz = tcatoix(argv[i]);
304
+ } else if(!strcmp(argv[i], "-df")){
305
+ if(++i >= argc) usage();
306
+ dfunit = tcatoix(argv[i]);
307
+ } else if(!strcmp(argv[i], "-nl")){
308
+ omode |= BDBONOLCK;
309
+ } else if(!strcmp(argv[i], "-nb")){
310
+ omode |= BDBOLCKNB;
311
+ } else if(!strcmp(argv[i], "-rnd")){
312
+ rnd = true;
313
+ } else {
314
+ usage();
315
+ }
316
+ } else if(!path){
317
+ path = argv[i];
318
+ } else if(!tstr){
319
+ tstr = argv[i];
320
+ } else if(!rstr){
321
+ rstr = argv[i];
322
+ } else if(!lmstr){
323
+ lmstr = argv[i];
324
+ } else if(!nmstr){
325
+ nmstr = argv[i];
326
+ } else if(!bstr){
327
+ bstr = argv[i];
328
+ } else if(!astr){
329
+ astr = argv[i];
330
+ } else if(!fstr){
331
+ fstr = argv[i];
332
+ } else {
333
+ usage();
334
+ }
335
+ }
336
+ if(!path || !tstr || !rstr) usage();
337
+ int tnum = tcatoix(tstr);
338
+ int rnum = tcatoix(rstr);
339
+ if(tnum < 1 || rnum < 1) usage();
340
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
341
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
342
+ int bnum = bstr ? tcatoix(bstr) : -1;
343
+ int apow = astr ? tcatoix(astr) : -1;
344
+ int fpow = fstr ? tcatoix(fstr) : -1;
345
+ int rv = procwrite(path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
346
+ omode, rnd);
347
+ return rv;
348
+ }
349
+
350
+
351
+ /* parse arguments of read command */
352
+ static int runread(int argc, char **argv){
353
+ char *path = NULL;
354
+ char *tstr = NULL;
355
+ int xmsiz = -1;
356
+ int dfunit = 0;
357
+ int omode = 0;
358
+ bool rnd = false;
359
+ bool wb = false;
360
+ for(int i = 2; i < argc; i++){
361
+ if(!path && argv[i][0] == '-'){
362
+ if(!strcmp(argv[i], "-xm")){
363
+ if(++i >= argc) usage();
364
+ xmsiz = tcatoix(argv[i]);
365
+ } else if(!strcmp(argv[i], "-df")){
366
+ if(++i >= argc) usage();
367
+ dfunit = tcatoix(argv[i]);
368
+ } else if(!strcmp(argv[i], "-nl")){
369
+ omode |= BDBONOLCK;
370
+ } else if(!strcmp(argv[i], "-nb")){
371
+ omode |= BDBOLCKNB;
372
+ } else if(!strcmp(argv[i], "-wb")){
373
+ wb = true;
374
+ } else if(!strcmp(argv[i], "-rnd")){
375
+ rnd = true;
376
+ } else {
377
+ usage();
378
+ }
379
+ } else if(!path){
380
+ path = argv[i];
381
+ } else if(!tstr){
382
+ tstr = argv[i];
383
+ } else {
384
+ usage();
385
+ }
386
+ }
387
+ if(!path || !tstr) usage();
388
+ int tnum = tcatoix(tstr);
389
+ if(tnum < 1) usage();
390
+ int rv = procread(path, tnum, xmsiz, dfunit, omode, wb, rnd);
391
+ return rv;
392
+ }
393
+
394
+
395
+ /* parse arguments of remove command */
396
+ static int runremove(int argc, char **argv){
397
+ char *path = NULL;
398
+ char *tstr = NULL;
399
+ int xmsiz = -1;
400
+ int dfunit = 0;
401
+ int omode = 0;
402
+ bool rnd = false;
403
+ for(int i = 2; i < argc; i++){
404
+ if(!path && argv[i][0] == '-'){
405
+ if(!strcmp(argv[i], "-xm")){
406
+ if(++i >= argc) usage();
407
+ xmsiz = tcatoix(argv[i]);
408
+ } else if(!strcmp(argv[i], "-df")){
409
+ if(++i >= argc) usage();
410
+ dfunit = tcatoix(argv[i]);
411
+ } else if(!strcmp(argv[i], "-nl")){
412
+ omode |= BDBONOLCK;
413
+ } else if(!strcmp(argv[i], "-nb")){
414
+ omode |= BDBOLCKNB;
415
+ } else if(!strcmp(argv[i], "-rnd")){
416
+ rnd = true;
417
+ } else {
418
+ usage();
419
+ }
420
+ } else if(!path){
421
+ path = argv[i];
422
+ } else if(!tstr){
423
+ tstr = argv[i];
424
+ } else {
425
+ usage();
426
+ }
427
+ }
428
+ if(!path || !tstr) usage();
429
+ int tnum = tcatoix(tstr);
430
+ if(tnum < 1) usage();
431
+ int rv = procremove(path, tnum, xmsiz, dfunit, omode, rnd);
432
+ return rv;
433
+ }
434
+
435
+
436
+ /* parse arguments of wicked command */
437
+ static int runwicked(int argc, char **argv){
438
+ char *path = NULL;
439
+ char *tstr = NULL;
440
+ char *rstr = NULL;
441
+ int opts = 0;
442
+ int omode = 0;
443
+ bool nc = false;
444
+ for(int i = 2; i < argc; i++){
445
+ if(!path && argv[i][0] == '-'){
446
+ if(!strcmp(argv[i], "-tl")){
447
+ opts |= BDBTLARGE;
448
+ } else if(!strcmp(argv[i], "-td")){
449
+ opts |= BDBTDEFLATE;
450
+ } else if(!strcmp(argv[i], "-tb")){
451
+ opts |= BDBTBZIP;
452
+ } else if(!strcmp(argv[i], "-tt")){
453
+ opts |= BDBTTCBS;
454
+ } else if(!strcmp(argv[i], "-tx")){
455
+ opts |= BDBTEXCODEC;
456
+ } else if(!strcmp(argv[i], "-nl")){
457
+ omode |= BDBONOLCK;
458
+ } else if(!strcmp(argv[i], "-nb")){
459
+ omode |= BDBOLCKNB;
460
+ } else if(!strcmp(argv[i], "-nc")){
461
+ nc = true;
462
+ } else {
463
+ usage();
464
+ }
465
+ } else if(!path){
466
+ path = argv[i];
467
+ } else if(!tstr){
468
+ tstr = argv[i];
469
+ } else if(!rstr){
470
+ rstr = argv[i];
471
+ } else {
472
+ usage();
473
+ }
474
+ }
475
+ if(!path || !tstr || !rstr) usage();
476
+ int tnum = tcatoix(tstr);
477
+ int rnum = tcatoix(rstr);
478
+ if(tnum < 1 || rnum < 1) usage();
479
+ int rv = procwicked(path, tnum, rnum, opts, omode, nc);
480
+ return rv;
481
+ }
482
+
483
+
484
+ /* parse arguments of typical command */
485
+ static int runtypical(int argc, char **argv){
486
+ char *path = NULL;
487
+ char *tstr = NULL;
488
+ char *rstr = NULL;
489
+ char *lmstr = NULL;
490
+ char *nmstr = NULL;
491
+ char *bstr = NULL;
492
+ char *astr = NULL;
493
+ char *fstr = NULL;
494
+ int opts = 0;
495
+ int xmsiz = -1;
496
+ int dfunit = 0;
497
+ int omode = 0;
498
+ int rratio = -1;
499
+ bool nc = false;
500
+ for(int i = 2; i < argc; i++){
501
+ if(!path && argv[i][0] == '-'){
502
+ if(!strcmp(argv[i], "-tl")){
503
+ opts |= BDBTLARGE;
504
+ } else if(!strcmp(argv[i], "-td")){
505
+ opts |= BDBTDEFLATE;
506
+ } else if(!strcmp(argv[i], "-tb")){
507
+ opts |= BDBTBZIP;
508
+ } else if(!strcmp(argv[i], "-tt")){
509
+ opts |= BDBTTCBS;
510
+ } else if(!strcmp(argv[i], "-tx")){
511
+ opts |= BDBTEXCODEC;
512
+ } else if(!strcmp(argv[i], "-xm")){
513
+ if(++i >= argc) usage();
514
+ xmsiz = tcatoix(argv[i]);
515
+ } else if(!strcmp(argv[i], "-df")){
516
+ if(++i >= argc) usage();
517
+ dfunit = tcatoix(argv[i]);
518
+ } else if(!strcmp(argv[i], "-nl")){
519
+ omode |= BDBONOLCK;
520
+ } else if(!strcmp(argv[i], "-nb")){
521
+ omode |= BDBOLCKNB;
522
+ } else if(!strcmp(argv[i], "-nc")){
523
+ nc = true;
524
+ } else if(!strcmp(argv[i], "-rr")){
525
+ if(++i >= argc) usage();
526
+ rratio = tcatoix(argv[i]);
527
+ } else {
528
+ usage();
529
+ }
530
+ } else if(!path){
531
+ path = argv[i];
532
+ } else if(!tstr){
533
+ tstr = argv[i];
534
+ } else if(!rstr){
535
+ rstr = argv[i];
536
+ } else if(!lmstr){
537
+ lmstr = argv[i];
538
+ } else if(!nmstr){
539
+ nmstr = argv[i];
540
+ } else if(!bstr){
541
+ bstr = argv[i];
542
+ } else if(!astr){
543
+ astr = argv[i];
544
+ } else if(!fstr){
545
+ fstr = argv[i];
546
+ } else {
547
+ usage();
548
+ }
549
+ }
550
+ if(!path || !tstr || !rstr) usage();
551
+ int tnum = tcatoix(tstr);
552
+ int rnum = tcatoix(rstr);
553
+ if(tnum < 1 || rnum < 1) usage();
554
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
555
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
556
+ int bnum = bstr ? tcatoix(bstr) : -1;
557
+ int apow = astr ? tcatoix(astr) : -1;
558
+ int fpow = fstr ? tcatoix(fstr) : -1;
559
+ int rv = proctypical(path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
560
+ omode, nc, rratio);
561
+ return rv;
562
+ }
563
+
564
+
565
+ /* parse arguments of race command */
566
+ static int runrace(int argc, char **argv){
567
+ char *path = NULL;
568
+ char *tstr = NULL;
569
+ char *rstr = NULL;
570
+ char *lmstr = NULL;
571
+ char *nmstr = NULL;
572
+ char *bstr = NULL;
573
+ char *astr = NULL;
574
+ char *fstr = NULL;
575
+ int opts = 0;
576
+ int xmsiz = -1;
577
+ int dfunit = 0;
578
+ int omode = 0;
579
+ for(int i = 2; i < argc; i++){
580
+ if(!path && argv[i][0] == '-'){
581
+ if(!strcmp(argv[i], "-tl")){
582
+ opts |= BDBTLARGE;
583
+ } else if(!strcmp(argv[i], "-td")){
584
+ opts |= BDBTDEFLATE;
585
+ } else if(!strcmp(argv[i], "-tb")){
586
+ opts |= BDBTBZIP;
587
+ } else if(!strcmp(argv[i], "-tt")){
588
+ opts |= BDBTTCBS;
589
+ } else if(!strcmp(argv[i], "-tx")){
590
+ opts |= BDBTEXCODEC;
591
+ } else if(!strcmp(argv[i], "-xm")){
592
+ if(++i >= argc) usage();
593
+ xmsiz = tcatoix(argv[i]);
594
+ } else if(!strcmp(argv[i], "-df")){
595
+ if(++i >= argc) usage();
596
+ dfunit = tcatoix(argv[i]);
597
+ } else if(!strcmp(argv[i], "-nl")){
598
+ omode |= BDBONOLCK;
599
+ } else if(!strcmp(argv[i], "-nb")){
600
+ omode |= BDBOLCKNB;
601
+ } else {
602
+ usage();
603
+ }
604
+ } else if(!path){
605
+ path = argv[i];
606
+ } else if(!tstr){
607
+ tstr = argv[i];
608
+ } else if(!rstr){
609
+ rstr = argv[i];
610
+ } else if(!lmstr){
611
+ lmstr = argv[i];
612
+ } else if(!nmstr){
613
+ nmstr = argv[i];
614
+ } else if(!bstr){
615
+ bstr = argv[i];
616
+ } else if(!astr){
617
+ astr = argv[i];
618
+ } else if(!fstr){
619
+ fstr = argv[i];
620
+ } else {
621
+ usage();
622
+ }
623
+ }
624
+ if(!path || !tstr || !rstr) usage();
625
+ int tnum = tcatoix(tstr);
626
+ int rnum = tcatoix(rstr);
627
+ if(tnum < 1 || rnum < 1) usage();
628
+ int lmemb = lmstr ? tcatoix(lmstr) : -1;
629
+ int nmemb = nmstr ? tcatoix(nmstr) : -1;
630
+ int bnum = bstr ? tcatoix(bstr) : -1;
631
+ int apow = astr ? tcatoix(astr) : -1;
632
+ int fpow = fstr ? tcatoix(fstr) : -1;
633
+ int rv = procrace(path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
634
+ omode);
635
+ return rv;
636
+ }
637
+
638
+
639
+ /* perform write command */
640
+ static int procwrite(const char *path, int tnum, int rnum, int lmemb, int nmemb,
641
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
642
+ bool rnd){
643
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d lmemb=%d nmemb=%d"
644
+ " bnum=%d apow=%d fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d rnd=%d\n\n",
645
+ g_randseed, path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
646
+ omode, rnd);
647
+ bool err = false;
648
+ double stime = tctime();
649
+ TCBDB *bdb = tcbdbnew();
650
+ if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd);
651
+ if(!tcbdbsetmutex(bdb)){
652
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
653
+ err = true;
654
+ }
655
+ if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
656
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
657
+ err = true;
658
+ }
659
+ if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
660
+ eprint(bdb, __LINE__, "tcbdbtune");
661
+ err = true;
662
+ }
663
+ if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
664
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
665
+ err = true;
666
+ }
667
+ if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
668
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
669
+ err = true;
670
+ }
671
+ if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
672
+ eprint(bdb, __LINE__, "tcbdbopen");
673
+ err = true;
674
+ }
675
+ TARGWRITE targs[tnum];
676
+ pthread_t threads[tnum];
677
+ if(tnum == 1){
678
+ targs[0].bdb = bdb;
679
+ targs[0].rnum = rnum;
680
+ targs[0].rnd = rnd;
681
+ targs[0].id = 0;
682
+ if(threadwrite(targs) != NULL) err = true;
683
+ } else {
684
+ for(int i = 0; i < tnum; i++){
685
+ targs[i].bdb = bdb;
686
+ targs[i].rnum = rnum;
687
+ targs[i].rnd = rnd;
688
+ targs[i].id = i;
689
+ if(pthread_create(threads + i, NULL, threadwrite, targs + i) != 0){
690
+ eprint(bdb, __LINE__, "pthread_create");
691
+ targs[i].id = -1;
692
+ err = true;
693
+ }
694
+ }
695
+ for(int i = 0; i < tnum; i++){
696
+ if(targs[i].id == -1) continue;
697
+ void *rv;
698
+ if(pthread_join(threads[i], &rv) != 0){
699
+ eprint(bdb, __LINE__, "pthread_join");
700
+ err = true;
701
+ } else if(rv){
702
+ err = true;
703
+ }
704
+ }
705
+ }
706
+ iprintf("record number: %llu\n", (unsigned long long)tcbdbrnum(bdb));
707
+ iprintf("size: %llu\n", (unsigned long long)tcbdbfsiz(bdb));
708
+ mprint(bdb);
709
+ sysprint();
710
+ if(!tcbdbclose(bdb)){
711
+ eprint(bdb, __LINE__, "tcbdbclose");
712
+ err = true;
713
+ }
714
+ tcbdbdel(bdb);
715
+ iprintf("time: %.3f\n", tctime() - stime);
716
+ iprintf("%s\n\n", err ? "error" : "ok");
717
+ return err ? 1 : 0;
718
+ }
719
+
720
+
721
+ /* perform read command */
722
+ static int procread(const char *path, int tnum, int xmsiz, int dfunit, int omode,
723
+ bool wb, bool rnd){
724
+ iprintf("<Reading Test>\n seed=%u path=%s tnum=%d xmsiz=%d dfunit=%d omode=%d"
725
+ " wb=%d rnd=%d\n\n", g_randseed, path, tnum, xmsiz, dfunit, omode, wb, rnd);
726
+ bool err = false;
727
+ double stime = tctime();
728
+ TCBDB *bdb = tcbdbnew();
729
+ if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd);
730
+ if(!tcbdbsetmutex(bdb)){
731
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
732
+ err = true;
733
+ }
734
+ if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
735
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
736
+ err = true;
737
+ }
738
+ if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
739
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
740
+ err = true;
741
+ }
742
+ if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
743
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
744
+ err = true;
745
+ }
746
+ if(!tcbdbopen(bdb, path, BDBOREADER | omode)){
747
+ eprint(bdb, __LINE__, "tcbdbopen");
748
+ err = true;
749
+ }
750
+ int rnum = tcbdbrnum(bdb) / tnum;
751
+ TARGREAD targs[tnum];
752
+ pthread_t threads[tnum];
753
+ if(tnum == 1){
754
+ targs[0].bdb = bdb;
755
+ targs[0].rnum = rnum;
756
+ targs[0].wb = wb;
757
+ targs[0].rnd = rnd;
758
+ targs[0].id = 0;
759
+ if(threadread(targs) != NULL) err = true;
760
+ } else {
761
+ for(int i = 0; i < tnum; i++){
762
+ targs[i].bdb = bdb;
763
+ targs[i].rnum = rnum;
764
+ targs[i].wb = wb;
765
+ targs[i].rnd = rnd;
766
+ targs[i].id = i;
767
+ if(pthread_create(threads + i, NULL, threadread, targs + i) != 0){
768
+ eprint(bdb, __LINE__, "pthread_create");
769
+ targs[i].id = -1;
770
+ err = true;
771
+ }
772
+ }
773
+ for(int i = 0; i < tnum; i++){
774
+ if(targs[i].id == -1) continue;
775
+ void *rv;
776
+ if(pthread_join(threads[i], &rv) != 0){
777
+ eprint(bdb, __LINE__, "pthread_join");
778
+ err = true;
779
+ } else if(rv){
780
+ err = true;
781
+ }
782
+ }
783
+ }
784
+ iprintf("record number: %llu\n", (unsigned long long)tcbdbrnum(bdb));
785
+ iprintf("size: %llu\n", (unsigned long long)tcbdbfsiz(bdb));
786
+ mprint(bdb);
787
+ sysprint();
788
+ if(!tcbdbclose(bdb)){
789
+ eprint(bdb, __LINE__, "tcbdbclose");
790
+ err = true;
791
+ }
792
+ tcbdbdel(bdb);
793
+ iprintf("time: %.3f\n", tctime() - stime);
794
+ iprintf("%s\n\n", err ? "error" : "ok");
795
+ return err ? 1 : 0;
796
+ }
797
+
798
+
799
+ /* perform remove command */
800
+ static int procremove(const char *path, int tnum, int xmsiz, int dfunit, int omode, bool rnd){
801
+ iprintf("<Removing Test>\n seed=%u path=%s tnum=%d xmsiz=%d dfunit=%d omode=%d"
802
+ " rnd=%d\n\n", g_randseed, path, tnum, xmsiz, dfunit, omode, rnd);
803
+ bool err = false;
804
+ double stime = tctime();
805
+ TCBDB *bdb = tcbdbnew();
806
+ if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd);
807
+ if(!tcbdbsetmutex(bdb)){
808
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
809
+ err = true;
810
+ }
811
+ if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
812
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
813
+ err = true;
814
+ }
815
+ if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
816
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
817
+ err = true;
818
+ }
819
+ if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
820
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
821
+ err = true;
822
+ }
823
+ if(!tcbdbopen(bdb, path, BDBOWRITER | omode)){
824
+ eprint(bdb, __LINE__, "tcbdbopen");
825
+ err = true;
826
+ }
827
+ int rnum = tcbdbrnum(bdb) / tnum;
828
+ TARGREMOVE targs[tnum];
829
+ pthread_t threads[tnum];
830
+ if(tnum == 1){
831
+ targs[0].bdb = bdb;
832
+ targs[0].rnum = rnum;
833
+ targs[0].rnd = rnd;
834
+ targs[0].id = 0;
835
+ if(threadremove(targs) != NULL) err = true;
836
+ } else {
837
+ for(int i = 0; i < tnum; i++){
838
+ targs[i].bdb = bdb;
839
+ targs[i].rnum = rnum;
840
+ targs[i].rnd = rnd;
841
+ targs[i].id = i;
842
+ if(pthread_create(threads + i, NULL, threadremove, targs + i) != 0){
843
+ eprint(bdb, __LINE__, "pthread_create");
844
+ targs[i].id = -1;
845
+ err = true;
846
+ }
847
+ }
848
+ for(int i = 0; i < tnum; i++){
849
+ if(targs[i].id == -1) continue;
850
+ void *rv;
851
+ if(pthread_join(threads[i], &rv) != 0){
852
+ eprint(bdb, __LINE__, "pthread_join");
853
+ err = true;
854
+ } else if(rv){
855
+ err = true;
856
+ }
857
+ }
858
+ }
859
+ iprintf("record number: %llu\n", (unsigned long long)tcbdbrnum(bdb));
860
+ iprintf("size: %llu\n", (unsigned long long)tcbdbfsiz(bdb));
861
+ mprint(bdb);
862
+ sysprint();
863
+ if(!tcbdbclose(bdb)){
864
+ eprint(bdb, __LINE__, "tcbdbclose");
865
+ err = true;
866
+ }
867
+ tcbdbdel(bdb);
868
+ iprintf("time: %.3f\n", tctime() - stime);
869
+ iprintf("%s\n\n", err ? "error" : "ok");
870
+ return err ? 1 : 0;
871
+ }
872
+
873
+
874
+ /* perform wicked command */
875
+ static int procwicked(const char *path, int tnum, int rnum, int opts, int omode, bool nc){
876
+ iprintf("<Writing Test>\n seed=%u path=%s tnum=%d rnum=%d opts=%d omode=%d nc=%d\n\n",
877
+ g_randseed, path, tnum, rnum, opts, omode, nc);
878
+ bool err = false;
879
+ double stime = tctime();
880
+ TCBDB *bdb = tcbdbnew();
881
+ if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd);
882
+ if(!tcbdbsetmutex(bdb)){
883
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
884
+ err = true;
885
+ }
886
+ if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
887
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
888
+ err = true;
889
+ }
890
+ if(!tcbdbtune(bdb, 10, 10, rnum / 50, 10, -1, opts)){
891
+ eprint(bdb, __LINE__, "tcbdbtune");
892
+ err = true;
893
+ }
894
+ if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
895
+ eprint(bdb, __LINE__, "tcbdbopen");
896
+ err = true;
897
+ }
898
+ TARGWICKED targs[tnum];
899
+ pthread_t threads[tnum];
900
+ TCMAP *map = tcmapnew();
901
+ if(tnum == 1){
902
+ targs[0].bdb = bdb;
903
+ targs[0].rnum = rnum;
904
+ targs[0].nc = nc;
905
+ targs[0].id = 0;
906
+ targs[0].map = map;
907
+ if(threadwicked(targs) != NULL) err = true;
908
+ } else {
909
+ for(int i = 0; i < tnum; i++){
910
+ targs[i].bdb = bdb;
911
+ targs[i].rnum = rnum;
912
+ targs[i].nc = nc;
913
+ targs[i].id = i;
914
+ targs[i].map = map;
915
+ if(pthread_create(threads + i, NULL, threadwicked, targs + i) != 0){
916
+ eprint(bdb, __LINE__, "pthread_create");
917
+ targs[i].id = -1;
918
+ err = true;
919
+ }
920
+ }
921
+ for(int i = 0; i < tnum; i++){
922
+ if(targs[i].id == -1) continue;
923
+ void *rv;
924
+ if(pthread_join(threads[i], &rv) != 0){
925
+ eprint(bdb, __LINE__, "pthread_join");
926
+ err = true;
927
+ } else if(rv){
928
+ err = true;
929
+ }
930
+ }
931
+ }
932
+ if(!nc){
933
+ if(!tcbdbsync(bdb)){
934
+ eprint(bdb, __LINE__, "tcbdbsync");
935
+ err = true;
936
+ }
937
+ if(tcbdbrnum(bdb) != tcmaprnum(map)){
938
+ eprint(bdb, __LINE__, "(validation)");
939
+ err = true;
940
+ }
941
+ int end = rnum * tnum;
942
+ for(int i = 1; i <= end && !err; i++){
943
+ char kbuf[RECBUFSIZ];
944
+ int ksiz = sprintf(kbuf, "%d", i - 1);
945
+ int vsiz;
946
+ const char *vbuf = tcmapget(map, kbuf, ksiz, &vsiz);
947
+ int rsiz;
948
+ char *rbuf = tcbdbget(bdb, kbuf, ksiz, &rsiz);
949
+ if(vbuf){
950
+ iputchar('.');
951
+ if(!rbuf){
952
+ eprint(bdb, __LINE__, "tcbdbget");
953
+ err = true;
954
+ } else if(rsiz != vsiz || memcmp(rbuf, vbuf, rsiz)){
955
+ eprint(bdb, __LINE__, "(validation)");
956
+ err = true;
957
+ }
958
+ } else {
959
+ iputchar('*');
960
+ if(rbuf || tcbdbecode(bdb) != TCENOREC){
961
+ eprint(bdb, __LINE__, "(validation)");
962
+ err = true;
963
+ }
964
+ }
965
+ tcfree(rbuf);
966
+ if(i % 50 == 0) iprintf(" (%08d)\n", i);
967
+ }
968
+ if(rnum % 50 > 0) iprintf(" (%08d)\n", rnum);
969
+ }
970
+ tcmapdel(map);
971
+ iprintf("record number: %llu\n", (unsigned long long)tcbdbrnum(bdb));
972
+ iprintf("size: %llu\n", (unsigned long long)tcbdbfsiz(bdb));
973
+ mprint(bdb);
974
+ sysprint();
975
+ if(!tcbdbclose(bdb)){
976
+ eprint(bdb, __LINE__, "tcbdbclose");
977
+ err = true;
978
+ }
979
+ tcbdbdel(bdb);
980
+ iprintf("time: %.3f\n", tctime() - stime);
981
+ iprintf("%s\n\n", err ? "error" : "ok");
982
+ return err ? 1 : 0;
983
+ }
984
+
985
+
986
+ /* perform typical command */
987
+ static int proctypical(const char *path, int tnum, int rnum, int lmemb, int nmemb,
988
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode,
989
+ bool nc, int rratio){
990
+ iprintf("<Typical Access Test>\n seed=%u path=%s tnum=%d rnum=%d lmemb=%d nmemb=%d"
991
+ " bnum=%d apow=%d fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d"
992
+ " nc=%d rratio=%d\n\n",
993
+ g_randseed, path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts, xmsiz, dfunit,
994
+ omode, nc, rratio);
995
+ bool err = false;
996
+ double stime = tctime();
997
+ TCBDB *bdb = tcbdbnew();
998
+ if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd);
999
+ if(!tcbdbsetmutex(bdb)){
1000
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
1001
+ err = true;
1002
+ }
1003
+ if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
1004
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
1005
+ err = true;
1006
+ }
1007
+ if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
1008
+ eprint(bdb, __LINE__, "tcbdbtune");
1009
+ err = true;
1010
+ }
1011
+ if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
1012
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
1013
+ err = true;
1014
+ }
1015
+ if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
1016
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
1017
+ err = true;
1018
+ }
1019
+ if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
1020
+ eprint(bdb, __LINE__, "tcbdbopen");
1021
+ err = true;
1022
+ }
1023
+ TARGTYPICAL targs[tnum];
1024
+ pthread_t threads[tnum];
1025
+ if(tnum == 1){
1026
+ targs[0].bdb = bdb;
1027
+ targs[0].rnum = rnum;
1028
+ targs[0].nc = nc;
1029
+ targs[0].rratio = rratio;
1030
+ targs[0].id = 0;
1031
+ if(threadtypical(targs) != NULL) err = true;
1032
+ } else {
1033
+ for(int i = 0; i < tnum; i++){
1034
+ targs[i].bdb = bdb;
1035
+ targs[i].rnum = rnum;
1036
+ targs[i].nc = nc;
1037
+ targs[i].rratio = rratio;
1038
+ targs[i].id = i;
1039
+ if(pthread_create(threads + i, NULL, threadtypical, targs + i) != 0){
1040
+ eprint(bdb, __LINE__, "pthread_create");
1041
+ targs[i].id = -1;
1042
+ err = true;
1043
+ }
1044
+ }
1045
+ for(int i = 0; i < tnum; i++){
1046
+ if(targs[i].id == -1) continue;
1047
+ void *rv;
1048
+ if(pthread_join(threads[i], &rv) != 0){
1049
+ eprint(bdb, __LINE__, "pthread_join");
1050
+ err = true;
1051
+ } else if(rv){
1052
+ err = true;
1053
+ }
1054
+ }
1055
+ }
1056
+ iprintf("record number: %llu\n", (unsigned long long)tcbdbrnum(bdb));
1057
+ iprintf("size: %llu\n", (unsigned long long)tcbdbfsiz(bdb));
1058
+ mprint(bdb);
1059
+ sysprint();
1060
+ if(!tcbdbclose(bdb)){
1061
+ eprint(bdb, __LINE__, "tcbdbclose");
1062
+ err = true;
1063
+ }
1064
+ tcbdbdel(bdb);
1065
+ iprintf("time: %.3f\n", tctime() - stime);
1066
+ iprintf("%s\n\n", err ? "error" : "ok");
1067
+ return err ? 1 : 0;
1068
+ }
1069
+
1070
+
1071
+ /* perform race command */
1072
+ static int procrace(const char *path, int tnum, int rnum, int lmemb, int nmemb,
1073
+ int bnum, int apow, int fpow, int opts, int xmsiz, int dfunit, int omode){
1074
+ iprintf("<Race Condition Test>\n seed=%u path=%s tnum=%d rnum=%d lmemb=%d nmemb=%d"
1075
+ " bnum=%d apow=%d fpow=%d opts=%d xmsiz=%d dfunit=%d omode=%d\n\n",
1076
+ g_randseed, path, tnum, rnum, lmemb, nmemb, bnum, apow, fpow, opts,
1077
+ xmsiz, dfunit, omode);
1078
+ bool err = false;
1079
+ double stime = tctime();
1080
+ TCBDB *bdb = tcbdbnew();
1081
+ if(g_dbgfd >= 0) tcbdbsetdbgfd(bdb, g_dbgfd);
1082
+ if(!tcbdbsetmutex(bdb)){
1083
+ eprint(bdb, __LINE__, "tcbdbsetmutex");
1084
+ err = true;
1085
+ }
1086
+ if(!tcbdbsetcodecfunc(bdb, _tc_recencode, NULL, _tc_recdecode, NULL)){
1087
+ eprint(bdb, __LINE__, "tcbdbsetcodecfunc");
1088
+ err = true;
1089
+ }
1090
+ if(!tcbdbtune(bdb, lmemb, nmemb, bnum, apow, fpow, opts)){
1091
+ eprint(bdb, __LINE__, "tcbdbtune");
1092
+ err = true;
1093
+ }
1094
+ if(xmsiz >= 0 && !tcbdbsetxmsiz(bdb, xmsiz)){
1095
+ eprint(bdb, __LINE__, "tcbdbsetxmsiz");
1096
+ err = true;
1097
+ }
1098
+ if(dfunit >= 0 && !tcbdbsetdfunit(bdb, dfunit)){
1099
+ eprint(bdb, __LINE__, "tcbdbsetdfunit");
1100
+ err = true;
1101
+ }
1102
+ if(!tcbdbopen(bdb, path, BDBOWRITER | BDBOCREAT | BDBOTRUNC | omode)){
1103
+ eprint(bdb, __LINE__, "tcbdbopen");
1104
+ err = true;
1105
+ }
1106
+ TARGRACE targs[tnum];
1107
+ pthread_t threads[tnum];
1108
+ if(tnum == 1){
1109
+ targs[0].bdb = bdb;
1110
+ targs[0].rnum = rnum;
1111
+ targs[0].id = 0;
1112
+ if(threadrace(targs) != NULL) err = true;
1113
+ } else {
1114
+ for(int i = 0; i < tnum; i++){
1115
+ targs[i].bdb = bdb;
1116
+ targs[i].rnum = rnum;
1117
+ targs[i].id = i;
1118
+ if(pthread_create(threads + i, NULL, threadrace, targs + i) != 0){
1119
+ eprint(bdb, __LINE__, "pthread_create");
1120
+ targs[i].id = -1;
1121
+ err = true;
1122
+ }
1123
+ }
1124
+ for(int i = 0; i < tnum; i++){
1125
+ if(targs[i].id == -1) continue;
1126
+ void *rv;
1127
+ if(pthread_join(threads[i], &rv) != 0){
1128
+ eprint(bdb, __LINE__, "pthread_join");
1129
+ err = true;
1130
+ } else if(rv){
1131
+ err = true;
1132
+ }
1133
+ }
1134
+ }
1135
+ iprintf("record number: %llu\n", (unsigned long long)tcbdbrnum(bdb));
1136
+ iprintf("size: %llu\n", (unsigned long long)tcbdbfsiz(bdb));
1137
+ mprint(bdb);
1138
+ sysprint();
1139
+ if(!tcbdbclose(bdb)){
1140
+ eprint(bdb, __LINE__, "tcbdbclose");
1141
+ err = true;
1142
+ }
1143
+ tcbdbdel(bdb);
1144
+ iprintf("time: %.3f\n", tctime() - stime);
1145
+ iprintf("%s\n\n", err ? "error" : "ok");
1146
+ return err ? 1 : 0;
1147
+ }
1148
+
1149
+
1150
+ /* thread the write function */
1151
+ static void *threadwrite(void *targ){
1152
+ TCBDB *bdb = ((TARGWRITE *)targ)->bdb;
1153
+ int rnum = ((TARGWRITE *)targ)->rnum;
1154
+ bool rnd = ((TARGWRITE *)targ)->rnd;
1155
+ int id = ((TARGWRITE *)targ)->id;
1156
+ bool err = false;
1157
+ int base = id * rnum;
1158
+ for(int i = 1; i <= rnum; i++){
1159
+ char buf[RECBUFSIZ];
1160
+ int len = sprintf(buf, "%08d", base + (rnd ? myrand(i) : i));
1161
+ if(!tcbdbput(bdb, buf, len, buf, len)){
1162
+ eprint(bdb, __LINE__, "tcbdbput");
1163
+ err = true;
1164
+ break;
1165
+ }
1166
+ if(id <= 0 && rnum > 250 && i % (rnum / 250) == 0){
1167
+ iputchar('.');
1168
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1169
+ }
1170
+ }
1171
+ return err ? "error" : NULL;
1172
+ }
1173
+
1174
+
1175
+ /* thread the read function */
1176
+ static void *threadread(void *targ){
1177
+ TCBDB *bdb = ((TARGREAD *)targ)->bdb;
1178
+ int rnum = ((TARGREAD *)targ)->rnum;
1179
+ bool wb = ((TARGREAD *)targ)->wb;
1180
+ bool rnd = ((TARGREAD *)targ)->rnd;
1181
+ int id = ((TARGREAD *)targ)->id;
1182
+ bool err = false;
1183
+ int base = id * rnum;
1184
+ for(int i = 1; i <= rnum && !err; i++){
1185
+ char kbuf[RECBUFSIZ];
1186
+ int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrandnd(i) : i));
1187
+ int vsiz;
1188
+ if(wb){
1189
+ int vsiz;
1190
+ const char *vbuf = tcbdbget3(bdb, kbuf, ksiz, &vsiz);
1191
+ if(!vbuf && (!rnd || tcbdbecode(bdb) != TCENOREC)){
1192
+ eprint(bdb, __LINE__, "tcbdbget3");
1193
+ err = true;
1194
+ }
1195
+ } else {
1196
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
1197
+ if(!vbuf && (!rnd || tcbdbecode(bdb) != TCENOREC)){
1198
+ eprint(bdb, __LINE__, "tcbdbget");
1199
+ err = true;
1200
+ }
1201
+ tcfree(vbuf);
1202
+ }
1203
+ if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
1204
+ iputchar('.');
1205
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1206
+ }
1207
+ }
1208
+ return err ? "error" : NULL;
1209
+ }
1210
+
1211
+
1212
+ /* thread the remove function */
1213
+ static void *threadremove(void *targ){
1214
+ TCBDB *bdb = ((TARGREMOVE *)targ)->bdb;
1215
+ int rnum = ((TARGREMOVE *)targ)->rnum;
1216
+ bool rnd = ((TARGREMOVE *)targ)->rnd;
1217
+ int id = ((TARGREMOVE *)targ)->id;
1218
+ bool err = false;
1219
+ int base = id * rnum;
1220
+ for(int i = 1; i <= rnum; i++){
1221
+ char kbuf[RECBUFSIZ];
1222
+ int ksiz = sprintf(kbuf, "%08d", base + (rnd ? myrand(i + 1) : i));
1223
+ if(!tcbdbout(bdb, kbuf, ksiz) && (!rnd || tcbdbecode(bdb) != TCENOREC)){
1224
+ eprint(bdb, __LINE__, "tcbdbout");
1225
+ err = true;
1226
+ break;
1227
+ }
1228
+ if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
1229
+ iputchar('.');
1230
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1231
+ }
1232
+ }
1233
+ return err ? "error" : NULL;
1234
+ }
1235
+
1236
+
1237
+ /* thread the wicked function */
1238
+ static void *threadwicked(void *targ){
1239
+ TCBDB *bdb = ((TARGWICKED *)targ)->bdb;
1240
+ int rnum = ((TARGWICKED *)targ)->rnum;
1241
+ bool nc = ((TARGWICKED *)targ)->nc;
1242
+ int id = ((TARGWICKED *)targ)->id;
1243
+ TCMAP *map = ((TARGWICKED *)targ)->map;
1244
+ BDBCUR *cur = tcbdbcurnew(bdb);
1245
+ bool err = false;
1246
+ for(int i = 1; i <= rnum && !err; i++){
1247
+ char kbuf[RECBUFSIZ];
1248
+ int ksiz = sprintf(kbuf, "%d", myrand(rnum * (id + 1)));
1249
+ char vbuf[RECBUFSIZ];
1250
+ int vsiz = myrand(RECBUFSIZ);
1251
+ memset(vbuf, '*', vsiz);
1252
+ vbuf[vsiz] = '\0';
1253
+ char *rbuf;
1254
+ if(!nc) tcglobalmutexlock();
1255
+ switch(myrand(16)){
1256
+ case 0:
1257
+ if(id == 0) iputchar('0');
1258
+ if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
1259
+ eprint(bdb, __LINE__, "tcbdbput");
1260
+ err = true;
1261
+ }
1262
+ if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
1263
+ break;
1264
+ case 1:
1265
+ if(id == 0) iputchar('1');
1266
+ if(!tcbdbput2(bdb, kbuf, vbuf)){
1267
+ eprint(bdb, __LINE__, "tcbdbput2");
1268
+ err = true;
1269
+ }
1270
+ if(!nc) tcmapput2(map, kbuf, vbuf);
1271
+ break;
1272
+ case 2:
1273
+ if(id == 0) iputchar('2');
1274
+ if(!tcbdbputkeep(bdb, kbuf, ksiz, vbuf, vsiz) && tcbdbecode(bdb) != TCEKEEP){
1275
+ eprint(bdb, __LINE__, "tcbdbputkeep");
1276
+ err = true;
1277
+ }
1278
+ if(!nc) tcmapputkeep(map, kbuf, ksiz, vbuf, vsiz);
1279
+ break;
1280
+ case 3:
1281
+ if(id == 0) iputchar('3');
1282
+ if(!tcbdbputkeep2(bdb, kbuf, vbuf) && tcbdbecode(bdb) != TCEKEEP){
1283
+ eprint(bdb, __LINE__, "tcbdbputkeep2");
1284
+ err = true;
1285
+ }
1286
+ if(!nc) tcmapputkeep2(map, kbuf, vbuf);
1287
+ break;
1288
+ case 4:
1289
+ if(id == 0) iputchar('4');
1290
+ if(!tcbdbputcat(bdb, kbuf, ksiz, vbuf, vsiz)){
1291
+ eprint(bdb, __LINE__, "tcbdbputcat");
1292
+ err = true;
1293
+ }
1294
+ if(!nc) tcmapputcat(map, kbuf, ksiz, vbuf, vsiz);
1295
+ break;
1296
+ case 5:
1297
+ if(id == 0) iputchar('5');
1298
+ if(!tcbdbputcat2(bdb, kbuf, vbuf)){
1299
+ eprint(bdb, __LINE__, "tcbdbputcat2");
1300
+ err = true;
1301
+ }
1302
+ if(!nc) tcmapputcat2(map, kbuf, vbuf);
1303
+ break;
1304
+ case 6:
1305
+ if(id == 0) iputchar('6');
1306
+ if(nc){
1307
+ if(!tcbdbputdup(bdb, kbuf, ksiz, vbuf, vsiz)){
1308
+ eprint(bdb, __LINE__, "tcbdbputdup");
1309
+ err = true;
1310
+ }
1311
+ }
1312
+ break;
1313
+ case 7:
1314
+ if(id == 0) iputchar('7');
1315
+ if(nc){
1316
+ if(!tcbdbputdup2(bdb, kbuf, vbuf)){
1317
+ eprint(bdb, __LINE__, "tcbdbputdup2");
1318
+ err = true;
1319
+ }
1320
+ }
1321
+ break;
1322
+ case 8:
1323
+ if(id == 0) iputchar('8');
1324
+ if(myrand(2) == 0){
1325
+ if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
1326
+ eprint(bdb, __LINE__, "tcbdbout");
1327
+ err = true;
1328
+ }
1329
+ if(!nc) tcmapout(map, kbuf, ksiz);
1330
+ }
1331
+ break;
1332
+ case 9:
1333
+ if(id == 0) iputchar('9');
1334
+ if(myrand(2) == 0){
1335
+ if(!tcbdbout2(bdb, kbuf) && tcbdbecode(bdb) != TCENOREC){
1336
+ eprint(bdb, __LINE__, "tcbdbout2");
1337
+ err = true;
1338
+ }
1339
+ if(!nc) tcmapout2(map, kbuf);
1340
+ }
1341
+ break;
1342
+ case 10:
1343
+ if(id == 0) iputchar('A');
1344
+ if(!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz))){
1345
+ if(tcbdbecode(bdb) != TCENOREC){
1346
+ eprint(bdb, __LINE__, "tcbdbget");
1347
+ err = true;
1348
+ }
1349
+ rbuf = tcsprintf("[%d]", myrand(i + 1));
1350
+ vsiz = strlen(rbuf);
1351
+ }
1352
+ vsiz += myrand(vsiz);
1353
+ if(myrand(3) == 0) vsiz += PATH_MAX;
1354
+ rbuf = tcrealloc(rbuf, vsiz + 1);
1355
+ for(int j = 0; j < vsiz; j++){
1356
+ rbuf[j] = myrand(0x100);
1357
+ }
1358
+ if(!tcbdbput(bdb, kbuf, ksiz, rbuf, vsiz)){
1359
+ eprint(bdb, __LINE__, "tcbdbput");
1360
+ err = true;
1361
+ }
1362
+ if(!nc) tcmapput(map, kbuf, ksiz, rbuf, vsiz);
1363
+ tcfree(rbuf);
1364
+ break;
1365
+ case 11:
1366
+ if(id == 0) iputchar('B');
1367
+ if(!(rbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz)) && tcbdbecode(bdb) != TCENOREC){
1368
+ eprint(bdb, __LINE__, "tcbdbget");
1369
+ err = true;
1370
+ }
1371
+ tcfree(rbuf);
1372
+ break;
1373
+ case 12:
1374
+ if(id == 0) iputchar('C');
1375
+ if(!(rbuf = tcbdbget2(bdb, kbuf)) && tcbdbecode(bdb) != TCENOREC){
1376
+ eprint(bdb, __LINE__, "tcbdbget2");
1377
+ err = true;
1378
+ }
1379
+ tcfree(rbuf);
1380
+ break;
1381
+ case 13:
1382
+ if(id == 0) iputchar('D');
1383
+ if(!tcbdbget3(bdb, kbuf, ksiz, &vsiz) && tcbdbecode(bdb) != TCENOREC){
1384
+ eprint(bdb, __LINE__, "tcbdbget3");
1385
+ err = true;
1386
+ }
1387
+ break;
1388
+ case 14:
1389
+ if(id == 0) iputchar('E');
1390
+ if(myrand(rnum / 50) == 0){
1391
+ switch(myrand(5)){
1392
+ case 0:
1393
+ if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
1394
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
1395
+ err = true;
1396
+ }
1397
+ break;
1398
+ case 1:
1399
+ if(!tcbdbcurlast(cur) && tcbdbecode(bdb) != TCENOREC){
1400
+ eprint(bdb, __LINE__, "tcbdbcurlast");
1401
+ err = true;
1402
+ }
1403
+ break;
1404
+ default:
1405
+ if(!tcbdbcurjump(cur, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
1406
+ eprint(bdb, __LINE__, "tcbdbcurjump");
1407
+ err = true;
1408
+ }
1409
+ break;
1410
+ }
1411
+ }
1412
+ TCXSTR *ikey = tcxstrnew();
1413
+ TCXSTR *ival = tcxstrnew();
1414
+ for(int j = myrand(rnum) / 1000 + 1; j >= 0; j--){
1415
+ if(j % 3 == 0){
1416
+ if(!tcbdbcurrec(cur, ikey, ival)){
1417
+ int ecode = tcbdbecode(bdb);
1418
+ if(ecode != TCEINVALID && ecode != TCENOREC){
1419
+ eprint(bdb, __LINE__, "tcbdbcurrec");
1420
+ err = true;
1421
+ }
1422
+ }
1423
+ } else {
1424
+ int iksiz;
1425
+ if(!tcbdbcurkey3(cur, &iksiz)){
1426
+ int ecode = tcbdbecode(bdb);
1427
+ if(ecode != TCEINVALID && ecode != TCENOREC){
1428
+ eprint(bdb, __LINE__, "tcbdbcurkey3");
1429
+ err = true;
1430
+ }
1431
+ }
1432
+ }
1433
+ if(myrand(5) == 0){
1434
+ if(!tcbdbcurprev(cur)){
1435
+ int ecode = tcbdbecode(bdb);
1436
+ if(ecode != TCEINVALID && ecode != TCENOREC){
1437
+ eprint(bdb, __LINE__, "tcbdbcurprev");
1438
+ err = true;
1439
+ }
1440
+ }
1441
+ } else {
1442
+ if(!tcbdbcurnext(cur)){
1443
+ int ecode = tcbdbecode(bdb);
1444
+ if(ecode != TCEINVALID && ecode != TCENOREC){
1445
+ eprint(bdb, __LINE__, "tcbdbcurnext");
1446
+ err = true;
1447
+ }
1448
+ }
1449
+ }
1450
+ }
1451
+ tcxstrdel(ival);
1452
+ tcxstrdel(ikey);
1453
+ break;
1454
+ default:
1455
+ if(id == 0) iputchar('@');
1456
+ if(tcbdbtranbegin(bdb)){
1457
+ if(myrand(2) == 0){
1458
+ if(!tcbdbput(bdb, kbuf, ksiz, vbuf, vsiz)){
1459
+ eprint(bdb, __LINE__, "tcbdbput");
1460
+ err = true;
1461
+ }
1462
+ if(!nc) tcmapput(map, kbuf, ksiz, vbuf, vsiz);
1463
+ } else {
1464
+ if(!tcbdbout(bdb, kbuf, ksiz) && tcbdbecode(bdb) != TCENOREC){
1465
+ eprint(bdb, __LINE__, "tcbdbout");
1466
+ err = true;
1467
+ }
1468
+ if(!nc) tcmapout(map, kbuf, ksiz);
1469
+ }
1470
+ if(nc && myrand(2) == 0){
1471
+ if(!tcbdbtranabort(bdb)){
1472
+ eprint(bdb, __LINE__, "tcbdbtranabort");
1473
+ err = true;
1474
+ }
1475
+ } else {
1476
+ if(!tcbdbtrancommit(bdb)){
1477
+ eprint(bdb, __LINE__, "tcbdbtrancommit");
1478
+ err = true;
1479
+ }
1480
+ }
1481
+ } else {
1482
+ eprint(bdb, __LINE__, "tcbdbtranbegin");
1483
+ err = true;
1484
+ }
1485
+ if(myrand(1000) == 0){
1486
+ if(!tcbdbforeach(bdb, iterfunc, NULL)){
1487
+ eprint(bdb, __LINE__, "tcbdbforeach");
1488
+ err = true;
1489
+ }
1490
+ }
1491
+ if(myrand(10000) == 0) srand((unsigned int)(tctime() * 1000) % UINT_MAX);
1492
+ break;
1493
+ }
1494
+ if(!nc) tcglobalmutexunlock();
1495
+ if(id == 0){
1496
+ if(i % 50 == 0) iprintf(" (%08d)\n", i);
1497
+ if(id == 0 && i == rnum / 4){
1498
+ if(!tcbdboptimize(bdb, -1, -1, -1, -1, -1, -1) && tcbdbecode(bdb) != TCEINVALID){
1499
+ eprint(bdb, __LINE__, "tcbdboptimize");
1500
+ err = true;
1501
+ }
1502
+ if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
1503
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
1504
+ err = true;
1505
+ }
1506
+ }
1507
+ }
1508
+ }
1509
+ tcbdbcurdel(cur);
1510
+ return err ? "error" : NULL;
1511
+ }
1512
+
1513
+
1514
+ /* thread the typical function */
1515
+ static void *threadtypical(void *targ){
1516
+ TCBDB *bdb = ((TARGTYPICAL *)targ)->bdb;
1517
+ int rnum = ((TARGTYPICAL *)targ)->rnum;
1518
+ bool nc = ((TARGTYPICAL *)targ)->nc;
1519
+ int rratio = ((TARGTYPICAL *)targ)->rratio;
1520
+ int id = ((TARGTYPICAL *)targ)->id;
1521
+ bool err = false;
1522
+ TCMAP *map = (!nc && id == 0) ? tcmapnew2(rnum + 1) : NULL;
1523
+ int base = id * rnum;
1524
+ int mrange = tclmax(50 + rratio, 100);
1525
+ BDBCUR *cur = tcbdbcurnew(bdb);
1526
+ for(int i = 1; !err && i <= rnum; i++){
1527
+ char buf[RECBUFSIZ];
1528
+ int len = sprintf(buf, "%08d", base + myrandnd(i));
1529
+ int rnd = myrand(mrange);
1530
+ if(rnd < 10){
1531
+ if(!tcbdbput(bdb, buf, len, buf, len)){
1532
+ eprint(bdb, __LINE__, "tcbdbput");
1533
+ err = true;
1534
+ }
1535
+ if(map) tcmapput(map, buf, len, buf, len);
1536
+ } else if(rnd < 15){
1537
+ if(!tcbdbputkeep(bdb, buf, len, buf, len) && tcbdbecode(bdb) != TCEKEEP){
1538
+ eprint(bdb, __LINE__, "tcbdbputkeep");
1539
+ err = true;
1540
+ }
1541
+ if(map) tcmapputkeep(map, buf, len, buf, len);
1542
+ } else if(rnd < 20){
1543
+ if(!tcbdbputcat(bdb, buf, len, buf, len)){
1544
+ eprint(bdb, __LINE__, "tcbdbputcat");
1545
+ err = true;
1546
+ }
1547
+ if(map) tcmapputcat(map, buf, len, buf, len);
1548
+ } else if(rnd < 25){
1549
+ if(!tcbdbout(bdb, buf, len) && tcbdbecode(bdb) && tcbdbecode(bdb) != TCENOREC){
1550
+ eprint(bdb, __LINE__, "tcbdbout");
1551
+ err = true;
1552
+ }
1553
+ if(map) tcmapout(map, buf, len);
1554
+ } else if(rnd < 27){
1555
+ switch(myrand(3)){
1556
+ case 0:
1557
+ if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
1558
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
1559
+ err = true;
1560
+ }
1561
+ for(int j = 0; !err && j < 10; j++){
1562
+ int ksiz;
1563
+ char *kbuf = tcbdbcurkey(cur, &ksiz);
1564
+ if(kbuf){
1565
+ int vsiz;
1566
+ char *vbuf = tcbdbcurval(cur, &vsiz);
1567
+ if(vbuf){
1568
+ tcfree(vbuf);
1569
+ } else if(tcbdbecode(bdb) != TCENOREC){
1570
+ eprint(bdb, __LINE__, "tcbdbcurval");
1571
+ err = true;
1572
+ }
1573
+ tcfree(kbuf);
1574
+ } else if(tcbdbecode(bdb) != TCENOREC){
1575
+ eprint(bdb, __LINE__, "tcbdbcurkey");
1576
+ err = true;
1577
+ }
1578
+ tcbdbcurnext(cur);
1579
+ }
1580
+ break;
1581
+ case 1:
1582
+ if(!tcbdbcurlast(cur) && tcbdbecode(bdb) != TCENOREC){
1583
+ eprint(bdb, __LINE__, "tcbdbcurlast");
1584
+ err = true;
1585
+ }
1586
+ for(int j = 0; !err && j < 10; j++){
1587
+ int ksiz;
1588
+ char *kbuf = tcbdbcurkey(cur, &ksiz);
1589
+ if(kbuf){
1590
+ int vsiz;
1591
+ char *vbuf = tcbdbcurval(cur, &vsiz);
1592
+ if(vbuf){
1593
+ tcfree(vbuf);
1594
+ } else if(tcbdbecode(bdb) != TCENOREC){
1595
+ eprint(bdb, __LINE__, "tcbdbcurval");
1596
+ err = true;
1597
+ }
1598
+ tcfree(kbuf);
1599
+ } else if(tcbdbecode(bdb) != TCENOREC){
1600
+ eprint(bdb, __LINE__, "tcbdbcurkey");
1601
+ err = true;
1602
+ }
1603
+ tcbdbcurprev(cur);
1604
+ }
1605
+ break;
1606
+ case 2:
1607
+ if(!tcbdbcurjump(cur, buf, len) && tcbdbecode(bdb) != TCENOREC){
1608
+ eprint(bdb, __LINE__, "tcbdbcurjump");
1609
+ err = true;
1610
+ }
1611
+ for(int j = 0; !err && j < 10; j++){
1612
+ int ksiz;
1613
+ char *kbuf = tcbdbcurkey(cur, &ksiz);
1614
+ if(kbuf){
1615
+ int vsiz;
1616
+ char *vbuf = tcbdbcurval(cur, &vsiz);
1617
+ if(vbuf){
1618
+ tcfree(vbuf);
1619
+ } else if(tcbdbecode(bdb) != TCENOREC){
1620
+ eprint(bdb, __LINE__, "tcbdbcurval");
1621
+ err = true;
1622
+ }
1623
+ tcfree(kbuf);
1624
+ } else if(tcbdbecode(bdb) != TCENOREC){
1625
+ eprint(bdb, __LINE__, "tcbdbcurkey");
1626
+ err = true;
1627
+ }
1628
+ tcbdbcurnext(cur);
1629
+ }
1630
+ break;
1631
+ }
1632
+ } else {
1633
+ int vsiz;
1634
+ char *vbuf = tcbdbget(bdb, buf, len, &vsiz);
1635
+ if(vbuf){
1636
+ if(map){
1637
+ int msiz;
1638
+ const char *mbuf = tcmapget(map, buf, len, &msiz);
1639
+ if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
1640
+ eprint(bdb, __LINE__, "(validation)");
1641
+ err = true;
1642
+ }
1643
+ }
1644
+ tcfree(vbuf);
1645
+ } else {
1646
+ if(tcbdbecode(bdb) != TCENOREC){
1647
+ eprint(bdb, __LINE__, "tcbdbget");
1648
+ err = true;
1649
+ }
1650
+ if(map && tcmapget(map, buf, len, &vsiz)){
1651
+ eprint(bdb, __LINE__, "(validation)");
1652
+ err = true;
1653
+ }
1654
+ }
1655
+ }
1656
+ if(id == 0 && rnum > 250 && i % (rnum / 250) == 0){
1657
+ iputchar('.');
1658
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1659
+ }
1660
+ }
1661
+ tcbdbcurdel(cur);
1662
+ if(map){
1663
+ tcmapiterinit(map);
1664
+ int ksiz;
1665
+ const char *kbuf;
1666
+ while(!err && (kbuf = tcmapiternext(map, &ksiz)) != NULL){
1667
+ int vsiz;
1668
+ char *vbuf = tcbdbget(bdb, kbuf, ksiz, &vsiz);
1669
+ if(vbuf){
1670
+ int msiz;
1671
+ const char *mbuf = tcmapget(map, kbuf, ksiz, &msiz);
1672
+ if(!mbuf || msiz != vsiz || memcmp(mbuf, vbuf, vsiz)){
1673
+ eprint(bdb, __LINE__, "(validation)");
1674
+ err = true;
1675
+ }
1676
+ tcfree(vbuf);
1677
+ } else {
1678
+ eprint(bdb, __LINE__, "(validation)");
1679
+ err = true;
1680
+ }
1681
+ }
1682
+ tcmapdel(map);
1683
+ }
1684
+ return err ? "error" : NULL;
1685
+ }
1686
+
1687
+
1688
+ /* thread the race function */
1689
+ static void *threadrace(void *targ){
1690
+ TCBDB *bdb = ((TARGRACE *)targ)->bdb;
1691
+ int rnum = ((TARGRACE *)targ)->rnum;
1692
+ int id = ((TARGRACE *)targ)->id;
1693
+ bool err = false;
1694
+ int mid = rnum * 2;
1695
+ for(int i = 1; !err && i <= rnum; i++){
1696
+ char buf[RECBUFSIZ];
1697
+ int len = sprintf(buf, "%d", myrandnd(i));
1698
+ int rnd = myrand(100);
1699
+ if(rnd < 10){
1700
+ if(!tcbdbputkeep(bdb, buf, len, buf, len) && tcbdbecode(bdb) != TCEKEEP){
1701
+ eprint(bdb, __LINE__, "tcbdbputkeep");
1702
+ err = true;
1703
+ }
1704
+ } else if(rnd < 20){
1705
+ if(!tcbdbputcat(bdb, buf, len, buf, len)){
1706
+ eprint(bdb, __LINE__, "tcbdbputcat");
1707
+ err = true;
1708
+ }
1709
+ } else if(rnd < 30){
1710
+ if(!tcbdbputdup(bdb, buf, len, buf, len)){
1711
+ eprint(bdb, __LINE__, "tcbdbputdup");
1712
+ err = true;
1713
+ }
1714
+ } else if(rnd < 40){
1715
+ if(!tcbdbputdupback(bdb, buf, len, buf, len)){
1716
+ eprint(bdb, __LINE__, "tcbdbputdupback");
1717
+ err = true;
1718
+ }
1719
+ } else if(rnd < 50){
1720
+ if(!tcbdbout(bdb, buf, len) && tcbdbecode(bdb) != TCENOREC){
1721
+ eprint(bdb, __LINE__, "tcbdbout");
1722
+ err = true;
1723
+ }
1724
+ } else {
1725
+ if(myrand(10) == 0){
1726
+ int rsiz = myrand(1024);
1727
+ char *rbuf = tcmalloc(rsiz + 1);
1728
+ for(int j = 0; j < rsiz; j++){
1729
+ rbuf[j] = myrand('z' - 'a') + 'a';
1730
+ }
1731
+ if(myrand(2) == 0){
1732
+ if(!tcbdbput(bdb, buf, len, rbuf, rsiz)){
1733
+ eprint(bdb, __LINE__, "tcbdbputcat");
1734
+ err = true;
1735
+ }
1736
+ } else {
1737
+ if(!tcbdbputcat(bdb, buf, len, rbuf, rsiz)){
1738
+ eprint(bdb, __LINE__, "tcbdbputcat");
1739
+ err = true;
1740
+ }
1741
+ }
1742
+ tcfree(rbuf);
1743
+ } else {
1744
+ if(!tcbdbput(bdb, buf, len, buf, len)){
1745
+ eprint(bdb, __LINE__, "tcbdbput");
1746
+ err = true;
1747
+ }
1748
+ }
1749
+ }
1750
+ if(id == 0){
1751
+ if(myrand(mid) == 0){
1752
+ iprintf("[v]");
1753
+ if(!tcbdbvanish(bdb)){
1754
+ eprint(bdb, __LINE__, "tcbdbvanish");
1755
+ err = true;
1756
+ }
1757
+ }
1758
+ if(myrand(mid) == 0){
1759
+ iprintf("[o]");
1760
+ if(!tcbdboptimize(bdb, -1, -1, myrand(rnum) + 1, myrand(10), myrand(10), 0)){
1761
+ eprint(bdb, __LINE__, "tcbdbvanish");
1762
+ err = true;
1763
+ }
1764
+ }
1765
+ if(myrand(mid) == 0){
1766
+ iprintf("[d]");
1767
+ if(!tcbdbdefrag(bdb, -1)){
1768
+ eprint(bdb, __LINE__, "tcbdbdefrag");
1769
+ err = true;
1770
+ }
1771
+ }
1772
+ if(myrand(mid) == 0){
1773
+ iprintf("[i]");
1774
+ BDBCUR *cur = tcbdbcurnew(bdb);
1775
+ if(!tcbdbcurfirst(cur) && tcbdbecode(bdb) != TCENOREC){
1776
+ eprint(bdb, __LINE__, "tcbdbcurfirst");
1777
+ err = true;
1778
+ }
1779
+ char *kbuf;
1780
+ int ksiz;
1781
+ while((kbuf = tcbdbcurkey(cur, &ksiz)) != NULL){
1782
+ int vsiz;
1783
+ char *vbuf = tcbdbcurval(cur, &vsiz);
1784
+ if(vbuf){
1785
+ tcfree(vbuf);
1786
+ } else if(tcbdbecode(bdb) != TCENOREC){
1787
+ eprint(bdb, __LINE__, "tcbdbget");
1788
+ err = true;
1789
+ }
1790
+ tcfree(kbuf);
1791
+ tcbdbcurnext(cur);
1792
+ }
1793
+ if(tcbdbecode(bdb) != TCENOREC){
1794
+ eprint(bdb, __LINE__, "(validation)");
1795
+ err = true;
1796
+ }
1797
+ tcbdbcurdel(cur);
1798
+ }
1799
+ if(rnum > 250 && i % (rnum / 250) == 0){
1800
+ iputchar('.');
1801
+ if(i == rnum || i % (rnum / 10) == 0) iprintf(" (%08d)\n", i);
1802
+ }
1803
+ }
1804
+ }
1805
+ return err ? "error" : NULL;
1806
+ }
1807
+
1808
+
1809
+
1810
+ // END OF FILE