tigerbeetle 0.0.40 → 0.17.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (293) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -25
  3. data/README.md +670 -80
  4. data/docs/migration.md +201 -0
  5. data/sig/tigerbeetle.rbs +271 -0
  6. data/src/ext/tigerbeetle/extconf.rb +47 -0
  7. data/src/ext/tigerbeetle/lib/aarch64-linux-gnu.2.27/libtb_client.so +0 -0
  8. data/src/ext/tigerbeetle/lib/aarch64-linux-musl/libtb_client.so +0 -0
  9. data/src/ext/tigerbeetle/lib/aarch64-macos/libtb_client.dylib +0 -0
  10. data/src/ext/tigerbeetle/lib/x86_64-linux-gnu.2.27/libtb_client.so +0 -0
  11. data/src/ext/tigerbeetle/lib/x86_64-linux-musl/libtb_client.so +0 -0
  12. data/src/ext/tigerbeetle/lib/x86_64-macos/libtb_client.dylib +0 -0
  13. data/src/ext/tigerbeetle/lib/x86_64-windows/tb_client.dll +0 -0
  14. data/src/ext/tigerbeetle/rb_tb_gen.h +458 -0
  15. data/{ext/tb_client/tigerbeetle/src/clients/rust/assets → src/ext/tigerbeetle}/tb_client.h +18 -16
  16. data/src/ext/tigerbeetle/tigerbeetle.c +310 -0
  17. data/src/tigerbeetle/bindings.rb +347 -0
  18. data/src/tigerbeetle/client.rb +129 -0
  19. data/src/tigerbeetle/completion_dispatcher.rb +108 -0
  20. data/src/tigerbeetle/id.rb +40 -0
  21. data/src/tigerbeetle/tb.rb +3 -0
  22. data/src/tigerbeetle/version.rb +3 -0
  23. data/src/tigerbeetle.rb +39 -0
  24. metadata +33 -350
  25. data/CHANGELOG.md +0 -162
  26. data/ext/tb_client/extconf.rb +0 -41
  27. data/ext/tb_client/tigerbeetle/LICENSE +0 -177
  28. data/ext/tb_client/tigerbeetle/build.zig +0 -2296
  29. data/ext/tb_client/tigerbeetle/src/aof.zig +0 -1000
  30. data/ext/tb_client/tigerbeetle/src/build/fetch.zig +0 -112
  31. data/ext/tb_client/tigerbeetle/src/build_multiversion.zig +0 -808
  32. data/ext/tb_client/tigerbeetle/src/cdc/amqp/protocol.zig +0 -1283
  33. data/ext/tb_client/tigerbeetle/src/cdc/amqp/spec.zig +0 -1704
  34. data/ext/tb_client/tigerbeetle/src/cdc/amqp/types.zig +0 -341
  35. data/ext/tb_client/tigerbeetle/src/cdc/amqp.zig +0 -1450
  36. data/ext/tb_client/tigerbeetle/src/cdc/runner.zig +0 -1659
  37. data/ext/tb_client/tigerbeetle/src/clients/c/samples/main.c +0 -406
  38. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/context.zig +0 -1092
  39. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/echo_client.zig +0 -286
  40. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/packet.zig +0 -158
  41. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/signal.zig +0 -229
  42. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/signal_fuzz.zig +0 -110
  43. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client.h +0 -386
  44. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client.zig +0 -34
  45. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client_exports.zig +0 -281
  46. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client_header.zig +0 -312
  47. data/ext/tb_client/tigerbeetle/src/clients/c/tb_client_header_test.zig +0 -138
  48. data/ext/tb_client/tigerbeetle/src/clients/c/test.zig +0 -466
  49. data/ext/tb_client/tigerbeetle/src/clients/docs_samples.zig +0 -157
  50. data/ext/tb_client/tigerbeetle/src/clients/docs_types.zig +0 -90
  51. data/ext/tb_client/tigerbeetle/src/clients/dotnet/ci.zig +0 -203
  52. data/ext/tb_client/tigerbeetle/src/clients/dotnet/docs.zig +0 -79
  53. data/ext/tb_client/tigerbeetle/src/clients/dotnet/dotnet_bindings.zig +0 -542
  54. data/ext/tb_client/tigerbeetle/src/clients/go/ci.zig +0 -109
  55. data/ext/tb_client/tigerbeetle/src/clients/go/docs.zig +0 -86
  56. data/ext/tb_client/tigerbeetle/src/clients/go/go_bindings.zig +0 -370
  57. data/ext/tb_client/tigerbeetle/src/clients/go/pkg/native/tb_client.h +0 -386
  58. data/ext/tb_client/tigerbeetle/src/clients/java/ci.zig +0 -167
  59. data/ext/tb_client/tigerbeetle/src/clients/java/docs.zig +0 -126
  60. data/ext/tb_client/tigerbeetle/src/clients/java/java_bindings.zig +0 -996
  61. data/ext/tb_client/tigerbeetle/src/clients/java/src/client.zig +0 -748
  62. data/ext/tb_client/tigerbeetle/src/clients/java/src/jni.zig +0 -3238
  63. data/ext/tb_client/tigerbeetle/src/clients/java/src/jni_tests.zig +0 -1718
  64. data/ext/tb_client/tigerbeetle/src/clients/java/src/jni_thread_cleaner.zig +0 -190
  65. data/ext/tb_client/tigerbeetle/src/clients/node/ci.zig +0 -104
  66. data/ext/tb_client/tigerbeetle/src/clients/node/docs.zig +0 -75
  67. data/ext/tb_client/tigerbeetle/src/clients/node/node.zig +0 -522
  68. data/ext/tb_client/tigerbeetle/src/clients/node/node_bindings.zig +0 -267
  69. data/ext/tb_client/tigerbeetle/src/clients/node/src/c.zig +0 -3
  70. data/ext/tb_client/tigerbeetle/src/clients/node/src/translate.zig +0 -379
  71. data/ext/tb_client/tigerbeetle/src/clients/python/ci.zig +0 -131
  72. data/ext/tb_client/tigerbeetle/src/clients/python/docs.zig +0 -63
  73. data/ext/tb_client/tigerbeetle/src/clients/python/python_bindings.zig +0 -588
  74. data/ext/tb_client/tigerbeetle/src/clients/rust/ci.zig +0 -73
  75. data/ext/tb_client/tigerbeetle/src/clients/rust/docs.zig +0 -106
  76. data/ext/tb_client/tigerbeetle/src/clients/rust/rust_bindings.zig +0 -305
  77. data/ext/tb_client/tigerbeetle/src/config.zig +0 -296
  78. data/ext/tb_client/tigerbeetle/src/constants.zig +0 -790
  79. data/ext/tb_client/tigerbeetle/src/copyhound.zig +0 -202
  80. data/ext/tb_client/tigerbeetle/src/counting_allocator.zig +0 -72
  81. data/ext/tb_client/tigerbeetle/src/direction.zig +0 -120
  82. data/ext/tb_client/tigerbeetle/src/docs_website/build.zig +0 -158
  83. data/ext/tb_client/tigerbeetle/src/docs_website/src/content.zig +0 -156
  84. data/ext/tb_client/tigerbeetle/src/docs_website/src/docs.zig +0 -252
  85. data/ext/tb_client/tigerbeetle/src/docs_website/src/file_checker.zig +0 -313
  86. data/ext/tb_client/tigerbeetle/src/docs_website/src/html.zig +0 -87
  87. data/ext/tb_client/tigerbeetle/src/docs_website/src/page_writer.zig +0 -63
  88. data/ext/tb_client/tigerbeetle/src/docs_website/src/redirects.zig +0 -47
  89. data/ext/tb_client/tigerbeetle/src/docs_website/src/search_index_writer.zig +0 -28
  90. data/ext/tb_client/tigerbeetle/src/docs_website/src/service_worker_writer.zig +0 -61
  91. data/ext/tb_client/tigerbeetle/src/docs_website/src/single_page_writer.zig +0 -169
  92. data/ext/tb_client/tigerbeetle/src/docs_website/src/website.zig +0 -46
  93. data/ext/tb_client/tigerbeetle/src/ewah.zig +0 -445
  94. data/ext/tb_client/tigerbeetle/src/ewah_benchmark.zig +0 -128
  95. data/ext/tb_client/tigerbeetle/src/ewah_fuzz.zig +0 -171
  96. data/ext/tb_client/tigerbeetle/src/fuzz_tests.zig +0 -179
  97. data/ext/tb_client/tigerbeetle/src/integration_tests.zig +0 -662
  98. data/ext/tb_client/tigerbeetle/src/io/common.zig +0 -155
  99. data/ext/tb_client/tigerbeetle/src/io/darwin.zig +0 -1093
  100. data/ext/tb_client/tigerbeetle/src/io/linux.zig +0 -1880
  101. data/ext/tb_client/tigerbeetle/src/io/test.zig +0 -1005
  102. data/ext/tb_client/tigerbeetle/src/io/windows.zig +0 -1598
  103. data/ext/tb_client/tigerbeetle/src/io.zig +0 -34
  104. data/ext/tb_client/tigerbeetle/src/iops.zig +0 -134
  105. data/ext/tb_client/tigerbeetle/src/list.zig +0 -236
  106. data/ext/tb_client/tigerbeetle/src/lsm/binary_search.zig +0 -848
  107. data/ext/tb_client/tigerbeetle/src/lsm/binary_search_benchmark.zig +0 -179
  108. data/ext/tb_client/tigerbeetle/src/lsm/cache_map.zig +0 -424
  109. data/ext/tb_client/tigerbeetle/src/lsm/cache_map_fuzz.zig +0 -420
  110. data/ext/tb_client/tigerbeetle/src/lsm/compaction.zig +0 -2114
  111. data/ext/tb_client/tigerbeetle/src/lsm/composite_key.zig +0 -185
  112. data/ext/tb_client/tigerbeetle/src/lsm/forest.zig +0 -1146
  113. data/ext/tb_client/tigerbeetle/src/lsm/forest_fuzz.zig +0 -1102
  114. data/ext/tb_client/tigerbeetle/src/lsm/forest_table_iterator.zig +0 -200
  115. data/ext/tb_client/tigerbeetle/src/lsm/groove.zig +0 -1495
  116. data/ext/tb_client/tigerbeetle/src/lsm/k_way_merge.zig +0 -739
  117. data/ext/tb_client/tigerbeetle/src/lsm/k_way_merge_benchmark.zig +0 -166
  118. data/ext/tb_client/tigerbeetle/src/lsm/manifest.zig +0 -754
  119. data/ext/tb_client/tigerbeetle/src/lsm/manifest_level.zig +0 -1294
  120. data/ext/tb_client/tigerbeetle/src/lsm/manifest_level_fuzz.zig +0 -510
  121. data/ext/tb_client/tigerbeetle/src/lsm/manifest_log.zig +0 -1241
  122. data/ext/tb_client/tigerbeetle/src/lsm/manifest_log_fuzz.zig +0 -628
  123. data/ext/tb_client/tigerbeetle/src/lsm/node_pool.zig +0 -247
  124. data/ext/tb_client/tigerbeetle/src/lsm/scan_buffer.zig +0 -116
  125. data/ext/tb_client/tigerbeetle/src/lsm/scan_builder.zig +0 -543
  126. data/ext/tb_client/tigerbeetle/src/lsm/scan_fuzz.zig +0 -938
  127. data/ext/tb_client/tigerbeetle/src/lsm/scan_lookup.zig +0 -293
  128. data/ext/tb_client/tigerbeetle/src/lsm/scan_merge.zig +0 -359
  129. data/ext/tb_client/tigerbeetle/src/lsm/scan_range.zig +0 -99
  130. data/ext/tb_client/tigerbeetle/src/lsm/scan_state.zig +0 -17
  131. data/ext/tb_client/tigerbeetle/src/lsm/scan_tree.zig +0 -962
  132. data/ext/tb_client/tigerbeetle/src/lsm/schema.zig +0 -617
  133. data/ext/tb_client/tigerbeetle/src/lsm/scratch_memory.zig +0 -84
  134. data/ext/tb_client/tigerbeetle/src/lsm/segmented_array.zig +0 -1500
  135. data/ext/tb_client/tigerbeetle/src/lsm/segmented_array_benchmark.zig +0 -149
  136. data/ext/tb_client/tigerbeetle/src/lsm/segmented_array_fuzz.zig +0 -7
  137. data/ext/tb_client/tigerbeetle/src/lsm/set_associative_cache.zig +0 -865
  138. data/ext/tb_client/tigerbeetle/src/lsm/table.zig +0 -607
  139. data/ext/tb_client/tigerbeetle/src/lsm/table_memory.zig +0 -843
  140. data/ext/tb_client/tigerbeetle/src/lsm/table_value_iterator.zig +0 -90
  141. data/ext/tb_client/tigerbeetle/src/lsm/timestamp_range.zig +0 -40
  142. data/ext/tb_client/tigerbeetle/src/lsm/tree.zig +0 -629
  143. data/ext/tb_client/tigerbeetle/src/lsm/tree_fuzz.zig +0 -933
  144. data/ext/tb_client/tigerbeetle/src/lsm/zig_zag_merge.zig +0 -534
  145. data/ext/tb_client/tigerbeetle/src/message_buffer.zig +0 -469
  146. data/ext/tb_client/tigerbeetle/src/message_bus.zig +0 -1219
  147. data/ext/tb_client/tigerbeetle/src/message_bus_fuzz.zig +0 -936
  148. data/ext/tb_client/tigerbeetle/src/message_pool.zig +0 -343
  149. data/ext/tb_client/tigerbeetle/src/multiversion.zig +0 -2195
  150. data/ext/tb_client/tigerbeetle/src/queue.zig +0 -390
  151. data/ext/tb_client/tigerbeetle/src/repl/completion.zig +0 -201
  152. data/ext/tb_client/tigerbeetle/src/repl/parser.zig +0 -1356
  153. data/ext/tb_client/tigerbeetle/src/repl/terminal.zig +0 -496
  154. data/ext/tb_client/tigerbeetle/src/repl.zig +0 -1034
  155. data/ext/tb_client/tigerbeetle/src/scripts/amqp.zig +0 -973
  156. data/ext/tb_client/tigerbeetle/src/scripts/cfo.zig +0 -1866
  157. data/ext/tb_client/tigerbeetle/src/scripts/changelog.zig +0 -304
  158. data/ext/tb_client/tigerbeetle/src/scripts/ci.zig +0 -227
  159. data/ext/tb_client/tigerbeetle/src/scripts/client_readmes.zig +0 -658
  160. data/ext/tb_client/tigerbeetle/src/scripts/devhub.zig +0 -466
  161. data/ext/tb_client/tigerbeetle/src/scripts/release.zig +0 -1058
  162. data/ext/tb_client/tigerbeetle/src/scripts.zig +0 -105
  163. data/ext/tb_client/tigerbeetle/src/shell.zig +0 -1195
  164. data/ext/tb_client/tigerbeetle/src/stack.zig +0 -260
  165. data/ext/tb_client/tigerbeetle/src/state_machine/auditor.zig +0 -911
  166. data/ext/tb_client/tigerbeetle/src/state_machine/workload.zig +0 -2079
  167. data/ext/tb_client/tigerbeetle/src/state_machine.zig +0 -4872
  168. data/ext/tb_client/tigerbeetle/src/state_machine_fuzz.zig +0 -288
  169. data/ext/tb_client/tigerbeetle/src/state_machine_tests.zig +0 -3128
  170. data/ext/tb_client/tigerbeetle/src/static_allocator.zig +0 -82
  171. data/ext/tb_client/tigerbeetle/src/stdx/bit_set.zig +0 -157
  172. data/ext/tb_client/tigerbeetle/src/stdx/bounded_array.zig +0 -292
  173. data/ext/tb_client/tigerbeetle/src/stdx/debug.zig +0 -65
  174. data/ext/tb_client/tigerbeetle/src/stdx/flags.zig +0 -1414
  175. data/ext/tb_client/tigerbeetle/src/stdx/huge_page_allocator.zig +0 -115
  176. data/ext/tb_client/tigerbeetle/src/stdx/mlock.zig +0 -92
  177. data/ext/tb_client/tigerbeetle/src/stdx/prng.zig +0 -677
  178. data/ext/tb_client/tigerbeetle/src/stdx/radix.zig +0 -336
  179. data/ext/tb_client/tigerbeetle/src/stdx/ring_buffer.zig +0 -511
  180. data/ext/tb_client/tigerbeetle/src/stdx/sort_test.zig +0 -112
  181. data/ext/tb_client/tigerbeetle/src/stdx/stdx.zig +0 -1163
  182. data/ext/tb_client/tigerbeetle/src/stdx/testing/low_level_hash_vectors.zig +0 -142
  183. data/ext/tb_client/tigerbeetle/src/stdx/testing/snaptest.zig +0 -361
  184. data/ext/tb_client/tigerbeetle/src/stdx/time_units.zig +0 -275
  185. data/ext/tb_client/tigerbeetle/src/stdx/unshare.zig +0 -295
  186. data/ext/tb_client/tigerbeetle/src/stdx/vendored/aegis.zig +0 -436
  187. data/ext/tb_client/tigerbeetle/src/stdx/windows.zig +0 -48
  188. data/ext/tb_client/tigerbeetle/src/stdx/zipfian.zig +0 -402
  189. data/ext/tb_client/tigerbeetle/src/storage.zig +0 -489
  190. data/ext/tb_client/tigerbeetle/src/storage_fuzz.zig +0 -180
  191. data/ext/tb_client/tigerbeetle/src/testing/bench.zig +0 -146
  192. data/ext/tb_client/tigerbeetle/src/testing/cluster/grid_checker.zig +0 -53
  193. data/ext/tb_client/tigerbeetle/src/testing/cluster/journal_checker.zig +0 -61
  194. data/ext/tb_client/tigerbeetle/src/testing/cluster/manifest_checker.zig +0 -76
  195. data/ext/tb_client/tigerbeetle/src/testing/cluster/message_bus.zig +0 -110
  196. data/ext/tb_client/tigerbeetle/src/testing/cluster/network.zig +0 -412
  197. data/ext/tb_client/tigerbeetle/src/testing/cluster/state_checker.zig +0 -331
  198. data/ext/tb_client/tigerbeetle/src/testing/cluster/storage_checker.zig +0 -458
  199. data/ext/tb_client/tigerbeetle/src/testing/cluster.zig +0 -1198
  200. data/ext/tb_client/tigerbeetle/src/testing/exhaustigen.zig +0 -128
  201. data/ext/tb_client/tigerbeetle/src/testing/fixtures.zig +0 -181
  202. data/ext/tb_client/tigerbeetle/src/testing/fuzz.zig +0 -144
  203. data/ext/tb_client/tigerbeetle/src/testing/id.zig +0 -97
  204. data/ext/tb_client/tigerbeetle/src/testing/io.zig +0 -317
  205. data/ext/tb_client/tigerbeetle/src/testing/marks.zig +0 -126
  206. data/ext/tb_client/tigerbeetle/src/testing/packet_simulator.zig +0 -533
  207. data/ext/tb_client/tigerbeetle/src/testing/reply_sequence.zig +0 -154
  208. data/ext/tb_client/tigerbeetle/src/testing/state_machine.zig +0 -389
  209. data/ext/tb_client/tigerbeetle/src/testing/storage.zig +0 -1247
  210. data/ext/tb_client/tigerbeetle/src/testing/table.zig +0 -249
  211. data/ext/tb_client/tigerbeetle/src/testing/time.zig +0 -98
  212. data/ext/tb_client/tigerbeetle/src/testing/tmp_tigerbeetle.zig +0 -212
  213. data/ext/tb_client/tigerbeetle/src/testing/vortex/constants.zig +0 -26
  214. data/ext/tb_client/tigerbeetle/src/testing/vortex/faulty_network.zig +0 -579
  215. data/ext/tb_client/tigerbeetle/src/testing/vortex/java_driver/ci.zig +0 -39
  216. data/ext/tb_client/tigerbeetle/src/testing/vortex/logged_process.zig +0 -214
  217. data/ext/tb_client/tigerbeetle/src/testing/vortex/rust_driver/ci.zig +0 -34
  218. data/ext/tb_client/tigerbeetle/src/testing/vortex/supervisor.zig +0 -785
  219. data/ext/tb_client/tigerbeetle/src/testing/vortex/workload.zig +0 -543
  220. data/ext/tb_client/tigerbeetle/src/testing/vortex/zig_driver.zig +0 -181
  221. data/ext/tb_client/tigerbeetle/src/tidy.zig +0 -1449
  222. data/ext/tb_client/tigerbeetle/src/tigerbeetle/benchmark_driver.zig +0 -227
  223. data/ext/tb_client/tigerbeetle/src/tigerbeetle/benchmark_load.zig +0 -1069
  224. data/ext/tb_client/tigerbeetle/src/tigerbeetle/cli.zig +0 -1422
  225. data/ext/tb_client/tigerbeetle/src/tigerbeetle/inspect.zig +0 -1658
  226. data/ext/tb_client/tigerbeetle/src/tigerbeetle/inspect_integrity.zig +0 -518
  227. data/ext/tb_client/tigerbeetle/src/tigerbeetle/libtb_client.zig +0 -36
  228. data/ext/tb_client/tigerbeetle/src/tigerbeetle/main.zig +0 -646
  229. data/ext/tb_client/tigerbeetle/src/tigerbeetle.zig +0 -958
  230. data/ext/tb_client/tigerbeetle/src/time.zig +0 -236
  231. data/ext/tb_client/tigerbeetle/src/trace/event.zig +0 -745
  232. data/ext/tb_client/tigerbeetle/src/trace/statsd.zig +0 -462
  233. data/ext/tb_client/tigerbeetle/src/trace.zig +0 -556
  234. data/ext/tb_client/tigerbeetle/src/unit_tests.zig +0 -321
  235. data/ext/tb_client/tigerbeetle/src/vopr.zig +0 -1785
  236. data/ext/tb_client/tigerbeetle/src/vortex.zig +0 -101
  237. data/ext/tb_client/tigerbeetle/src/vsr/checkpoint_trailer.zig +0 -473
  238. data/ext/tb_client/tigerbeetle/src/vsr/checksum.zig +0 -208
  239. data/ext/tb_client/tigerbeetle/src/vsr/checksum_benchmark.zig +0 -43
  240. data/ext/tb_client/tigerbeetle/src/vsr/client.zig +0 -768
  241. data/ext/tb_client/tigerbeetle/src/vsr/client_replies.zig +0 -532
  242. data/ext/tb_client/tigerbeetle/src/vsr/client_sessions.zig +0 -338
  243. data/ext/tb_client/tigerbeetle/src/vsr/clock.zig +0 -1019
  244. data/ext/tb_client/tigerbeetle/src/vsr/fault_detector.zig +0 -279
  245. data/ext/tb_client/tigerbeetle/src/vsr/free_set.zig +0 -1381
  246. data/ext/tb_client/tigerbeetle/src/vsr/free_set_fuzz.zig +0 -315
  247. data/ext/tb_client/tigerbeetle/src/vsr/grid.zig +0 -1460
  248. data/ext/tb_client/tigerbeetle/src/vsr/grid_blocks_missing.zig +0 -757
  249. data/ext/tb_client/tigerbeetle/src/vsr/grid_scrubber.zig +0 -797
  250. data/ext/tb_client/tigerbeetle/src/vsr/journal.zig +0 -2586
  251. data/ext/tb_client/tigerbeetle/src/vsr/marzullo.zig +0 -308
  252. data/ext/tb_client/tigerbeetle/src/vsr/message_header.zig +0 -1777
  253. data/ext/tb_client/tigerbeetle/src/vsr/multi_batch.zig +0 -715
  254. data/ext/tb_client/tigerbeetle/src/vsr/multi_batch_fuzz.zig +0 -185
  255. data/ext/tb_client/tigerbeetle/src/vsr/repair_budget.zig +0 -333
  256. data/ext/tb_client/tigerbeetle/src/vsr/replica.zig +0 -12356
  257. data/ext/tb_client/tigerbeetle/src/vsr/replica_format.zig +0 -416
  258. data/ext/tb_client/tigerbeetle/src/vsr/replica_reformat.zig +0 -165
  259. data/ext/tb_client/tigerbeetle/src/vsr/replica_test.zig +0 -2928
  260. data/ext/tb_client/tigerbeetle/src/vsr/routing.zig +0 -1075
  261. data/ext/tb_client/tigerbeetle/src/vsr/superblock.zig +0 -1603
  262. data/ext/tb_client/tigerbeetle/src/vsr/superblock_fuzz.zig +0 -484
  263. data/ext/tb_client/tigerbeetle/src/vsr/superblock_quorums.zig +0 -405
  264. data/ext/tb_client/tigerbeetle/src/vsr/superblock_quorums_fuzz.zig +0 -355
  265. data/ext/tb_client/tigerbeetle/src/vsr/sync.zig +0 -29
  266. data/ext/tb_client/tigerbeetle/src/vsr.zig +0 -1727
  267. data/lib/tb_client/shared_lib.rb +0 -66
  268. data/lib/tb_client.rb +0 -282
  269. data/lib/tigerbeetle/account.rb +0 -38
  270. data/lib/tigerbeetle/account_balance.rb +0 -23
  271. data/lib/tigerbeetle/account_filter.rb +0 -31
  272. data/lib/tigerbeetle/atomic_counter.rb +0 -14
  273. data/lib/tigerbeetle/client.rb +0 -214
  274. data/lib/tigerbeetle/converters/account.rb +0 -63
  275. data/lib/tigerbeetle/converters/account_balance.rb +0 -31
  276. data/lib/tigerbeetle/converters/account_filter.rb +0 -32
  277. data/lib/tigerbeetle/converters/base.rb +0 -35
  278. data/lib/tigerbeetle/converters/create_accounts_result.rb +0 -21
  279. data/lib/tigerbeetle/converters/create_transfers_result.rb +0 -21
  280. data/lib/tigerbeetle/converters/query_filter.rb +0 -33
  281. data/lib/tigerbeetle/converters/time.rb +0 -23
  282. data/lib/tigerbeetle/converters/transfer.rb +0 -64
  283. data/lib/tigerbeetle/converters/uint_128.rb +0 -24
  284. data/lib/tigerbeetle/converters.rb +0 -12
  285. data/lib/tigerbeetle/error.rb +0 -4
  286. data/lib/tigerbeetle/id.rb +0 -30
  287. data/lib/tigerbeetle/platforms.rb +0 -9
  288. data/lib/tigerbeetle/query_filter.rb +0 -31
  289. data/lib/tigerbeetle/request.rb +0 -7
  290. data/lib/tigerbeetle/transfer.rb +0 -40
  291. data/lib/tigerbeetle/version.rb +0 -4
  292. data/lib/tigerbeetle.rb +0 -13
  293. data/tigerbeetle.gemspec +0 -60
