commitlog: Truncate segment before resuming#5116
Open
kim wants to merge 2 commits into
Open
Conversation
Contributor
|
Don't know if it's a github bug or what but It is looking like a empty commit. |
`read_exact` doesn't distinguish between EOF and not enough bytes to fill the given buffer. We may thus consider a segment valid to be resumed, but leave in trailing bytes (less than the commit header length). That can cause silent data loss, because appending more data will render the segment corrupt: a restart will then start a new segment, leaving anything after the trailing bytes unreachable. To fix this, truncate the segment to the size determined by `Metadata::extract` before resuming writes.
8bd704b to
f6afc9a
Compare
Shubham8287
reviewed
May 26, 2026
| // trailing bytes in the segment, but less than the commit header | ||
| // length. This is difficult to detect due to the use of `read_exact`, | ||
| // so ensure we remove any trailing bytes. | ||
| writer.ftruncate(tx_range.end, size_in_bytes)?; |
Contributor
There was a problem hiding this comment.
I would have preferred to treat this case similar to corrupted commits i.e to return ResumedSegment::Corrupted here and let caller create new segment. . Which looks more consistent and safer behavior.
Maybe, we can check in Metadata::with_header , if reader is at EOF. wdyt?
Contributor
Author
There was a problem hiding this comment.
We'd need to look at all ways in which read_exact is used. Not sure if that gains us that much.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
read_exactdoesn't distinguish between EOF and not enough bytes to fill the given buffer. We may thus consider a segment valid to be resumed, but leave in trailing bytes (less than the commit header length). That can cause silent data loss, because appending more data will render the segment corrupt: a restart will then start a new segment, leaving anything after the trailing bytes unreachable.To fix this, truncate the segment to the size determined by
Metadata::extractbefore resuming writes.Expected complexity level and risk
2
Testing
Added a test