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.
- package/README.md +19 -5
- package/dist/benchmark.js.map +1 -1
- package/dist/index.d.ts +18 -16
- package/dist/index.js +35 -13
- package/dist/index.js.map +1 -1
- package/dist/test.js +12 -0
- package/dist/test.js.map +1 -1
- package/package.json +2 -2
- package/scripts/postinstall.sh +2 -2
- package/src/benchmark.ts +2 -2
- package/src/index.ts +29 -4
- package/src/node.zig +120 -17
- package/src/test.ts +14 -0
- package/src/tigerbeetle/scripts/install.sh +1 -1
- package/src/tigerbeetle/scripts/install_zig.bat +109 -0
- package/src/tigerbeetle/scripts/install_zig.sh +4 -2
- package/src/tigerbeetle/scripts/lint.zig +8 -2
- package/src/tigerbeetle/scripts/vopr.bat +48 -0
- package/src/tigerbeetle/src/benchmark.zig +10 -8
- package/src/tigerbeetle/src/cli.zig +6 -4
- package/src/tigerbeetle/src/config.zig +2 -2
- package/src/tigerbeetle/src/demo.zig +119 -89
- package/src/tigerbeetle/src/demo_01_create_accounts.zig +5 -3
- package/src/tigerbeetle/src/demo_02_lookup_accounts.zig +2 -3
- package/src/tigerbeetle/src/demo_03_create_transfers.zig +5 -3
- package/src/tigerbeetle/src/demo_04_create_transfers_two_phase_commit.zig +5 -3
- package/src/tigerbeetle/src/demo_05_accept_transfers.zig +5 -3
- package/src/tigerbeetle/src/demo_06_reject_transfers.zig +5 -3
- package/src/tigerbeetle/src/demo_07_lookup_transfers.zig +7 -0
- package/src/tigerbeetle/src/io/benchmark.zig +238 -0
- package/src/tigerbeetle/src/{io_darwin.zig → io/darwin.zig} +89 -124
- package/src/tigerbeetle/src/io/linux.zig +933 -0
- package/src/tigerbeetle/src/io/test.zig +621 -0
- package/src/tigerbeetle/src/io.zig +7 -1328
- package/src/tigerbeetle/src/main.zig +18 -10
- package/src/tigerbeetle/src/message_bus.zig +43 -60
- package/src/tigerbeetle/src/message_pool.zig +3 -2
- package/src/tigerbeetle/src/ring_buffer.zig +135 -68
- package/src/tigerbeetle/src/simulator.zig +41 -37
- package/src/tigerbeetle/src/state_machine.zig +851 -26
- package/src/tigerbeetle/src/storage.zig +49 -46
- package/src/tigerbeetle/src/test/cluster.zig +2 -2
- package/src/tigerbeetle/src/test/message_bus.zig +6 -6
- package/src/tigerbeetle/src/test/network.zig +3 -3
- package/src/tigerbeetle/src/test/packet_simulator.zig +32 -29
- package/src/tigerbeetle/src/test/state_checker.zig +2 -2
- package/src/tigerbeetle/src/test/state_machine.zig +4 -0
- package/src/tigerbeetle/src/test/storage.zig +39 -19
- package/src/tigerbeetle/src/test/time.zig +2 -2
- package/src/tigerbeetle/src/tigerbeetle.zig +6 -129
- package/src/tigerbeetle/src/time.zig +6 -5
- package/src/tigerbeetle/src/vsr/client.zig +11 -11
- package/src/tigerbeetle/src/vsr/clock.zig +26 -43
- package/src/tigerbeetle/src/vsr/journal.zig +7 -6
- package/src/tigerbeetle/src/vsr/marzullo.zig +6 -3
- package/src/tigerbeetle/src/vsr/replica.zig +51 -48
- package/src/tigerbeetle/src/vsr.zig +24 -20
- 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 =
|
|
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 (
|
|
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 (
|
|
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 =
|
|
60
|
+
const random = prng.random();
|
|
60
61
|
|
|
61
|
-
const replica_count = 1 +
|
|
62
|
-
const client_count = 1 +
|
|
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 +
|
|
68
|
-
const idle_on_probability =
|
|
69
|
-
const idle_off_probability = 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,
|
|
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 =
|
|
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 =
|
|
83
|
-
.one_way_delay_mean = 3 +
|
|
84
|
-
.one_way_delay_min =
|
|
85
|
-
.packet_loss_probability =
|
|
86
|
-
.path_maximum_capacity = 20 +
|
|
87
|
-
.path_clog_duration_mean =
|
|
88
|
-
.path_clog_probability =
|
|
89
|
-
.packet_replay_probability =
|
|
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 =
|
|
93
|
-
.unpartition_probability = 1 +
|
|
94
|
-
.partition_stability = 100 +
|
|
95
|
-
.unpartition_stability =
|
|
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 =
|
|
100
|
-
.read_latency_min =
|
|
101
|
-
.read_latency_mean = 3 +
|
|
102
|
-
.write_latency_min =
|
|
103
|
-
.write_latency_mean = 3 +
|
|
104
|
-
.read_fault_probability =
|
|
105
|
-
.write_fault_probability =
|
|
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.
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
}
|