Commit 00062db
storage: fix compaction minting future record timestamps
copy_data_segment_reducer::filter() re-encodes a batch when some of its
records are compacted away. It advanced the new batch's first_timestamp
to the first surviving record's absolute timestamp, but did NOT rebase
the per-record timestamp deltas, which remain relative to the batch's
original first_timestamp. On read, every surviving record therefore
resolves to new_first_timestamp + delta, i.e. shifted forward by a
constant (the first surviving record's original delta).
This is only non-zero when the batch's base record (delta 0) is dropped
(e.g. a tombstone), and the shift is large and positive when the batch
is out of order (the dropped base record is much older than the first
surviving record) -- turning strictly-past records into records with
future timestamps. This breaks broker timestamp validation
(log.message.timestamp.after.max.ms) and freezes downstream Kafka
Streams monotonic-max KTable aggregates in the future. Replicas compact
independently, so the same offset can carry different timestamps on
different brokers. Offsets are unaffected because base_offset is
preserved on compaction; this restores the same symmetry for timestamps.
Fix: preserve the original first_timestamp (so the unchanged per-record
deltas stay valid) and compute max_timestamp from the greatest surviving
delta (out-of-order safe), instead of assuming the last record is the
max.
Reproduced on v26.1.6 and v26.1.12 (compact topic + out-of-order
timestamps + tombstones): records produced strictly in the past read
back with timestamps hundreds of days in the future after compaction.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Aangbaeck <3142272+Aangbaeck@users.noreply.github.com>1 parent 6248e7f commit 00062db
1 file changed
Lines changed: 22 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
233 | | - | |
234 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
235 | 239 | | |
236 | 240 | | |
237 | 241 | | |
238 | 242 | | |
239 | 243 | | |
240 | 244 | | |
241 | | - | |
242 | | - | |
| 245 | + | |
243 | 246 | | |
244 | 247 | | |
245 | 248 | | |
| |||
255 | 258 | | |
256 | 259 | | |
257 | 260 | | |
258 | | - | |
259 | | - | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
260 | 265 | | |
261 | | - | |
262 | 266 | | |
263 | 267 | | |
264 | 268 | | |
| |||
303 | 307 | | |
304 | 308 | | |
305 | 309 | | |
306 | | - | |
307 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
308 | 319 | | |
309 | 320 | | |
310 | | - | |
| 321 | + | |
| 322 | + | |
311 | 323 | | |
312 | 324 | | |
313 | 325 | | |
| |||
0 commit comments