tigerbeetle-node 0.11.4 → 0.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/.client.node.sha256 +1 -1
  2. package/dist/index.d.ts +41 -42
  3. package/dist/index.js +41 -42
  4. package/dist/index.js.map +1 -1
  5. package/package.json +2 -2
  6. package/src/index.ts +0 -1
  7. package/src/node.zig +5 -5
  8. package/src/tigerbeetle/scripts/benchmark.bat +6 -1
  9. package/src/tigerbeetle/scripts/benchmark.sh +1 -1
  10. package/src/tigerbeetle/src/benchmark.zig +4 -4
  11. package/src/tigerbeetle/src/c/tb_client/context.zig +6 -6
  12. package/src/tigerbeetle/src/c/tb_client/echo_client.zig +2 -2
  13. package/src/tigerbeetle/src/c/tb_client/thread.zig +0 -1
  14. package/src/tigerbeetle/src/c/tb_client.h +42 -43
  15. package/src/tigerbeetle/src/c/tb_client.zig +2 -2
  16. package/src/tigerbeetle/src/c/test.zig +8 -8
  17. package/src/tigerbeetle/src/cli.zig +41 -17
  18. package/src/tigerbeetle/src/config.zig +24 -3
  19. package/src/tigerbeetle/src/constants.zig +8 -5
  20. package/src/tigerbeetle/src/demo.zig +4 -4
  21. package/src/tigerbeetle/src/io/darwin.zig +4 -4
  22. package/src/tigerbeetle/src/io/linux.zig +6 -6
  23. package/src/tigerbeetle/src/io/windows.zig +4 -4
  24. package/src/tigerbeetle/src/lsm/compaction.zig +17 -51
  25. package/src/tigerbeetle/src/lsm/forest.zig +2 -2
  26. package/src/tigerbeetle/src/lsm/forest_fuzz.zig +11 -16
  27. package/src/tigerbeetle/src/lsm/grid.zig +5 -5
  28. package/src/tigerbeetle/src/lsm/groove.zig +7 -4
  29. package/src/tigerbeetle/src/lsm/level_iterator.zig +2 -2
  30. package/src/tigerbeetle/src/lsm/manifest.zig +19 -18
  31. package/src/tigerbeetle/src/lsm/manifest_level.zig +3 -2
  32. package/src/tigerbeetle/src/lsm/manifest_log.zig +8 -8
  33. package/src/tigerbeetle/src/lsm/manifest_log_fuzz.zig +31 -15
  34. package/src/tigerbeetle/src/lsm/merge_iterator.zig +106 -0
  35. package/src/tigerbeetle/src/lsm/posted_groove.zig +4 -3
  36. package/src/tigerbeetle/src/lsm/segmented_array.zig +1 -0
  37. package/src/tigerbeetle/src/lsm/segmented_array_benchmark.zig +13 -13
  38. package/src/tigerbeetle/src/lsm/set_associative_cache.zig +2 -2
  39. package/src/tigerbeetle/src/lsm/table.zig +33 -19
  40. package/src/tigerbeetle/src/lsm/table_immutable.zig +4 -4
  41. package/src/tigerbeetle/src/lsm/table_iterator.zig +19 -11
  42. package/src/tigerbeetle/src/lsm/table_mutable.zig +52 -18
  43. package/src/tigerbeetle/src/lsm/test.zig +14 -10
  44. package/src/tigerbeetle/src/lsm/tree.zig +48 -45
  45. package/src/tigerbeetle/src/lsm/tree_fuzz.zig +310 -271
  46. package/src/tigerbeetle/src/main.zig +40 -36
  47. package/src/tigerbeetle/src/message_bus.zig +25 -25
  48. package/src/tigerbeetle/src/message_pool.zig +18 -17
  49. package/src/tigerbeetle/src/simulator.zig +28 -83
  50. package/src/tigerbeetle/src/{test/accounting → state_machine}/auditor.zig +9 -9
  51. package/src/tigerbeetle/src/{test/accounting → state_machine}/workload.zig +112 -52
  52. package/src/tigerbeetle/src/state_machine.zig +20 -14
  53. package/src/tigerbeetle/src/storage.zig +12 -12
  54. package/src/tigerbeetle/src/test/cluster.zig +17 -17
  55. package/src/tigerbeetle/src/test/conductor.zig +8 -8
  56. package/src/tigerbeetle/src/test/id.zig +10 -0
  57. package/src/tigerbeetle/src/test/message_bus.zig +0 -2
  58. package/src/tigerbeetle/src/test/network.zig +5 -5
  59. package/src/tigerbeetle/src/test/state_checker.zig +2 -2
  60. package/src/tigerbeetle/src/test/state_machine.zig +151 -46
  61. package/src/tigerbeetle/src/test/storage.zig +54 -51
  62. package/src/tigerbeetle/src/test/storage_checker.zig +3 -3
  63. package/src/tigerbeetle/src/tigerbeetle.zig +0 -1
  64. package/src/tigerbeetle/src/time.zig +0 -1
  65. package/src/tigerbeetle/src/tracer.zig +4 -4
  66. package/src/tigerbeetle/src/unit_tests.zig +2 -2
  67. package/src/tigerbeetle/src/vsr/client.zig +10 -10
  68. package/src/tigerbeetle/src/vsr/clock.zig +11 -10
  69. package/src/tigerbeetle/src/vsr/journal.zig +581 -531
  70. package/src/tigerbeetle/src/vsr/journal_format_fuzz.zig +11 -11
  71. package/src/tigerbeetle/src/vsr/replica.zig +377 -367
  72. package/src/tigerbeetle/src/vsr/replica_format.zig +14 -11
  73. package/src/tigerbeetle/src/vsr/superblock.zig +125 -80
  74. package/src/tigerbeetle/src/vsr/superblock_client_table.zig +9 -9
  75. package/src/tigerbeetle/src/vsr/superblock_free_set.zig +4 -4
  76. package/src/tigerbeetle/src/vsr/superblock_fuzz.zig +11 -6
  77. package/src/tigerbeetle/src/vsr/superblock_manifest.zig +5 -5
  78. package/src/tigerbeetle/src/vsr/superblock_quorums_fuzz.zig +3 -3
  79. package/src/tigerbeetle/src/vsr.zig +25 -25
