fix: prevent XML corruption and identity collisions#170
Merged
Conversation
Issue #166: During transaction commit, FileInsertWriter used stale in-memory data instead of re-reading from disk, causing data loss when multiple connections committed concurrently. Fix: force re-read from disk during commit (via MarkTableToUpdate + ReadFile) and stop/start file watching in FileTransaction.Commit() to prevent mid-write file watcher events. Issue #159: Identity generation used the last row's value + 1, which could collide with existing rows when the maximum identity value wasn't in the last row position (e.g., after deletions or with non-sequential ordering). Fix: use MAX(identity_column) across all rows instead of LastOrDefault(). Closes #166, Closes #159 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SummarySummary
CoverageData.Common - 77.5%
Data.Csv - 90.7%
Data.Json - 81.5%
Data.Tests.Common - 88.4%
Data.Xls - 66.1%
Data.Xml - 88.2%
EFCore.Common - 68.5%
EFCore.Csv - 68.2%
EFCore.Json - 71.8%
EFCore.Xml - 73%
|
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.
Summary
Fixes two related data integrity issues under concurrent access:
XML file corruption during concurrent transaction commits #166 — XML corruption during concurrent transaction commits:
FileInsertWriter.Execute()used stale in-memory data during transaction commit, causing data loss when multiple connections committed concurrently. The fix forces a re-read from disk during the commit path (viaMarkTableToUpdate+ReadFile) and addsStopWatching/StartWatchinginFileTransaction.Commit()to prevent mid-write file watcher events.Bug: FileInsertWriter identity generation uses last row value + 1, causing collisions #159 — Identity collisions after deletions: Identity generation used
LastOrDefault()to get the last row's value + 1, which could collide with existing rows when the maximum identity value wasn't in the last row (e.g., after deletions). The fix usesMAX(identity_column)across all rows via a newFindRowWithMaxIdentitymethod.Changes
FileInsertWriter.cs: Re-read table from disk during commit; use MAX for identity generationFileTransaction.cs: Stop/start file watching around commit writesConcurrencyTests.cs: Tightened — no longer tolerates XmlException (corruption should not occur)InsertTests.cs: AddedInsert_IdentityColumn_AfterDelete_UsesMaxValuetestCloses #166, Closes #159
Test plan
🤖 Generated with Claude Code