Repository navigation
test(transaction-scope): read Sch-M at a held load instead of sampling it - #888
Merged
Merged
Conversation
…g it The lock tests sampled the building session every 0.1s during a 1.5M-row load and failed on a sample that landed at the very end: the batch's trailing DROP VIEW, or a Sch-M taken for a moment as the minimally logged INSERT commits (seen under PREEMPTIVE_OS_FLUSHFILEBUFFERS). Neither is held across the load, but a sampler can't tell them apart. The test now holds an X lock on one source row, so the INSERT, the only statement that reads rows from the source, waits mid-load. The locks are read once at that point, then the gate is rolled back. READCOMMITTEDLOCK keeps the wait under READ_COMMITTED_SNAPSHOT. The five lock tests drop from 57s to 4s serially.
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.
The
pre_hook_transaction_scopelock tests sampled the building session every 0.1 s during a 1.5M-row load and failed when a sample landed on the load's last instant, as in #884's pyodbc / SQL2025 job. Two momentary Sch-M locks show up there: the load batch's trailingDROP VIEW, and one taken as the minimally logged INSERT commits (seen underPREEMPTIVE_OS_FLUSHFILEBUFFERS). Neither is held across the load, but a sampler can't tell them apart.The tests now hold the load instead of racing it:
LCK_M_%,TABLOCKin its current statement), the building session's Sch-M is read once, and the gate is rolled back.READCOMMITTEDLOCKon the model's source keeps the wait underREAD_COMMITTED_SNAPSHOT.close()alone left the transaction open and the load waiting.Same five cases and assertions. The build-scope case checks Sch-M at one point mid-load rather than in every sample; a transaction's locks are held to commit, so it can't have been released earlier.
Verification
test_pre_hook_transaction_scope.pywith-n 4: 18 passed in each of 6 runs on mssql-python 1.14.0 and 6 on pyodbc (ODBC Driver 18), SQL Server 2022 CU27. The sampling version failed about 1 run in 6 on pyodbc locally.TestBuildScopeWithoutAnInTxHookHoldsNothingan in-transaction pre-hook makes it fail withSch-M held during the load.-n 4.tests/functional, mssql-python: 424 passed, 40 skipped, 2 xfailed.