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