tigerbeetle 0.0.34 → 0.0.37
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/ext/tb_client/extconf.rb +13 -13
- data/ext/tb_client/tigerbeetle/LICENSE +177 -0
- data/ext/tb_client/tigerbeetle/build.zig +2327 -0
- data/ext/tb_client/tigerbeetle/src/aof.zig +1000 -0
- data/ext/tb_client/tigerbeetle/src/build_multiversion.zig +808 -0
- data/ext/tb_client/tigerbeetle/src/cdc/amqp/protocol.zig +1283 -0
- data/ext/tb_client/tigerbeetle/src/cdc/amqp/spec.zig +1704 -0
- data/ext/tb_client/tigerbeetle/src/cdc/amqp/types.zig +341 -0
- data/ext/tb_client/tigerbeetle/src/cdc/amqp.zig +1450 -0
- data/ext/tb_client/tigerbeetle/src/cdc/runner.zig +1659 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/samples/main.c +406 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/context.zig +1084 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/echo_client.zig +286 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/packet.zig +158 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/signal.zig +229 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client/signal_fuzz.zig +110 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client.h +386 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client.zig +34 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client_exports.zig +281 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client_header.zig +312 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/tb_client_header_test.zig +138 -0
- data/ext/tb_client/tigerbeetle/src/clients/c/test.zig +466 -0
- data/ext/tb_client/tigerbeetle/src/clients/docs_samples.zig +157 -0
- data/ext/tb_client/tigerbeetle/src/clients/docs_types.zig +90 -0
- data/ext/tb_client/tigerbeetle/src/clients/dotnet/ci.zig +203 -0
- data/ext/tb_client/tigerbeetle/src/clients/dotnet/docs.zig +79 -0
- data/ext/tb_client/tigerbeetle/src/clients/dotnet/dotnet_bindings.zig +542 -0
- data/ext/tb_client/tigerbeetle/src/clients/go/ci.zig +109 -0
- data/ext/tb_client/tigerbeetle/src/clients/go/docs.zig +86 -0
- data/ext/tb_client/tigerbeetle/src/clients/go/go_bindings.zig +370 -0
- data/ext/tb_client/tigerbeetle/src/clients/go/pkg/native/tb_client.h +386 -0
- data/ext/tb_client/tigerbeetle/src/clients/java/ci.zig +167 -0
- data/ext/tb_client/tigerbeetle/src/clients/java/docs.zig +126 -0
- data/ext/tb_client/tigerbeetle/src/clients/java/java_bindings.zig +996 -0
- data/ext/tb_client/tigerbeetle/src/clients/java/src/client.zig +748 -0
- data/ext/tb_client/tigerbeetle/src/clients/java/src/jni.zig +3238 -0
- data/ext/tb_client/tigerbeetle/src/clients/java/src/jni_tests.zig +1718 -0
- data/ext/tb_client/tigerbeetle/src/clients/java/src/jni_thread_cleaner.zig +190 -0
- data/ext/tb_client/tigerbeetle/src/clients/node/ci.zig +104 -0
- data/ext/tb_client/tigerbeetle/src/clients/node/docs.zig +75 -0
- data/ext/tb_client/tigerbeetle/src/clients/node/node.zig +522 -0
- data/ext/tb_client/tigerbeetle/src/clients/node/node_bindings.zig +267 -0
- data/ext/tb_client/tigerbeetle/src/clients/node/src/c.zig +3 -0
- data/ext/tb_client/tigerbeetle/src/clients/node/src/translate.zig +379 -0
- data/ext/tb_client/tigerbeetle/src/clients/python/ci.zig +131 -0
- data/ext/tb_client/tigerbeetle/src/clients/python/docs.zig +63 -0
- data/ext/tb_client/tigerbeetle/src/clients/python/python_bindings.zig +588 -0
- data/ext/tb_client/tigerbeetle/src/clients/rust/assets/tb_client.h +386 -0
- data/ext/tb_client/tigerbeetle/src/clients/rust/ci.zig +73 -0
- data/ext/tb_client/tigerbeetle/src/clients/rust/docs.zig +106 -0
- data/ext/tb_client/tigerbeetle/src/clients/rust/rust_bindings.zig +305 -0
- data/ext/tb_client/tigerbeetle/src/config.zig +296 -0
- data/ext/tb_client/tigerbeetle/src/constants.zig +790 -0
- data/ext/tb_client/tigerbeetle/src/copyhound.zig +202 -0
- data/ext/tb_client/tigerbeetle/src/counting_allocator.zig +72 -0
- data/ext/tb_client/tigerbeetle/src/direction.zig +11 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/build.zig +158 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/content.zig +156 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/docs.zig +252 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/file_checker.zig +313 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/html.zig +87 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/page_writer.zig +63 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/redirects.zig +47 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/search_index_writer.zig +28 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/service_worker_writer.zig +61 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/single_page_writer.zig +169 -0
- data/ext/tb_client/tigerbeetle/src/docs_website/src/website.zig +46 -0
- data/ext/tb_client/tigerbeetle/src/ewah.zig +445 -0
- data/ext/tb_client/tigerbeetle/src/ewah_benchmark.zig +128 -0
- data/ext/tb_client/tigerbeetle/src/ewah_fuzz.zig +171 -0
- data/ext/tb_client/tigerbeetle/src/fuzz_tests.zig +179 -0
- data/ext/tb_client/tigerbeetle/src/integration_tests.zig +662 -0
- data/ext/tb_client/tigerbeetle/src/io/common.zig +155 -0
- data/ext/tb_client/tigerbeetle/src/io/darwin.zig +1093 -0
- data/ext/tb_client/tigerbeetle/src/io/linux.zig +1880 -0
- data/ext/tb_client/tigerbeetle/src/io/test.zig +1005 -0
- data/ext/tb_client/tigerbeetle/src/io/windows.zig +1598 -0
- data/ext/tb_client/tigerbeetle/src/io.zig +34 -0
- data/ext/tb_client/tigerbeetle/src/iops.zig +134 -0
- data/ext/tb_client/tigerbeetle/src/list.zig +236 -0
- data/ext/tb_client/tigerbeetle/src/lsm/binary_search.zig +848 -0
- data/ext/tb_client/tigerbeetle/src/lsm/binary_search_benchmark.zig +179 -0
- data/ext/tb_client/tigerbeetle/src/lsm/cache_map.zig +424 -0
- data/ext/tb_client/tigerbeetle/src/lsm/cache_map_fuzz.zig +420 -0
- data/ext/tb_client/tigerbeetle/src/lsm/compaction.zig +2117 -0
- data/ext/tb_client/tigerbeetle/src/lsm/composite_key.zig +182 -0
- data/ext/tb_client/tigerbeetle/src/lsm/forest.zig +1119 -0
- data/ext/tb_client/tigerbeetle/src/lsm/forest_fuzz.zig +1102 -0
- data/ext/tb_client/tigerbeetle/src/lsm/forest_table_iterator.zig +200 -0
- data/ext/tb_client/tigerbeetle/src/lsm/groove.zig +1495 -0
- data/ext/tb_client/tigerbeetle/src/lsm/k_way_merge.zig +739 -0
- data/ext/tb_client/tigerbeetle/src/lsm/k_way_merge_benchmark.zig +166 -0
- data/ext/tb_client/tigerbeetle/src/lsm/manifest.zig +754 -0
- data/ext/tb_client/tigerbeetle/src/lsm/manifest_level.zig +1294 -0
- data/ext/tb_client/tigerbeetle/src/lsm/manifest_level_fuzz.zig +510 -0
- data/ext/tb_client/tigerbeetle/src/lsm/manifest_log.zig +1263 -0
- data/ext/tb_client/tigerbeetle/src/lsm/manifest_log_fuzz.zig +628 -0
- data/ext/tb_client/tigerbeetle/src/lsm/node_pool.zig +247 -0
- data/ext/tb_client/tigerbeetle/src/lsm/scan_buffer.zig +116 -0
- data/ext/tb_client/tigerbeetle/src/lsm/scan_builder.zig +543 -0
- data/ext/tb_client/tigerbeetle/src/lsm/scan_fuzz.zig +938 -0
- data/ext/tb_client/tigerbeetle/src/lsm/scan_lookup.zig +293 -0
- data/ext/tb_client/tigerbeetle/src/lsm/scan_merge.zig +362 -0
- data/ext/tb_client/tigerbeetle/src/lsm/scan_range.zig +99 -0
- data/ext/tb_client/tigerbeetle/src/lsm/scan_state.zig +17 -0
- data/ext/tb_client/tigerbeetle/src/lsm/scan_tree.zig +1036 -0
- data/ext/tb_client/tigerbeetle/src/lsm/schema.zig +617 -0
- data/ext/tb_client/tigerbeetle/src/lsm/scratch_memory.zig +84 -0
- data/ext/tb_client/tigerbeetle/src/lsm/segmented_array.zig +1500 -0
- data/ext/tb_client/tigerbeetle/src/lsm/segmented_array_benchmark.zig +149 -0
- data/ext/tb_client/tigerbeetle/src/lsm/segmented_array_fuzz.zig +7 -0
- data/ext/tb_client/tigerbeetle/src/lsm/set_associative_cache.zig +865 -0
- data/ext/tb_client/tigerbeetle/src/lsm/table.zig +607 -0
- data/ext/tb_client/tigerbeetle/src/lsm/table_memory.zig +843 -0
- data/ext/tb_client/tigerbeetle/src/lsm/table_value_iterator.zig +105 -0
- data/ext/tb_client/tigerbeetle/src/lsm/timestamp_range.zig +40 -0
- data/ext/tb_client/tigerbeetle/src/lsm/tree.zig +630 -0
- data/ext/tb_client/tigerbeetle/src/lsm/tree_fuzz.zig +933 -0
- data/ext/tb_client/tigerbeetle/src/lsm/zig_zag_merge.zig +557 -0
- data/ext/tb_client/tigerbeetle/src/message_buffer.zig +469 -0
- data/ext/tb_client/tigerbeetle/src/message_bus.zig +1214 -0
- data/ext/tb_client/tigerbeetle/src/message_bus_fuzz.zig +936 -0
- data/ext/tb_client/tigerbeetle/src/message_pool.zig +343 -0
- data/ext/tb_client/tigerbeetle/src/multiversion.zig +2195 -0
- data/ext/tb_client/tigerbeetle/src/queue.zig +390 -0
- data/ext/tb_client/tigerbeetle/src/repl/completion.zig +201 -0
- data/ext/tb_client/tigerbeetle/src/repl/parser.zig +1356 -0
- data/ext/tb_client/tigerbeetle/src/repl/terminal.zig +496 -0
- data/ext/tb_client/tigerbeetle/src/repl.zig +1034 -0
- data/ext/tb_client/tigerbeetle/src/scripts/amqp.zig +973 -0
- data/ext/tb_client/tigerbeetle/src/scripts/cfo.zig +1866 -0
- data/ext/tb_client/tigerbeetle/src/scripts/changelog.zig +304 -0
- data/ext/tb_client/tigerbeetle/src/scripts/ci.zig +227 -0
- data/ext/tb_client/tigerbeetle/src/scripts/client_readmes.zig +658 -0
- data/ext/tb_client/tigerbeetle/src/scripts/devhub.zig +466 -0
- data/ext/tb_client/tigerbeetle/src/scripts/release.zig +1058 -0
- data/ext/tb_client/tigerbeetle/src/scripts.zig +105 -0
- data/ext/tb_client/tigerbeetle/src/shell.zig +1195 -0
- data/ext/tb_client/tigerbeetle/src/stack.zig +260 -0
- data/ext/tb_client/tigerbeetle/src/state_machine/auditor.zig +911 -0
- data/ext/tb_client/tigerbeetle/src/state_machine/workload.zig +2079 -0
- data/ext/tb_client/tigerbeetle/src/state_machine.zig +4872 -0
- data/ext/tb_client/tigerbeetle/src/state_machine_fuzz.zig +288 -0
- data/ext/tb_client/tigerbeetle/src/state_machine_tests.zig +3128 -0
- data/ext/tb_client/tigerbeetle/src/static_allocator.zig +82 -0
- data/ext/tb_client/tigerbeetle/src/stdx/bit_set.zig +157 -0
- data/ext/tb_client/tigerbeetle/src/stdx/bounded_array.zig +292 -0
- data/ext/tb_client/tigerbeetle/src/stdx/debug.zig +65 -0
- data/ext/tb_client/tigerbeetle/src/stdx/flags.zig +1414 -0
- data/ext/tb_client/tigerbeetle/src/stdx/mlock.zig +92 -0
- data/ext/tb_client/tigerbeetle/src/stdx/prng.zig +677 -0
- data/ext/tb_client/tigerbeetle/src/stdx/radix.zig +336 -0
- data/ext/tb_client/tigerbeetle/src/stdx/ring_buffer.zig +511 -0
- data/ext/tb_client/tigerbeetle/src/stdx/sort_test.zig +112 -0
- data/ext/tb_client/tigerbeetle/src/stdx/stdx.zig +1160 -0
- data/ext/tb_client/tigerbeetle/src/stdx/testing/low_level_hash_vectors.zig +142 -0
- data/ext/tb_client/tigerbeetle/src/stdx/testing/snaptest.zig +361 -0
- data/ext/tb_client/tigerbeetle/src/stdx/time_units.zig +275 -0
- data/ext/tb_client/tigerbeetle/src/stdx/unshare.zig +295 -0
- data/ext/tb_client/tigerbeetle/src/stdx/vendored/aegis.zig +436 -0
- data/ext/tb_client/tigerbeetle/src/stdx/windows.zig +48 -0
- data/ext/tb_client/tigerbeetle/src/stdx/zipfian.zig +402 -0
- data/ext/tb_client/tigerbeetle/src/storage.zig +489 -0
- data/ext/tb_client/tigerbeetle/src/storage_fuzz.zig +180 -0
- data/ext/tb_client/tigerbeetle/src/testing/bench.zig +146 -0
- data/ext/tb_client/tigerbeetle/src/testing/cluster/grid_checker.zig +53 -0
- data/ext/tb_client/tigerbeetle/src/testing/cluster/journal_checker.zig +61 -0
- data/ext/tb_client/tigerbeetle/src/testing/cluster/manifest_checker.zig +76 -0
- data/ext/tb_client/tigerbeetle/src/testing/cluster/message_bus.zig +110 -0
- data/ext/tb_client/tigerbeetle/src/testing/cluster/network.zig +412 -0
- data/ext/tb_client/tigerbeetle/src/testing/cluster/state_checker.zig +331 -0
- data/ext/tb_client/tigerbeetle/src/testing/cluster/storage_checker.zig +458 -0
- data/ext/tb_client/tigerbeetle/src/testing/cluster.zig +1198 -0
- data/ext/tb_client/tigerbeetle/src/testing/exhaustigen.zig +128 -0
- data/ext/tb_client/tigerbeetle/src/testing/fixtures.zig +181 -0
- data/ext/tb_client/tigerbeetle/src/testing/fuzz.zig +144 -0
- data/ext/tb_client/tigerbeetle/src/testing/id.zig +97 -0
- data/ext/tb_client/tigerbeetle/src/testing/io.zig +317 -0
- data/ext/tb_client/tigerbeetle/src/testing/marks.zig +126 -0
- data/ext/tb_client/tigerbeetle/src/testing/packet_simulator.zig +533 -0
- data/ext/tb_client/tigerbeetle/src/testing/reply_sequence.zig +154 -0
- data/ext/tb_client/tigerbeetle/src/testing/state_machine.zig +389 -0
- data/ext/tb_client/tigerbeetle/src/testing/storage.zig +1247 -0
- data/ext/tb_client/tigerbeetle/src/testing/table.zig +249 -0
- data/ext/tb_client/tigerbeetle/src/testing/time.zig +98 -0
- data/ext/tb_client/tigerbeetle/src/testing/tmp_tigerbeetle.zig +212 -0
- data/ext/tb_client/tigerbeetle/src/testing/vortex/constants.zig +26 -0
- data/ext/tb_client/tigerbeetle/src/testing/vortex/faulty_network.zig +580 -0
- data/ext/tb_client/tigerbeetle/src/testing/vortex/java_driver/ci.zig +39 -0
- data/ext/tb_client/tigerbeetle/src/testing/vortex/logged_process.zig +214 -0
- data/ext/tb_client/tigerbeetle/src/testing/vortex/rust_driver/ci.zig +34 -0
- data/ext/tb_client/tigerbeetle/src/testing/vortex/supervisor.zig +766 -0
- data/ext/tb_client/tigerbeetle/src/testing/vortex/workload.zig +543 -0
- data/ext/tb_client/tigerbeetle/src/testing/vortex/zig_driver.zig +181 -0
- data/ext/tb_client/tigerbeetle/src/tidy.zig +1448 -0
- data/ext/tb_client/tigerbeetle/src/tigerbeetle/benchmark_driver.zig +227 -0
- data/ext/tb_client/tigerbeetle/src/tigerbeetle/benchmark_load.zig +1069 -0
- data/ext/tb_client/tigerbeetle/src/tigerbeetle/cli.zig +1422 -0
- data/ext/tb_client/tigerbeetle/src/tigerbeetle/inspect.zig +1658 -0
- data/ext/tb_client/tigerbeetle/src/tigerbeetle/inspect_integrity.zig +518 -0
- data/ext/tb_client/tigerbeetle/src/tigerbeetle/libtb_client.zig +36 -0
- data/ext/tb_client/tigerbeetle/src/tigerbeetle/main.zig +646 -0
- data/ext/tb_client/tigerbeetle/src/tigerbeetle.zig +958 -0
- data/ext/tb_client/tigerbeetle/src/time.zig +236 -0
- data/ext/tb_client/tigerbeetle/src/trace/event.zig +745 -0
- data/ext/tb_client/tigerbeetle/src/trace/statsd.zig +462 -0
- data/ext/tb_client/tigerbeetle/src/trace.zig +556 -0
- data/ext/tb_client/tigerbeetle/src/unit_tests.zig +321 -0
- data/ext/tb_client/tigerbeetle/src/vopr.zig +1785 -0
- data/ext/tb_client/tigerbeetle/src/vortex.zig +101 -0
- data/ext/tb_client/tigerbeetle/src/vsr/checkpoint_trailer.zig +473 -0
- data/ext/tb_client/tigerbeetle/src/vsr/checksum.zig +208 -0
- data/ext/tb_client/tigerbeetle/src/vsr/checksum_benchmark.zig +43 -0
- data/ext/tb_client/tigerbeetle/src/vsr/client.zig +768 -0
- data/ext/tb_client/tigerbeetle/src/vsr/client_replies.zig +532 -0
- data/ext/tb_client/tigerbeetle/src/vsr/client_sessions.zig +338 -0
- data/ext/tb_client/tigerbeetle/src/vsr/clock.zig +1019 -0
- data/ext/tb_client/tigerbeetle/src/vsr/fault_detector.zig +279 -0
- data/ext/tb_client/tigerbeetle/src/vsr/free_set.zig +1381 -0
- data/ext/tb_client/tigerbeetle/src/vsr/free_set_fuzz.zig +315 -0
- data/ext/tb_client/tigerbeetle/src/vsr/grid.zig +1460 -0
- data/ext/tb_client/tigerbeetle/src/vsr/grid_blocks_missing.zig +757 -0
- data/ext/tb_client/tigerbeetle/src/vsr/grid_scrubber.zig +797 -0
- data/ext/tb_client/tigerbeetle/src/vsr/journal.zig +2586 -0
- data/ext/tb_client/tigerbeetle/src/vsr/marzullo.zig +308 -0
- data/ext/tb_client/tigerbeetle/src/vsr/message_header.zig +1777 -0
- data/ext/tb_client/tigerbeetle/src/vsr/multi_batch.zig +715 -0
- data/ext/tb_client/tigerbeetle/src/vsr/multi_batch_fuzz.zig +185 -0
- data/ext/tb_client/tigerbeetle/src/vsr/repair_budget.zig +333 -0
- data/ext/tb_client/tigerbeetle/src/vsr/replica.zig +12355 -0
- data/ext/tb_client/tigerbeetle/src/vsr/replica_format.zig +416 -0
- data/ext/tb_client/tigerbeetle/src/vsr/replica_reformat.zig +165 -0
- data/ext/tb_client/tigerbeetle/src/vsr/replica_test.zig +2910 -0
- data/ext/tb_client/tigerbeetle/src/vsr/routing.zig +1075 -0
- data/ext/tb_client/tigerbeetle/src/vsr/superblock.zig +1603 -0
- data/ext/tb_client/tigerbeetle/src/vsr/superblock_fuzz.zig +484 -0
- data/ext/tb_client/tigerbeetle/src/vsr/superblock_quorums.zig +405 -0
- data/ext/tb_client/tigerbeetle/src/vsr/superblock_quorums_fuzz.zig +355 -0
- data/ext/tb_client/tigerbeetle/src/vsr/sync.zig +29 -0
- data/ext/tb_client/tigerbeetle/src/vsr.zig +1727 -0
- data/lib/tb_client/shared_lib.rb +12 -5
- data/lib/tigerbeetle/client.rb +1 -1
- data/lib/tigerbeetle/platforms.rb +9 -0
- data/lib/tigerbeetle/version.rb +2 -2
- data/tigerbeetle.gemspec +22 -5
- metadata +242 -3
- data/ext/tb_client/pkg.tar.gz +0 -0
|
@@ -0,0 +1,1777 @@
|
|
|
1
|
+
const std = @import("std");
|
|
2
|
+
const assert = std.debug.assert;
|
|
3
|
+
const maybe = stdx.maybe;
|
|
4
|
+
|
|
5
|
+
const constants = @import("../constants.zig");
|
|
6
|
+
const stdx = @import("stdx");
|
|
7
|
+
const vsr = @import("../vsr.zig");
|
|
8
|
+
const Command = vsr.Command;
|
|
9
|
+
const Operation = vsr.Operation;
|
|
10
|
+
const schema = @import("../lsm/schema.zig");
|
|
11
|
+
|
|
12
|
+
const checksum_body_empty = vsr.checksum(&.{});
|
|
13
|
+
|
|
14
|
+
/// Network message, prepare, and grid block header:
|
|
15
|
+
/// We reuse the same header for both so that prepare messages from the primary can simply be
|
|
16
|
+
/// journalled as is by the backups without requiring any further modification.
|
|
17
|
+
pub const Header = extern struct {
|
|
18
|
+
/// A checksum covering only the remainder of this header.
|
|
19
|
+
/// This allows the header to be trusted without having to recv() or read() the associated body.
|
|
20
|
+
/// This checksum is enough to uniquely identify a network message or prepare.
|
|
21
|
+
checksum: u128,
|
|
22
|
+
|
|
23
|
+
// TODO(zig): When Zig supports u256 in extern-structs, merge this into `checksum`.
|
|
24
|
+
checksum_padding: u128,
|
|
25
|
+
|
|
26
|
+
/// A checksum covering only the associated body after this header.
|
|
27
|
+
checksum_body: u128,
|
|
28
|
+
|
|
29
|
+
// TODO(zig): When Zig supports u256 in extern-structs, merge this into `checksum_body`.
|
|
30
|
+
checksum_body_padding: u128,
|
|
31
|
+
|
|
32
|
+
/// Reserved for future use by AEAD.
|
|
33
|
+
nonce_reserved: u128,
|
|
34
|
+
|
|
35
|
+
/// The cluster number binds intention into the header, so that a client or replica can indicate
|
|
36
|
+
/// the cluster it believes it is speaking to, instead of accidentally talking to the wrong
|
|
37
|
+
/// cluster (for example, staging vs production).
|
|
38
|
+
cluster: u128,
|
|
39
|
+
|
|
40
|
+
/// The size of the Header structure (always), plus any associated body.
|
|
41
|
+
size: u32,
|
|
42
|
+
|
|
43
|
+
/// The cluster reconfiguration epoch number (for future use).
|
|
44
|
+
epoch: u32,
|
|
45
|
+
|
|
46
|
+
/// Every message sent from one replica to another contains the sending replica's current view.
|
|
47
|
+
/// A `u32` allows for a minimum lifetime of 136 years at a rate of one view change per second.
|
|
48
|
+
view: u32,
|
|
49
|
+
|
|
50
|
+
/// The release version set by the state machine.
|
|
51
|
+
/// (This field is not set for all message types.)
|
|
52
|
+
release: vsr.Release,
|
|
53
|
+
|
|
54
|
+
/// The version of the protocol implementation that originated this message.
|
|
55
|
+
protocol: u16,
|
|
56
|
+
|
|
57
|
+
/// The Viewstamped Replication protocol command for this message.
|
|
58
|
+
command: Command,
|
|
59
|
+
|
|
60
|
+
/// The index of the replica in the cluster configuration array that authored this message.
|
|
61
|
+
/// This identifies only the ultimate author because messages may be forwarded amongst replicas.
|
|
62
|
+
replica: u8,
|
|
63
|
+
|
|
64
|
+
/// Reserved for future use by the header frame (i.e. to be shared by all message types).
|
|
65
|
+
reserved_frame: [12]u8,
|
|
66
|
+
|
|
67
|
+
/// This data's schema is different depending on the `Header.command`.
|
|
68
|
+
/// (No default value – `Header`s should not be constructed directly.)
|
|
69
|
+
reserved_command: [128]u8,
|
|
70
|
+
|
|
71
|
+
comptime {
|
|
72
|
+
assert(@sizeOf(Header) == 256);
|
|
73
|
+
assert(stdx.no_padding(Header));
|
|
74
|
+
assert(@offsetOf(Header, "reserved_command") % @sizeOf(u256) == 0);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
pub fn Type(comptime command: Command) type {
|
|
78
|
+
return switch (command) {
|
|
79
|
+
.reserved => Reserved,
|
|
80
|
+
.ping => Ping,
|
|
81
|
+
.pong => Pong,
|
|
82
|
+
.ping_client => PingClient,
|
|
83
|
+
.pong_client => PongClient,
|
|
84
|
+
.request => Request,
|
|
85
|
+
.prepare => Prepare,
|
|
86
|
+
.prepare_ok => PrepareOk,
|
|
87
|
+
.reply => Reply,
|
|
88
|
+
.commit => Commit,
|
|
89
|
+
.start_view_change => StartViewChange,
|
|
90
|
+
.do_view_change => DoViewChange,
|
|
91
|
+
.start_view => StartView,
|
|
92
|
+
.request_start_view => RequestStartView,
|
|
93
|
+
.request_headers => RequestHeaders,
|
|
94
|
+
.request_prepare => RequestPrepare,
|
|
95
|
+
.request_reply => RequestReply,
|
|
96
|
+
.headers => Headers,
|
|
97
|
+
.eviction => Eviction,
|
|
98
|
+
.request_blocks => RequestBlocks,
|
|
99
|
+
.block => Block,
|
|
100
|
+
.deprecated_12 => Deprecated,
|
|
101
|
+
.deprecated_21 => Deprecated,
|
|
102
|
+
.deprecated_22 => Deprecated,
|
|
103
|
+
.deprecated_23 => Deprecated,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pub fn calculate_checksum(self: *const Header) u128 {
|
|
108
|
+
const checksum_size = @sizeOf(@TypeOf(self.checksum));
|
|
109
|
+
assert(checksum_size == 16);
|
|
110
|
+
const checksum_value = vsr.checksum(std.mem.asBytes(self)[checksum_size..]);
|
|
111
|
+
assert(@TypeOf(checksum_value) == @TypeOf(self.checksum));
|
|
112
|
+
return checksum_value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
pub fn calculate_checksum_body(self: *const Header, body: []const u8) u128 {
|
|
116
|
+
assert(self.size == @sizeOf(Header) + body.len);
|
|
117
|
+
const checksum_size = @sizeOf(@TypeOf(self.checksum_body));
|
|
118
|
+
assert(checksum_size == 16);
|
|
119
|
+
const checksum_value = vsr.checksum(body);
|
|
120
|
+
assert(@TypeOf(checksum_value) == @TypeOf(self.checksum_body));
|
|
121
|
+
return checksum_value;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/// This must be called only after set_checksum_body() so that checksum_body is also covered:
|
|
125
|
+
pub fn set_checksum(self: *Header) void {
|
|
126
|
+
self.checksum = self.calculate_checksum();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
pub fn set_checksum_body(self: *Header, body: []const u8) void {
|
|
130
|
+
self.checksum_body = self.calculate_checksum_body(body);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
pub fn valid_checksum(self: *const Header) bool {
|
|
134
|
+
return self.checksum == self.calculate_checksum();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
pub fn valid_checksum_body(self: *const Header, body: []const u8) bool {
|
|
138
|
+
return self.checksum_body == self.calculate_checksum_body(body);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
pub const AnyHeaderPointer = stdx.EnumUnionType(Command, struct {
|
|
142
|
+
fn PointerForCommandType(comptime variant: Command) type {
|
|
143
|
+
return *const Type(variant);
|
|
144
|
+
}
|
|
145
|
+
}.PointerForCommandType);
|
|
146
|
+
|
|
147
|
+
pub fn into_any(self: *const Header) AnyHeaderPointer {
|
|
148
|
+
switch (self.command) {
|
|
149
|
+
inline else => |command| {
|
|
150
|
+
return @unionInit(AnyHeaderPointer, @tagName(command), self.into_const(command).?);
|
|
151
|
+
},
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
pub fn into(self: *Header, comptime command: Command) ?*Type(command) {
|
|
156
|
+
if (self.command != command) return null;
|
|
157
|
+
return std.mem.bytesAsValue(Type(command), std.mem.asBytes(self));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
pub fn into_const(self: *const Header, comptime command: Command) ?*const Type(command) {
|
|
161
|
+
if (self.command != command) return null;
|
|
162
|
+
return std.mem.bytesAsValue(Type(command), std.mem.asBytes(self));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/// Returns null if all fields are set correctly according to the command, or else a warning.
|
|
166
|
+
/// This does not verify that checksum is valid, and expects that this has already been done.
|
|
167
|
+
pub fn invalid(self: *const Header) ?[]const u8 {
|
|
168
|
+
if (self.checksum_padding != 0) return "checksum_padding != 0";
|
|
169
|
+
if (self.checksum_body_padding != 0) return "checksum_body_padding != 0";
|
|
170
|
+
if (self.nonce_reserved != 0) return "nonce_reserved != 0";
|
|
171
|
+
if (self.size < @sizeOf(Header)) return "size < @sizeOf(Header)";
|
|
172
|
+
if (self.size > constants.message_size_max) return "size > message_size_max";
|
|
173
|
+
if (self.epoch != 0) return "epoch != 0";
|
|
174
|
+
if (!stdx.zeroed(&self.reserved_frame)) return "reserved_frame != 0";
|
|
175
|
+
|
|
176
|
+
if (self.command == .block) {
|
|
177
|
+
if (self.protocol > vsr.Version) return "block: protocol > Version";
|
|
178
|
+
} else {
|
|
179
|
+
if (self.protocol != vsr.Version) return "protocol != Version";
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
switch (self.into_any()) {
|
|
183
|
+
inline else => |command_header| return command_header.invalid_header(),
|
|
184
|
+
// The `Command` enum is exhaustive, so we can't write an "else" branch here. An unknown
|
|
185
|
+
// command is a possibility, but that means that someone has send us a message with
|
|
186
|
+
// matching cluster, matching version, correct checksum, and a command we don't know
|
|
187
|
+
// about. Ignoring unknown commands might be unsafe, so the replica intentionally
|
|
188
|
+
// crashes here, which is guaranteed by Zig's ReleaseSafe semantics.
|
|
189
|
+
//
|
|
190
|
+
// _ => unreachable
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// Returns whether the immediate sender is a replica or client (if this can be determined).
|
|
195
|
+
/// Some commands such as .request or .prepare may be forwarded on to other replicas so that
|
|
196
|
+
/// Header.replica or Header.client only identifies the ultimate origin, not the latest peer.
|
|
197
|
+
pub fn peer_type(self: *const Header) vsr.Peer {
|
|
198
|
+
return switch (self.into_any()) {
|
|
199
|
+
.reserved => unreachable,
|
|
200
|
+
|
|
201
|
+
.reply,
|
|
202
|
+
.prepare,
|
|
203
|
+
.block,
|
|
204
|
+
=> .unknown,
|
|
205
|
+
|
|
206
|
+
// The peer may be a replica or a client, since replicas forward request messages.
|
|
207
|
+
// However, we return the client ID, as it is useful for the MessageBus. Specifically,
|
|
208
|
+
// a replica that receives a request from a client can immediately cache the connection
|
|
209
|
+
// in its client map, instead of waiting for an infrequent PingClient message to do so.
|
|
210
|
+
.request => |request| .{ .client_likely = request.client },
|
|
211
|
+
|
|
212
|
+
// The peer is certainly a client:
|
|
213
|
+
.ping_client => |ping| .{ .client = ping.client },
|
|
214
|
+
|
|
215
|
+
// The peer is certainly a replica:
|
|
216
|
+
.ping,
|
|
217
|
+
.pong,
|
|
218
|
+
.pong_client,
|
|
219
|
+
.prepare_ok,
|
|
220
|
+
.commit,
|
|
221
|
+
.start_view_change,
|
|
222
|
+
.do_view_change,
|
|
223
|
+
.start_view,
|
|
224
|
+
.request_start_view,
|
|
225
|
+
.request_headers,
|
|
226
|
+
.request_prepare,
|
|
227
|
+
.request_reply,
|
|
228
|
+
.headers,
|
|
229
|
+
.eviction,
|
|
230
|
+
.request_blocks,
|
|
231
|
+
=> .{ .replica = self.replica },
|
|
232
|
+
|
|
233
|
+
.deprecated_12,
|
|
234
|
+
.deprecated_21,
|
|
235
|
+
.deprecated_22,
|
|
236
|
+
.deprecated_23,
|
|
237
|
+
=> .unknown,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
pub fn format(
|
|
242
|
+
self: *const Header,
|
|
243
|
+
comptime fmt: []const u8,
|
|
244
|
+
options: std.fmt.FormatOptions,
|
|
245
|
+
writer: anytype,
|
|
246
|
+
) !void {
|
|
247
|
+
switch (self.into_any()) {
|
|
248
|
+
inline else => |header| return try header.format(fmt, options, writer),
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
fn HeaderFunctionsType(comptime CommandHeader: type) type {
|
|
253
|
+
return struct {
|
|
254
|
+
pub fn frame(header: *CommandHeader) *Header {
|
|
255
|
+
return std.mem.bytesAsValue(Header, std.mem.asBytes(header));
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
pub fn frame_const(header: *const CommandHeader) *const Header {
|
|
259
|
+
return std.mem.bytesAsValue(Header, std.mem.asBytes(header));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
pub fn invalid(self: *const CommandHeader) ?[]const u8 {
|
|
263
|
+
return self.frame_const().invalid();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
pub fn calculate_checksum(self: *const CommandHeader) u128 {
|
|
267
|
+
return self.frame_const().calculate_checksum();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
pub fn calculate_checksum_body(self: *const CommandHeader, body: []const u8) u128 {
|
|
271
|
+
return self.frame_const().calculate_checksum_body(body);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
pub fn set_checksum(self: *CommandHeader) void {
|
|
275
|
+
self.frame().set_checksum();
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
pub fn set_checksum_body(self: *CommandHeader, body: []const u8) void {
|
|
279
|
+
self.frame().set_checksum_body(body);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
pub fn valid_checksum(self: *const CommandHeader) bool {
|
|
283
|
+
return self.frame_const().valid_checksum();
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
pub fn valid_checksum_body(self: *const CommandHeader, body: []const u8) bool {
|
|
287
|
+
return self.frame_const().valid_checksum_body(body);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
pub fn format(
|
|
291
|
+
self: *const CommandHeader,
|
|
292
|
+
comptime _: []const u8,
|
|
293
|
+
_: std.fmt.FormatOptions,
|
|
294
|
+
writer: anytype,
|
|
295
|
+
) !void {
|
|
296
|
+
return format_header(CommandHeader, self, writer);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/// This type isn't ever actually a constructed, but makes Type() simpler by providing a header
|
|
302
|
+
/// type for each command.
|
|
303
|
+
pub const Reserved = extern struct {
|
|
304
|
+
checksum: u128,
|
|
305
|
+
checksum_padding: u128 = 0,
|
|
306
|
+
checksum_body: u128,
|
|
307
|
+
checksum_body_padding: u128 = 0,
|
|
308
|
+
nonce_reserved: u128,
|
|
309
|
+
cluster: u128,
|
|
310
|
+
size: u32,
|
|
311
|
+
epoch: u32 = 0,
|
|
312
|
+
view: u32 = 0,
|
|
313
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
314
|
+
protocol: u16 = vsr.Version,
|
|
315
|
+
command: Command,
|
|
316
|
+
replica: u8 = 0,
|
|
317
|
+
reserved_frame: [12]u8,
|
|
318
|
+
|
|
319
|
+
reserved: [128]u8 = @splat(0),
|
|
320
|
+
|
|
321
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
322
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
323
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
324
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
325
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
326
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
327
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
328
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
329
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
330
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
331
|
+
|
|
332
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
333
|
+
assert(self.command == .reserved);
|
|
334
|
+
return "reserved is invalid";
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/// This type isn't ever actually a constructed, but makes Type() simpler by providing a header
|
|
339
|
+
/// type for each command.
|
|
340
|
+
pub const Deprecated = extern struct {
|
|
341
|
+
checksum: u128,
|
|
342
|
+
checksum_padding: u128 = 0,
|
|
343
|
+
checksum_body: u128,
|
|
344
|
+
checksum_body_padding: u128 = 0,
|
|
345
|
+
nonce_reserved: u128,
|
|
346
|
+
cluster: u128,
|
|
347
|
+
size: u32,
|
|
348
|
+
epoch: u32 = 0,
|
|
349
|
+
view: u32 = 0,
|
|
350
|
+
release: vsr.Release,
|
|
351
|
+
protocol: u16 = vsr.Version,
|
|
352
|
+
command: Command,
|
|
353
|
+
replica: u8 = 0,
|
|
354
|
+
reserved_frame: [12]u8,
|
|
355
|
+
|
|
356
|
+
reserved: [128]u8 = @splat(0),
|
|
357
|
+
|
|
358
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
359
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
360
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
361
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
362
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
363
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
364
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
365
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
366
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
367
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
368
|
+
|
|
369
|
+
fn invalid_header(_: *const @This()) ?[]const u8 {
|
|
370
|
+
return "deprecated message type";
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
pub const Ping = extern struct {
|
|
375
|
+
checksum: u128 = 0,
|
|
376
|
+
checksum_padding: u128 = 0,
|
|
377
|
+
checksum_body: u128 = 0,
|
|
378
|
+
checksum_body_padding: u128 = 0,
|
|
379
|
+
nonce_reserved: u128 = 0,
|
|
380
|
+
cluster: u128,
|
|
381
|
+
size: u32,
|
|
382
|
+
epoch: u32 = 0,
|
|
383
|
+
// NB: unlike every other message, pings and pongs use on disk view, rather than in-memory
|
|
384
|
+
// view, to avoid disrupting clock synchronization while the view is being updated.
|
|
385
|
+
view: u32,
|
|
386
|
+
release: vsr.Release,
|
|
387
|
+
protocol: u16 = vsr.Version,
|
|
388
|
+
command: Command,
|
|
389
|
+
replica: u8,
|
|
390
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
391
|
+
|
|
392
|
+
/// Current checkpoint id.
|
|
393
|
+
checkpoint_id: u128,
|
|
394
|
+
/// Current checkpoint op.
|
|
395
|
+
checkpoint_op: u64,
|
|
396
|
+
|
|
397
|
+
ping_timestamp_monotonic: u64,
|
|
398
|
+
release_count: u16,
|
|
399
|
+
route_padding: [6]u8 = @splat(0),
|
|
400
|
+
route: u64,
|
|
401
|
+
|
|
402
|
+
reserved: [80]u8 = @splat(0),
|
|
403
|
+
|
|
404
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
405
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
406
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
407
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
408
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
409
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
410
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
411
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
412
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
413
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
414
|
+
|
|
415
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
416
|
+
assert(self.command == .ping);
|
|
417
|
+
if (self.size != @sizeOf(Header) + @sizeOf(vsr.Release) * constants.vsr_releases_max) {
|
|
418
|
+
return "size != @sizeOf(Header) + " ++
|
|
419
|
+
"@sizeOf(vsr.Release) * constants.vsr_releases_max";
|
|
420
|
+
}
|
|
421
|
+
if (self.release.value == 0) return "release == 0";
|
|
422
|
+
if (!vsr.Checkpoint.valid(self.checkpoint_op)) return "checkpoint_op invalid";
|
|
423
|
+
if (self.ping_timestamp_monotonic == 0) return "ping_timestamp_monotonic != expected";
|
|
424
|
+
if (self.release_count == 0) return "release_count == 0";
|
|
425
|
+
if (self.release_count > constants.vsr_releases_max) {
|
|
426
|
+
return "release_count > vsr_releases_max";
|
|
427
|
+
}
|
|
428
|
+
if (!stdx.zeroed(&self.route_padding)) return "route_padding != 0";
|
|
429
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
430
|
+
return null;
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
pub const Pong = extern struct {
|
|
435
|
+
checksum: u128 = 0,
|
|
436
|
+
checksum_padding: u128 = 0,
|
|
437
|
+
checksum_body: u128 = 0,
|
|
438
|
+
checksum_body_padding: u128 = 0,
|
|
439
|
+
nonce_reserved: u128 = 0,
|
|
440
|
+
cluster: u128,
|
|
441
|
+
size: u32 = @sizeOf(Header),
|
|
442
|
+
epoch: u32 = 0,
|
|
443
|
+
// NB: unlike every other message, pings and pongs use on disk view, rather than in-memory
|
|
444
|
+
// view, to avoid disrupting clock synchronization while the view is being updated.
|
|
445
|
+
view: u32,
|
|
446
|
+
release: vsr.Release,
|
|
447
|
+
protocol: u16 = vsr.Version,
|
|
448
|
+
command: Command,
|
|
449
|
+
replica: u8,
|
|
450
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
451
|
+
|
|
452
|
+
ping_timestamp_monotonic: u64,
|
|
453
|
+
pong_timestamp_wall: u64,
|
|
454
|
+
|
|
455
|
+
reserved: [112]u8 = @splat(0),
|
|
456
|
+
|
|
457
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
458
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
459
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
460
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
461
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
462
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
463
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
464
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
465
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
466
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
467
|
+
|
|
468
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
469
|
+
assert(self.command == .pong);
|
|
470
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
471
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
472
|
+
if (self.release.value == 0) return "release == 0";
|
|
473
|
+
if (self.ping_timestamp_monotonic == 0) return "ping_timestamp_monotonic == 0";
|
|
474
|
+
if (self.pong_timestamp_wall == 0) return "pong_timestamp_wall == 0";
|
|
475
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
476
|
+
return null;
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
pub const PingClient = extern struct {
|
|
481
|
+
checksum: u128 = 0,
|
|
482
|
+
checksum_padding: u128 = 0,
|
|
483
|
+
checksum_body: u128 = 0,
|
|
484
|
+
checksum_body_padding: u128 = 0,
|
|
485
|
+
nonce_reserved: u128 = 0,
|
|
486
|
+
cluster: u128,
|
|
487
|
+
size: u32 = @sizeOf(Header),
|
|
488
|
+
epoch: u32 = 0,
|
|
489
|
+
view: u32 = 0, // Always 0.
|
|
490
|
+
release: vsr.Release,
|
|
491
|
+
protocol: u16 = vsr.Version,
|
|
492
|
+
command: Command,
|
|
493
|
+
replica: u8 = 0, // Always 0.
|
|
494
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
495
|
+
|
|
496
|
+
client: u128,
|
|
497
|
+
ping_timestamp_monotonic: u64,
|
|
498
|
+
reserved: [104]u8 = @splat(0),
|
|
499
|
+
|
|
500
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
501
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
502
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
503
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
504
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
505
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
506
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
507
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
508
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
509
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
510
|
+
|
|
511
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
512
|
+
assert(self.command == .ping_client);
|
|
513
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
514
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
515
|
+
if (self.release.value == 0) return "release == 0";
|
|
516
|
+
if (self.replica != 0) return "replica != 0";
|
|
517
|
+
if (self.view != 0) return "view != 0";
|
|
518
|
+
if (self.client == 0) return "client == 0";
|
|
519
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
pub const PongClient = extern struct {
|
|
525
|
+
checksum: u128 = 0,
|
|
526
|
+
checksum_padding: u128 = 0,
|
|
527
|
+
checksum_body: u128 = 0,
|
|
528
|
+
checksum_body_padding: u128 = 0,
|
|
529
|
+
nonce_reserved: u128 = 0,
|
|
530
|
+
cluster: u128,
|
|
531
|
+
size: u32 = @sizeOf(Header),
|
|
532
|
+
epoch: u32 = 0,
|
|
533
|
+
view: u32,
|
|
534
|
+
release: vsr.Release,
|
|
535
|
+
protocol: u16 = vsr.Version,
|
|
536
|
+
command: Command,
|
|
537
|
+
replica: u8,
|
|
538
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
539
|
+
|
|
540
|
+
ping_timestamp_monotonic: u64,
|
|
541
|
+
reserved: [120]u8 = @splat(0),
|
|
542
|
+
|
|
543
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
544
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
545
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
546
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
547
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
548
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
549
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
550
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
551
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
552
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
553
|
+
|
|
554
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
555
|
+
assert(self.command == .pong_client);
|
|
556
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
557
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
558
|
+
if (self.release.value == 0) return "release == 0";
|
|
559
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
560
|
+
return null;
|
|
561
|
+
}
|
|
562
|
+
};
|
|
563
|
+
|
|
564
|
+
pub const Request = extern struct {
|
|
565
|
+
checksum: u128 = 0,
|
|
566
|
+
checksum_padding: u128 = 0,
|
|
567
|
+
checksum_body: u128 = 0,
|
|
568
|
+
checksum_body_padding: u128 = 0,
|
|
569
|
+
nonce_reserved: u128 = 0,
|
|
570
|
+
cluster: u128,
|
|
571
|
+
size: u32 = @sizeOf(Header),
|
|
572
|
+
epoch: u32 = 0,
|
|
573
|
+
view: u32 = 0,
|
|
574
|
+
/// The client's release version.
|
|
575
|
+
release: vsr.Release,
|
|
576
|
+
protocol: u16 = vsr.Version,
|
|
577
|
+
command: Command,
|
|
578
|
+
replica: u8 = 0, // Always 0.
|
|
579
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
580
|
+
|
|
581
|
+
/// Clients hash-chain their requests to verify linearizability:
|
|
582
|
+
/// - A session's first request (operation=register) sets `parent=0`.
|
|
583
|
+
/// - A session's subsequent requests (operation≠register) set `parent` to the checksum of
|
|
584
|
+
/// the preceding reply.
|
|
585
|
+
parent: u128 = 0,
|
|
586
|
+
parent_padding: u128 = 0,
|
|
587
|
+
/// Each client process generates a unique, random and ephemeral client ID at
|
|
588
|
+
/// initialization. The client ID identifies connections made by the client to the cluster
|
|
589
|
+
/// for the sake of routing messages back to the client.
|
|
590
|
+
///
|
|
591
|
+
/// With the client ID in hand, the client then registers a monotonically increasing session
|
|
592
|
+
/// number (committed through the cluster) to allow the client's session to be evicted
|
|
593
|
+
/// safely from the client table if too many concurrent clients cause the client table to
|
|
594
|
+
/// overflow. The monotonically increasing session number prevents duplicate client requests
|
|
595
|
+
/// from being replayed.
|
|
596
|
+
///
|
|
597
|
+
/// The problem of routing is therefore solved by the 128-bit client ID, and the problem of
|
|
598
|
+
/// detecting whether a session has been evicted is solved by the session number.
|
|
599
|
+
client: u128,
|
|
600
|
+
/// When operation=register, this is zero.
|
|
601
|
+
/// When operation≠register, this is the commit number of register.
|
|
602
|
+
session: u64 = 0,
|
|
603
|
+
/// Only nonzero during AOF recovery.
|
|
604
|
+
/// TODO: Use this for bulk-import to state machine?
|
|
605
|
+
timestamp: u64 = 0,
|
|
606
|
+
/// Each request is given a number by the client and later requests must have larger numbers
|
|
607
|
+
/// than earlier ones. The request number is used by the replicas to avoid running requests
|
|
608
|
+
/// more than once; it is also used by the client to discard duplicate replies to its
|
|
609
|
+
/// requests.
|
|
610
|
+
///
|
|
611
|
+
/// A client is allowed to have at most one request inflight at a time.
|
|
612
|
+
request: u32,
|
|
613
|
+
operation: Operation,
|
|
614
|
+
previous_request_latency_padding: [3]u8 = @splat(0),
|
|
615
|
+
/// Nanosecond interval measuring the time between when the client first began to construct
|
|
616
|
+
/// the previous request's body and the time that the client received the corresponding
|
|
617
|
+
/// reply.
|
|
618
|
+
previous_request_latency: u32,
|
|
619
|
+
reserved: [52]u8 = @splat(0),
|
|
620
|
+
|
|
621
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
622
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
623
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
624
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
625
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
626
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
627
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
628
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
629
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
630
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
631
|
+
|
|
632
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
633
|
+
assert(self.command == .request);
|
|
634
|
+
if (self.release.value == 0) return "release == 0";
|
|
635
|
+
if (self.parent_padding != 0) return "parent_padding != 0";
|
|
636
|
+
switch (self.operation) {
|
|
637
|
+
.reserved => return "operation == .reserved",
|
|
638
|
+
.root => return "operation == .root",
|
|
639
|
+
.register => {
|
|
640
|
+
// The first request a client makes must be to register with the cluster:
|
|
641
|
+
if (self.replica != 0) return "register: replica != 0";
|
|
642
|
+
if (self.client == 0) return "register: client == 0";
|
|
643
|
+
if (self.parent != 0) return "register: parent != 0";
|
|
644
|
+
if (self.session != 0) return "register: session != 0";
|
|
645
|
+
if (self.request != 0) return "register: request != 0";
|
|
646
|
+
// Support `register` requests without the body to correctly
|
|
647
|
+
// reply with `client_release_too_low` for clients <= v0.15.3.
|
|
648
|
+
if (self.size != @sizeOf(Header) and
|
|
649
|
+
self.size != @sizeOf(Header) + @sizeOf(vsr.RegisterRequest))
|
|
650
|
+
{
|
|
651
|
+
return "register: size != @sizeOf(Header) [+ @sizeOf(vsr.RegisterRequest)]";
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
.pulse => {
|
|
655
|
+
// These requests don't originate from a real client or session.
|
|
656
|
+
if (self.client != 0) return "pulse: client != 0";
|
|
657
|
+
if (self.parent != 0) return "pulse: parent != 0";
|
|
658
|
+
if (self.session != 0) return "pulse: session != 0";
|
|
659
|
+
if (self.request != 0) return "pulse: request != 0";
|
|
660
|
+
if (self.size != @sizeOf(Header)) return "pulse: size != @sizeOf(Header)";
|
|
661
|
+
},
|
|
662
|
+
.upgrade => {
|
|
663
|
+
// These requests don't originate from a real client or session.
|
|
664
|
+
if (self.client != 0) return "upgrade: client != 0";
|
|
665
|
+
if (self.parent != 0) return "upgrade: parent != 0";
|
|
666
|
+
if (self.session != 0) return "upgrade: session != 0";
|
|
667
|
+
if (self.request != 0) return "upgrade: request != 0";
|
|
668
|
+
|
|
669
|
+
if (self.size != @sizeOf(Header) + @sizeOf(vsr.UpgradeRequest)) {
|
|
670
|
+
return "upgrade: size != @sizeOf(Header) + @sizeOf(vsr.UpgradeRequest)";
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
else => {
|
|
674
|
+
if (self.operation == .reconfigure) {
|
|
675
|
+
if (self.size != @sizeOf(Header) + @sizeOf(vsr.ReconfigurationRequest)) {
|
|
676
|
+
return "size != @sizeOf(Header) + @sizeOf(ReconfigurationRequest)";
|
|
677
|
+
}
|
|
678
|
+
} else if (self.operation == .noop) {
|
|
679
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
680
|
+
} else if (@intFromEnum(self.operation) < constants.vsr_operations_reserved) {
|
|
681
|
+
return "operation is reserved";
|
|
682
|
+
}
|
|
683
|
+
if (self.replica != 0) return "replica != 0";
|
|
684
|
+
if (self.client == 0) return "client == 0";
|
|
685
|
+
// Thereafter, the client must provide the session number:
|
|
686
|
+
// These requests should set `parent` to the `checksum` of the previous reply.
|
|
687
|
+
if (self.session == 0) return "session == 0";
|
|
688
|
+
if (self.request == 0) return "request == 0";
|
|
689
|
+
// The Replica is responsible for checking the `Operation` is a valid variant –
|
|
690
|
+
// the check requires the StateMachine type.
|
|
691
|
+
},
|
|
692
|
+
}
|
|
693
|
+
if (!stdx.zeroed(&self.previous_request_latency_padding)) return "padding != 0";
|
|
694
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
695
|
+
return null;
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
|
|
699
|
+
pub const Prepare = extern struct {
|
|
700
|
+
checksum: u128 = 0,
|
|
701
|
+
checksum_padding: u128 = 0,
|
|
702
|
+
checksum_body: u128 = 0,
|
|
703
|
+
checksum_body_padding: u128 = 0,
|
|
704
|
+
nonce_reserved: u128 = 0,
|
|
705
|
+
cluster: u128,
|
|
706
|
+
size: u32 = @sizeOf(Header),
|
|
707
|
+
epoch: u32 = 0,
|
|
708
|
+
view: u32,
|
|
709
|
+
/// The corresponding Request's release version.
|
|
710
|
+
release: vsr.Release,
|
|
711
|
+
protocol: u16 = vsr.Version,
|
|
712
|
+
command: Command,
|
|
713
|
+
replica: u8 = 0,
|
|
714
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
715
|
+
|
|
716
|
+
/// A backpointer to the previous prepare checksum for hash chain verification.
|
|
717
|
+
/// This provides a strong guarantee for linearizability across our distributed log
|
|
718
|
+
/// of prepares.
|
|
719
|
+
///
|
|
720
|
+
/// This may also be used as the initialization vector for AEAD encryption at rest, provided
|
|
721
|
+
/// that the primary ratchets the encryption key every view change to ensure that prepares
|
|
722
|
+
/// reordered through a view change never repeat the same IV for the same encryption key.
|
|
723
|
+
parent: u128,
|
|
724
|
+
parent_padding: u128 = 0,
|
|
725
|
+
/// The checksum of the client's request.
|
|
726
|
+
request_checksum: u128,
|
|
727
|
+
request_checksum_padding: u128 = 0,
|
|
728
|
+
/// The id of the checkpoint where:
|
|
729
|
+
///
|
|
730
|
+
/// prepare.op > checkpoint_op
|
|
731
|
+
/// prepare.op ≤ checkpoint_after(checkpoint_op)
|
|
732
|
+
///
|
|
733
|
+
/// The purpose of including the checkpoint id is to strictly bound the number of commits
|
|
734
|
+
/// that it may take to discover a divergent replica. If a replica diverges, then that
|
|
735
|
+
/// divergence will be discovered *at latest* when the divergent replica attempts to commit
|
|
736
|
+
/// the first op after the next checkpoint.
|
|
737
|
+
checkpoint_id: u128,
|
|
738
|
+
client: u128,
|
|
739
|
+
/// The op number of the latest prepare that may or may not yet be committed. Uncommitted
|
|
740
|
+
/// ops may be replaced by different ops if they do not survive through a view change.
|
|
741
|
+
op: u64,
|
|
742
|
+
/// The commit number of the latest committed prepare. Committed ops are immutable.
|
|
743
|
+
commit: u64,
|
|
744
|
+
/// The primary's state machine `prepare_timestamp`.
|
|
745
|
+
/// For `create_accounts` and `create_transfers` this is the batch's highest timestamp.
|
|
746
|
+
timestamp: u64,
|
|
747
|
+
request: u32,
|
|
748
|
+
/// The state machine operation to apply.
|
|
749
|
+
operation: Operation,
|
|
750
|
+
reserved: [3]u8 = @splat(0),
|
|
751
|
+
|
|
752
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
753
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
754
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
755
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
756
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
757
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
758
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
759
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
760
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
761
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
762
|
+
|
|
763
|
+
fn invalid_header(self: *const Prepare) ?[]const u8 {
|
|
764
|
+
assert(self.command == .prepare);
|
|
765
|
+
if (self.parent_padding != 0) return "parent_padding != 0";
|
|
766
|
+
if (self.request_checksum_padding != 0) return "request_checksum_padding != 0";
|
|
767
|
+
switch (self.operation) {
|
|
768
|
+
.reserved => {
|
|
769
|
+
if (self.size != @sizeOf(Header)) return "reserved: size != @sizeOf(Header)";
|
|
770
|
+
if (self.checksum_body != checksum_body_empty) {
|
|
771
|
+
return "reserved: checksum_body != expected";
|
|
772
|
+
}
|
|
773
|
+
if (self.view != 0) return "reserved: view != 0";
|
|
774
|
+
if (self.release.value != 0) return "release != 0";
|
|
775
|
+
if (self.replica != 0) return "reserved: replica != 0";
|
|
776
|
+
if (self.parent != 0) return "reserved: parent != 0";
|
|
777
|
+
if (self.client != 0) return "reserved: client != 0";
|
|
778
|
+
if (self.request_checksum != 0) return "reserved: request_checksum != 0";
|
|
779
|
+
if (self.checkpoint_id != 0) return "reserved: checkpoint_id != 0";
|
|
780
|
+
maybe(self.op == 0);
|
|
781
|
+
if (self.commit != 0) return "reserved: commit != 0";
|
|
782
|
+
if (self.request != 0) return "reserved: request != 0";
|
|
783
|
+
if (self.timestamp != 0) return "reserved: timestamp != 0";
|
|
784
|
+
},
|
|
785
|
+
.root => {
|
|
786
|
+
if (self.size != @sizeOf(Header)) return "root: size != @sizeOf(Header)";
|
|
787
|
+
if (self.checksum_body != checksum_body_empty) {
|
|
788
|
+
return "root: checksum_body != expected";
|
|
789
|
+
}
|
|
790
|
+
if (self.view != 0) return "root: view != 0";
|
|
791
|
+
if (self.release.value != 0) return "release != 0";
|
|
792
|
+
if (self.replica != 0) return "root: replica != 0";
|
|
793
|
+
if (self.parent != 0) return "root: parent != 0";
|
|
794
|
+
if (self.client != 0) return "root: client != 0";
|
|
795
|
+
if (self.request_checksum != 0) return "root: request_checksum != 0";
|
|
796
|
+
if (self.checkpoint_id != 0) return "root: checkpoint_id != 0";
|
|
797
|
+
if (self.op != 0) return "root: op != 0";
|
|
798
|
+
if (self.commit != 0) return "root: commit != 0";
|
|
799
|
+
if (self.timestamp != 0) return "root: timestamp != 0";
|
|
800
|
+
if (self.request != 0) return "root: request != 0";
|
|
801
|
+
},
|
|
802
|
+
else => {
|
|
803
|
+
if (self.release.value == 0) return "release == 0";
|
|
804
|
+
if (self.operation == .pulse or
|
|
805
|
+
self.operation == .upgrade)
|
|
806
|
+
{
|
|
807
|
+
if (self.client != 0) return "client != 0";
|
|
808
|
+
} else {
|
|
809
|
+
if (self.client == 0) return "client == 0";
|
|
810
|
+
}
|
|
811
|
+
if (self.op == 0) return "op == 0";
|
|
812
|
+
if (self.op <= self.commit) return "op <= commit";
|
|
813
|
+
if (self.timestamp == 0) return "timestamp == 0";
|
|
814
|
+
if (self.operation == .register or
|
|
815
|
+
self.operation == .pulse or
|
|
816
|
+
self.operation == .upgrade)
|
|
817
|
+
{
|
|
818
|
+
if (self.request != 0) return "request != 0";
|
|
819
|
+
} else {
|
|
820
|
+
if (self.request == 0) return "request == 0";
|
|
821
|
+
}
|
|
822
|
+
},
|
|
823
|
+
}
|
|
824
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
pub fn reserve(cluster: u128, slot: u64) Prepare {
|
|
829
|
+
assert(slot < constants.journal_slot_count);
|
|
830
|
+
|
|
831
|
+
var header = Prepare{
|
|
832
|
+
.command = .prepare,
|
|
833
|
+
.cluster = cluster,
|
|
834
|
+
.release = vsr.Release.zero,
|
|
835
|
+
.op = slot,
|
|
836
|
+
.operation = .reserved,
|
|
837
|
+
.view = 0,
|
|
838
|
+
.request_checksum = 0,
|
|
839
|
+
.checkpoint_id = 0,
|
|
840
|
+
.parent = 0,
|
|
841
|
+
.client = 0,
|
|
842
|
+
.commit = 0,
|
|
843
|
+
.timestamp = 0,
|
|
844
|
+
.request = 0,
|
|
845
|
+
};
|
|
846
|
+
header.set_checksum_body(&[0]u8{});
|
|
847
|
+
header.set_checksum();
|
|
848
|
+
assert(header.invalid() == null);
|
|
849
|
+
return header;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
pub fn root(cluster: u128) Prepare {
|
|
853
|
+
var header = Prepare{
|
|
854
|
+
.cluster = cluster,
|
|
855
|
+
.size = @sizeOf(Header),
|
|
856
|
+
.release = vsr.Release.zero,
|
|
857
|
+
.command = .prepare,
|
|
858
|
+
.operation = .root,
|
|
859
|
+
.op = 0,
|
|
860
|
+
.view = 0,
|
|
861
|
+
.request_checksum = 0,
|
|
862
|
+
.checkpoint_id = 0,
|
|
863
|
+
.parent = 0,
|
|
864
|
+
.client = 0,
|
|
865
|
+
.commit = 0,
|
|
866
|
+
.timestamp = 0,
|
|
867
|
+
.request = 0,
|
|
868
|
+
};
|
|
869
|
+
header.set_checksum_body(&[0]u8{});
|
|
870
|
+
header.set_checksum();
|
|
871
|
+
assert(header.invalid() == null);
|
|
872
|
+
return header;
|
|
873
|
+
}
|
|
874
|
+
};
|
|
875
|
+
|
|
876
|
+
pub const PrepareOk = extern struct {
|
|
877
|
+
checksum: u128 = 0,
|
|
878
|
+
checksum_padding: u128 = 0,
|
|
879
|
+
checksum_body: u128 = 0,
|
|
880
|
+
checksum_body_padding: u128 = 0,
|
|
881
|
+
nonce_reserved: u128 = 0,
|
|
882
|
+
cluster: u128,
|
|
883
|
+
size: u32 = @sizeOf(Header),
|
|
884
|
+
epoch: u32 = 0,
|
|
885
|
+
view: u32,
|
|
886
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
887
|
+
protocol: u16 = vsr.Version,
|
|
888
|
+
command: Command,
|
|
889
|
+
replica: u8,
|
|
890
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
891
|
+
|
|
892
|
+
/// The previous prepare's checksum.
|
|
893
|
+
/// (Same as the corresponding Prepare's `parent`.)
|
|
894
|
+
parent: u128,
|
|
895
|
+
parent_padding: u128 = 0,
|
|
896
|
+
/// The corresponding prepare's checksum.
|
|
897
|
+
prepare_checksum: u128,
|
|
898
|
+
prepare_checksum_padding: u128 = 0,
|
|
899
|
+
/// The corresponding prepare's checkpoint_id.
|
|
900
|
+
checkpoint_id: u128,
|
|
901
|
+
client: u128,
|
|
902
|
+
op: u64,
|
|
903
|
+
commit_min: u64,
|
|
904
|
+
timestamp: u64,
|
|
905
|
+
request: u32,
|
|
906
|
+
operation: Operation = .reserved,
|
|
907
|
+
reserved: [3]u8 = @splat(0),
|
|
908
|
+
|
|
909
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
910
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
911
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
912
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
913
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
914
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
915
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
916
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
917
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
918
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
919
|
+
|
|
920
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
921
|
+
assert(self.command == .prepare_ok);
|
|
922
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
923
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
924
|
+
if (self.release.value != 0) return "release != 0";
|
|
925
|
+
if (self.prepare_checksum_padding != 0) return "prepare_checksum_padding != 0";
|
|
926
|
+
switch (self.operation) {
|
|
927
|
+
.reserved => return "operation == .reserved",
|
|
928
|
+
.root => {
|
|
929
|
+
const root_checksum = Header.Prepare.root(self.cluster).checksum;
|
|
930
|
+
if (self.parent != 0) return "root: parent != 0";
|
|
931
|
+
if (self.client != 0) return "root: client != 0";
|
|
932
|
+
if (self.prepare_checksum != root_checksum) {
|
|
933
|
+
return "root: prepare_checksum != expected";
|
|
934
|
+
}
|
|
935
|
+
if (self.request != 0) return "root: request != 0";
|
|
936
|
+
if (self.op != 0) return "root: op != 0";
|
|
937
|
+
if (self.timestamp != 0) return "root: timestamp != 0";
|
|
938
|
+
},
|
|
939
|
+
else => {
|
|
940
|
+
if (self.operation == .upgrade or
|
|
941
|
+
self.operation == .pulse)
|
|
942
|
+
{
|
|
943
|
+
if (self.client != 0) return "client != 0";
|
|
944
|
+
} else {
|
|
945
|
+
if (self.client == 0) return "client == 0";
|
|
946
|
+
}
|
|
947
|
+
if (self.op == 0) return "op == 0";
|
|
948
|
+
if (self.timestamp == 0) return "timestamp == 0";
|
|
949
|
+
if (self.operation == .register or
|
|
950
|
+
self.operation == .upgrade)
|
|
951
|
+
{
|
|
952
|
+
if (self.request != 0) return "request != 0";
|
|
953
|
+
} else if (self.client == 0) {
|
|
954
|
+
if (self.request != 0) return "request != 0";
|
|
955
|
+
} else {
|
|
956
|
+
if (self.request == 0) return "request == 0";
|
|
957
|
+
}
|
|
958
|
+
},
|
|
959
|
+
}
|
|
960
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
961
|
+
return null;
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
pub const Reply = extern struct {
|
|
966
|
+
checksum: u128 = 0,
|
|
967
|
+
checksum_padding: u128 = 0,
|
|
968
|
+
checksum_body: u128 = 0,
|
|
969
|
+
checksum_body_padding: u128 = 0,
|
|
970
|
+
nonce_reserved: u128 = 0,
|
|
971
|
+
cluster: u128,
|
|
972
|
+
size: u32 = @sizeOf(Header),
|
|
973
|
+
epoch: u32 = 0,
|
|
974
|
+
view: u32,
|
|
975
|
+
/// The corresponding Request's (and Prepare's, and client's) release version.
|
|
976
|
+
/// `Reply.release` matches `Request.release` (rather than the cluster release):
|
|
977
|
+
/// - to serve as an escape hatch if state machines ever need to branch on client release.
|
|
978
|
+
/// - to emphasize that the reply's format must be compatible with the client's version –
|
|
979
|
+
/// which is potentially behind the cluster's version when the prepare commits.
|
|
980
|
+
release: vsr.Release,
|
|
981
|
+
protocol: u16 = vsr.Version,
|
|
982
|
+
command: Command,
|
|
983
|
+
replica: u8,
|
|
984
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
985
|
+
|
|
986
|
+
/// The checksum of the corresponding Request.
|
|
987
|
+
request_checksum: u128,
|
|
988
|
+
request_checksum_padding: u128 = 0,
|
|
989
|
+
/// The checksum to be included with the next request as parent checksum.
|
|
990
|
+
/// It's almost exactly the same as entire header's checksum, except that it is computed
|
|
991
|
+
/// with a fixed view and remains stable if reply is retransmitted in a newer view.
|
|
992
|
+
/// This allows for strong guarantees beyond request, op, and commit numbers, which
|
|
993
|
+
/// have low entropy and may otherwise collide in the event of any correctness bugs.
|
|
994
|
+
context: u128 = 0,
|
|
995
|
+
context_padding: u128 = 0,
|
|
996
|
+
client: u128,
|
|
997
|
+
op: u64,
|
|
998
|
+
commit: u64,
|
|
999
|
+
/// The corresponding `prepare`'s timestamp.
|
|
1000
|
+
/// This allows the test workload to verify transfer timeouts.
|
|
1001
|
+
timestamp: u64,
|
|
1002
|
+
request: u32,
|
|
1003
|
+
operation: Operation = .reserved,
|
|
1004
|
+
reserved: [19]u8 = @splat(0),
|
|
1005
|
+
|
|
1006
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1007
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1008
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1009
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1010
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1011
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1012
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1013
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1014
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1015
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1016
|
+
|
|
1017
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1018
|
+
assert(self.command == .reply);
|
|
1019
|
+
if (self.release.value == 0) return "release == 0";
|
|
1020
|
+
// Initialization within `client.zig` asserts that client `id` is greater than zero:
|
|
1021
|
+
if (self.client == 0) return "client == 0";
|
|
1022
|
+
if (self.request_checksum_padding != 0) return "request_checksum_padding != 0";
|
|
1023
|
+
if (self.context_padding != 0) return "context_padding != 0";
|
|
1024
|
+
if (self.op != self.commit) return "op != commit";
|
|
1025
|
+
if (self.timestamp == 0) return "timestamp == 0";
|
|
1026
|
+
if (self.operation == .register) {
|
|
1027
|
+
if (self.size != @sizeOf(Header) + @sizeOf(vsr.RegisterResult)) {
|
|
1028
|
+
return "register: size != @sizeOf(Header) + @sizeOf(vsr.RegisterResult)";
|
|
1029
|
+
}
|
|
1030
|
+
// In this context, the commit number is the newly registered session number.
|
|
1031
|
+
// The `0` commit number is reserved for cluster initialization.
|
|
1032
|
+
if (self.commit == 0) return "commit == 0";
|
|
1033
|
+
if (self.request != 0) return "request != 0";
|
|
1034
|
+
} else {
|
|
1035
|
+
if (self.commit == 0) return "commit == 0";
|
|
1036
|
+
if (self.request == 0) return "request == 0";
|
|
1037
|
+
}
|
|
1038
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1039
|
+
return null;
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
pub const Commit = extern struct {
|
|
1044
|
+
checksum: u128 = 0,
|
|
1045
|
+
checksum_padding: u128 = 0,
|
|
1046
|
+
checksum_body: u128 = 0,
|
|
1047
|
+
checksum_body_padding: u128 = 0,
|
|
1048
|
+
nonce_reserved: u128 = 0,
|
|
1049
|
+
cluster: u128,
|
|
1050
|
+
size: u32 = @sizeOf(Header),
|
|
1051
|
+
epoch: u32 = 0,
|
|
1052
|
+
view: u32,
|
|
1053
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1054
|
+
protocol: u16 = vsr.Version,
|
|
1055
|
+
command: Command,
|
|
1056
|
+
replica: u8,
|
|
1057
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1058
|
+
|
|
1059
|
+
/// The latest committed prepare's checksum.
|
|
1060
|
+
commit_checksum: u128,
|
|
1061
|
+
commit_checksum_padding: u128 = 0,
|
|
1062
|
+
|
|
1063
|
+
/// Current checkpoint id.
|
|
1064
|
+
checkpoint_id: u128,
|
|
1065
|
+
|
|
1066
|
+
/// Current checkpoint op.
|
|
1067
|
+
checkpoint_op: u64,
|
|
1068
|
+
|
|
1069
|
+
/// The latest committed prepare's op.
|
|
1070
|
+
commit: u64,
|
|
1071
|
+
|
|
1072
|
+
timestamp_monotonic: u64,
|
|
1073
|
+
|
|
1074
|
+
reserved: [56]u8 = @splat(0),
|
|
1075
|
+
|
|
1076
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1077
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1078
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1079
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1080
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1081
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1082
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1083
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1084
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1085
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1086
|
+
|
|
1087
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1088
|
+
assert(self.command == .commit);
|
|
1089
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
1090
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
1091
|
+
if (self.release.value != 0) return "release != 0";
|
|
1092
|
+
if (self.commit < self.checkpoint_op) return "commit < checkpoint_op";
|
|
1093
|
+
if (self.timestamp_monotonic == 0) return "timestamp_monotonic == 0";
|
|
1094
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1095
|
+
return null;
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
|
|
1099
|
+
pub const StartViewChange = extern struct {
|
|
1100
|
+
checksum: u128 = 0,
|
|
1101
|
+
checksum_padding: u128 = 0,
|
|
1102
|
+
checksum_body: u128 = 0,
|
|
1103
|
+
checksum_body_padding: u128 = 0,
|
|
1104
|
+
nonce_reserved: u128 = 0,
|
|
1105
|
+
cluster: u128,
|
|
1106
|
+
size: u32 = @sizeOf(Header),
|
|
1107
|
+
epoch: u32 = 0,
|
|
1108
|
+
view: u32,
|
|
1109
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1110
|
+
protocol: u16 = vsr.Version,
|
|
1111
|
+
command: Command,
|
|
1112
|
+
replica: u8,
|
|
1113
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1114
|
+
|
|
1115
|
+
reserved: [128]u8 = @splat(0),
|
|
1116
|
+
|
|
1117
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1118
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1119
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1120
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1121
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1122
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1123
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1124
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1125
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1126
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1127
|
+
|
|
1128
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1129
|
+
assert(self.command == .start_view_change);
|
|
1130
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
1131
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
1132
|
+
if (self.release.value != 0) return "release != 0";
|
|
1133
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1134
|
+
return null;
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
|
|
1138
|
+
pub const DoViewChange = extern struct {
|
|
1139
|
+
checksum: u128 = 0,
|
|
1140
|
+
checksum_padding: u128 = 0,
|
|
1141
|
+
checksum_body: u128 = 0,
|
|
1142
|
+
checksum_body_padding: u128 = 0,
|
|
1143
|
+
nonce_reserved: u128 = 0,
|
|
1144
|
+
cluster: u128,
|
|
1145
|
+
size: u32 = @sizeOf(Header),
|
|
1146
|
+
epoch: u32 = 0,
|
|
1147
|
+
view: u32,
|
|
1148
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1149
|
+
protocol: u16 = vsr.Version,
|
|
1150
|
+
command: Command,
|
|
1151
|
+
replica: u8,
|
|
1152
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1153
|
+
|
|
1154
|
+
/// A bitset of "present" prepares. If a bit is set, then the corresponding header is not
|
|
1155
|
+
/// "blank", the replica has the prepare, and the prepare is not known to be faulty.
|
|
1156
|
+
present_bitset: u128,
|
|
1157
|
+
/// A bitset, with set bits indicating headers in the message body which it has definitely
|
|
1158
|
+
/// not prepared (i.e. "nack"). The corresponding header may be an actual prepare header, or
|
|
1159
|
+
/// it may be a "blank" header.
|
|
1160
|
+
nack_bitset: u128,
|
|
1161
|
+
op: u64,
|
|
1162
|
+
/// Set to `commit_min`, to indicate the sending replica's progress.
|
|
1163
|
+
/// The sending replica may continue to commit after sending the DVC.
|
|
1164
|
+
commit_min: u64,
|
|
1165
|
+
checkpoint_op: u64,
|
|
1166
|
+
log_view: u32,
|
|
1167
|
+
reserved: [68]u8 = @splat(0),
|
|
1168
|
+
|
|
1169
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1170
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1171
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1172
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1173
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1174
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1175
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1176
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1177
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1178
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1179
|
+
|
|
1180
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1181
|
+
assert(self.command == .do_view_change);
|
|
1182
|
+
if ((self.size - @sizeOf(Header)) % @sizeOf(Header) != 0) {
|
|
1183
|
+
return "size multiple invalid";
|
|
1184
|
+
}
|
|
1185
|
+
if (self.release.value != 0) return "release != 0";
|
|
1186
|
+
if (self.op < self.commit_min) return "op < commit_min";
|
|
1187
|
+
if (self.commit_min < self.checkpoint_op) return "commit_min < checkpoint_op";
|
|
1188
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1189
|
+
return null;
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
|
|
1193
|
+
pub const StartView = extern struct {
|
|
1194
|
+
checksum: u128 = 0,
|
|
1195
|
+
checksum_padding: u128 = 0,
|
|
1196
|
+
checksum_body: u128 = 0,
|
|
1197
|
+
checksum_body_padding: u128 = 0,
|
|
1198
|
+
nonce_reserved: u128 = 0,
|
|
1199
|
+
cluster: u128,
|
|
1200
|
+
size: u32 = @sizeOf(Header),
|
|
1201
|
+
epoch: u32 = 0,
|
|
1202
|
+
view: u32,
|
|
1203
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1204
|
+
protocol: u16 = vsr.Version,
|
|
1205
|
+
command: Command,
|
|
1206
|
+
replica: u8,
|
|
1207
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1208
|
+
|
|
1209
|
+
/// Set to zero for a new view, and to a nonce from an RSV when responding to the RSV.
|
|
1210
|
+
nonce: u128,
|
|
1211
|
+
op: u64,
|
|
1212
|
+
/// Equal to `commit_min` if the SV message is being sent by a .normal primary, but may not
|
|
1213
|
+
/// be equal if the SV message is being sent by potential primary in .view_change status.
|
|
1214
|
+
commit_max: u64,
|
|
1215
|
+
/// The replica's `op_checkpoint`.
|
|
1216
|
+
checkpoint_op: u64,
|
|
1217
|
+
reserved: [88]u8 = @splat(0),
|
|
1218
|
+
|
|
1219
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1220
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1221
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1222
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1223
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1224
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1225
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1226
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1227
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1228
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1229
|
+
|
|
1230
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1231
|
+
assert(self.command == .start_view);
|
|
1232
|
+
const body_size = self.size - @sizeOf(Header);
|
|
1233
|
+
if (body_size < @sizeOf(vsr.CheckpointState)) return "checkpointstate missing";
|
|
1234
|
+
const headers_size = body_size - @sizeOf(vsr.CheckpointState);
|
|
1235
|
+
if (headers_size % @sizeOf(Header) != 0) {
|
|
1236
|
+
return "headers size multiple invalid";
|
|
1237
|
+
}
|
|
1238
|
+
if (self.release.value != 0) return "release != 0";
|
|
1239
|
+
if (self.op < self.commit_max) return "op < commit_max";
|
|
1240
|
+
if (self.commit_max < self.checkpoint_op) return "commit_max < checkpoint_op";
|
|
1241
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1242
|
+
return null;
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
|
|
1246
|
+
pub const RequestStartView = extern struct {
|
|
1247
|
+
checksum: u128 = 0,
|
|
1248
|
+
checksum_padding: u128 = 0,
|
|
1249
|
+
checksum_body: u128 = 0,
|
|
1250
|
+
checksum_body_padding: u128 = 0,
|
|
1251
|
+
nonce_reserved: u128 = 0,
|
|
1252
|
+
cluster: u128,
|
|
1253
|
+
size: u32 = @sizeOf(Header),
|
|
1254
|
+
epoch: u32 = 0,
|
|
1255
|
+
view: u32,
|
|
1256
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1257
|
+
protocol: u16 = vsr.Version,
|
|
1258
|
+
command: Command,
|
|
1259
|
+
replica: u8,
|
|
1260
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1261
|
+
|
|
1262
|
+
nonce: u128,
|
|
1263
|
+
reserved: [112]u8 = @splat(0),
|
|
1264
|
+
|
|
1265
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1266
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1267
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1268
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1269
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1270
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1271
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1272
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1273
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1274
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1275
|
+
|
|
1276
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1277
|
+
assert(self.command == .request_start_view);
|
|
1278
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
1279
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
1280
|
+
if (self.release.value != 0) return "release != 0";
|
|
1281
|
+
if (self.nonce == 0) return "nonce == 0";
|
|
1282
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1283
|
+
return null;
|
|
1284
|
+
}
|
|
1285
|
+
};
|
|
1286
|
+
|
|
1287
|
+
pub const RequestHeaders = extern struct {
|
|
1288
|
+
checksum: u128 = 0,
|
|
1289
|
+
checksum_padding: u128 = 0,
|
|
1290
|
+
checksum_body: u128 = 0,
|
|
1291
|
+
checksum_body_padding: u128 = 0,
|
|
1292
|
+
nonce_reserved: u128 = 0,
|
|
1293
|
+
cluster: u128,
|
|
1294
|
+
size: u32 = @sizeOf(Header),
|
|
1295
|
+
epoch: u32 = 0,
|
|
1296
|
+
view: u32 = 0, // Always 0.
|
|
1297
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1298
|
+
protocol: u16 = vsr.Version,
|
|
1299
|
+
command: Command,
|
|
1300
|
+
replica: u8,
|
|
1301
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1302
|
+
|
|
1303
|
+
/// The minimum op requested (inclusive).
|
|
1304
|
+
op_min: u64,
|
|
1305
|
+
/// The maximum op requested (inclusive).
|
|
1306
|
+
op_max: u64,
|
|
1307
|
+
reserved: [112]u8 = @splat(0),
|
|
1308
|
+
|
|
1309
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1310
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1311
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1312
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1313
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1314
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1315
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1316
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1317
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1318
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1319
|
+
|
|
1320
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1321
|
+
assert(self.command == .request_headers);
|
|
1322
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
1323
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
1324
|
+
if (self.view != 0) return "view == 0";
|
|
1325
|
+
if (self.release.value != 0) return "release != 0";
|
|
1326
|
+
if (self.op_min > self.op_max) return "op_min > op_max";
|
|
1327
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1328
|
+
return null;
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
pub const RequestPrepare = extern struct {
|
|
1333
|
+
checksum: u128 = 0,
|
|
1334
|
+
checksum_padding: u128 = 0,
|
|
1335
|
+
checksum_body: u128 = 0,
|
|
1336
|
+
checksum_body_padding: u128 = 0,
|
|
1337
|
+
nonce_reserved: u128 = 0,
|
|
1338
|
+
cluster: u128,
|
|
1339
|
+
size: u32 = @sizeOf(Header),
|
|
1340
|
+
epoch: u32 = 0,
|
|
1341
|
+
view: u32,
|
|
1342
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1343
|
+
protocol: u16 = vsr.Version,
|
|
1344
|
+
command: Command,
|
|
1345
|
+
replica: u8,
|
|
1346
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1347
|
+
|
|
1348
|
+
prepare_checksum: u128,
|
|
1349
|
+
prepare_checksum_padding: u128 = 0,
|
|
1350
|
+
prepare_op: u64,
|
|
1351
|
+
reserved: [88]u8 = @splat(0),
|
|
1352
|
+
|
|
1353
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1354
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1355
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1356
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1357
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1358
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1359
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1360
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1361
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1362
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1363
|
+
|
|
1364
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1365
|
+
assert(self.command == .request_prepare);
|
|
1366
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
1367
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
1368
|
+
if (self.view != 0 and self.prepare_checksum != 0) return "view != 0 and checksum != 0";
|
|
1369
|
+
if (self.release.value != 0) return "release != 0";
|
|
1370
|
+
if (self.prepare_checksum_padding != 0) return "prepare_checksum_padding != 0";
|
|
1371
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1372
|
+
return null;
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
pub const RequestReply = extern struct {
|
|
1377
|
+
checksum: u128 = 0,
|
|
1378
|
+
checksum_padding: u128 = 0,
|
|
1379
|
+
checksum_body: u128 = 0,
|
|
1380
|
+
checksum_body_padding: u128 = 0,
|
|
1381
|
+
nonce_reserved: u128 = 0,
|
|
1382
|
+
cluster: u128,
|
|
1383
|
+
size: u32 = @sizeOf(Header),
|
|
1384
|
+
epoch: u32 = 0,
|
|
1385
|
+
view: u32 = 0, // Always 0.
|
|
1386
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1387
|
+
protocol: u16 = vsr.Version,
|
|
1388
|
+
command: Command,
|
|
1389
|
+
replica: u8,
|
|
1390
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1391
|
+
|
|
1392
|
+
reply_checksum: u128,
|
|
1393
|
+
reply_checksum_padding: u128 = 0,
|
|
1394
|
+
reply_client: u128,
|
|
1395
|
+
reply_op: u64,
|
|
1396
|
+
reserved: [72]u8 = @splat(0),
|
|
1397
|
+
|
|
1398
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1399
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1400
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1401
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1402
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1403
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1404
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1405
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1406
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1407
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1408
|
+
|
|
1409
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1410
|
+
assert(self.command == .request_reply);
|
|
1411
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
1412
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
1413
|
+
if (self.release.value != 0) return "release != 0";
|
|
1414
|
+
if (self.reply_checksum_padding != 0) return "reply_checksum_padding != 0";
|
|
1415
|
+
if (self.view != 0) return "view == 0";
|
|
1416
|
+
if (self.reply_client == 0) return "reply_client == 0";
|
|
1417
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1418
|
+
return null;
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
|
|
1422
|
+
pub const Headers = extern struct {
|
|
1423
|
+
checksum: u128 = 0,
|
|
1424
|
+
checksum_padding: u128 = 0,
|
|
1425
|
+
checksum_body: u128 = 0,
|
|
1426
|
+
checksum_body_padding: u128 = 0,
|
|
1427
|
+
nonce_reserved: u128 = 0,
|
|
1428
|
+
cluster: u128,
|
|
1429
|
+
size: u32 = @sizeOf(Header),
|
|
1430
|
+
epoch: u32 = 0,
|
|
1431
|
+
view: u32,
|
|
1432
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1433
|
+
protocol: u16 = vsr.Version,
|
|
1434
|
+
command: Command,
|
|
1435
|
+
replica: u8,
|
|
1436
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1437
|
+
|
|
1438
|
+
reserved: [128]u8 = @splat(0),
|
|
1439
|
+
|
|
1440
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1441
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1442
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1443
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1444
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1445
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1446
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1447
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1448
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1449
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1450
|
+
|
|
1451
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1452
|
+
assert(self.command == .headers);
|
|
1453
|
+
if (self.size == @sizeOf(Header)) return "size == @sizeOf(Header)";
|
|
1454
|
+
if ((self.size - @sizeOf(Header)) % @sizeOf(Header) != 0) {
|
|
1455
|
+
return "size multiple invalid";
|
|
1456
|
+
}
|
|
1457
|
+
if (self.release.value != 0) return "release != 0";
|
|
1458
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1459
|
+
return null;
|
|
1460
|
+
}
|
|
1461
|
+
};
|
|
1462
|
+
|
|
1463
|
+
pub const Eviction = extern struct {
|
|
1464
|
+
checksum: u128 = 0,
|
|
1465
|
+
checksum_padding: u128 = 0,
|
|
1466
|
+
checksum_body: u128 = 0,
|
|
1467
|
+
checksum_body_padding: u128 = 0,
|
|
1468
|
+
nonce_reserved: u128 = 0,
|
|
1469
|
+
cluster: u128,
|
|
1470
|
+
size: u32 = @sizeOf(Header),
|
|
1471
|
+
epoch: u32 = 0,
|
|
1472
|
+
view: u32,
|
|
1473
|
+
release: vsr.Release,
|
|
1474
|
+
protocol: u16 = vsr.Version,
|
|
1475
|
+
command: Command,
|
|
1476
|
+
replica: u8,
|
|
1477
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1478
|
+
|
|
1479
|
+
client: u128,
|
|
1480
|
+
reserved: [111]u8 = @splat(0),
|
|
1481
|
+
reason: Reason,
|
|
1482
|
+
|
|
1483
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1484
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1485
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1486
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1487
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1488
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1489
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1490
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1491
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1492
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1493
|
+
|
|
1494
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1495
|
+
assert(self.command == .eviction);
|
|
1496
|
+
if (self.size != @sizeOf(Header)) return "size != @sizeOf(Header)";
|
|
1497
|
+
if (self.checksum_body != checksum_body_empty) return "checksum_body != expected";
|
|
1498
|
+
if (self.release.value == 0) return "release == 0";
|
|
1499
|
+
if (self.client == 0) return "client == 0";
|
|
1500
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1501
|
+
|
|
1502
|
+
const reasons = comptime std.enums.values(Reason);
|
|
1503
|
+
inline for (reasons) |reason| {
|
|
1504
|
+
if (@intFromEnum(self.reason) == @intFromEnum(reason)) break;
|
|
1505
|
+
} else return "reason invalid";
|
|
1506
|
+
if (self.reason == .reserved) return "reason == reserved";
|
|
1507
|
+
return null;
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
pub const Reason = enum(u8) {
|
|
1511
|
+
reserved = 0,
|
|
1512
|
+
no_session = 1,
|
|
1513
|
+
client_release_too_low = 2,
|
|
1514
|
+
client_release_too_high = 3,
|
|
1515
|
+
invalid_request_operation = 4,
|
|
1516
|
+
invalid_request_body = 5,
|
|
1517
|
+
invalid_request_body_size = 6,
|
|
1518
|
+
session_too_low = 7,
|
|
1519
|
+
session_release_mismatch = 8,
|
|
1520
|
+
|
|
1521
|
+
comptime {
|
|
1522
|
+
for (std.enums.values(Reason), 0..) |reason, index| {
|
|
1523
|
+
assert(@intFromEnum(reason) == index);
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
};
|
|
1527
|
+
};
|
|
1528
|
+
|
|
1529
|
+
pub const RequestBlocks = extern struct {
|
|
1530
|
+
checksum: u128 = 0,
|
|
1531
|
+
checksum_padding: u128 = 0,
|
|
1532
|
+
checksum_body: u128 = 0,
|
|
1533
|
+
checksum_body_padding: u128 = 0,
|
|
1534
|
+
nonce_reserved: u128 = 0,
|
|
1535
|
+
cluster: u128,
|
|
1536
|
+
size: u32 = @sizeOf(Header),
|
|
1537
|
+
epoch: u32 = 0,
|
|
1538
|
+
view: u32 = 0, // Always 0.
|
|
1539
|
+
release: vsr.Release = vsr.Release.zero, // Always 0.
|
|
1540
|
+
protocol: u16 = vsr.Version,
|
|
1541
|
+
command: Command,
|
|
1542
|
+
replica: u8,
|
|
1543
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1544
|
+
|
|
1545
|
+
reserved: [128]u8 = @splat(0),
|
|
1546
|
+
|
|
1547
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1548
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1549
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1550
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1551
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1552
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1553
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1554
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1555
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1556
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1557
|
+
|
|
1558
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1559
|
+
assert(self.command == .request_blocks);
|
|
1560
|
+
if (self.view != 0) return "view != 0";
|
|
1561
|
+
if (self.size == @sizeOf(Header)) return "size == @sizeOf(Header)";
|
|
1562
|
+
if ((self.size - @sizeOf(Header)) % @sizeOf(vsr.BlockRequest) != 0) {
|
|
1563
|
+
return "size multiple invalid";
|
|
1564
|
+
}
|
|
1565
|
+
if (self.release.value != 0) return "release != 0";
|
|
1566
|
+
if (!stdx.zeroed(&self.reserved)) return "reserved != 0";
|
|
1567
|
+
return null;
|
|
1568
|
+
}
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
pub const Block = extern struct {
|
|
1572
|
+
pub const metadata_size = 96;
|
|
1573
|
+
|
|
1574
|
+
checksum: u128 = 0,
|
|
1575
|
+
checksum_padding: u128 = 0,
|
|
1576
|
+
checksum_body: u128 = 0,
|
|
1577
|
+
checksum_body_padding: u128 = 0,
|
|
1578
|
+
nonce_reserved: u128 = 0,
|
|
1579
|
+
cluster: u128,
|
|
1580
|
+
size: u32 = @sizeOf(Header),
|
|
1581
|
+
epoch: u32 = 0,
|
|
1582
|
+
view: u32 = 0, // Always 0.
|
|
1583
|
+
/// The release that generated this block.
|
|
1584
|
+
release: vsr.Release,
|
|
1585
|
+
protocol: u16 = vsr.Version,
|
|
1586
|
+
command: Command,
|
|
1587
|
+
replica: u8 = 0, // Always 0.
|
|
1588
|
+
reserved_frame: [12]u8 = @splat(0),
|
|
1589
|
+
|
|
1590
|
+
// Schema is determined by `block_type`.
|
|
1591
|
+
metadata_bytes: [metadata_size]u8,
|
|
1592
|
+
|
|
1593
|
+
// Fields shared by all block types:
|
|
1594
|
+
address: u64,
|
|
1595
|
+
snapshot: u64,
|
|
1596
|
+
block_type: schema.BlockType,
|
|
1597
|
+
reserved_block: [15]u8 = @splat(0),
|
|
1598
|
+
|
|
1599
|
+
pub const frame = HeaderFunctionsType(@This()).frame;
|
|
1600
|
+
pub const frame_const = HeaderFunctionsType(@This()).frame_const;
|
|
1601
|
+
pub const invalid = HeaderFunctionsType(@This()).invalid;
|
|
1602
|
+
pub const calculate_checksum = HeaderFunctionsType(@This()).calculate_checksum;
|
|
1603
|
+
pub const calculate_checksum_body = HeaderFunctionsType(@This()).calculate_checksum_body;
|
|
1604
|
+
pub const set_checksum = HeaderFunctionsType(@This()).set_checksum;
|
|
1605
|
+
pub const set_checksum_body = HeaderFunctionsType(@This()).set_checksum_body;
|
|
1606
|
+
pub const valid_checksum = HeaderFunctionsType(@This()).valid_checksum;
|
|
1607
|
+
pub const valid_checksum_body = HeaderFunctionsType(@This()).valid_checksum_body;
|
|
1608
|
+
pub const format = HeaderFunctionsType(@This()).format;
|
|
1609
|
+
|
|
1610
|
+
fn invalid_header(self: *const @This()) ?[]const u8 {
|
|
1611
|
+
assert(self.command == .block);
|
|
1612
|
+
if (self.size > constants.block_size) return "size > block_size";
|
|
1613
|
+
if (self.size == @sizeOf(Header)) return "size = @sizeOf(Header)";
|
|
1614
|
+
if (self.view != 0) return "view != 0";
|
|
1615
|
+
if (self.release.value == 0) return "release == 0";
|
|
1616
|
+
if (self.replica != 0) return "replica != 0";
|
|
1617
|
+
if (self.address == 0) return "address == 0"; // address ≠ 0
|
|
1618
|
+
if (!self.block_type.valid()) return "block_type invalid";
|
|
1619
|
+
if (self.block_type == .reserved) return "block_type == .reserved";
|
|
1620
|
+
// TODO When manifest blocks include a snapshot, verify that snapshot≠0.
|
|
1621
|
+
return null;
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
};
|
|
1625
|
+
|
|
1626
|
+
/// Messages are printed fairly frequently, so we provide a custom formatting function:
|
|
1627
|
+
/// - checksums are printed in hex,
|
|
1628
|
+
/// - padding and reserved fields are skipped if they are zeroed-out.
|
|
1629
|
+
fn format_header(T: type, header: *const T, writer: anytype) !void {
|
|
1630
|
+
const simple_type_name = comptime name_blk: {
|
|
1631
|
+
const type_name = @typeName(T);
|
|
1632
|
+
const last_part_idx = std.mem.lastIndexOf(u8, type_name, ".");
|
|
1633
|
+
break :name_blk if (last_part_idx) |idx| type_name[idx + 1 ..] else type_name;
|
|
1634
|
+
};
|
|
1635
|
+
|
|
1636
|
+
try writer.writeAll(simple_type_name ++ "{");
|
|
1637
|
+
inline for (@typeInfo(T).@"struct".fields, 0..) |field, field_index| {
|
|
1638
|
+
comptime assert((field_index == 0) == std.mem.eql(u8, field.name, "checksum"));
|
|
1639
|
+
try format_header_field(field.name, field.type, &@field(header, field.name), writer);
|
|
1640
|
+
}
|
|
1641
|
+
try writer.writeAll(" }");
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1644
|
+
fn format_header_field(
|
|
1645
|
+
comptime field_name: []const u8,
|
|
1646
|
+
comptime T: type,
|
|
1647
|
+
field_value: *const T,
|
|
1648
|
+
writer: anytype,
|
|
1649
|
+
) !void {
|
|
1650
|
+
if (format_header_field_skip(field_name, T, field_value)) return;
|
|
1651
|
+
|
|
1652
|
+
const separator = comptime if (std.mem.eql(u8, field_name, "checksum")) " " else ", ";
|
|
1653
|
+
try writer.writeAll(separator ++ "." ++ field_name ++ "=");
|
|
1654
|
+
|
|
1655
|
+
if (T == u128) {
|
|
1656
|
+
// Exhaustively list all checksum and non-checksum fields.
|
|
1657
|
+
inline for (.{
|
|
1658
|
+
"checksum", "checksum_padding",
|
|
1659
|
+
"checksum_body", "checksum_body_padding",
|
|
1660
|
+
"prepare_checksum", "prepare_checksum_padding",
|
|
1661
|
+
"commit_checksum", "commit_checksum_padding",
|
|
1662
|
+
"request_checksum", "request_checksum_padding",
|
|
1663
|
+
"reply_checksum", "reply_checksum_padding",
|
|
1664
|
+
"parent", "parent_padding",
|
|
1665
|
+
"context", "context_padding",
|
|
1666
|
+
"checkpoint_id",
|
|
1667
|
+
}) |field_name_checksum| {
|
|
1668
|
+
if (comptime std.mem.eql(u8, field_name, field_name_checksum)) {
|
|
1669
|
+
return try writer.print("{x:0>32}", .{field_value.*});
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
inline for (.{
|
|
1673
|
+
"cluster", "client",
|
|
1674
|
+
"present_bitset", "nack_bitset",
|
|
1675
|
+
"nonce", "nonce_reserved",
|
|
1676
|
+
"reply_client",
|
|
1677
|
+
}) |field_name_non_checksum| {
|
|
1678
|
+
if (comptime std.mem.eql(u8, field_name, field_name_non_checksum)) {
|
|
1679
|
+
return try writer.print("{d}", .{field_value.*});
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
@compileError("unhandled field: " ++ field_name);
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
try writer.print("{any}", .{field_value.*});
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
fn format_header_field_skip(
|
|
1689
|
+
comptime field_name: []const u8,
|
|
1690
|
+
comptime T: type,
|
|
1691
|
+
field_value: *const T,
|
|
1692
|
+
) bool {
|
|
1693
|
+
if (comptime std.mem.startsWith(u8, field_name, "reserved") or
|
|
1694
|
+
std.mem.endsWith(u8, field_name, "reserved") or
|
|
1695
|
+
std.mem.endsWith(u8, field_name, "padding"))
|
|
1696
|
+
{
|
|
1697
|
+
return if (@typeInfo(T) == .int) field_value.* == 0 else stdx.zeroed(field_value);
|
|
1698
|
+
} else {
|
|
1699
|
+
return false;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
// Verify each Command's header type.
|
|
1704
|
+
comptime {
|
|
1705
|
+
@setEvalBranchQuota(20_000);
|
|
1706
|
+
|
|
1707
|
+
for (std.enums.values(Command)) |command| {
|
|
1708
|
+
const CommandHeader = Header.Type(command);
|
|
1709
|
+
assert(@sizeOf(CommandHeader) == @sizeOf(Header));
|
|
1710
|
+
assert(@alignOf(CommandHeader) == @alignOf(Header));
|
|
1711
|
+
assert(@typeInfo(CommandHeader) == .@"struct");
|
|
1712
|
+
assert(@typeInfo(CommandHeader).@"struct".layout == .@"extern");
|
|
1713
|
+
assert(stdx.no_padding(CommandHeader));
|
|
1714
|
+
|
|
1715
|
+
// Verify that the command's header's frame is identical to Header's.
|
|
1716
|
+
for (std.meta.fields(Header)) |header_field| {
|
|
1717
|
+
if (std.mem.eql(u8, header_field.name, "reserved_command")) {
|
|
1718
|
+
assert(std.meta.fieldIndex(CommandHeader, header_field.name) == null);
|
|
1719
|
+
} else {
|
|
1720
|
+
const command_field_index = std.meta.fieldIndex(CommandHeader, header_field.name).?;
|
|
1721
|
+
const command_field = std.meta.fields(CommandHeader)[command_field_index];
|
|
1722
|
+
assert(command_field.type == header_field.type);
|
|
1723
|
+
assert(command_field.alignment == header_field.alignment);
|
|
1724
|
+
assert(@offsetOf(CommandHeader, command_field.name) ==
|
|
1725
|
+
@offsetOf(Header, header_field.name));
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
// Verify that the command's header's re-exports all Header's functions.
|
|
1730
|
+
const HeaderFunctions = Header.HeaderFunctionsType(CommandHeader);
|
|
1731
|
+
for (@typeInfo(HeaderFunctions).@"struct".decls) |decl| {
|
|
1732
|
+
assert(@hasDecl(CommandHeader, decl.name));
|
|
1733
|
+
|
|
1734
|
+
const a = @field(CommandHeader, decl.name);
|
|
1735
|
+
const b = @field(HeaderFunctions, decl.name);
|
|
1736
|
+
assert(a == b);
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
const Snap = stdx.Snap;
|
|
1742
|
+
const module_path = "src";
|
|
1743
|
+
const snap = Snap.snap_fn(module_path);
|
|
1744
|
+
|
|
1745
|
+
test format_header {
|
|
1746
|
+
var prepare = Header.Prepare{
|
|
1747
|
+
.checksum = 0x0123456789ABCDEF,
|
|
1748
|
+
.checksum_body = 0xFEDCBA9876543210,
|
|
1749
|
+
.cluster = 1,
|
|
1750
|
+
.size = 321,
|
|
1751
|
+
.view = 2,
|
|
1752
|
+
.release = vsr.Release.zero,
|
|
1753
|
+
.command = .prepare,
|
|
1754
|
+
.replica = 3,
|
|
1755
|
+
.parent = 0xABCDEFFEDCBA00123456789,
|
|
1756
|
+
.request_checksum = 0x12345678987654321,
|
|
1757
|
+
.checkpoint_id = 4,
|
|
1758
|
+
.client = 5,
|
|
1759
|
+
.op = 5,
|
|
1760
|
+
.commit = 6,
|
|
1761
|
+
.timestamp = 123456789,
|
|
1762
|
+
.request = 7,
|
|
1763
|
+
.operation = .pulse,
|
|
1764
|
+
};
|
|
1765
|
+
|
|
1766
|
+
try snap(@src(),
|
|
1767
|
+
\\Prepare{ .checksum=00000000000000000123456789abcdef, .checksum_body=0000000000000000fedcba9876543210, .cluster=1, .size=321, .epoch=0, .view=2, .release=0.0.0, .protocol=0, .command=vsr.Command.prepare, .replica=3, .parent=000000000abcdeffedcba00123456789, .request_checksum=00000000000000012345678987654321, .checkpoint_id=00000000000000000000000000000004, .client=5, .op=5, .commit=6, .timestamp=123456789, .request=7, .operation=vsr.Operation.pulse }
|
|
1768
|
+
).diff_fmt("{}", .{prepare});
|
|
1769
|
+
|
|
1770
|
+
// Check that non-zero padding/reserved fields are printed.
|
|
1771
|
+
prepare.checksum_padding = 1;
|
|
1772
|
+
prepare.reserved_frame[0] = 2;
|
|
1773
|
+
prepare.reserved[0] = 3;
|
|
1774
|
+
try snap(@src(),
|
|
1775
|
+
\\Prepare{ .checksum=00000000000000000123456789abcdef, .checksum_padding=00000000000000000000000000000001, .checksum_body=0000000000000000fedcba9876543210, .cluster=1, .size=321, .epoch=0, .view=2, .release=0.0.0, .protocol=0, .command=vsr.Command.prepare, .replica=3, .reserved_frame={ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, .parent=000000000abcdeffedcba00123456789, .request_checksum=00000000000000012345678987654321, .checkpoint_id=00000000000000000000000000000004, .client=5, .op=5, .commit=6, .timestamp=123456789, .request=7, .operation=vsr.Operation.pulse, .reserved={ 3, 0, 0 } }
|
|
1776
|
+
).diff_fmt("{}", .{prepare});
|
|
1777
|
+
}
|