Commit 11abdda
committed
hlc: introduce synthetic flag on timestamps
Informs #52745.
Informs #36431.
This commit introduces an 8-bit flags field on the hlc timestamp struct.
The flags are used to provide details about the timestamp and its
meaning. They do not affect the sort order of Timestamps.
The commit then introduces the first flag: SYNTHETIC. As discussed
in #52745, a synthetic timestamp is defined as a timestamp that makes no
claim about the value of clocks in the system. While standard timestamps
are pulled from HLC clocks and indicate that some node in the system has
a clock with a reading equal to or above its value, a synthetic
timestamp makes no such indication. By avoiding a connection to "real
time", synthetic timestamps can be used to write values at a future time
and to indicate that observed timestamps do not apply to such writes for
the purposes of tracking causality between the write and its observers.
Observed timestamps will be a critical part of implementing non-blocking
transactions (#52745) and fixing the interaction between observed
timestamps and transaction refreshing (#36431).
The original plan was to reserve the high-order bit in the logical
portion of a timestamp as a "synthetic bit". This is how I began
implementing things, but was turned off for a few reasons. First, it was
fairly subtle and seemed too easy to get wrong. Using a separate field
is more explicit and avoids a class of bugs. Second, I began to have
serious concerns about how the synthetic bit would impact timestamp
ordering. Every timestamp comparison would need to mask out the bit or
risk being incorrect. This was even true of the LSM custom comparator.
This seemed difficult to get right, and seemed particularly concerning
since we're planning on marking only some of a transaction's committed
values as synthetic to fix #36431, so if we weren't careful, we could
get atomicity violations. There were also minor backwards compatibility
concerns.
But a separate field is more expensive in theory, so we need to be
careful. However, it turns out that a separate field is mostly free in
each case that we care about. In memory, the separate field is
effectively free because the Timestamp struct was previously 12 bytes
but was always padded out to 16 bytes when included as a field in any
other struct. This means that the flags field is replacing existing
padding. Over the wire, the field will not be included when zero and
will use a varint encoding when not zero, so again, it is mostly free.
In the engine key encoding, the field is also not included when zero,
and takes up only 1 byte when non-zero, so it is mostly free.1 parent df5e066 commit 11abdda
36 files changed
Lines changed: 552 additions & 146 deletions
File tree
- pkg
- ccl
- changefeedccl/kvfeed
- storageccl
- jobs
- kv/kvserver
- gc
- liveness
- rangefeed
- tscache
- roachpb
- server
- storage
- enginepb
- util/hlc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| 214 | + | |
214 | 215 | | |
215 | 216 | | |
216 | 217 | | |
| |||
266 | 267 | | |
267 | 268 | | |
268 | 269 | | |
| 270 | + | |
269 | 271 | | |
270 | 272 | | |
271 | 273 | | |
| |||
284 | 286 | | |
285 | 287 | | |
286 | 288 | | |
| 289 | + | |
287 | 290 | | |
288 | 291 | | |
289 | 292 | | |
| |||
300 | 303 | | |
301 | 304 | | |
302 | 305 | | |
| 306 | + | |
303 | 307 | | |
304 | 308 | | |
305 | 309 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
584 | | - | |
585 | | - | |
586 | | - | |
587 | | - | |
588 | | - | |
| 584 | + | |
589 | 585 | | |
590 | 586 | | |
591 | 587 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | 129 | | |
130 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
| 253 | + | |
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
825 | 825 | | |
826 | 826 | | |
827 | 827 | | |
828 | | - | |
829 | | - | |
| 828 | + | |
830 | 829 | | |
831 | 830 | | |
832 | 831 | | |
| |||
873 | 872 | | |
874 | 873 | | |
875 | 874 | | |
876 | | - | |
877 | | - | |
| 875 | + | |
878 | 876 | | |
879 | 877 | | |
880 | 878 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
29 | 28 | | |
30 | 29 | | |
31 | 30 | | |
| |||
196 | 195 | | |
197 | 196 | | |
198 | 197 | | |
199 | | - | |
| 198 | + | |
200 | 199 | | |
201 | 200 | | |
202 | 201 | | |
| |||
958 | 957 | | |
959 | 958 | | |
960 | 959 | | |
961 | | - | |
| 960 | + | |
962 | 961 | | |
963 | 962 | | |
964 | 963 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
351 | | - | |
| 351 | + | |
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| |||
0 commit comments