Fix: Preserve CreatedAt timestamp during compaction #773
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #771
In v0.5.0, LTX files became unavailable for timestamp-based restoration after compaction. When level 0 files were compacted into level 1, the compacted file was assigned the current time as its
CreatedAt
timestamp rather than preserving the earliest timestamp from the source files.This caused restoration to fail for any timestamp that fell between:
After compaction deleted the L0 files, these timestamps became "unavailable" because the L1 file's
CreatedAt
was too late to match the requested restoration point.Solution
Per author's suggestion, this PR implements a cleaner approach: reading timestamps from LTX file headers rather than file system or object metadata.
LTX files contain an authoritative
Timestamp
field in their headers (milliseconds since epoch). The issue was thatLTXFiles()
implementations were reading timestamps from:This fix modifies
LTXFiles()
in all storage backends to useltx.PeekHeader()
to read the authoritative timestamp from each LTX file's header.Benefits of this approach:
Changes
ltx.PeekHeader()
, addtime
importCreatedAt
field and read from headerTestCompaction_PreservesEarliestTimestamp
verifying timestamp preservationAll implementations use a fallback to file/object metadata if header reading fails, ensuring robustness.
Testing
TestCompaction_PreservesEarliestTimestamp
passes-short
)Example
Before this fix:
After this fix:
Performance Consideration
Reading headers adds one network/disk request per file when listing files. This is necessary for correctness and only occurs during list operations, not during normal replication.