tigerbeetle-node 0.11.12 → 0.12.0

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 (143) hide show
  1. package/README.md +212 -196
  2. package/dist/bin/aarch64-linux-gnu/client.node +0 -0
  3. package/dist/bin/aarch64-linux-musl/client.node +0 -0
  4. package/dist/bin/aarch64-macos/client.node +0 -0
  5. package/dist/bin/x86_64-linux-gnu/client.node +0 -0
  6. package/dist/bin/x86_64-linux-musl/client.node +0 -0
  7. package/dist/bin/x86_64-macos/client.node +0 -0
  8. package/dist/index.js +33 -1
  9. package/dist/index.js.map +1 -1
  10. package/package-lock.json +66 -0
  11. package/package.json +8 -17
  12. package/src/index.ts +56 -1
  13. package/src/node.zig +10 -9
  14. package/dist/.client.node.sha256 +0 -1
  15. package/scripts/build_lib.sh +0 -61
  16. package/scripts/download_node_headers.sh +0 -32
  17. package/src/tigerbeetle/scripts/benchmark.bat +0 -48
  18. package/src/tigerbeetle/scripts/benchmark.sh +0 -66
  19. package/src/tigerbeetle/scripts/confirm_image.sh +0 -44
  20. package/src/tigerbeetle/scripts/fuzz_loop.sh +0 -15
  21. package/src/tigerbeetle/scripts/fuzz_unique_errors.sh +0 -7
  22. package/src/tigerbeetle/scripts/install.bat +0 -7
  23. package/src/tigerbeetle/scripts/install.sh +0 -21
  24. package/src/tigerbeetle/scripts/install_zig.bat +0 -113
  25. package/src/tigerbeetle/scripts/install_zig.sh +0 -90
  26. package/src/tigerbeetle/scripts/lint.zig +0 -199
  27. package/src/tigerbeetle/scripts/pre-commit.sh +0 -9
  28. package/src/tigerbeetle/scripts/scripts/benchmark.bat +0 -48
  29. package/src/tigerbeetle/scripts/scripts/benchmark.sh +0 -66
  30. package/src/tigerbeetle/scripts/scripts/confirm_image.sh +0 -44
  31. package/src/tigerbeetle/scripts/scripts/fuzz_loop.sh +0 -15
  32. package/src/tigerbeetle/scripts/scripts/fuzz_unique_errors.sh +0 -7
  33. package/src/tigerbeetle/scripts/scripts/install.bat +0 -7
  34. package/src/tigerbeetle/scripts/scripts/install.sh +0 -21
  35. package/src/tigerbeetle/scripts/scripts/install_zig.bat +0 -113
  36. package/src/tigerbeetle/scripts/scripts/install_zig.sh +0 -90
  37. package/src/tigerbeetle/scripts/scripts/lint.zig +0 -199
  38. package/src/tigerbeetle/scripts/scripts/pre-commit.sh +0 -9
  39. package/src/tigerbeetle/scripts/scripts/shellcheck.sh +0 -5
  40. package/src/tigerbeetle/scripts/scripts/tests_on_alpine.sh +0 -10
  41. package/src/tigerbeetle/scripts/scripts/tests_on_ubuntu.sh +0 -14
  42. package/src/tigerbeetle/scripts/scripts/upgrade_ubuntu_kernel.sh +0 -48
  43. package/src/tigerbeetle/scripts/scripts/validate_docs.sh +0 -23
  44. package/src/tigerbeetle/scripts/scripts/vr_state_enumerate +0 -46
  45. package/src/tigerbeetle/scripts/shellcheck.sh +0 -5
  46. package/src/tigerbeetle/scripts/tests_on_alpine.sh +0 -10
  47. package/src/tigerbeetle/scripts/tests_on_ubuntu.sh +0 -14
  48. package/src/tigerbeetle/scripts/upgrade_ubuntu_kernel.sh +0 -48
  49. package/src/tigerbeetle/scripts/validate_docs.sh +0 -23
  50. package/src/tigerbeetle/scripts/vr_state_enumerate +0 -46
  51. package/src/tigerbeetle/src/benchmark.zig +0 -314
  52. package/src/tigerbeetle/src/config.zig +0 -234
  53. package/src/tigerbeetle/src/constants.zig +0 -436
  54. package/src/tigerbeetle/src/ewah.zig +0 -286
  55. package/src/tigerbeetle/src/ewah_benchmark.zig +0 -120
  56. package/src/tigerbeetle/src/ewah_fuzz.zig +0 -130
  57. package/src/tigerbeetle/src/fifo.zig +0 -120
  58. package/src/tigerbeetle/src/io/benchmark.zig +0 -213
  59. package/src/tigerbeetle/src/io/darwin.zig +0 -814
  60. package/src/tigerbeetle/src/io/linux.zig +0 -1062
  61. package/src/tigerbeetle/src/io/test.zig +0 -643
  62. package/src/tigerbeetle/src/io/windows.zig +0 -1183
  63. package/src/tigerbeetle/src/io.zig +0 -34
  64. package/src/tigerbeetle/src/iops.zig +0 -107
  65. package/src/tigerbeetle/src/lsm/README.md +0 -308
  66. package/src/tigerbeetle/src/lsm/binary_search.zig +0 -341
  67. package/src/tigerbeetle/src/lsm/bloom_filter.zig +0 -125
  68. package/src/tigerbeetle/src/lsm/compaction.zig +0 -603
  69. package/src/tigerbeetle/src/lsm/composite_key.zig +0 -77
  70. package/src/tigerbeetle/src/lsm/direction.zig +0 -11
  71. package/src/tigerbeetle/src/lsm/eytzinger.zig +0 -587
  72. package/src/tigerbeetle/src/lsm/eytzinger_benchmark.zig +0 -330
  73. package/src/tigerbeetle/src/lsm/forest.zig +0 -204
  74. package/src/tigerbeetle/src/lsm/forest_fuzz.zig +0 -401
  75. package/src/tigerbeetle/src/lsm/grid.zig +0 -573
  76. package/src/tigerbeetle/src/lsm/groove.zig +0 -972
  77. package/src/tigerbeetle/src/lsm/k_way_merge.zig +0 -474
  78. package/src/tigerbeetle/src/lsm/level_iterator.zig +0 -332
  79. package/src/tigerbeetle/src/lsm/manifest.zig +0 -617
  80. package/src/tigerbeetle/src/lsm/manifest_level.zig +0 -877
  81. package/src/tigerbeetle/src/lsm/manifest_log.zig +0 -789
  82. package/src/tigerbeetle/src/lsm/manifest_log_fuzz.zig +0 -691
  83. package/src/tigerbeetle/src/lsm/merge_iterator.zig +0 -106
  84. package/src/tigerbeetle/src/lsm/node_pool.zig +0 -235
  85. package/src/tigerbeetle/src/lsm/posted_groove.zig +0 -378
  86. package/src/tigerbeetle/src/lsm/segmented_array.zig +0 -1328
  87. package/src/tigerbeetle/src/lsm/segmented_array_benchmark.zig +0 -148
  88. package/src/tigerbeetle/src/lsm/segmented_array_fuzz.zig +0 -9
  89. package/src/tigerbeetle/src/lsm/set_associative_cache.zig +0 -850
  90. package/src/tigerbeetle/src/lsm/table.zig +0 -1031
  91. package/src/tigerbeetle/src/lsm/table_immutable.zig +0 -203
  92. package/src/tigerbeetle/src/lsm/table_iterator.zig +0 -340
  93. package/src/tigerbeetle/src/lsm/table_mutable.zig +0 -220
  94. package/src/tigerbeetle/src/lsm/test.zig +0 -438
  95. package/src/tigerbeetle/src/lsm/tree.zig +0 -1193
  96. package/src/tigerbeetle/src/lsm/tree_fuzz.zig +0 -474
  97. package/src/tigerbeetle/src/message_bus.zig +0 -1012
  98. package/src/tigerbeetle/src/message_pool.zig +0 -156
  99. package/src/tigerbeetle/src/ring_buffer.zig +0 -399
  100. package/src/tigerbeetle/src/simulator.zig +0 -569
  101. package/src/tigerbeetle/src/state_machine/auditor.zig +0 -577
  102. package/src/tigerbeetle/src/state_machine/workload.zig +0 -883
  103. package/src/tigerbeetle/src/state_machine.zig +0 -1881
  104. package/src/tigerbeetle/src/static_allocator.zig +0 -65
  105. package/src/tigerbeetle/src/stdx.zig +0 -162
  106. package/src/tigerbeetle/src/storage.zig +0 -393
  107. package/src/tigerbeetle/src/testing/cluster/message_bus.zig +0 -82
  108. package/src/tigerbeetle/src/testing/cluster/network.zig +0 -237
  109. package/src/tigerbeetle/src/testing/cluster/state_checker.zig +0 -169
  110. package/src/tigerbeetle/src/testing/cluster/storage_checker.zig +0 -202
  111. package/src/tigerbeetle/src/testing/cluster.zig +0 -443
  112. package/src/tigerbeetle/src/testing/fuzz.zig +0 -140
  113. package/src/tigerbeetle/src/testing/hash_log.zig +0 -66
  114. package/src/tigerbeetle/src/testing/id.zig +0 -99
  115. package/src/tigerbeetle/src/testing/packet_simulator.zig +0 -364
  116. package/src/tigerbeetle/src/testing/priority_queue.zig +0 -645
  117. package/src/tigerbeetle/src/testing/reply_sequence.zig +0 -139
  118. package/src/tigerbeetle/src/testing/state_machine.zig +0 -249
  119. package/src/tigerbeetle/src/testing/storage.zig +0 -757
  120. package/src/tigerbeetle/src/testing/table.zig +0 -247
  121. package/src/tigerbeetle/src/testing/time.zig +0 -84
  122. package/src/tigerbeetle/src/tigerbeetle.zig +0 -227
  123. package/src/tigerbeetle/src/time.zig +0 -112
  124. package/src/tigerbeetle/src/tracer.zig +0 -529
  125. package/src/tigerbeetle/src/unit_tests.zig +0 -42
  126. package/src/tigerbeetle/src/vopr.zig +0 -495
  127. package/src/tigerbeetle/src/vsr/README.md +0 -209
  128. package/src/tigerbeetle/src/vsr/client.zig +0 -544
  129. package/src/tigerbeetle/src/vsr/clock.zig +0 -853
  130. package/src/tigerbeetle/src/vsr/journal.zig +0 -2413
  131. package/src/tigerbeetle/src/vsr/journal_format_fuzz.zig +0 -111
  132. package/src/tigerbeetle/src/vsr/marzullo.zig +0 -309
  133. package/src/tigerbeetle/src/vsr/replica.zig +0 -6381
  134. package/src/tigerbeetle/src/vsr/replica_format.zig +0 -219
  135. package/src/tigerbeetle/src/vsr/superblock.zig +0 -1631
  136. package/src/tigerbeetle/src/vsr/superblock_client_table.zig +0 -256
  137. package/src/tigerbeetle/src/vsr/superblock_free_set.zig +0 -929
  138. package/src/tigerbeetle/src/vsr/superblock_free_set_fuzz.zig +0 -334
  139. package/src/tigerbeetle/src/vsr/superblock_fuzz.zig +0 -390
  140. package/src/tigerbeetle/src/vsr/superblock_manifest.zig +0 -615
  141. package/src/tigerbeetle/src/vsr/superblock_quorums.zig +0 -394
  142. package/src/tigerbeetle/src/vsr/superblock_quorums_fuzz.zig +0 -314
  143. package/src/tigerbeetle/src/vsr.zig +0 -1352
