Commit cff8f9b
committed
Generate meaningful segment ids using UUIDv7
Closes #971.
Segment ids were generated as random UUIDv4. Those 16 bytes carried no
information: they were not sortable and told you nothing about when a
segment was created.
This switches non-test segment id generation to UUIDv7 (RFC 9562), which
embeds a 48-bit millisecond creation timestamp in the most significant
bits followed by random bits. The result is still universally unique and
still lock-free to generate from any indexing thread (the properties the
original UUIDv4 was chosen for), while additionally being:
- chronologically sortable: `SegmentId`'s `Ord` is a byte comparison, so
ids now sort by creation time.
- self-describing: the new `SegmentId::creation_time()` recovers the
embedded timestamp for debugging.
This is fully backward compatible. The on-disk format is unchanged (a
32-char hex uuid). Ids from older indices are UUIDv4 and keep working;
`creation_time()` returns `None` for them (and for the autoincrement ids
used in tests).
Note: this deliberately does not encode a hostname/label or merge origin
into the id. As discussed in #971, that information is a better fit for
segment attributes on `SegmentMeta` (#999) than for the id itself, and
avoids the unresolved question of how labels should be combined on merge.1 parent 31ca1a8 commit cff8f9b
3 files changed
Lines changed: 63 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
| |||
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
43 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
44 | 57 | | |
45 | 58 | | |
46 | 59 | | |
| |||
74 | 87 | | |
75 | 88 | | |
76 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
77 | 108 | | |
78 | 109 | | |
79 | 110 | | |
| |||
139 | 170 | | |
140 | 171 | | |
141 | 172 | | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
142 | 202 | | |
0 commit comments