tigerbeetle-node 0.4.2 → 0.5.2

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 (58) hide show
  1. package/README.md +19 -5
  2. package/dist/benchmark.js.map +1 -1
  3. package/dist/index.d.ts +18 -16
  4. package/dist/index.js +35 -13
  5. package/dist/index.js.map +1 -1
  6. package/dist/test.js +12 -0
  7. package/dist/test.js.map +1 -1
  8. package/package.json +2 -2
  9. package/scripts/postinstall.sh +2 -2
  10. package/src/benchmark.ts +2 -2
  11. package/src/index.ts +29 -4
  12. package/src/node.zig +120 -17
  13. package/src/test.ts +14 -0
  14. package/src/tigerbeetle/scripts/install.sh +1 -1
  15. package/src/tigerbeetle/scripts/install_zig.bat +109 -0
  16. package/src/tigerbeetle/scripts/install_zig.sh +4 -2
  17. package/src/tigerbeetle/scripts/lint.zig +8 -2
  18. package/src/tigerbeetle/scripts/vopr.bat +48 -0
  19. package/src/tigerbeetle/src/benchmark.zig +10 -8
  20. package/src/tigerbeetle/src/cli.zig +6 -4
  21. package/src/tigerbeetle/src/config.zig +2 -2
  22. package/src/tigerbeetle/src/demo.zig +119 -89
  23. package/src/tigerbeetle/src/demo_01_create_accounts.zig +5 -3
  24. package/src/tigerbeetle/src/demo_02_lookup_accounts.zig +2 -3
  25. package/src/tigerbeetle/src/demo_03_create_transfers.zig +5 -3
  26. package/src/tigerbeetle/src/demo_04_create_transfers_two_phase_commit.zig +5 -3
  27. package/src/tigerbeetle/src/demo_05_accept_transfers.zig +5 -3
  28. package/src/tigerbeetle/src/demo_06_reject_transfers.zig +5 -3
  29. package/src/tigerbeetle/src/demo_07_lookup_transfers.zig +7 -0
  30. package/src/tigerbeetle/src/io/benchmark.zig +238 -0
  31. package/src/tigerbeetle/src/{io_darwin.zig → io/darwin.zig} +89 -124
  32. package/src/tigerbeetle/src/io/linux.zig +933 -0
  33. package/src/tigerbeetle/src/io/test.zig +621 -0
  34. package/src/tigerbeetle/src/io.zig +7 -1328
  35. package/src/tigerbeetle/src/main.zig +18 -10
  36. package/src/tigerbeetle/src/message_bus.zig +43 -60
  37. package/src/tigerbeetle/src/message_pool.zig +3 -2
  38. package/src/tigerbeetle/src/ring_buffer.zig +135 -68
  39. package/src/tigerbeetle/src/simulator.zig +41 -37
  40. package/src/tigerbeetle/src/state_machine.zig +851 -26
  41. package/src/tigerbeetle/src/storage.zig +49 -46
  42. package/src/tigerbeetle/src/test/cluster.zig +2 -2
  43. package/src/tigerbeetle/src/test/message_bus.zig +6 -6
  44. package/src/tigerbeetle/src/test/network.zig +3 -3
  45. package/src/tigerbeetle/src/test/packet_simulator.zig +32 -29
  46. package/src/tigerbeetle/src/test/state_checker.zig +2 -2
  47. package/src/tigerbeetle/src/test/state_machine.zig +4 -0
  48. package/src/tigerbeetle/src/test/storage.zig +39 -19
  49. package/src/tigerbeetle/src/test/time.zig +2 -2
  50. package/src/tigerbeetle/src/tigerbeetle.zig +6 -129
  51. package/src/tigerbeetle/src/time.zig +6 -5
  52. package/src/tigerbeetle/src/vsr/client.zig +11 -11
  53. package/src/tigerbeetle/src/vsr/clock.zig +26 -43
  54. package/src/tigerbeetle/src/vsr/journal.zig +7 -6
  55. package/src/tigerbeetle/src/vsr/marzullo.zig +6 -3
  56. package/src/tigerbeetle/src/vsr/replica.zig +51 -48
  57. package/src/tigerbeetle/src/vsr.zig +24 -20
  58. package/src/translate.zig +55 -55
@@ -1,4 +1,5 @@
1
1
  const std = @import("std");
2
+ const builtin = @import("builtin");
2
3
  const assert = std.debug.assert;
3
4
  const mem = std.mem;
4
5
 
@@ -17,7 +18,7 @@ const output = std.log.scoped(.state_checker);
17
18
 
18
19
  /// Set this to `false` if you want to see how literally everything works.
19
20
  /// This will run much slower but will trace all logic across the cluster.