@@ -1,34 +0,0 @@
1
- const std = @import("std");
2
- const builtin = @import("builtin");
3
- const assert = std.debug.assert;
4
- const os = std.os;
5
-
6
- const FIFO = @import("fifo.zig").FIFO;
7
- const IO_Linux = @import("io/linux.zig").IO;
8
- const IO_Darwin = @import("io/darwin.zig").IO;
9
- const IO_Windows = @import("io/windows.zig").IO;
10
-
11
- pub const IO = switch (builtin.target.os.tag) {
12
- .linux => IO_Linux,
13
- .windows => IO_Windows,
14
- .macos, .tvos, .watchos, .ios => IO_Darwin,
15
- else => @compileError("IO is not supported for platform"),
16
- };
17
-
18
- pub fn buffer_limit(buffer_len: usize) usize {
19
- // Linux limits how much may be written in a `pwrite()/pread()` call, which is `0x7ffff000` on
20
- // both 64-bit and 32-bit systems, due to using a signed C int as the return value, as well as
21
- // stuffing the errno codes into the last `4096` values.
22
- // Darwin limits writes to `0x7fffffff` bytes, more than that returns `EINVAL`.
23
- // The corresponding POSIX limit is `std.math.maxInt(isize)`.
24
- const limit = switch (builtin.target.os.tag) {
25
- .linux => 0x7ffff000,
26
- .macos, .ios, .watchos, .tvos => std.math.maxInt(i32),
27
- else => std.math.maxInt(isize),
28
- };
29
- return std.math.min(limit, buffer_len);
30
- }
31
-
32
- test "I/O" {
33
- _ = @import("io/test.zig");
34
- }
@@ -1,107 +0,0 @@
1
- const std = @import("std");
2
- const assert = std.debug.assert;
3
-
4
- /// Take a u6 to limit to 64 items max (2^6 = 64)
5
- pub fn IOPS(comptime T: type, comptime size: u6) type {
6
- const Map = std.StaticBitSet(size);
7
- return struct {
8
- const Self = @This();
9
-
10
- items: [size]T = undefined,
11
- /// 1 bits are free items.
12
- free: Map = Map.initFull(),
13
-
14
- pub fn acquire(self: *Self) ?*T {
15
- const i = self.free.findFirstSet() orelse return null;
16
- self.free.unset(i);
17
- return &self.items[i];
18
- }
19
-
20
- pub fn release(self: *Self, item: *T) void {
21
- item.* = undefined;
22
- const i = self.index(item);
23
- assert(!self.free.isSet(i));
24
- self.free.set(i);
25
- }
26
-
27
- pub fn index(self: *Self, item: *T) usize {
28
- const i = (@ptrToInt(item) - @ptrToInt(&self.items)) / @sizeOf(T);
29
- assert(i < size);
30
- return i;
31
- }
32
-
33
- /// Returns the count of IOPs available.
34
- pub fn available(self: *const Self) usize {
35
- return self.free.count();
36
- }
37
-
38
- /// Returns the count of IOPs in use.
39
- pub fn executing(self: *const Self) usize {
40
- return size - self.available();
41
- }
42
-
43
- pub const Iterator = struct {
44
- iops: *Self,
45
- bitset_iterator: Map.Iterator(.{ .kind = .unset }),
46
-
47
- pub fn next(iterator: *@This()) ?*T {
48
- const i = iterator.bitset_iterator.next() orelse return null;
49
- return &iterator.iops.items[i];
50
- }
51
- };
52
-
53
- pub fn iterate(self: *Self) Iterator {
54
- return .{
55
- .iops = self,
56
- .bitset_iterator = self.free.iterator(.{ .kind = .unset }),
57
- };
58
- }
59
- };
60
- }
61
-
62
- test "IOPS" {
63
- const testing = std.testing;
64
- var iops = IOPS(u32, 4){};
65
-
66
- try testing.expectEqual(@as(usize, 4), iops.available());
67
- try testing.expectEqual(@as(usize, 0), iops.executing());
68
-
69
- var one = iops.acquire().?;
70
-
71
- try testing.expectEqual(@as(usize, 3), iops.available());
72
- try testing.expectEqual(@as(usize, 1), iops.executing());
73
-
74
- var two = iops.acquire().?;
75
- var three = iops.acquire().?;
76
-
77
- try testing.expectEqual(@as(usize, 1), iops.available());
78
- try testing.expectEqual(@as(usize, 3), iops.executing());
79
-
80
- var four = iops.acquire().?;
81
- try testing.expectEqual(@as(?*u32, null), iops.acquire());
82
-
83
- try testing.expectEqual(@as(usize, 0), iops.available());
84
- try testing.expectEqual(@as(usize, 4), iops.executing());
85
-
86
- iops.release(two);
87
-
88
- try testing.expectEqual(@as(usize, 1), iops.available());
89
- try testing.expectEqual(@as(usize, 3), iops.executing());
90
-
91
- // there is only one slot free, so we will get the same pointer back.
92
- try testing.expectEqual(@as(?*u32, two), iops.acquire());
93
-
94
- iops.release(four);
95
- iops.release(two);
96
- iops.release(one);
97
- iops.release(three);
98
-
99
- try testing.expectEqual(@as(usize, 4), iops.available());
100
- try testing.expectEqual(@as(usize, 0), iops.executing());
101
-
102
- one = iops.acquire().?;
103
- two = iops.acquire().?;
104
- three = iops.acquire().?;
105
- four = iops.acquire().?;
106
- try testing.expectEqual(@as(?*u32, null), iops.acquire());
107
- }
@@ -1,308 +0,0 @@
1
- # Glossary
2
-
3
- - _bar_/_measure_: `lsm_batch_multiple` beats; unit of incremental compaction.
4
- - _beat_: `op % lsm_batch_multiple`; Single step of an incremental compaction.
5
- - _groove_: A collection of LSM trees, storing objects and their indices.
6
- - _immutable table_: in-memory table; one per tree. Used to periodically flush the mutable table to
7
- disk.
8
- - _level_: Between `0` and `lsm_levels - 1` (usually `lsm_levels = 7`).
9
- - _forest_: a collection of grooves.
10
- - _manifest_: index of table and level metadata; one per tree.
11
- - _mutable table_: in-memory table; one per tree. All tree updates are applied only to this table.
12
- - _snapshot_: sequence number which selects the queryable partition of on-disk tables.
13
-
14
- # Tree
15
- ## Tables
16
-
17
- A tree is a hierarchy of in-memory and on-disk tables. There are three categories of tables:
18
-
19
- - The [mutable table](table_mutable.zig) is an in-memory table.
20
- - Each tree has a single mutable table.
21
- - All tree updates, inserts, and removes are applied to the mutable table.
22
- - The mutable table's size is allocated to accommodate a full bar of updates.
23
- - The [immutable table](table_immutable.zig) is an in-memory table.
24
- - Each tree has a single immutable table.
25
- - The mutable table's contents are periodically moved to the immutable table,
26
- where they are stored while being flushed to level `0`.
27
- - Level `0` … level `config.lsm_levels - 1` each contain an exponentially increasing number of
28
- immutable on-disk tables.
29
- - Each tree has as many as `config.lsm_growth_factor ^ (level + 1)` tables per level.
30
- (`config.lsm_growth_factor` is typically 8).
31
- - Within a given level and snapshot, the tables' key ranges are [disjoint](manifest_level.zig).
32
-
33
- ## Compaction
34
-
35
- Tree compaction runs to the sound of music!
36
-
37
- Compacting LSM trees involves merging and moving tables into the next levels as needed.
38
- To avoid write amplification stalls and bound latency, compaction is done incrementally.
39
-
40
- A full compaction phase is denoted as a bar or measure, using terms from music notation.
41
- Each bar consists of `lsm_batch_multiple` beats or "compaction ticks" of work.
42
- A compaction tick executes asynchronously immediately after every commit, with
43
- `beat = commit.op % lsm_batch_multiple`.
44
-
45
- A bar is split in half according to the "first" beat and "middle" beat.
46
- The first half of the bar compacts even levels while the latter compacts odd levels.
47
- Mutable table changes are sorted and compacted into the immutable table.
48
- The immutable table is compacted into level 0 during the odd level half of the bar.
49
-
50
- At any given point, there are at most `⌈levels/2⌉` compactions running concurrently.
51
- The source level is denoted as `level_a` and the target level as `level_b`.
52
- The last level in the LSM tree has no target level so it is never a source level.
53
- Each compaction compacts a [single table](#table-selection) from `level_a` into all tables in
54
- `level_b` which intersect the `level_a` table's key range.
55
-
56
- Invariants:
57
- * At the end of every beat, there is space in mutable table for the next beat.
58
- * The manifest log is compacted at the end of every beat.
59
- * The compactions' output tables are not [visible](#snapshots-and-compaction) until the compaction has finished.
60
-
61
- 1. First half-bar, first beat ("first beat"):
62
- * Assert no compactions are currently running.
63
- * Allow the per-level table limits to overflow if needed (for example, if we may compact a table
64
- from level `A` to level `B`, where level `B` is already full).
65
- * Start compactions from even levels that have reached their table limit.
66
- * Acquire reservations from the Free Set for all blocks (upper-bound) that will be written
67
- during this half-bar.
68
-
69
- 2. First half-bar, last beat:
70
- * Finish ticking any incomplete even-level compactions.
71
- * Assert on callback completion that all compactions are complete.
72
- * Release reservations from the Free Set.
73
-
74
- 3. Second half-bar, first beat ("middle beat"):
75
- * Assert no compactions are currently running.
76
- * Start compactions from odd levels that have reached their table limit.
77
- * Compact the immutable table if it contains any sorted values (it might be empty).
78
- * Acquire reservations from the Free Set for all blocks (upper-bound) that will be written
79
- during this half-bar.
80
-
81
- 4. Second half-bar, last beat:
82
- * Finish ticking any incomplete odd-level and immutable table compactions.
83
- * Assert on callback completion that all compactions are complete.
84
- * Assert on callback completion that no level's table count overflows.
85
- * Flush, clear, and sort mutable table values into immutable table for next bar.
86
- * Remove input tables that are invisible to all current and persisted snapshots.
87
- * Release reservations from the Free Set.
88
-
89
- ### Compaction Selection Policy
90
-
91
- Compaction targets the table from level `A` which overlaps the fewest tables of level `B`.
92
-
93
- For example, in the following table (with `lsm_growth_factor=2`), each table is depicted as the range of keys it includes. The tables with uppercase letters would be chosen for compaction next.
94
-
95
- ```
96
- Level 0 A─────────────H l───────────────────────────z
97
- Level 1 a───────e L─M o───────s u───────y
98
- Level 2 b───d e─────h i───k l───n o─p q───s u─v w─────z
99
- (Keys) a b c d e f g h i j k l m n o p q r s t u v w x y z
100
- ```
101
-
102
- Links:
103
- - [`Manifest.compaction_table`](manifest.zig)
104
- - [Constructing and Analyzing the LSM Compaction Design Space](http://vldb.org/pvldb/vol14/p2216-sarkar.pdf) describes the tradeoffs of various data movement policies. TigerBeetle implements the "least overlapping with parent" policy.
105
- - [Option of Compaction Priority](https://rocksdb.org/blog/2016/01/29/compaction_pri.html)
106
-
107
- ## Snapshots
108
-
109
- Each table has a minimum and maximum integer snapshot (`snapshot_min` and `snapshot_max`).
110
-
111
- Each query targets a particular snapshot. A table `T` is _visible_ to a snapshot `S` when
112
-
113
- ```
114
- T.snapshot_min ≤ S ≤ T.snapshot_max
115
- ```
116
-
117
- and is _invisible_ to the snapshot otherwise.
118
-
119
- Compaction does not modify tables in place — it copies data. Snapshots control and distinguish
120
- which copies are useful, and which can be deleted. Snapshots can also be persisted, enabling
121
- queries against past states of the tree (unimplemented; future work).
122
-
123
- ### Snapshots and Compaction
124
-
125
- Consider the half-bar compaction beginning at op=`X` (`12`), with `lsm_batch_multiple=M` (`8`).
126
- Each half-bar contains `N=M/2` (`4`) beats. The next half-bar begins at `Y=X+N` (`16`).
127
-
128
- During the half-bar compaction `X` (op=`X…Y-1`; `12…15`), each commit prefetches from the snapshot
129
- [equal to its own op](#current-snapshot). As shown, they continue to query the old (input) tables.
130
-
131
- During the half-bar compaction `X`:
132
- - `snapshot_max` of each input table is truncated to `Y-1` (`15`).
133
- - `snapshot_min` of each output table is initialized to `Y` (`16`).
134
-
135
- ```
136
- 0 4 8 12 16 20 24 (op, snapshot)
137
- ┼───┬───┼───┬───┼───┬───┼
138
- ####
139
- ····────────X────────···· (input tables, before compaction)
140
- ····──────────── (input tables, after compaction)
141
- Y────···· (output tables, after compaction)
142
- ```
143
-
144
- Beginning from the next op after the compaction (`Y`; `16`):
145
- - The output tables of the above compaction `X` are visible.
146
- - The input tables of the above compaction `X` are invisible.
147
- - Therefore, it will lookup from the output tables, but ignore the input tables.
148
- - Callers must not query from the output tables of `X` before the compaction half-bar has finished
149
- (i.e. before the end of beat `Y-1` (`15`)), since those tables are incomplete.
150
-
151
- At this point the input tables can be removed if they are invisible to all persistent snapshots.
152
-
153
- ### Snapshot Queries
154
-
155
- Each query targets a particular snapshot, either:
156
- - the [current snapshot](#current-snapshot), or
157
- - a [persisted snapshot](#persistent-snapshots).
158
-
159
- #### Current Snapshot
160
-
161
- Each tree tracks the highest snapshot safe to query from (`tree.lookup_snapshot_max`), to ensure that
162
- an ongoing compaction's incomplete output tables are not visible. Queries targeting
163
- `tree.lookup_snapshot_max` always read from the mutable and immutable tables — so each commit can
164
- see all previous commits' updates.)
165
-
166
- During typical operation, the `lookup_snapshot_max` when prefetching op `S` is snapshot `S`.
167
- The following chart depicts:
168
- - `lookup_snapshot_max` (`$`)
169
- - for each commit op (the left column)
170
- - and a compaction that began at op `12` and completed at the end of op `15`.
171
-
172
- ```
173
- op 0 4 8 12 16 20 24 (op, snapshot)
174
- ┼───┬───┼───┬───┼───┬───┼
175
- 12 ····────────$───
176
- 13 ····─────────$──
177
- 14 ····──────────$─
178
- 15 ····───────────$
179
- 16 $────····
180
- 17 ─$───····
181
- 18 ──$──····
182
- 19 ───$─····
183
- ```
184
-
185
- However, commits in the first measure following recovery from a checkpoint prefetch from a higher
186
- snapshot to avoid querying tables that were deleted at the checkpoint.
187
- See [`lookup_snapshot_max_for_checkpoint()`](#tree.zig) for more detail.
188
-
189
- #### Persistent Snapshots
190
-
191
- TODO(Persistent Snapshots): Expand this section.
192
-
193
- ### Snapshot Values
194
-
195
- - The on-disk tables visible to a snapshot `B` do not contain the updates from the commit with op `B`.
196
- - Rather, snapshot `B` is first visible to a prefetch from the commit with op `B`.
197
-
198
- Consider the following diagram (`lsm_batch_multiple=8`):
199
-
200
- ```
201
- 0 4 8 12 16 20 24 28 (op, snapshot)
202
- ┼───┬───┼───┬───┼───┬───┼───┬
203
- ,,,,,,,,........
204
- ↑A ↑B ↑C
205
- ```
206
-
207
- Compaction is driven by the commits of ops `B→C` (`16…23`). While these ops are being committed:
208
- - Updates from ops `0→A` (`0…7`) are on-disk.
209
- - Updates from ops `A→B` (`8…15`) are in the immutable table.
210
- - These updates were moved to the immutable table from the immutable table at the end of op `B-1`
211
- (`15`).
212
- - These updates will exist in the immutable table until it is reset at the end of op `C-1` (`23`).
213
- - Updates from ops `B→C` (`16…23`) are added to the mutable table (by the respective commit).
214
- - `tree.lookup_snapshot_max` is `B` when committing op `B`.
215
- - `tree.lookup_snapshot_max` is `x` when committing op `x` (for `x ∈ {16,17,…,23}`).
216
-
217
- At the end of the last beat of the compaction bar (`23`):
218
- - Updates from ops `0→B` (`0…15`) are on disk.
219
- - Updates from ops `B→C` (`16…23`) are moved from the mutable table to the immutable table.
220
- - `tree.lookup_snapshot_max` is `x` when committing op `x` (for `x ∈ {24,25,…}`).
221
-
222
-
223
- ## Manifest
224
-
225
- The manifest is a tree's index of table locations and metadata.
226
- (Not to be confused with the [SuperBlock Manifest](../vsr/README.md#manifest)).
227
-
228
- Each manifest has two components:
229
- - a single [`ManifestLog`](#manifest-log) shared by all levels, and
230
- - one [`ManifestLevel`](#manifest-level) for each on-disk level.
231
-
232
- ### Manifest Log
233
-
234
- The manifest log is an on-disk log of all updates to the tree's table index.
235
-
236
- The manifest log tracks:
237
-
238
- - tables created as compaction output
239
- - tables updated as compaction input (modifying their `snapshot_max`)
240
- - tables moved between levels by compaction
241
- - tables deleted after compaction
242
-
243
- Updates are accumulated in-memory before being flushed:
244
-
245
- - incrementally during compaction, or
246
- - in their entirety during checkpoint.
247
-
248
- The manifest log is periodically compacted to remove older entries that have been superseded by
249
- newer entries. For example, if a table is created and later deleted, manifest log compaction
250
- will eventually remove any reference to the table from the log blocks.
251
-
252
- All manifest log blocks are tracked in the superblock manifest.
253
-
254
- ### Manifest Level
255
-
256
- A `ManifestLevel` is an in-memory collection of the table metadata for a single level of a tree.
257
-
258
- For a given level and snapshot, there may be gaps in the key ranges of the visible tables,
259
- but the key ranges are disjoint.
260
-
261
- Manifest levels are queried for tables at a target snapshot and within a key range.
262
-
263
- #### Example
264
-
265
- Given the `ManifestLevel` tables (with values chosen for visualization, not realism):
266
-
267
- label A B C D E F G H I J K L M
268
- key_min 0 4 12 16 4 8 12 26 4 25 4 16 24
269
- key_max 3 11 15 19 7 11 15 27 7 27 11 19 27
270
- snapshot_min 1 1 1 1 3 3 3 3 5 5 7 7 7
271
- snapshot_max 9 3 3 7 5 7 9 5 7 7 9 9 9
272
-
273
- A level's tables can be visualized in 2D as a partitioned rectangle:
274
-
275
- 0 1 2
276
- 0 4 8 2 6 0 4 8
277
- 9┌───┬───────┬───┬───┬───┬───┐
278
- │ │ K │ │ L │###│ M │
279
- 7│ ├───┬───┤ ├───┤###└┬──┤
280
- │ │ I │ │ G │ │####│ J│
281
- 5│ A ├───┤ F │ │ │####└┬─┤
282
- │ │ E │ │ │ D │#####│H│
283
- 3│ ├───┴───┼───┤ │#####└─┤
284
- │ │ B │ C │ │#######│
285
- 1└───┴───────┴───┴───┴───────┘
286
-
287
- Example iterations:
288
-
289
- visibility snapshots direction key_min key_max tables
290
- visible 2 ascending 0 28 A, B, C, D
291
- visible 4 ascending 0 28 A, E, F, G, D, H
292
- visible 6 descending 12 28 J, D, G
293
- visible 8 ascending 0 28 A, K, G, L, M
294
- invisible 2, 4, 6 ascending 0 28 K, L, M
295
-
296
- Legend:
297
-
298
- - `#` represents a gap — no tables cover these keys during the snapshot.
299
- - The horizontal axis represents the key range.
300
- - The vertical axis represents the snapshot range.
301
- - Each rectangle is a table within the manifest level.
302
- - The sides of each rectangle depict:
303
- - left: `table.key_min` (the diagram is inclusive, and the `table.key_min` is inclusive)
304
- - right: `table.key_max` (the diagram is EXCLUSIVE, but the `table.key_max` is INCLUSIVE)
305
- - bottom: `table.snapshot_min` (inclusive)
306
- - top: `table.snapshot_max` (inclusive)
307
- - (Not depicted: tables may have `table.key_min == table.key_max`.)
308
- - (Not depicted: the newest set of tables would have `table.snapshot_max == maxInt(u64)`.)