@@ -11,6 +11,8 @@ test {
11
11
  //_ = @import("vsr/clock.zig");
12
12
 
13
13
  _ = @import("state_machine.zig");
14
+ _ = @import("state_machine/auditor.zig");
15
+ _ = @import("state_machine/workload.zig");
14
16
 
15
17
  _ = @import("fifo.zig");
16
18
  _ = @import("ring_buffer.zig");
@@ -30,8 +32,6 @@ test {
30
32
  _ = @import("lsm/segmented_array.zig");
31
33
 
32
34
  _ = @import("test/id.zig");
33
- _ = @import("test/accounting/auditor.zig");
34
- _ = @import("test/accounting/workload.zig");
35
35
  _ = @import("test/storage.zig");
36
36
  _ = @import("test/table.zig");
37
37
  }
@@ -2,7 +2,7 @@ const std = @import("std");
2
2
  const assert = std.debug.assert;
3
3
  const mem = std.mem;
4
4
 
5
- const config = @import("../constants.zig");
5
+ const constants = @import("../constants.zig");
6
6
  const vsr = @import("../vsr.zig");
7
7
  const Header = vsr.Header;
8
8
 
@@ -64,19 +64,19 @@ pub fn Client(comptime StateMachine_: type, comptime MessageBus: type) type {
64
64
  request_number: u32 = 0,
65
65
 
66
66
  /// The highest view number seen by the client in messages exchanged with the cluster.
67
- /// Used to locate the current leader, and provide more information to a partitioned leader.
67
+ /// Used to locate the current primary, and provide more information to a partitioned primary.
68
68
  view: u32 = 0,
69
69
 
70
70
  /// A client is allowed at most one inflight request at a time at the protocol layer.
71
71
  /// We therefore queue any further concurrent requests made by the application layer.
72
- request_queue: RingBuffer(Request, config.client_request_queue_max, .array) = .{},
72
+ request_queue: RingBuffer(Request, constants.client_request_queue_max, .array) = .{},
73
73
 
74
74
  /// The number of ticks without a reply before the client resends the inflight request.
75
75
  /// Dynamically adjusted as a function of recent request round-trip time.
76
76
  request_timeout: vsr.Timeout,
77
77
 
78
78
  /// The number of ticks before the client broadcasts a ping to the cluster.
79
- /// Used for end-to-end keepalive, and to discover a new leader between requests.
79
+ /// Used for end-to-end keepalive, and to discover a new primary between requests.
80
80
  ping_timeout: vsr.Timeout,
81
81
 
82
82
  /// Used to calculate exponential backoff with random jitter.
@@ -122,12 +122,12 @@ pub fn Client(comptime StateMachine_: type, comptime MessageBus: type) type {
122
122
  .request_timeout = .{
123
123
  .name = "request_timeout",
124
124
  .id = id,
125
- .after = config.rtt_ticks * config.rtt_multiple,
125
+ .after = constants.rtt_ticks * constants.rtt_multiple,
126
126
  },
127
127
  .ping_timeout = .{
128
128
  .name = "ping_timeout",
129
129
  .id = id,
130
- .after = 30000 / config.tick_ms,
130
+ .after = 30000 / constants.tick_ms,
131
131
  },
132
132
  .prng = std.rand.DefaultPrng.init(@truncate(u64, id)),
133
133
  };
@@ -407,7 +407,7 @@ pub fn Client(comptime StateMachine_: type, comptime MessageBus: type) type {
407
407
  message.header.checksum,
408
408
  });
409
409
 
410
- // We assume the leader is down and round-robin through the cluster:
410
+ // We assume the primary is down and round-robin through the cluster:
411
411
  self.send_message_to_replica(
412
412
  @intCast(u8, (self.view + self.request_timeout.attempts) % self.replica_count),
413
413
  message,
@@ -503,7 +503,7 @@ pub fn Client(comptime StateMachine_: type, comptime MessageBus: type) type {
503
503
  assert(message.header.context == 0);
504
504
  assert(message.header.request < self.request_number);
505
505
  assert(message.header.view == 0);
506
- assert(message.header.size <= config.message_size_max);
506
+ assert(message.header.size <= constants.message_size_max);
507
507
 
508
508
  // We set the message checksums only when sending the request for the first time,
509
509
  // which is when we have the checksum of the latest reply available to set as `parent`,
@@ -529,8 +529,8 @@ pub fn Client(comptime StateMachine_: type, comptime MessageBus: type) type {
529
529
  assert(!self.request_timeout.ticking);
530
530
  self.request_timeout.start();
531
531
 
532
- // If our view number is out of date, then the old leader will forward our request.
533
- // If the leader is offline, then our request timeout will fire and we will round-robin.
532
+ // If our view number is out of date, then the old primary will forward our request.
533
+ // If the primary is offline, then our request timeout will fire and we will round-robin.
534
534
  self.send_message_to_replica(@intCast(u8, self.view % self.replica_count), message);
535
535
  }
536
536
  };
@@ -3,12 +3,12 @@ const assert = std.debug.assert;
3
3
  const log = std.log.scoped(.clock);
4
4
  const fmt = std.fmt;
5
5
 
6
- const config = @import("../constants.zig");
6
+ const constants = @import("../constants.zig");
7
7
 
8
- const clock_offset_tolerance_max: u64 = config.clock_offset_tolerance_max_ms * std.time.ns_per_ms;
9
- const epoch_max: u64 = config.clock_epoch_max_ms * std.time.ns_per_ms;
10
- const window_min: u64 = config.clock_synchronization_window_min_ms * std.time.ns_per_ms;
11
- const window_max: u64 = config.clock_synchronization_window_max_ms * std.time.ns_per_ms;
8
+ const clock_offset_tolerance_max: u64 = constants.clock_offset_tolerance_max_ms * std.time.ns_per_ms;
9
+ const epoch_max: u64 = constants.clock_epoch_max_ms * std.time.ns_per_ms;
10
+ const window_min: u64 = constants.clock_synchronization_window_min_ms * std.time.ns_per_ms;
11
+ const window_max: u64 = constants.clock_synchronization_window_max_ms * std.time.ns_per_ms;
12
12
 
13
13
  const Marzullo = @import("marzullo.zig").Marzullo;
14
14
 
@@ -83,7 +83,8 @@ pub fn Clock(comptime Time: type) type {
83
83
  time: *Time,
84
84
 
85
85
  /// An epoch from which the clock can read synchronized clock timestamps within safe bounds.
86
- /// At least `config.clock_synchronization_window_min_ms` is needed for this to be ready to use.
86
+ /// At least `constants.clock_synchronization_window_min_ms` is needed for this to be ready
87
+ /// to use.
87
88
  epoch: Epoch,
88
89
 
89
90
  /// The next epoch (collecting samples and being synchronized) to replace the current epoch.
@@ -156,8 +157,8 @@ pub fn Clock(comptime Time: type) type {
156
157
 
157
158
  // Our m0 and m2 readings should always be monotonically increasing if not equal.
158
159
  // Crucially, it is possible for a very fast network to have m0 == m2, especially where
159
- // `config.tick_ms` is at a more course granularity. We must therefore tolerate RTT=0 or
160
- // otherwise we would have a liveness bug simply because we would be throwing away
160
+ // `constants.tick_ms` is at a more course granularity. We must therefore tolerate RTT=0
161
+ // or otherwise we would have a liveness bug simply because we would be throwing away
161
162
  // perfectly good clock samples.
162
163
  // This condition should never be true. Reject this as a bad sample:
163
164
  if (m0 > m2) {
@@ -246,8 +247,8 @@ pub fn Clock(comptime Time: type) type {
246
247
  return self.time.realtime();
247
248
  }
248
249
 
249
- /// Called by `StateMachine.prepare_timestamp()` when the leader wants to timestamp a batch.
250
- /// If the leader's clock is not synchronized with the cluster, it must wait until it is.
250
+ /// Called by `StateMachine.prepare_timestamp()` when the primary wants to timestamp a batch.
251
+ /// If the primary's clock is not synchronized with the cluster, it must wait until it is.
251
252
  /// Returns the system time clamped to be within our synchronized lower and upper bounds.
252
253
  /// This is complementary to NTP and allows clusters with very accurate time to make use of it,
253
254
  /// while providing guard rails for when NTP is partitioned or unable to correct quickly enough.