20
- const log_state_transitions_only = std.builtin.mode != .Debug;
21
+ const log_state_transitions_only = builtin.mode != .Debug;
21
22
 
22
23
  /// You can fine tune your log levels even further (debug/info/notice/warn/err/crit/alert/emerg):
23
24
  pub const log_level: std.log.Level = if (log_state_transitions_only) .info else .debug;
@@ -40,13 +41,13 @@ pub fn main() !void {
40
41
  break :seed_from_arg parse_seed(arg_two);
41
42
  };
42
43
 
43
- if (std.builtin.mode == .ReleaseFast or std.builtin.mode == .ReleaseSmall) {
44
+ if (builtin.mode == .ReleaseFast or builtin.mode == .ReleaseSmall) {
44
45
  // We do not support ReleaseFast or ReleaseSmall because they disable assertions.
45
46
  @panic("the simulator must be run with -OReleaseSafe");
46
47
  }
47
48
 
48
49
  if (seed == seed_random) {
49
- if (std.builtin.mode != .ReleaseSafe) {
50
+ if (builtin.mode != .ReleaseSafe) {
50
51
  // If no seed is provided, than Debug is too slow and ReleaseSafe is much faster.
51
52
  @panic("no seed provided: the simulator must be run with -OReleaseSafe");
52
53
  }
@@ -56,53 +57,53 @@ pub fn main() !void {
56
57
  }
57
58
 
58
59
  var prng = std.rand.DefaultPrng.init(seed);
59
- const random = &prng.random;
60
+ const random = prng.random();
60
61
 
61
- const replica_count = 1 + prng.random.uintLessThan(u8, config.replicas_max);
62
- const client_count = 1 + prng.random.uintLessThan(u8, config.clients_max);
62
+ const replica_count = 1 + random.uintLessThan(u8, config.replicas_max);
63
+ const client_count = 1 + random.uintLessThan(u8, config.clients_max);
63
64
  const node_count = replica_count + client_count;
64
65
 
65
66
  const ticks_max = 100_000_000;
66
67
  const transitions_max = config.journal_size_max / config.message_size_max;
67
- const request_probability = 1 + prng.random.uintLessThan(u8, 99);
68
- const idle_on_probability = prng.random.uintLessThan(u8, 20);
69
- const idle_off_probability = 10 + prng.random.uintLessThan(u8, 10);
68
+ const request_probability = 1 + random.uintLessThan(u8, 99);
69
+ const idle_on_probability = random.uintLessThan(u8, 20);
70
+ const idle_off_probability = 10 + random.uintLessThan(u8, 10);
70
71
 
71
- cluster = try Cluster.create(allocator, &prng.random, .{
72
+ cluster = try Cluster.create(allocator, random, .{
72
73
  .cluster = 0,
73
74
  .replica_count = replica_count,
74
75
  .client_count = client_count,
75
- .seed = prng.random.int(u64),
76
+ .seed = random.int(u64),
76
77
  .network_options = .{
77
78
  .packet_simulator_options = .{
78
79
  .replica_count = replica_count,
79
80
  .client_count = client_count,
80
81
  .node_count = node_count,
81
82
 
82
- .seed = prng.random.int(u64),
83
- .one_way_delay_mean = 3 + prng.random.uintLessThan(u16, 10),
84
- .one_way_delay_min = prng.random.uintLessThan(u16, 3),
85
- .packet_loss_probability = prng.random.uintLessThan(u8, 30),
86
- .path_maximum_capacity = 20 + prng.random.uintLessThan(u8, 20),
87
- .path_clog_duration_mean = prng.random.uintLessThan(u16, 500),
88
- .path_clog_probability = prng.random.uintLessThan(u8, 2),
89
- .packet_replay_probability = prng.random.uintLessThan(u8, 50),
83
+ .seed = random.int(u64),
84
+ .one_way_delay_mean = 3 + random.uintLessThan(u16, 10),
85
+ .one_way_delay_min = random.uintLessThan(u16, 3),
86
+ .packet_loss_probability = random.uintLessThan(u8, 30),
87
+ .path_maximum_capacity = 20 + random.uintLessThan(u8, 20),
88
+ .path_clog_duration_mean = random.uintLessThan(u16, 500),
89
+ .path_clog_probability = random.uintLessThan(u8, 2),
90
+ .packet_replay_probability = random.uintLessThan(u8, 50),
90
91
 
91
92
  .partition_mode = random_partition_mode(random),
92
- .partition_probability = prng.random.uintLessThan(u8, 3),
93
- .unpartition_probability = 1 + prng.random.uintLessThan(u8, 10),
94
- .partition_stability = 100 + prng.random.uintLessThan(u32, 100),
95
- .unpartition_stability = prng.random.uintLessThan(u32, 20),
93
+ .partition_probability = random.uintLessThan(u8, 3),
94
+ .unpartition_probability = 1 + random.uintLessThan(u8, 10),
95
+ .partition_stability = 100 + random.uintLessThan(u32, 100),
96
+ .unpartition_stability = random.uintLessThan(u32, 20),
96
97
  },
97
98
  },
98
99
  .storage_options = .{
99
- .seed = prng.random.int(u64),
100
- .read_latency_min = prng.random.uintLessThan(u16, 3),
101
- .read_latency_mean = 3 + prng.random.uintLessThan(u16, 10),
102
- .write_latency_min = prng.random.uintLessThan(u16, 3),
103
- .write_latency_mean = 3 + prng.random.uintLessThan(u16, 10),
104
- .read_fault_probability = prng.random.uintLessThan(u8, 10),
105
- .write_fault_probability = prng.random.uintLessThan(u8, 10),
100
+ .seed = random.int(u64),
101
+ .read_latency_min = random.uintLessThan(u16, 3),
102
+ .read_latency_mean = 3 + random.uintLessThan(u16, 10),
103
+ .write_latency_min = random.uintLessThan(u16, 3),
104
+ .write_latency_mean = 3 + random.uintLessThan(u16, 10),
105
+ .read_fault_probability = random.uintLessThan(u8, 10),
106
+ .write_fault_probability = random.uintLessThan(u8, 10),
106
107
  },
107
108
  });
108
109
  defer cluster.destroy();
@@ -206,7 +207,7 @@ pub fn main() !void {
206
207
  }
207
208
 
208
209
  if (cluster.state_checker.transitions < transitions_max) {
209
- output.emerg("you can reproduce this failure with seed={}", .{seed});
210
+ output.err("you can reproduce this failure with seed={}", .{seed});
210
211
  @panic("unable to complete transitions_max before ticks_max");
211
212
  }
212
213
 
@@ -216,13 +217,13 @@ pub fn main() !void {
216
217
  }
217
218
 
218
219
  /// Returns true, `p` percent of the time, else false.
219
- fn chance(random: *std.rand.Random, p: u8) bool {
220
+ fn chance(random: std.rand.Random, p: u8) bool {
220
221
  assert(p <= 100);
221
222
  return random.uintLessThan(u8, 100) < p;
222
223
  }
223
224
 
224
225
  /// Returns the next argument for the simulator or null (if none available)
225
- fn args_next(args: *std.process.ArgIterator, allocator: *std.mem.Allocator) ?[:0]const u8 {
226
+ fn args_next(args: *std.process.ArgIterator, allocator: std.mem.Allocator) ?[:0]const u8 {
226
227
  const err_or_bytes = args.next(allocator) orelse return null;
227
228
  return err_or_bytes catch @panic("Unable to extract next value from args");
228
229
  }
@@ -232,7 +233,7 @@ fn on_change_replica(replica: *Replica) void {
232
233
  cluster.state_checker.check_state(replica.replica);
233
234
  }
234
235
 
235
- fn send_request(random: *std.rand.Random) bool {
236
+ fn send_request(random: std.rand.Random) bool {
236
237
  const client_index = random.uintLessThan(u8, cluster.options.client_count);
237
238
 
238
239
  const client = &cluster.clients[client_index];
@@ -280,11 +281,14 @@ fn client_callback(
280
281
  operation: StateMachine.Operation,
281
282
  results: Client.Error![]const u8,
282
283
  ) void {
284
+ _ = operation;
285
+ _ = results catch unreachable;
286
+
283
287
  assert(user_data == 0);
284
288
  }
285
289
 
286
290
  /// Returns a random partitioning mode, excluding .custom
287
- fn random_partition_mode(random: *std.rand.Random) PartitionMode {
291
+ fn random_partition_mode(random: std.rand.Random) PartitionMode {
288
292
  const typeInfo = @typeInfo(PartitionMode).Enum;
289
293
  var enumAsInt = random.uintAtMost(typeInfo.tag_type, typeInfo.fields.len - 2);
290
294
  if (enumAsInt >= @enumToInt(PartitionMode.custom)) enumAsInt += 1;
@@ -310,8 +314,8 @@ pub fn log(
310
314
  const prefix = if (log_state_transitions_only) "" else prefix_default;
311
315
 
312
316
  // Print the message to stdout, silently ignoring any errors
313
- const held = std.debug.getStderrMutex().acquire();
314
- defer held.release();
315
317
  const stderr = std.io.getStdErr().writer();
318
+ std.debug.getStderrMutex().lock();
319
+ defer std.debug.getStderrMutex().unlock();
316
320
  nosuspend stderr.print(prefix ++ format ++ "\n", args) catch return;
317
321
  }