Repository navigation
fix: PageBased transaction rollback and in-transaction columnar scans (known issues 13 and 12) - #520
Open
CastleSoft wants to merge 1 commit into
Conversation
… (known issues 13 and 12) - PageBased rollback: each PageManager keeps a page's image on its first change inside a transaction (BeginUndoScope); CancelBatchUpdate / RollbackStorageTransaction restore the images (marked dirty) and free pages the transaction allocated, then every table rebuilds its primary-key index and marks hash indexes stale. This also fixes a columnar rollback that left the hash index on the rolled-back value. Outside a transaction a write pays one null check. ExecuteBatchSQL's internal failure rollback is not hooked yet (recorded in issue 13). - In-transaction columnar scans: ReadBytesWithRecordOffsets lays the transaction's buffered in-place overwrites and commit-time tombstones over the scanned records, and ReadBytesFrom returns nothing for a record the transaction deleted. Applies only while a transaction holds such changes for the file.
|
This was referenced Nov 16, 2026
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 known issues §13 (PageBased tables could not roll back) and §12 (inside a transaction, a columnar full scan missed the transaction's own UPDATEs and DELETEs). Both are about the transaction an ADO.NET
DbTransactionopens, and linq2db and EF Core transactions open the same one. Every fix has a regression test that was run red on #519's code and green after.§13 — PageBased rollback
Before:
CancelBatchUpdate()(DbTransaction.Rollback()) left a PageBased UPDATE or INSERT in place, and it was still there after a reopen. The PageBased engine writes into its page cache and page files directly, outside the storage transaction buffer, andPageBasedEngine.Rollback()was a stub: "we don't support rollback in this POC".Fix: an undo scope on each
PageManager.BeginBatchUpdate/EndBatchUpdate/CancelBatchUpdateand with the storage-only transaction the EF Core provider uses. A table first touched mid-transaction joins the scope.Also fixed: a columnar rollback restored the rows but not the in-memory hash index. After rolling back an UPDATE of an indexed column,
WHERE name = 'old'found nothing.TransactionRollbackTestscover:SharpCoreDBConnection.BeginTransaction()/Rollback().§12 — in-transaction columnar scans
Before: inside a transaction, a columnar full scan read the data file as it was on disk, while the transaction's in-place overwrites and its deletes were buffered until commit. So the scan:
WHERE n = 50afterSET n = 50.A primary-key lookup still returned the deleted row.
Fix:
Storage.ReadBytesWithRecordOffsets, the scan's data source, overlays the transaction's buffered changes on the records it returns:ReadBytesFromreturns nothing for a record the transaction deleted, checking a lock-free count first.InTransactionReadTestscover:NoEncryptMode, plus page-based tables.Still open (recorded in §13)
ExecuteBatchSQL's own failure rollback doesn't use the undo scope. That rollback is internal and runs when a statement in the batch fails. A PageBased table keeps the batch statements that ran before the failure. Hooking it adds a page copy per touched page to the most-measured write path, so it needs its own gate run.Tests
New:
TransactionRollbackTestsandInTransactionReadTests, 16 cases. 11 fail on #519's code. The 5 that pass there are cases that already worked: columnar rollback, the columnar ADO.NET rollback, and page-based in-transaction reads.ReopenRoundTripMatrixTests,FormatCompatPolicyTestsand others)SharpCoreDB.CI.slnfbuilds with 0 errors, and the documentation consistency tests pass.Performance
Write-path gate: GATE PASSED. Nothing is slower than baseline × 1.50.
The watch-band READ and DELETE ratios match the previous run on this machine (#519: default READ 1.33×, default DELETE 1.40×), which didn't change the read path. Outside a transaction, the new read-path code is one false bool check. The machine wasn't quieted first.