@@ -1,1785 +0,0 @@
1
- const std = @import("std");
2
- const stdx = @import("stdx");
3
- const builtin = @import("builtin");
4
- const assert = std.debug.assert;
5
- const maybe = stdx.maybe;
6
- const mem = std.mem;
7
- const ratio = stdx.PRNG.ratio;
8
- const Ratio = stdx.PRNG.Ratio;
9
- const range_inclusive_ms = @import("./testing/fuzz.zig").range_inclusive_ms;
10
-
11
- const constants = @import("constants.zig");
12
- const schema = @import("lsm/schema.zig");
13
- const vsr = @import("vsr.zig");
14
- const fuzz = @import("./testing/fuzz.zig");
15
- const Header = vsr.Header;
16
-
17
- pub const vsr_options = .{
18
- .config_verify = true,
19
- .git_commit = @import("vsr_options").git_commit,
20
- .release = @import("vsr_options").release,
21
- .release_client_min = @import("vsr_options").release_client_min,
22
- };
23
- const vsr_vopr_options = @import("vsr_vopr_options");
24
-
25
- const state_machine = vsr_vopr_options.state_machine;
26
- const StateMachineType = switch (state_machine) {
27
- .accounting => @import("state_machine.zig").StateMachineType,
28
- .testing => @import("testing/state_machine.zig").StateMachineType,
29
- };
30
-
31
- const Cluster = @import("testing/cluster.zig").ClusterType(StateMachineType);
32
- const Release = @import("testing/cluster.zig").Release;
33
- const StateMachine = Cluster.StateMachine;
34
- const Failure = @import("testing/cluster.zig").Failure;
35
- const PartitionMode = @import("testing/packet_simulator.zig").PartitionMode;
36
- const PartitionSymmetry = @import("testing/packet_simulator.zig").PartitionSymmetry;
37
- const Core = @import("testing/cluster/network.zig").Network.Core;
38
- const ReplySequence = @import("testing/reply_sequence.zig").ReplySequence;
39
- const Message = @import("message_pool.zig").MessagePool.Message;
40
-
41
- const MiB = stdx.MiB;
42
-
43
- const releases = [_]Release{
44
- .{
45
- .release = vsr.Release.from(.{ .major = 0, .minor = 0, .patch = 1 }),
46
- .release_client_min = vsr.Release.from(.{ .major = 0, .minor = 0, .patch = 1 }),
47
- },
48
- .{
49
- .release = vsr.Release.from(.{ .major = 0, .minor = 0, .patch = 2 }),
50
- .release_client_min = vsr.Release.from(.{ .major = 0, .minor = 0, .patch = 1 }),
51
- },
52
- .{
53
- .release = vsr.Release.from(.{ .major = 0, .minor = 0, .patch = 3 }),
54
- .release_client_min = vsr.Release.from(.{ .major = 0, .minor = 0, .patch = 1 }),
55
- },
56
- };
57
-
58
- const log = std.log.scoped(.simulator);
59
-
60
- pub const std_options: std.Options = .{
61
- // The -vopr-log=<full|short> build option selects two logging modes.
62
- // In "short" mode, only state transitions are printed (see `Cluster.log_replica`).
63
- // "full" mode is the usual logging according to the level.
64
- .log_level = if (vsr_vopr_options.log == .short) .info else .debug,
65
- .logFn = log_override,
66
-
67
- // Uncomment if you need per-scope control over the log levels.
68
- // pub const log_scope_levels: []const std.log.ScopeLevel = &.{
69
- // .{ .scope = .cluster, .level = .info },
70
- // .{ .scope = .replica, .level = .debug },
71
- // };
72
- };
73
-
74
- pub const tigerbeetle_config = @import("config.zig").configs.test_min;
75
-
76
- const cluster_id = 0;
77
-
78
- const CLIArgs = struct {
79
- // "lite" mode runs a small cluster and only looks for crashes.
80
- lite: bool = false,
81
- performance: bool = false,
82
- // Feel free to add more runtime overrides here!
83
- ticks_max_requests: u32 = 40_000_000,
84
- ticks_max_convergence: u32 = 10_000_000,
85
- packet_loss_ratio: ?Ratio = null,
86
- replica_missing: ?u8 = null,
87
- replica_missing_until_request: ?u32 = null,
88
- requests_max: ?u32 = null,
89
-
90
- @"--": void,
91
- seed: ?[]const u8 = null,
92
- };
93
-
94
- pub fn main() !void {
95
- comptime assert(constants.verify);
96
- // This must be initialized at runtime as stderr is not comptime known on e.g. Windows.
97
- log_buffer.unbuffered_writer = std.io.getStdErr().writer();
98
- fuzz.limit_ram();
99
-
100
- var gpa_instance: std.heap.GeneralPurposeAllocator(.{}) = .{};
101
- defer {
102
- _ = gpa_instance.detectLeaks();
103
- switch (gpa_instance.deinit()) {
104
- .ok => {},
105
- .leak => @panic("memory leaked"),
106
- }
107
- }
108
-
109
- const gpa = gpa_instance.allocator();
110
-
111
- var args = try std.process.argsWithAllocator(gpa);
112
- defer args.deinit();
113
-
114
- const cli_args = stdx.flags(&args, CLIArgs);
115
- if (cli_args.lite and cli_args.performance) {
116
- return vsr.fatal(.cli, "--lite and --performance are mutually exclusive", .{});
117
- }
118
- if (cli_args.replica_missing != null and !cli_args.performance) {
119
- return vsr.fatal(.cli, "--replica-missing requires --performance", .{});
120
- }
121
- if (cli_args.replica_missing == null and cli_args.replica_missing_until_request != null) {
122
- return vsr.fatal(.cli, "--replica-missing-until-request requires --replica-missing", .{});
123
- }
124
-
125
- log_performance_mode = cli_args.performance;
126
-
127
- const seed_random = std.crypto.random.int(u64);
128
- const seed = seed_from_arg: {
129
- const seed_argument = cli_args.seed orelse break :seed_from_arg seed_random;
130
- break :seed_from_arg vsr.testing.parse_seed(seed_argument);
131
- };
132
-
133
- // We do not support ReleaseFast or ReleaseSmall because they disable assertions.
134
- comptime assert(builtin.mode == .Debug or builtin.mode == .ReleaseSafe);
135
-
136
- if (seed == seed_random) {
137
- if (builtin.mode != .ReleaseSafe) {
138
- // If no seed is provided, than Debug is too slow and ReleaseSafe is much faster.
139
- return vsr.fatal(
140
- .cli,
141
- "no seed provided: the simulator must be run with -OReleaseSafe",
142
- .{},
143
- );
144
- }
145
- if (vsr_vopr_options.log != .short) {
146
- log.warn("no seed provided: full debug logs are enabled, this will be slow", .{});
147
- }
148
- }
149
-
150
- var prng = stdx.PRNG.from_seed(seed);
151
-
152
- var options = if (cli_args.lite)
153
- options_lite(&prng)
154
- else if (cli_args.performance)
155
- options_performance(&prng)
156
- else
157
- options_swarm(&prng);
158
-
159
- options.replica_missing = cli_args.replica_missing;
160
- options.replica_missing_until_request = cli_args.replica_missing_until_request;
161
- if (cli_args.packet_loss_ratio) |packet_loss_ratio| {
162
- options.network.packet_loss_probability = packet_loss_ratio;
163
- }
164
- if (cli_args.requests_max) |requests_max| {
165
- options.requests_max = requests_max;
166
- }
167
-
168
- log.info(
169
- \\
170
- \\ SEED={}
171
- \\
172
- \\ replicas={}
173
- \\ standbys={}
174
- \\ clients={}
175
- \\ request_probability={}
176
- \\ idle_on_probability={}
177
- \\ idle_off_probability={}
178
- \\ one_way_delay_mean={}
179
- \\ one_way_delay_min={}
180
- \\ packet_loss_probability={}
181
- \\ path_maximum_capacity={} messages
182
- \\ path_clog_duration_mean={}
183
- \\ path_clog_probability={}
184
- \\ packet_replay_probability={}
185
- \\ partition_mode={s}
186
- \\ partition_symmetry={s}
187
- \\ partition_probability={}
188
- \\ unpartition_probability={}
189
- \\ partition_stability={} ticks
190
- \\ unpartition_stability={} ticks
191
- \\ read_latency_min={}
192
- \\ read_latency_mean={}
193
- \\ write_latency_min={}
194
- \\ write_latency_mean={}
195
- \\ read_fault_probability={}
196
- \\ write_fault_probability={}
197
- \\ crash_probability={}
198
- \\ crash_stability={} ticks
199
- \\ restart_probability={}
200
- \\ restart_stability={} ticks
201
- , .{
202
- seed,
203
- options.cluster.replica_count,
204
- options.cluster.standby_count,
205
- options.cluster.client_count,
206
- options.request_probability,
207
- options.request_idle_on_probability,
208
- options.request_idle_off_probability,
209
- options.network.one_way_delay_mean,
210
- options.network.one_way_delay_min,
211
- options.network.packet_loss_probability,
212
- options.network.path_maximum_capacity,
213
- options.network.path_clog_duration_mean,
214
- options.network.path_clog_probability,
215
- options.network.packet_replay_probability,
216
- @tagName(options.network.partition_mode),
217
- @tagName(options.network.partition_symmetry),
218
- options.network.partition_probability,
219
- options.network.unpartition_probability,
220
- options.network.partition_stability,
221
- options.network.unpartition_stability,
222
- options.storage.read_latency_min,
223
- options.storage.read_latency_mean,
224
- options.storage.write_latency_min,
225
- options.storage.write_latency_mean,
226
- options.storage.read_fault_probability,
227
- options.storage.write_fault_probability,
228
- options.replica_crash_probability,
229
- options.replica_crash_stability,
230
- options.replica_restart_probability,
231
- options.replica_restart_stability,
232
- });
233
-
234
- var simulator = try Simulator.init(gpa, &prng, options);
235
- defer simulator.deinit(gpa);
236
-
237
- if (cli_args.performance) {
238
- // Simulate a missing replica by crashing it with ∞ stability.
239
- if (options.replica_missing) |replica_index| {
240
- if (replica_index > options.network.node_count) {
241
- vsr.fatal(.cli, "--replica-index too large", .{});
242
- }
243
- simulator.cluster.replica_crash(replica_index);
244
- simulator.replica_crash_stability[replica_index] = std.math.maxInt(u32);
245
- }
246
-
247
- // Warm-up the cluster before performance testing to get past the initial view change.
248
- simulator.options.request_probability = Ratio.zero();
249
- for (0..500) |_| simulator.tick();
250
- simulator.options.request_probability = options.request_probability;
251
- }
252
-
253
- for (0..options.cluster.client_count) |client_index| {
254
- simulator.cluster.register(client_index);
255
- }
256
-
257
- // Safety: replicas crash and restart; at any given point in time arbitrarily many replicas may
258
- // be crashed, but each replica restarts eventually. The cluster must process all requests
259
- // without split-brain.
260
- var tick_total: u64 = 0;
261
- var tick: u64 = 0;
262
- var requests_done: bool = false;
263
- var upgrades_done: bool = false;
264
-
265
- while (tick < cli_args.ticks_max_requests) : (tick += 1) {
266
- const requests_replied_old = simulator.requests_replied;
267
- simulator.tick();
268
- tick_total += 1;
269
- if (simulator.requests_replied > requests_replied_old) {
270
- tick = 0;
271
- }
272
- requests_done = simulator.requests_replied == simulator.options.requests_max;
273
- upgrades_done =
274
- for (simulator.cluster.replicas, simulator.cluster.replica_health) |*replica, health| {
275
- if (health != .up) continue;
276
- const release_latest = releases[simulator.replica_releases_limit - 1].release;
277
- if (replica.release.value == release_latest.value) {
278
- break true;
279
- }
280
- } else false;
281
-
282
- if (requests_done and upgrades_done) break;
283
- }
284
-
285
- if (cli_args.lite or
286
- (cli_args.performance and cli_args.replica_missing_until_request == null))
287
- {
288
- // Don't care about convergence.
289
- } else {
290
- const core = if (requests_done and upgrades_done)
291
- // Liveness: a core set of replicas is up and fully connected. The rest of the replicas
292
- // might be crashed or partitioned permanently. The core should converge to the same
293
- // state.
294
- random_core(
295
- simulator.prng,
296
- simulator.options.cluster.replica_count,
297
- simulator.options.cluster.standby_count,
298
- )
299
- else
300
- // Safety mode ran out of ticks without completing its requests, so now we check whether
301
- // it was correct to do so.
302
- //
303
- // Run a fully-connected core of replicas to repair all faulty grid blocks, headers, and
304
- // prepares that can be repaired. Thereafter, only correlated faults should remain.
305
- full_core(
306
- simulator.options.cluster.replica_count,
307
- simulator.options.cluster.standby_count,
308
- );
309
-
310
- simulator.transition_to_liveness_mode(core);
311
-
312
- tick = 0;
313
- while (tick < cli_args.ticks_max_convergence) : (tick += 1) {
314
- simulator.tick();
315
- tick_total += 1;
316
- if (simulator.pending() == null) {
317
- break;
318
- }
319
- }
320
-
321
- if (simulator.pending()) |reason| {
322
- if (try simulator.cluster_recoverable(gpa)) {
323
- log.info("no liveness, final cluster state (core={b}):", .{simulator.core.bits});
324
- simulator.cluster.log_cluster();
325
- log.err("you can reproduce this failure with seed={}", .{seed});
326
- fatal(.liveness, "no state convergence: {s}", .{reason});
327
- }
328
- } else {
329
- const commits = simulator.cluster.state_checker.commits.items;
330
- const last_checksum = commits[commits.len - 1].header.checksum;
331
- for (simulator.cluster.aofs, 0..) |*aof, replica_index| {
332
- if (simulator.core.is_set(replica_index)) {
333
- try aof.validate(gpa, last_checksum);
334
- } else {
335
- try aof.validate(gpa, null);
336
- }
337
- }
338
- }
339
- }
340
-
341
- if (cli_args.performance) {
342
- log.info("\nMessages:\n{}", .{simulator.cluster.network.message_summary});
343
- } else {
344
- log.debug("\nMessages:\n{}", .{simulator.cluster.network.message_summary});
345
- }
346
-
347
- log.info("\n PASSED ({} ticks)", .{tick_total});
348
- }
349
-
350
- fn options_swarm(prng: *stdx.PRNG) Simulator.Options {
351
- const replica_count = prng.range_inclusive(u8, 1, constants.replicas_max);
352
- const standby_count = prng.int_inclusive(u8, constants.standbys_max);
353
- const node_count = replica_count + standby_count;
354
- // -1 since otherwise it is possible that all clients will evict each other.
355
- // (Due to retried register messages from the first set of evicted clients.
356
- // See the "Cluster: eviction: session_too_low" replica test for a related scenario.)
357
- const client_count = prng.range_inclusive(u8, 1, constants.clients_max * 2 - 1);
358
-
359
- const batch_size_limit_min = comptime batch_size_limit_min: {
360
- var event_size_max: u32 = @sizeOf(vsr.RegisterRequest);
361
- for (std.enums.values(StateMachine.Operation)) |operation| {
362
- event_size_max = @max(event_size_max, operation.event_size());
363
- }
364
- break :batch_size_limit_min event_size_max;
365
- };
366
- const batch_size_limit: u32 = if (prng.boolean())
367
- constants.message_body_size_max
368
- else
369
- prng.range_inclusive(u32, batch_size_limit_min, constants.message_body_size_max);
370
-
371
- const multi_batch_per_request_limit: u32 = multi_batch_per_request_limit: {
372
- const event_max = @divFloor(batch_size_limit, batch_size_limit_min);
373
- assert(event_max > 0);
374
- break :multi_batch_per_request_limit if (event_max == 1) 1 else prng.range_inclusive(
375
- u32,
376
- 1,
377
- event_max - 1, // Minus one for the multi-batch trailer.
378
- );
379
- };
380
-
381
- const storage_size_limit = vsr.sector_floor(
382
- 200 * MiB - prng.int_inclusive(u64, 20 * MiB),
383
- );
384
-
385
- const cluster_options: Cluster.Options = .{
386
- .cluster_id = cluster_id,
387
- .replica_count = replica_count,
388
- .standby_count = standby_count,
389
- .client_count = client_count,
390
- .storage_size_limit = storage_size_limit,
391
- .seed = prng.int(u64),
392
- .releases = &releases,
393
- .client_release = releases[0].release,
394
- .reformats_max = replica_count + 2, // Arbitrary reformat limit.
395
-
396
- .state_machine = switch (state_machine) {
397
- .testing => .{
398
- .batch_size_limit = batch_size_limit,
399
- .lsm_forest_node_count = 4096,
400
- },
401
- .accounting => .{
402
- .batch_size_limit = batch_size_limit,
403
- .lsm_forest_compaction_block_count = prng.int_inclusive(u32, 256) +
404
- StateMachine.Forest.Options.compaction_block_count_min,
405
- .lsm_forest_node_count = 4096,
406
- .cache_entries_accounts = if (prng.boolean()) 256 else 0,
407
- .cache_entries_transfers = if (prng.boolean()) 256 else 0,
408
- .cache_entries_transfers_pending = if (prng.boolean()) 256 else 0,
409
- .log_trace = true,
410
- .aof_recovery = false,
411
- },
412
- },
413
- .replicate_options = .{
414
- .closed_loop = prng.chance(ratio(1, 5)),
415
- .star = prng.chance(ratio(1, 5)),
416
- },
417
- };
418
-
419
- const network_options: Cluster.NetworkOptions = .{
420
- .node_count = node_count,
421
- .client_count = client_count,
422
-
423
- .seed = prng.int(u64),
424
-
425
- .one_way_delay_min = range_inclusive_ms(prng, 0, 30),
426
- .one_way_delay_mean = range_inclusive_ms(prng, 30, 100),
427
- .packet_loss_probability = ratio(prng.int_inclusive(u8, 30), 100),
428
- .path_maximum_capacity = prng.range_inclusive(u8, 2, 20),
429
- .path_clog_duration_mean = range_inclusive_ms(prng, 0, 5_000),
430
- .path_clog_probability = ratio(prng.int_inclusive(u8, 2), 100),
431
- .packet_replay_probability = ratio(prng.int_inclusive(u8, 50), 100),
432
-
433
- .partition_mode = prng.enum_uniform(PartitionMode),
434
- .partition_symmetry = prng.enum_uniform(PartitionSymmetry),
435
- .partition_probability = ratio(prng.int_inclusive(u8, 3), 100),
436
- .unpartition_probability = ratio(prng.range_inclusive(u8, 1, 10), 100),
437
- .partition_stability = 100 + prng.int_inclusive(u32, 100),
438
- .unpartition_stability = prng.int_inclusive(u32, 20),
439
- };
440
-
441
- const read_latency_min = range_inclusive_ms(prng, 0, 30);
442
- const write_latency_min = range_inclusive_ms(prng, 0, 30);
443
- const storage_options: Cluster.Storage.Options = .{
444
- .size = cluster_options.storage_size_limit,
445
- .seed = prng.int(u64),
446
- .read_latency_min = read_latency_min,
447
- .read_latency_mean = range_inclusive_ms(prng, read_latency_min, 100),
448
- .write_latency_min = write_latency_min,
449
- .write_latency_mean = range_inclusive_ms(prng, write_latency_min, 1_000),
450
- .read_fault_probability = ratio(prng.range_inclusive(u8, 0, 10), 100),
451
- .write_fault_probability = ratio(prng.range_inclusive(u8, 0, 10), 100),
452
- .write_misdirect_probability = ratio(prng.range_inclusive(u8, 0, 10), 100),
453
- .crash_fault_probability = ratio(prng.range_inclusive(u8, 80, 100), 100),
454
- };
455
- const storage_fault_atlas: Cluster.StorageFaultAtlas.Options = .{
456
- .faulty_superblock = true,
457
- .faulty_wal_headers = replica_count > 1,
458
- .faulty_wal_prepares = replica_count > 1,
459
- .faulty_client_replies = replica_count > 1,
460
- // >2 instead of >1 because in R=2, a lagging replica may sync to the leading replica,
461
- // but then the leading replica may have the only copy of a block in the cluster.
462
- .faulty_grid = replica_count > 2,
463
- };
464
-
465
- const workload_options = StateMachine.Workload.Options.generate(prng, .{
466
- .batch_size_limit = batch_size_limit,
467
- .multi_batch_per_request_limit = multi_batch_per_request_limit,
468
- .client_count = client_count,
469
- // TODO(DJ) Once Workload no longer needs in_flight_max, make stalled_queue_capacity
470
- // private. Also maybe make it dynamic (computed from the client_count instead of
471
- // clients_max).
472
- .in_flight_max = ReplySequence.stalled_queue_capacity *
473
- multi_batch_per_request_limit,
474
- });
475
-
476
- return .{
477
- .cluster = cluster_options,
478
- .network = network_options,
479
- .storage = storage_options,
480
- .storage_fault_atlas = storage_fault_atlas,
481
- .workload = workload_options,
482
- // TODO Swarm testing: Test long+few crashes and short+many crashes separately.
483
- .replica_crash_probability = ratio(2, 10_000_000),
484
- .replica_crash_stability = prng.int_inclusive(u32, 1_000),
485
- .replica_restart_probability = ratio(2, 1_000_000),
486
- .replica_restart_stability = prng.int_inclusive(u32, 1_000),
487
- .replica_reformat_probability = ratio(30, 100),
488
-
489
- .replica_pause_probability = ratio(8, 10_000_000),
490
- .replica_pause_stability = prng.int_inclusive(u32, 1_000),
491
- .replica_unpause_probability = ratio(8, 1_000_000),
492
- .replica_unpause_stability = prng.int_inclusive(u32, 1_000),
493
-
494
- .replica_release_advance_probability = ratio(1, 1_000_000),
495
- .replica_release_catchup_probability = ratio(1, 100_000),
496
-
497
- .requests_max = constants.journal_slot_count * 3,
498
- .request_probability = ratio(prng.range_inclusive(u8, 1, 100), 100),
499
- .request_idle_on_probability = ratio(prng.range_inclusive(u8, 0, 20), 100),
500
- .request_idle_off_probability = ratio(prng.range_inclusive(u8, 10, 20), 100),
501
- };
502
- }
503
-
504
- fn options_lite(prng: *stdx.PRNG) Simulator.Options {
505
- var base = options_swarm(prng);
506
- base.cluster.replica_count = 3;
507
- base.cluster.standby_count = 0;
508
- base.network.node_count = 3;
509
- return base;
510
- }
511
-
512
- fn options_performance(prng: *stdx.PRNG) Simulator.Options {
513
- const cluster_options: Cluster.Options = .{
514
- .cluster_id = cluster_id,
515
- .replica_count = 6,
516
- .standby_count = 0,
517
- .client_count = 4,
518
- .storage_size_limit = vsr.sector_floor(200 * MiB),
519
- .seed = prng.int(u64),
520
- .releases = releases[0..1],
521
- .client_release = releases[0].release,
522
- .reformats_max = 0,
523
-
524
- .state_machine = switch (state_machine) {
525
- .testing => .{
526
- .batch_size_limit = constants.message_body_size_max,
527
- .lsm_forest_node_count = 4096,
528
- },
529
- .accounting => .{
530
- .batch_size_limit = constants.message_body_size_max,
531
- .lsm_forest_compaction_block_count = 128 +
532
- StateMachine.Forest.Options.compaction_block_count_min,
533
- .lsm_forest_node_count = 4096,
534
- .cache_entries_accounts = 256,
535
- .cache_entries_transfers = 0,
536
- .cache_entries_transfers_pending = 0,
537
- .log_trace = true,
538
- .aof_recovery = false,
539
- },
540
- },
541
- };
542
-
543
- const network_options: Cluster.NetworkOptions = .{
544
- .node_count = cluster_options.replica_count,
545
- .client_count = cluster_options.client_count,
546
-
547
- .seed = prng.int(u64),
548
-
549
- .one_way_delay_mean = .ms(50),
550
- .one_way_delay_min = .{ .ns = 0 },
551
- .packet_loss_probability = Ratio.zero(),
552
- .path_maximum_capacity = 10,
553
- .path_clog_duration_mean = .ms(2_000),
554
- .path_clog_probability = Ratio.zero(),
555
- .packet_replay_probability = Ratio.zero(),
556
-
557
- .partition_mode = .none,
558
- .partition_symmetry = .symmetric,
559
- .partition_probability = Ratio.zero(),
560
- .unpartition_probability = Ratio.zero(),
561
- .partition_stability = 100,
562
- .unpartition_stability = 10,
563
- };
564
-
565
- const storage_options: Cluster.Storage.Options = .{
566
- .size = cluster_options.storage_size_limit,
567
- .seed = prng.int(u64),
568
- .read_latency_min = .{ .ns = 0 },
569
- .read_latency_mean = .{ .ns = 0 },
570
- .write_latency_min = .{ .ns = 0 },
571
- .write_latency_mean = .{ .ns = 0 },
572
- .read_fault_probability = Ratio.zero(),
573
- .write_fault_probability = Ratio.zero(),
574
- .write_misdirect_probability = Ratio.zero(),
575
- .crash_fault_probability = Ratio.zero(),
576
- };
577
- const storage_fault_atlas: Cluster.StorageFaultAtlas.Options = .{
578
- .faulty_superblock = false,
579
- .faulty_wal_headers = false,
580
- .faulty_wal_prepares = false,
581
- .faulty_client_replies = false,
582
- .faulty_grid = false,
583
- };
584
-
585
- var workload_prng = stdx.PRNG.from_seed(92); // Fix workload for perf testing.
586
- const workload_options = StateMachine.Workload.Options.generate(&workload_prng, .{
587
- .batch_size_limit = constants.message_body_size_max,
588
- .multi_batch_per_request_limit = 1,
589
- .client_count = cluster_options.client_count,
590
- .in_flight_max = ReplySequence.stalled_queue_capacity,
591
- });
592
-
593
- return .{
594
- .cluster = cluster_options,
595
- .network = network_options,
596
- .storage = storage_options,
597
- .storage_fault_atlas = storage_fault_atlas,
598
- .workload = workload_options,
599
- .replica_crash_probability = Ratio.zero(),
600
- .replica_crash_stability = 500,
601
- .replica_restart_probability = Ratio.zero(),
602
- .replica_restart_stability = 500,
603
- .replica_reformat_probability = ratio(0, 100),
604
-
605
- .replica_pause_probability = Ratio.zero(),
606
- .replica_pause_stability = 500,
607
- .replica_unpause_probability = Ratio.zero(),
608
- .replica_unpause_stability = 500,
609
-
610
- .replica_release_advance_probability = Ratio.zero(),
611
- .replica_release_catchup_probability = Ratio.zero(),
612
-
613
- .requests_max = constants.journal_slot_count * 8,
614
- .request_probability = ratio(100, 100),
615
- .request_idle_on_probability = Ratio.zero(),
616
- .request_idle_off_probability = ratio(100, 100),
617
- };
618
- }
619
-
620
- pub const Simulator = struct {
621
- pub const Options = struct {
622
- cluster: Cluster.Options,
623
- network: Cluster.NetworkOptions,
624
- storage: Cluster.Storage.Options,
625
- storage_fault_atlas: Cluster.StorageFaultAtlas.Options,
626
-
627
- workload: StateMachine.Workload.Options,
628
-
629
- /// Probability per tick that a crash will occur.
630
- replica_crash_probability: Ratio,
631
- /// Minimum duration of a crash.
632
- replica_crash_stability: u32,
633
- /// Probability per tick that a crashed replica will recovery.
634
- replica_restart_probability: Ratio,
635
- /// Minimum time a replica is up until it is crashed again.
636
- replica_restart_stability: u32,
637
- /// Probability per restart that a replica will be reformatted with `tigerbeetle recover`
638
- /// (immediately before being restarted).
639
- replica_reformat_probability: Ratio,
640
-
641
- // A replica permanently or temporarily missing from the cluster, used in performance mode.
642
- replica_missing: ?u8 = null,
643
- /// Restart `replica_missing` after the specified request has received its reply.
644
- replica_missing_until_request: ?u32 = null,
645
-
646
- replica_pause_probability: Ratio,
647
- replica_pause_stability: u32,
648
- replica_unpause_probability: Ratio,
649
- replica_unpause_stability: u32,
650
-
651
- /// Probability per tick that a healthy replica will be crash-upgraded.
652
- /// This probability is set to 0 during liveness mode.
653
- replica_release_advance_probability: Ratio,
654
- /// Probability that a crashed with an outdated version will be upgraded as it restarts.
655
- /// This helps ensure that when the cluster upgrades, that replicas without the newest
656
- /// version don't take too long to receive that new version.
657
- /// This probability is set to 0 during liveness mode.
658
- replica_release_catchup_probability: Ratio,
659
-
660
- /// The total number of requests to send. Does not count `register` messages.
661
- requests_max: usize,
662
- request_probability: Ratio,
663
- request_idle_on_probability: Ratio,
664
- request_idle_off_probability: Ratio,
665
- };
666
-
667
- prng: *stdx.PRNG,
668
- options: Options,
669
- cluster: *Cluster,
670
- workload: StateMachine.Workload,
671
-
672
- // The number of releases in each replica's "binary".
673
- replica_releases: []usize,
674
- /// The maximum number of releases available in any replica's "binary".
675
- /// (i.e. the maximum of any `replica_releases`.)
676
- replica_releases_limit: usize = 1,
677
-
678
- /// Keep track of which replicas have possibly "lost" data.
679
- // TODO We could unset this when a replica fully recovers.
680
- replica_reformats: Core = .{},
681
-
682
- /// Protect a replica from fast successive crash/restarts.
683
- replica_crash_stability: []usize,
684
- reply_sequence: ReplySequence,
685
- reply_op_next: u64 = 1, // Skip the root op.
686
-
687
- /// Fully-connected subgraph of replicas for liveness checking.
688
- core: Core = .{},
689
-
690
- /// Total number of requests sent, including those that have not been delivered.
691
- /// Does not include `register` messages.
692
- requests_sent: usize = 0,
693
- /// Total number of replies received by non-evicted clients.
694
- /// Does not include `register` messages.
695
- requests_replied: usize = 0,
696
- requests_idle: bool = false,
697
-
698
- pub fn init(
699
- gpa: std.mem.Allocator,
700
- prng: *stdx.PRNG,
701
- options: Options,
702
- ) !Simulator {
703
- assert(options.requests_max > 0);
704
- assert(options.request_probability.numerator > 0);
705
- assert(options.request_idle_off_probability.numerator > 0);
706
-
707
- var cluster = try Cluster.init(gpa, .{
708
- .cluster = options.cluster,
709
- .network = options.network,
710
- .storage = options.storage,
711
- .storage_fault_atlas = options.storage_fault_atlas,
712
- .callbacks = .{
713
- .on_cluster_reply = on_cluster_reply,
714
- .on_client_reply = on_client_reply,
715
- },
716
- });
717
- errdefer cluster.deinit();
718
-
719
- var workload = try StateMachine.Workload.init(gpa, prng, options.workload);
720
- errdefer workload.deinit(gpa);
721
-
722
- const replica_releases = try gpa.alloc(
723
- usize,
724
- options.cluster.replica_count + options.cluster.standby_count,
725
- );
726
- errdefer gpa.free(replica_releases);
727
- @memset(replica_releases, 1);
728
-
729
- const replica_crash_stability = try gpa.alloc(
730
- usize,
731
- options.cluster.replica_count + options.cluster.standby_count,
732
- );
733
- errdefer gpa.free(replica_crash_stability);
734
- @memset(replica_crash_stability, 0);
735
-
736
- var reply_sequence = try ReplySequence.init(gpa);
737
- errdefer reply_sequence.deinit(gpa);
738
-
739
- return Simulator{
740
- .prng = prng,
741
- .options = options,
742
- .cluster = cluster,
743
- .workload = workload,
744
- .replica_releases = replica_releases,
745
- .replica_crash_stability = replica_crash_stability,
746
- .reply_sequence = reply_sequence,
747
- };
748
- }
749
-
750
- pub fn deinit(simulator: *Simulator, gpa: std.mem.Allocator) void {
751
- gpa.free(simulator.replica_releases);
752
- gpa.free(simulator.replica_crash_stability);
753
- simulator.reply_sequence.deinit(gpa);
754
- simulator.workload.deinit(gpa);
755
- simulator.cluster.deinit();
756
- }
757
-
758
- pub fn pending(simulator: *const Simulator) ?[]const u8 {
759
- assert(simulator.core.count() > 0);
760
- assert(simulator.requests_sent - simulator.cluster.client_eviction_requests_cancelled <=
761
- simulator.options.requests_max);
762
- assert(simulator.reply_sequence.empty());
763
- for (simulator.cluster.clients) |*client_maybe| {
764
- if (client_maybe.*) |client| {
765
- if (client.request_inflight) |_| return "pending request";
766
- }
767
- }
768
-
769
- // Even though there are no client requests in progress, the cluster may be upgrading.
770
- const release_max = simulator.core_release_max();
771
- for (simulator.cluster.replicas) |*replica| {
772
- if (simulator.core.is_set(replica.replica)) {
773
- // (If down, the replica is waiting to be upgraded.)
774
- maybe(simulator.cluster.replica_health[replica.replica] == .down);
775
-
776
- if (replica.release.value != release_max.value) return "pending upgrade";
777
- }
778
- }
779
-
780
- for (simulator.cluster.replicas) |*replica| {
781
- if (simulator.core.is_set(replica.replica)) {
782
- if (!simulator.cluster.state_checker.replica_convergence(replica.replica)) {
783
- return "pending replica convergence";
784
- }
785
- }
786
- }
787
-
788
- simulator.cluster.state_checker.assert_cluster_convergence();
789
-
790
- // Check whether the replica is still repairing prepares/tables/replies.
791
- const commit_max: u64 = simulator.cluster.state_checker.commits.items.len - 1;
792
- for (simulator.cluster.replicas) |*replica| {
793
- if (simulator.core.is_set(replica.replica)) {
794
- for (replica.op_checkpoint() + 1..commit_max + 1) |op| {
795
- const header = simulator.cluster.state_checker.header_with_op(op);
796
- if (!replica.journal.has_prepare(&header)) return "pending journal";
797
- }
798
- // It's okay for a replica to miss some prepares older than the current checkpoint.
799
- maybe(replica.journal.faulty.count > 0);
800
-
801
- if (!replica.sync_content_done()) return "pending sync content";
802
- }
803
- }
804
-
805
- // Expect that all core replicas have arrived at an identical (non-divergent) checkpoint.
806
- var checkpoint_id: ?u128 = null;
807
- for (simulator.cluster.replicas) |*replica| {
808
- if (simulator.core.is_set(replica.replica)) {
809
- const replica_checkpoint_id = replica.superblock.working.checkpoint_id();
810
- if (checkpoint_id) |id| {
811
- assert(checkpoint_id == id);
812
- } else {
813
- checkpoint_id = replica_checkpoint_id;
814
- }
815
- }
816
- }
817
- assert(checkpoint_id != null);
818
-
819
- return null;
820
- }
821
-
822
- pub fn tick(simulator: *Simulator) void {
823
- // TODO(Zig): Remove (see on_cluster_reply()).
824
- simulator.cluster.context = simulator;
825
-
826
- simulator.cluster.tick();
827
- simulator.tick_requests();
828
- simulator.tick_upgrade();
829
- simulator.tick_crash();
830
- simulator.tick_pause();
831
-
832
- if (simulator.options.replica_missing_until_request) |request| {
833
- if (simulator.requests_replied >= request) {
834
- simulator.options.replica_missing_until_request = null;
835
- simulator.replica_crash_stability[simulator.options.replica_missing.?] = 1;
836
- }
837
- }
838
- }
839
-
840
- pub fn cluster_recoverable(simulator: *Simulator, gpa: std.mem.Allocator) !bool {
841
- if (simulator.core_missing_primary()) {
842
- unimplemented("repair requires reachable primary");
843
- } else if (simulator.core_missing_quorum()) {
844
- log.warn("no liveness, core replicas cannot view-change", .{});
845
- } else if (try simulator.core_missing_prepare(gpa)) |op| {
846
- log.warn("no liveness, op={} is not available in core", .{op});
847
- } else if (try simulator.core_missing_blocks(gpa)) |blocks| {
848
- log.warn("no liveness, {} blocks are not available in core", .{blocks});
849
- } else if (simulator.core_missing_reply()) |header| {
850
- log.warn("no liveness, reply op={} is not available in core", .{header.op});
851
- } else if (simulator.core_reformat_evicted()) {
852
- log.warn("no liveness, one or more reformat clients was evicted", .{});
853
- } else {
854
- return true;
855
- }
856
-
857
- return false;
858
- }
859
-
860
- /// Executes the following:
861
- /// * Restart any core replicas that are down at the moment
862
- /// * Heal all network partitions between core replicas
863
- /// * Disable storage faults on the core replicas
864
- /// * For all failures involving non-core replicas, make those failures permanent.
865
- ///
866
- /// See https://tigerbeetle.com/blog/2023-07-06-simulation-testing-for-liveness for broader
867
- /// context.
868
- pub fn transition_to_liveness_mode(simulator: *Simulator, core: Core) void {
869
- log.debug("transition_to_liveness_mode: core={b}", .{core.bits});
870
- assert(simulator.core.count() == 0);
871
- defer assert(simulator.core.count() > 0);
872
-
873
- simulator.core = core;
874
-
875
- var it = core.iterate();
876
- while (it.next()) |replica_index| {
877
- const fault = false;
878
- if (simulator.cluster.replica_health[replica_index] == .down) {
879
- simulator.replica_restart(@intCast(replica_index), fault);
880
- }
881
-
882
- const replica_health = simulator.cluster.replica_health[replica_index];
883
- if (replica_health == .up and replica_health.up.paused) {
884
- simulator.cluster.replica_unpause(@intCast(replica_index));
885
- }
886
-
887
- simulator.cluster.storages[replica_index].transition_to_liveness_mode();
888
- }
889
-
890
- simulator.cluster.network.transition_to_liveness_mode(simulator.core);
891
- simulator.options.replica_crash_probability = Ratio.zero();
892
- simulator.options.replica_restart_probability = Ratio.zero();
893
- simulator.options.replica_reformat_probability = Ratio.zero();
894
- simulator.options.replica_pause_probability = Ratio.zero();
895
- simulator.options.replica_release_advance_probability = Ratio.zero();
896
- simulator.options.replica_release_catchup_probability = Ratio.zero();
897
- }
898
-
899
- // If a primary ends up being outside of a core, and is only partially connected to the core,
900
- // the core might fail to converge, as parts of the repair protocol rely on primary-sent
901
- // `.start_view_change` messages. Until we fix this issue, we special-case this scenario in
902
- // VOPR and don't treat it as a liveness failure.
903
- //
904
- // TODO: make sure that .recovering_head replicas can transition to normal even without direct
905
- // connection to the primary
906
- pub fn core_missing_primary(simulator: *const Simulator) bool {
907
- assert(simulator.core.count() > 0);
908
-
909
- for (simulator.cluster.replicas) |*replica| {
910
- if (simulator.cluster.replica_health[replica.replica] == .up and
911
- replica.status == .normal and replica.primary() and
912
- !simulator.core.is_set(replica.replica))
913
- {
914
- // `replica` considers itself a primary, check that at least part of the core thinks
915
- // so as well.
916
- var it = simulator.core.iterate();
917
- while (it.next()) |replica_core_index| {
918
- if (simulator.cluster.replicas[replica_core_index].view == replica.view) {
919
- return true;
920
- }
921
- }
922
- }
923
- }
924
- return false;
925
- }
926
-
927
- /// The core contains at least a view-change quorum of replicas. But if one or more of those
928
- /// replicas are in status=recovering_head (due to corruption) or are stuck reformatting, then
929
- /// that may be insufficient.
930
- pub fn core_missing_quorum(simulator: *const Simulator) bool {
931
- assert(simulator.core.count() > 0);
932
-
933
- var core_replicas: u8 = 0;
934
- var core_recovering: u8 = 0;
935
- for (
936
- simulator.cluster.replicas,
937
- simulator.cluster.replica_health,
938
- ) |*replica, health| {
939
- if (simulator.core.is_set(replica.replica) and !replica.standby()) {
940
- core_replicas += 1;
941
- switch (health) {
942
- .up => core_recovering += @intFromBool(replica.status == .recovering_head),
943
- .down => unreachable,
944
- .reformatting => core_recovering += 1,
945
- }
946
- }
947
- }
948
-
949
- const quorums = vsr.quorums(simulator.options.cluster.replica_count);
950
- assert(quorums.view_change <= core_replicas);
951
- return quorums.view_change > core_replicas - core_recovering;
952
- }
953
-
954
- fn core_repairable_replica(
955
- simulator: *const Simulator,
956
- comptime Replica: type,
957
- replica: *const Replica,
958
- ) bool {
959
- if (!simulator.core.is_set(replica.replica)) return false;
960
- if (replica.standby()) return false;
961
- if (simulator.cluster.replica_health[replica.replica] == .reformatting) return false;
962
- assert(simulator.cluster.replica_health[replica.replica] == .up);
963
-
964
- switch (replica.status) {
965
- .normal => return true,
966
- .recovering_head => return false,
967
- // Lagging replicas do not initiate WAL repair during view change.
968
- .view_change => return !vsr.Checkpoint.durable(
969
- replica.op_checkpoint_next(),
970
- replica.commit_max,
971
- ),
972
- .recovering => unreachable,
973
- }
974
- }
975
-
976
- // Returns an op for a prepare which can't be repaired by the core due to storage faults.
977
- //
978
- // If a replica cannot make progress on committing, then it may be stuck while repairing either
979
- // missing headers *or* prepares (see `repair` in replica.zig). This function checks for both.
980
- //
981
- // When generating a FaultAtlas, we don't try to protect core from excessive errors. Instead,
982
- // if the core gets stuck, we verify that this is indeed due to storage faults.
983
- pub fn core_missing_prepare(
984
- simulator: *const Simulator,
985
- gpa: std.mem.Allocator,
986
- ) error{OutOfMemory}!?u64 {
987
- assert(simulator.core.count() > 0);
988
- const replica_count = simulator.options.cluster.replica_count;
989
-
990
- var cluster_op_head: u64 = 0;
991
- var cluster_commit_max: u64 = 0;
992
- var cluster_log_view: u32 = 0;
993
- // maxInt(u16) is more than enough to accommodate `requests_max`.
994
- var cluster_op_repair_min: u64 = std.math.maxInt(u16);
995
-
996
- for (simulator.cluster.replicas) |replica| {
997
- if (!simulator.core_repairable_replica(Cluster.Replica, &replica)) continue;
998
-
999
- if (replica.log_view > cluster_log_view) {
1000
- maybe(cluster_op_head > replica.op);
1001
- cluster_op_head = replica.op;
1002
- } else if (replica.log_view == cluster_log_view) {
1003
- cluster_op_head = @max(cluster_op_head, replica.op);
1004
- }
1005
-
1006
- cluster_log_view = @max(cluster_log_view, replica.log_view);
1007
- cluster_commit_max = @max(cluster_commit_max, replica.commit_max);
1008
- cluster_op_repair_min = @min(cluster_op_repair_min, replica.op_repair_min());
1009
- }
1010
- assert(cluster_commit_max <= cluster_op_head);
1011
-
1012
- // Use replicas with the largest log_view to infer uncommitted headers. Replicas with a
1013
- // smaller log_view may have an outdated version of the same uncommitted op. There may be
1014
- // at most a pipeline of uncommitted headers in the cluster.
1015
- const pipeline_max = constants.pipeline_prepare_queue_max;
1016
- var uncommitted_headers: [pipeline_max]?vsr.Header.Prepare = @splat(null);
1017
- if (cluster_commit_max < cluster_op_head) {
1018
- for (simulator.cluster.replicas) |replica| {
1019
- if (!simulator.core_repairable_replica(Cluster.Replica, &replica)) continue;
1020
-
1021
- if (replica.log_view < cluster_log_view) continue;
1022
- for (cluster_commit_max + 1..cluster_op_head + 1) |op| {
1023
- if (header: {
1024
- if (replica.superblock.working.vsr_state.log_view <
1025
- replica.superblock.working.vsr_state.view)
1026
- {
1027
- // When we are view-changing, our journal headers may contain headers
1028
- // which were truncated then restored due to restart. If a view change
1029
- // completes then that will be resolved, but if the view-change is stuck
1030
- // (e.g. due to "quorum received, awaiting repair") then they may
1031
- // linger, so if we only looked at the journal headers it would appear
1032
- // as if the replicas disagreed about the uncommitted headers.
1033
- const headers_count = replica.superblock.working.view_headers_count;
1034
- const headers =
1035
- replica.superblock.working.view_headers_all[0..headers_count];
1036
- for (headers) |*header| {
1037
- if (header.op == op) {
1038
- break :header switch (vsr.Headers.dvc_header_type(header)) {
1039
- .valid => header,
1040
- .blank => null,
1041
- };
1042
- }
1043
- } else break :header null;
1044
- } else {
1045
- break :header replica.journal.header_with_op(op);
1046
- }
1047
- }) |header| {
1048
- if (uncommitted_headers[op % pipeline_max]) |header_existing| {
1049
- assert(header_existing.op == header.op);
1050
- assert(header_existing.view == header.view);
1051
- assert(header_existing.checksum == header.checksum);
1052
- } else {
1053
- uncommitted_headers[op % pipeline_max] = header.*;
1054
- }
1055
- }
1056
- }
1057
- }
1058
- }
1059
-
1060
- for (cluster_op_repair_min..cluster_op_head + 1) |op| {
1061
- if (op > cluster_commit_max) {
1062
- if (uncommitted_headers[op % pipeline_max] == null) {
1063
- // We can only be missing an uncommitted *header* (and be unable to nack it)
1064
- // if at least one replica was reformatted.
1065
- var core_replicas = simulator.core.iterate();
1066
- while (core_replicas.next()) |replica| {
1067
- if (simulator.replica_reformats.is_set(replica)) break;
1068
- } else unreachable;
1069
-
1070
- return op;
1071
- }
1072
- }
1073
- }
1074
-
1075
- const ReplicaSet = stdx.BitSetType(constants.replicas_max);
1076
- var replicas_missing_ops = try gpa.alloc(
1077
- ReplicaSet,
1078
- cluster_op_head - cluster_op_repair_min + 1,
1079
- );
1080
- defer gpa.free(replicas_missing_ops);
1081
-
1082
- for (replicas_missing_ops, cluster_op_repair_min..) |*replicas_missing_op, op| {
1083
- replicas_missing_op.* = .{};
1084
- const header = blk: {
1085
- if (op > cluster_commit_max) {
1086
- const uncommitted_header = uncommitted_headers[op % pipeline_max].?;
1087
- assert(uncommitted_header.op == op);
1088
- break :blk uncommitted_header;
1089
- } else {
1090
- break :blk simulator.cluster.state_checker.header_with_op(op);
1091
- }
1092
- };
1093
- for (simulator.cluster.replicas) |replica| {
1094
- // Replicas should be able to repair using any other replica in the core.
1095
- if (replica.standby()) continue;
1096
- if (simulator.cluster.replica_health[replica.replica] == .reformatting or
1097
- !simulator.core.is_set(replica.replica) or
1098
- !replica.journal.has_prepare(&header))
1099
- {
1100
- replicas_missing_op.set(replica.replica);
1101
- }
1102
- }
1103
- }
1104
-
1105
- // Check whether any of the uncommitted headers is corrupted on more than a nack
1106
- // quorum of replicas. If so, the cluster cannot initiate repair or commit (see the
1107
- // awaiting_repair and complete_invalid cases in the DVCQuorum).
1108
- const nack_quorum = vsr.quorums(replica_count).nack_prepare;
1109
- for (cluster_commit_max..cluster_op_head + 1) |op| {
1110
- if (replicas_missing_ops[op - cluster_op_repair_min].count() >= nack_quorum) {
1111
- const header = blk: {
1112
- if (op > cluster_commit_max) {
1113
- const uncommitted_header = uncommitted_headers[op % pipeline_max].?;
1114
- assert(uncommitted_header.op == op);
1115
- break :blk uncommitted_header;
1116
- } else {
1117
- break :blk simulator.cluster.state_checker.header_with_op(op);
1118
- }
1119
- };
1120
- return header.op;
1121
- }
1122
- }
1123
-
1124
- for (simulator.cluster.replicas) |replica| {
1125
- if (!simulator.core_repairable_replica(Cluster.Replica, &replica)) continue;
1126
- if (simulator.cluster.replica_health[replica.replica] == .reformatting) continue;
1127
-
1128
- // Check prepares between (commit_min, commit_max], replicas repair these first
1129
- // as commit progress depends on them.
1130
- if (replica.commit_min < replica.commit_max) {
1131
- for (replica.commit_min + 1..replica.commit_max + 1) |op| {
1132
- if (replicas_missing_ops[op - cluster_op_repair_min].count() == replica_count) {
1133
- return op;
1134
- }
1135
- }
1136
- }
1137
-
1138
- // Check prepares between [op_repair_min, commit_min] as view changing replicas
1139
- // cannot step up as primary unless they have all prepares intact.
1140
- if (replica.op_repair_min() <= replica.commit_min) {
1141
- for (replica.op_repair_min()..replica.commit_min + 1) |op| {
1142
- if (replicas_missing_ops[op - cluster_op_repair_min].count() == replica_count) {
1143
- return op;
1144
- }
1145
- }
1146
- }
1147
- }
1148
- return null;
1149
- }
1150
-
1151
- /// Check whether the cluster is stuck because the entire core is missing the same block[s].
1152
- pub fn core_missing_blocks(
1153
- simulator: *const Simulator,
1154
- gpa: std.mem.Allocator,
1155
- ) error{OutOfMemory}!?usize {
1156
- assert(simulator.core.count() > 0);
1157
-
1158
- const FaultyReplicas = stdx.BitSetType(constants.members_max);
1159
- var blocks_missing = std.AutoArrayHashMap(
1160
- struct { address: u64, checksum: u128 },
1161
- FaultyReplicas,
1162
- ).init(gpa);
1163
- defer blocks_missing.deinit();
1164
-
1165
- // Find all blocks that any replica in the core is missing.
1166
- for (simulator.cluster.replicas) |replica| {
1167
- if (!simulator.core.is_set(replica.replica)) continue;
1168
- if (simulator.cluster.replica_health[replica.replica] == .reformatting) continue;
1169
-
1170
- const storage = &simulator.cluster.storages[replica.replica];
1171
-
1172
- var fault_iterator = replica.grid.read_global_queue.iterate();
1173
- while (fault_iterator.next()) |faulty_read| {
1174
- const v = try blocks_missing.getOrPut(.{
1175
- .address = faulty_read.address,
1176
- .checksum = faulty_read.checksum,
1177
- });
1178
-
1179
- if (!v.found_existing) v.value_ptr.* = .{};
1180
- v.value_ptr.set(replica.replica);
1181
-
1182
- log.debug("{}: core_missing_blocks: " ++
1183
- "missing address={} checksum={x:0>32} corrupt={} (remote read)", .{
1184
- replica.replica,
1185
- faulty_read.address,
1186
- faulty_read.checksum,
1187
- storage.area_faulty(.{ .grid = .{ .address = faulty_read.address } }),
1188
- });
1189
- }
1190
-
1191
- var repair_iterator = replica.grid.blocks_missing.faulty_blocks.iterator();
1192
- while (repair_iterator.next()) |fault| {
1193
- const v = try blocks_missing.getOrPut(.{
1194
- .address = fault.key_ptr.*,
1195
- .checksum = fault.value_ptr.checksum,
1196
- });
1197
-
1198
- if (!v.found_existing) v.value_ptr.* = .{};
1199
- v.value_ptr.set(replica.replica);
1200
-
1201
- log.debug("{}: core_missing_blocks: " ++
1202
- "missing address={} checksum={x:0>32} corrupt={} (GridBlocksMissing)", .{
1203
- replica.replica,
1204
- fault.key_ptr.*,
1205
- fault.value_ptr.checksum,
1206
- storage.area_faulty(.{ .grid = .{ .address = fault.key_ptr.* } }),
1207
- });
1208
- }
1209
- }
1210
-
1211
- // Check whether every replica in the core is missing the blocks.
1212
- // (If any core replica has the block, then that is a bug, since it should have repaired.)
1213
- var blocks_missing_iterator = blocks_missing.iterator();
1214
- while (blocks_missing_iterator.next()) |block_missing_and_faulty_replicas| {
1215
- const block_missing = block_missing_and_faulty_replicas.key_ptr;
1216
- const faulty_replicas = block_missing_and_faulty_replicas.value_ptr;
1217
- for (simulator.cluster.replicas) |replica| {
1218
- const storage = &simulator.cluster.storages[replica.replica];
1219
-
1220
- // A replica might actually have the block that it is requesting, but not know.
1221
- // This can occur after state sync: if we compact and create a table, but then skip
1222
- // over that table via state sync, we will try to sync the table anyway.
1223
- if (faulty_replicas.is_set(replica.replica)) continue;
1224
-
1225
- if (!simulator.core.is_set(replica.replica)) continue;
1226
- if (simulator.cluster.replica_health[replica.replica] == .reformatting) continue;
1227
- if (replica.standby()) continue;
1228
- if (storage.area_faulty(.{
1229
- .grid = .{ .address = block_missing.address },
1230
- })) continue;
1231
-
1232
- const block = storage.grid_block(block_missing.address) orelse continue;
1233
- const block_header = schema.header_from_block(block);
1234
- if (block_header.checksum == block_missing.checksum) {
1235
- log.err("{}: core_missing_blocks: found address={} checksum={x:0>32}", .{
1236
- replica.replica,
1237
- block_missing.address,
1238
- block_missing.checksum,
1239
- });
1240
- @panic("block found in core");
1241
- }
1242
- }
1243
- }
1244
-
1245
- if (blocks_missing.count() == 0) {
1246
- return null;
1247
- } else {
1248
- return blocks_missing.count();
1249
- }
1250
- }
1251
-
1252
- /// Check whether the cluster is stuck because the entire core is missing the same reply[s].
1253
- pub fn core_missing_reply(simulator: *const Simulator) ?vsr.Header.Reply {
1254
- assert(simulator.core.count() > 0);
1255
-
1256
- for (simulator.cluster.state_checker.client_replies.values()) |reply| {
1257
- const reply_in_core = reply_in_core: for (simulator.cluster.replicas) |replica| {
1258
- if (simulator.cluster.replica_health[replica.replica] == .reformatting) continue;
1259
-
1260
- const storage = &simulator.cluster.storages[replica.replica];
1261
- const storage_replies = storage.client_replies();
1262
- if (simulator.core.is_set(replica.replica) and !replica.standby()) {
1263
- for (storage_replies, 0..) |storage_reply, reply_slot| {
1264
- if (storage_reply.header.checksum == reply.checksum and
1265
- !storage.area_faulty(.{ .client_replies = .{ .slot = reply_slot } }))
1266
- {
1267
- break :reply_in_core true;
1268
- }
1269
- }
1270
- }
1271
- } else false;
1272
-
1273
- if (!reply_in_core) return reply;
1274
- }
1275
-
1276
- return null;
1277
- }
1278
-
1279
- /// The cluster was unable to upgrade because one or more of its reformat clients were evicted.
1280
- /// This is not strictly related to the core -- an upgrade requires all (non-standby) replicas.
1281
- pub fn core_reformat_evicted(simulator: *const Simulator) bool {
1282
- assert(simulator.core.count() > 0);
1283
-
1284
- const eviction_reasons = simulator.cluster.client_eviction_reasons;
1285
- const eviction_reasons_reformats =
1286
- eviction_reasons[simulator.cluster.options.client_count..];
1287
- assert(eviction_reasons_reformats.len == simulator.cluster.options.reformats_max);
1288
-
1289
- for (eviction_reasons_reformats) |reason_or_null| {
1290
- if (reason_or_null) |reason| {
1291
- log.err("reformat evicted with {s}", .{@tagName(reason)});
1292
- assert(reason == .no_session or reason == .session_too_low);
1293
- return true;
1294
- }
1295
- }
1296
- return false;
1297
- }
1298
-
1299
- fn core_release_max(simulator: *const Simulator) vsr.Release {
1300
- assert(simulator.core.count() > 0);
1301
-
1302
- var release_max: vsr.Release = vsr.Release.zero;
1303
- for (simulator.cluster.replicas) |*replica| {
1304
- if (simulator.core.is_set(replica.replica)) {
1305
- release_max = release_max.max(replica.release);
1306
- if (replica.upgrade_release) |release| {
1307
- release_max = release_max.max(release);
1308
- }
1309
- }
1310
- }
1311
- assert(release_max.value > 0);
1312
- return release_max;
1313
- }
1314
-
1315
- fn on_cluster_reply(
1316
- cluster: *Cluster,
1317
- reply_client: ?usize,
1318
- prepare: *const Message.Prepare,
1319
- reply: *const Message.Reply,
1320
- ) void {
1321
- assert((reply_client == null) == (prepare.header.client == 0));
1322
-
1323
- const simulator: *Simulator = @ptrCast(@alignCast(cluster.context.?));
1324
-
1325
- if (reply.header.op < simulator.reply_op_next) return;
1326
- if (simulator.reply_sequence.contains(reply)) return;
1327
-
1328
- simulator.reply_sequence.insert(reply_client, prepare, reply);
1329
-
1330
- while (!simulator.reply_sequence.empty()) {
1331
- const op = simulator.reply_op_next;
1332
- const prepare_header = simulator.cluster.state_checker.commits.items[op].header;
1333
- assert(prepare_header.op == op);
1334
-
1335
- if (simulator.reply_sequence.peek(op)) |commit| {
1336
- defer simulator.reply_sequence.next();
1337
-
1338
- simulator.reply_op_next += 1;
1339
-
1340
- assert(commit.reply.references == 1);
1341
- assert(commit.reply.header.op == op);
1342
- assert(commit.reply.header.command == .reply);
1343
- assert(commit.reply.header.request == commit.prepare.header.request);
1344
- assert(commit.reply.header.operation == commit.prepare.header.operation);
1345
- assert(commit.prepare.references == 1);
1346
- assert(commit.prepare.header.checksum == prepare_header.checksum);
1347
- assert(commit.prepare.header.command == .prepare);
1348
-
1349
- log.debug("consume_stalled_replies: op={} operation={} client={} request={}", .{
1350
- commit.reply.header.op,
1351
- commit.reply.header.operation,
1352
- commit.prepare.header.client,
1353
- commit.prepare.header.request,
1354
- });
1355
-
1356
- if (prepare_header.operation == .pulse) {
1357
- simulator.workload.on_pulse(
1358
- prepare_header.operation.cast(StateMachine.Operation),
1359
- prepare_header.timestamp,
1360
- );
1361
- }
1362
-
1363
- if (!commit.prepare.header.operation.vsr_reserved()) {
1364
- simulator.workload.on_reply(
1365
- commit.client_index.?,
1366
- commit.reply.header.operation.cast(StateMachine.Operation),
1367
- commit.reply.header.timestamp,
1368
- commit.prepare.body_used(),
1369
- commit.reply.body_used(),
1370
- );
1371
- }
1372
- }
1373
- }
1374
- }
1375
-
1376
- fn on_client_reply(
1377
- cluster: *Cluster,
1378
- reply_client: usize,
1379
- request: *const Message.Request,
1380
- reply: *const Message.Reply,
1381
- ) void {
1382
- _ = reply;
1383
-
1384
- const simulator: *Simulator = @ptrCast(@alignCast(cluster.context.?));
1385
- assert(simulator.cluster.client_eviction_reasons[reply_client] == null);
1386
-
1387
- if (!request.header.operation.vsr_reserved()) {
1388
- simulator.requests_replied += 1;
1389
- }
1390
- }
1391
-
1392
- /// Maybe send a request from one of the cluster's clients.
1393
- fn tick_requests(simulator: *Simulator) void {
1394
- if (simulator.requests_idle) {
1395
- if (simulator.prng.chance(simulator.options.request_idle_off_probability)) {
1396
- simulator.requests_idle = false;
1397
- }
1398
- } else {
1399
- if (simulator.prng.chance(simulator.options.request_idle_on_probability)) {
1400
- simulator.requests_idle = true;
1401
- }
1402
- }
1403
-
1404
- if (simulator.requests_idle) return;
1405
- if (simulator.requests_sent - simulator.cluster.client_eviction_requests_cancelled ==
1406
- simulator.options.requests_max) return;
1407
- if (!simulator.prng.chance(simulator.options.request_probability)) return;
1408
-
1409
- const client_index = index: {
1410
- const client_count = simulator.options.cluster.client_count;
1411
- const client_index_base =
1412
- simulator.prng.int_inclusive(usize, client_count - 1);
1413
- for (0..client_count) |offset| {
1414
- const client_index = (client_index_base + offset) % client_count;
1415
- if (simulator.cluster.client_eviction_reasons[client_index] == null) {
1416
- break :index client_index;
1417
- }
1418
- } else {
1419
- for (0..client_count) |index| {
1420
- assert(simulator.cluster.client_eviction_reasons[index] != null);
1421
- assert(simulator.cluster.client_eviction_reasons[index] == .no_session or
1422
- simulator.cluster.client_eviction_reasons[index] == .session_too_low);
1423
- }
1424
- unimplemented("client replacement; all clients were evicted");
1425
- }
1426
- };
1427
-
1428
- var client = &simulator.cluster.clients[client_index].?;
1429
-
1430
- // Messages aren't added to the ReplySequence until a reply arrives.
1431
- // Before sending a new message, make sure there will definitely be room for it.
1432
- var reserved: usize = 0;
1433
- for (
1434
- simulator.cluster.clients,
1435
- ) |*client_maybe| {
1436
- if (client_maybe.*) |*c| {
1437
- // Count the number of clients that are still waiting for a `register` to complete,
1438
- // since they may start one at any time.
1439
- reserved += @intFromBool(c.session == 0);
1440
- // Count the number of non-register requests queued.
1441
- reserved += @intFromBool(c.request_inflight != null);
1442
- }
1443
- }
1444
- // +1 for the potential request — is there room in the sequencer's queue?
1445
- if (reserved + 1 > simulator.reply_sequence.free()) return;
1446
-
1447
- // Make sure that the client is ready to send a new request.
1448
- if (client.request_inflight != null) return;
1449
- const request_message = client.get_message();
1450
- errdefer client.release_message(request_message);
1451
-
1452
- const request_metadata = simulator.workload.build_request(
1453
- client_index,
1454
- request_message.buffer[@sizeOf(vsr.Header)..constants.message_size_max],
1455
- );
1456
- assert(request_metadata.size <= constants.message_body_size_max);
1457
-
1458
- simulator.cluster.request(
1459
- client_index,
1460
- request_metadata.operation,
1461
- request_message,
1462
- request_metadata.size,
1463
- );
1464
- // Since we already checked the client's request queue for free space, `client.request()`
1465
- // should always queue the request.
1466
- assert(request_message == client.request_inflight.?.message.base());
1467
- assert(request_message.header.size == @sizeOf(vsr.Header) + request_metadata.size);
1468
- assert(request_message.header.into(.request).?.operation.cast(StateMachine.Operation) ==
1469
- request_metadata.operation);
1470
-
1471
- simulator.requests_sent += 1;
1472
- assert(simulator.requests_sent - simulator.cluster.client_eviction_requests_cancelled <=
1473
- simulator.options.requests_max);
1474
- }
1475
-
1476
- fn tick_upgrade(simulator: *Simulator) void {
1477
- for (simulator.cluster.replicas) |*replica| {
1478
- const upgrade =
1479
- simulator.replica_releases[replica.replica] < releases.len and
1480
- simulator.prng.chance(simulator.options.replica_release_advance_probability);
1481
- if (upgrade) simulator.replica_upgrade(replica.replica);
1482
- }
1483
- }
1484
-
1485
- fn tick_crash(simulator: *Simulator) void {
1486
- for (simulator.cluster.replicas) |*replica| {
1487
- simulator.replica_crash_stability[replica.replica] -|= 1;
1488
- if (simulator.replica_crash_stability[replica.replica] > 0) continue;
1489
-
1490
- switch (simulator.cluster.replica_health[replica.replica]) {
1491
- .up => |up| {
1492
- if (!up.paused) simulator.tick_crash_up(replica);
1493
- },
1494
- .down => simulator.tick_crash_down(replica),
1495
- .reformatting => {},
1496
- }
1497
- }
1498
- }
1499
-
1500
- fn tick_crash_up(simulator: *Simulator, replica: *Cluster.Replica) void {
1501
- const replica_storage = &simulator.cluster.storages[replica.replica];
1502
- const replica_writes = replica_storage.writes.count();
1503
-
1504
- var crash_probability = simulator.options.replica_crash_probability;
1505
- if (replica_writes > 0) crash_probability.numerator *= 10;
1506
-
1507
- const crash_random = simulator.prng.chance(crash_probability);
1508
-
1509
- if (!crash_random) return;
1510
-
1511
- log.debug("{}: crash replica", .{replica.replica});
1512
- simulator.cluster.replica_crash(replica.replica);
1513
-
1514
- simulator.replica_crash_stability[replica.replica] =
1515
- simulator.options.replica_crash_stability;
1516
- }
1517
-
1518
- fn tick_crash_down(simulator: *Simulator, replica: *Cluster.Replica) void {
1519
- // If we are in liveness mode, we need to make sure that all replicas
1520
- // (eventually) make it to the same release.
1521
- const restart_upgrade =
1522
- simulator.replica_releases[replica.replica] <
1523
- simulator.replica_releases_limit and
1524
- (simulator.core.is_set(replica.replica) or
1525
- simulator.prng.chance(simulator.options.replica_release_catchup_probability));
1526
- if (restart_upgrade) simulator.replica_upgrade(replica.replica);
1527
-
1528
- const restart_random =
1529
- simulator.prng.chance(simulator.options.replica_restart_probability);
1530
-
1531
- if (!restart_upgrade and !restart_random) return;
1532
-
1533
- const recoverable_count_min =
1534
- vsr.quorums(simulator.options.cluster.replica_count).view_change;
1535
-
1536
- var recoverable_count: usize = 0;
1537
- for (simulator.cluster.replicas, 0..) |*r, i| {
1538
- recoverable_count += @intFromBool(simulator.cluster.replica_health[i] == .up and
1539
- !simulator.replica_reformats.is_set(replica.replica) and
1540
- !r.standby() and
1541
- r.status != .recovering_head and
1542
- r.syncing == .idle);
1543
- }
1544
-
1545
- // To improve VOPR utilization, try to prevent the replica from going into
1546
- // `.recovering_head` state if the replica is needed to form a quorum.
1547
- const fault = recoverable_count >= recoverable_count_min or replica.standby();
1548
- if (fault) {
1549
- const reformat_random =
1550
- !replica.standby() and
1551
- simulator.cluster.reformat_count < simulator.cluster.options.reformats_max and
1552
- simulator.prng.chance(simulator.options.replica_reformat_probability);
1553
- if (reformat_random) {
1554
- log.debug("{}: reformat replica", .{replica.replica});
1555
-
1556
- simulator.replica_reformats.set(replica.replica);
1557
- simulator.cluster.replica_reformat(replica.replica) catch unreachable;
1558
- return;
1559
- }
1560
- }
1561
- simulator.replica_restart(replica.replica, fault);
1562
- maybe(!fault and replica.status == .recovering_head);
1563
- }
1564
-
1565
- fn replica_restart(simulator: *Simulator, replica_index: u8, fault: bool) void {
1566
- assert(simulator.cluster.replica_health[replica_index] == .down);
1567
-
1568
- const replica_storage = &simulator.cluster.storages[replica_index];
1569
- const replica: *const Cluster.Replica = &simulator.cluster.replicas[replica_index];
1570
-
1571
- {
1572
- // If the entire Zone.wal_headers is corrupted, the replica becomes permanently
1573
- // unavailable (returns `WALInvalid` from `open`). In the simulator, there are only two
1574
- // WAL sectors, which could both get corrupted when a replica crashes while writing them
1575
- // simultaneously. Repair both sectors so that even if one of them becomes corrupted on
1576
- // startup, the replica still remains operational.
1577
- //
1578
- // In production `journal_iops_write_max < header_sector_count`, which makes is
1579
- // impossible to get torn writes for all journal header sectors at the same time.
1580
- const header_sector_offset =
1581
- @divExact(vsr.Zone.wal_headers.start(), constants.sector_size);
1582
- const header_sector_count =
1583
- @divExact(constants.journal_size_headers, constants.sector_size);
1584
- for (0..header_sector_count) |header_sector_index| {
1585
- replica_storage.faults.unset(header_sector_offset + header_sector_index);
1586
- }
1587
- // TODO Clear misdirects? Waiting for a seed to confirm.
1588
- }
1589
-
1590
- var header_prepare_view_mismatch: bool = false;
1591
- if (!fault) {
1592
- // The journal writes redundant headers of faulty ops as zeroes to ensure
1593
- // that they remain faulty after a crash/recover. Since that fault cannot
1594
- // be disabled by `storage.faulty`, we must manually repair it here to
1595
- // ensure a cluster cannot become stuck in status=recovering_head.
1596
- // See recover_slots() for more detail.
1597
- const headers_offset = vsr.Zone.wal_headers.offset(0);
1598
- const headers_size = vsr.Zone.wal_headers.size().?;
1599
- const headers_bytes = replica_storage.memory[headers_offset..][0..headers_size];
1600
- for (
1601
- mem.bytesAsSlice(vsr.Header.Prepare, headers_bytes),
1602
- replica_storage.wal_prepares(),
1603
- ) |*wal_header, *wal_prepare| {
1604
- if (wal_header.checksum == 0) {
1605
- wal_header.* = wal_prepare.header;
1606
- } else {
1607
- if (wal_header.view != wal_prepare.header.view) {
1608
- header_prepare_view_mismatch = true;
1609
- }
1610
- }
1611
- }
1612
- }
1613
-
1614
- log.debug("{}: restart replica (faults={} releases={})", .{
1615
- replica_index,
1616
- fault,
1617
- simulator.replica_releases[replica_index],
1618
- });
1619
-
1620
- replica_storage.faulty = fault;
1621
- simulator.cluster.replica_restart(replica_index) catch unreachable;
1622
-
1623
- if (replica.status == .recovering_head) {
1624
- // Even with faults disabled, a replica may wind up in status=recovering_head.
1625
- assert(fault or header_prepare_view_mismatch);
1626
- }
1627
-
1628
- replica_storage.faulty = true;
1629
- simulator.replica_crash_stability[replica_index] =
1630
- simulator.options.replica_restart_stability;
1631
- }
1632
-
1633
- fn replica_upgrade(simulator: *Simulator, replica_index: u8) void {
1634
- simulator.replica_releases[replica_index] =
1635
- @min(simulator.replica_releases[replica_index] + 1, releases.len);
1636
- simulator.replica_releases_limit =
1637
- @max(simulator.replica_releases[replica_index], simulator.replica_releases_limit);
1638
-
1639
- const replica_releases = simulator.replica_release_list(replica_index);
1640
- simulator.cluster.replica_set_releases(replica_index, &replica_releases);
1641
- }
1642
-
1643
- fn replica_release_list(simulator: *const Simulator, replica_index: u8) vsr.ReleaseList {
1644
- const replica_releases_count = simulator.replica_releases[replica_index];
1645
- var release_list: vsr.ReleaseList = .empty;
1646
- for (0..replica_releases_count) |i| {
1647
- release_list.push(releases[i].release);
1648
- }
1649
- release_list.verify();
1650
- return release_list;
1651
- }
1652
-
1653
- // Randomly pause replicas. A paused replica doesn't tick and doesn't complete any asynchronous
1654
- // work. The goals of pausing are:
1655
- // - catch more interesting interleaving of events,
1656
- // - simulate real-world scenario of VM migration.
1657
- fn tick_pause(simulator: *Simulator) void {
1658
- for (
1659
- simulator.cluster.replicas,
1660
- simulator.replica_crash_stability,
1661
- 0..,
1662
- ) |*replica, *stability, replica_index| {
1663
- stability.* -|= 1;
1664
- if (stability.* > 0) continue;
1665
-
1666
- if (simulator.cluster.replica_health[replica.replica] != .up) continue;
1667
- const paused = simulator.cluster.replica_health[replica.replica].up.paused;
1668
- const pause = simulator.prng.chance(simulator.options.replica_pause_probability);
1669
- const unpause = simulator.prng.chance(simulator.options.replica_unpause_probability);
1670
-
1671
- if (!paused and pause) {
1672
- simulator.cluster.replica_pause(@intCast(replica_index));
1673
- stability.* = simulator.options.replica_pause_stability;
1674
- } else if (paused and unpause) {
1675
- simulator.cluster.replica_unpause(@intCast(replica_index));
1676
- stability.* = simulator.options.replica_unpause_stability;
1677
- }
1678
- }
1679
- }
1680
- };
1681
-
1682
- /// Print an error message and then exit with an exit code.
1683
- fn fatal(failure: Failure, comptime fmt_string: []const u8, args: anytype) noreturn {
1684
- log.err(fmt_string, args);
1685
- std.process.exit(@intFromEnum(failure));
1686
- }
1687
-
1688
- /// Signal that something is not yet fully implemented, and abort the process.
1689
- ///
1690
- /// In VOPR, this will exit with status 0, to make it easy to find "real" failures by running
1691
- /// the simulator in a loop.
1692
- fn unimplemented(comptime message: []const u8) noreturn {
1693
- const full_message = "unimplemented: " ++ message;
1694
- log.info(full_message, .{});
1695
- log.info("not crashing in VOPR", .{});
1696
- std.process.exit(0);
1697
- }
1698
-
1699
- /// Returns a random fully-connected subgraph which includes at least view change
1700
- /// quorum of active replicas.
1701
- fn random_core(prng: *stdx.PRNG, replica_count: u8, standby_count: u8) Core {
1702
- assert(replica_count > 0);
1703
- assert(replica_count <= constants.replicas_max);
1704
- assert(standby_count <= constants.standbys_max);
1705
-
1706
- const quorum_view_change = vsr.quorums(replica_count).view_change;
1707
- const replica_core_count = prng.range_inclusive(u8, quorum_view_change, replica_count);
1708
- const standby_core_count = prng.range_inclusive(u8, 0, standby_count);
1709
-
1710
- var core: Core = .{};
1711
-
1712
- var combination = stdx.PRNG.Combination.init(.{
1713
- .total = replica_count,
1714
- .sample = replica_core_count,
1715
- });
1716
- for (0..replica_count) |replica| {
1717
- if (combination.take(prng)) core.set(replica);
1718
- }
1719
- assert(combination.done());
1720
-
1721
- combination = stdx.PRNG.Combination.init(.{
1722
- .total = standby_count,
1723
- .sample = standby_core_count,
1724
- });
1725
- for (replica_count..replica_count + standby_count) |standby| {
1726
- if (combination.take(prng)) core.set(standby);
1727
- }
1728
- assert(combination.done());
1729
-
1730
- assert(core.count() == replica_core_count + standby_core_count);
1731
-
1732
- return core;
1733
- }
1734
-
1735
- /// Returns a random fully-connected subgraph which includes all replicas and standbys.
1736
- fn full_core(replica_count: u8, standby_count: u8) Core {
1737
- assert(replica_count > 0);
1738
- assert(replica_count <= constants.replicas_max);
1739
- assert(standby_count <= constants.standbys_max);
1740
-
1741
- var core: Core = .{};
1742
-
1743
- for (0..replica_count + standby_count) |replica| core.set(replica);
1744
-
1745
- assert(core.count() == replica_count + standby_count);
1746
-
1747
- return core;
1748
- }
1749
-
1750
- var log_buffer: std.io.BufferedWriter(4096, std.fs.File.Writer) = .{
1751
- // This is initialized in main(), as std.io.getStdErr() is not comptime known on e.g. Windows.
1752
- .unbuffered_writer = undefined,
1753
- };
1754
-
1755
- var log_performance_mode: bool = false;
1756
-
1757
- fn log_override(
1758
- comptime level: std.log.Level,
1759
- comptime scope: @TypeOf(.enum_literal),
1760
- comptime format: []const u8,
1761
- args: anytype,
1762
- ) void {
1763
- if ((scope == .vsr and level == .err) or scope == .gpa) {
1764
- // Always print a message for vsr.fatal.
1765
- } else {
1766
- if (vsr_vopr_options.log == .short) {
1767
- if (log_performance_mode) {
1768
- if (scope != .simulator) return;
1769
- } else {
1770
- if (scope != .simulator and scope != .cluster) return;
1771
- }
1772
- }
1773
- }
1774
-
1775
- const prefix_default = "[" ++ @tagName(level) ++ "] " ++ "(" ++ @tagName(scope) ++ "): ";
1776
- const prefix = if (vsr_vopr_options.log == .short) "" else prefix_default;
1777
-
1778
- // Print the message to stderr using a buffer to avoid many small write() syscalls when
1779
- // providing many format arguments. Silently ignore failure.
1780
- log_buffer.writer().print(prefix ++ format ++ "\n", args) catch {};
1781
-
1782
- // Flush the buffer before returning to ensure, for example, that a log message
1783
- // immediately before a failing assertion is fully printed.
1784
- log_buffer.flush() catch {};
1785
- }