writing truncation log entry in case of truncation after failing a write#706
Merged
hg-ms merged 1 commit intoJun 12, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a recovery/consistency issue where a partial store rollback truncated a data file without writing a corresponding FILE_TRUNCATION transaction entry, allowing the transaction log to claim a larger length than the actual file and potentially preventing storage from reopening after restart.
Changes:
- Add a guard in
rollbackWrite()to only emit truncation behavior when needed. - Write a
FILE_TRUNCATIONtransaction entry before truncating during rollback, mirroringhandleLastFile()behavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
fh-ms
approved these changes
Jun 12, 2026
Contributor
Author
|
fixed #704 |
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.
Log a truncation entry when rolling back a partial store.
When one channel's write fails mid-store while a sibling channel already wrote its slice, the engine rolls back the successful channel by truncating its data file. Previously StorageFileManager.rollbackWrite truncated
the file but never recorded a matching truncation entry in the transaction log — so the store entry written earlier kept claiming the larger, pre-rollback length. On the next start, validateStorageDataFilesLength saw
a data file shorter than its logged length and threw StorageExceptionConsistency, leaving the storage permanently un-openable.
The fix makes rollbackWrite write a FILE_TRUNCATION transaction entry before truncating (mirroring handleLastFile), keeping the transaction log and the data file consistent. A totalLength() != size() guard ensures
only channels that actually wrote uncommitted data emit an entry. On restart, the recovery analysis resolves the store-then-truncate pair to the rolled-back length and reopens cleanly to the last consistent state —
the truncation case the transaction analysis was already designed to handle.