Repository navigation
Make JsonSyncable tolerate an interrupted write - #154
Draft
hahn-kev-bot wants to merge 2 commits into
Draft
hahn-kev-bot wants to merge 2 commits into
hahn-kev-bot wants to merge 2 commits into
Conversation
A client file can end in a partial line when a drive is pulled mid-sync. Reads now skip an unterminated last line that fails to parse, and appends first truncate that fragment (or terminate it, if it is a complete commit) so new commits land on their own line. Malformed lines elsewhere still throw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
AI summary
Summary
FwLite's flash-drive sync will use a
JsonSyncablefolder, and a drive pulled mid-write leaves aclient_<id>.jsonlfile ending in a partial line. Before this change, that one fragment made the whole folder unsyncable (JsonExceptionon every read), and the next append was written onto the same line as the fragment, corrupting it too.Dropping the fragment loses nothing: the device that wrote it still has the commit and re-sends it on the next sync, which deduplicates by commit
Id. A line counts as terminated only by\n, so\r\nworks and a bare trailing\rcounts as unterminated.Evidence
New tests in
JsonSyncableTests, run against the oldJsonSyncable.cs:Syncablebackend suite (53 tests) also passes, anddotnet format --verify-no-changesis clean.MalformedLineInTheMiddleThrowsandTerminatedMalformedLastLineThrowspass both before and after; they guard against mid-file corruption being silently skipped.Merge Danger
Door: two-way
Reverting restores the old behaviour. The only write-side effect is that a trailing fragment is truncated from a client file, and that fragment was unreadable anyway.
Blast Radius: contained
Only
JsonSyncablechanges. A file ending in a truncated line that is actually the only copy of a commit would lose that commit, but the writer appends commits it already holds, so that shouldn't happen.Test plan
dotnet test src/SIL.Harmony.Tests -- --filter-class '*JsonSyncableTests'dotnet test src/SIL.Harmony.Tests -- --filter-namespace 'SIL.Harmony.Tests.Syncable'🤖 Generated with Claude Code