Commit f50b48e
committed
MVCC observability — version-store garbage collection + three new DMVs (
sys.dm_tran_version_store, sys.dm_tran_version_store_space_usage, sys.dm_tran_active_snapshot_database_transactions). Closes two of the three documented phase-3 limitations; only multi-update-within-one-tx history collapse remains. **Active-snapshot tracking**: new Database.ActiveSnapshotTxs (ConcurrentDictionary<SimulatedDbTransaction, byte>) registers each SI tx at the moment BatchContext.ResolveSnapshotXidForRead first allocates its tx.SnapshotXid (on first user-table read), and unregisters at Commit / Rollback / Dispose via a shared SimulatedDbTransaction.UnregisterActiveSnapshot helper. RCSI per-statement snapshots aren't registered here — their sub-statement lifetime means the GC's once-per-tx-finalize cadence wouldn't observe them as load-bearing anyway, and the DMV intentionally excludes them (matching real SQL Server). **Version-store GC**: new VersionStore.RunGarbageCollection(Database) walks every per-table RowVersions chain after every tx finalization. Drops trailing HV nodes whose Xmax <= oldest_active_snapshot_xid — when no SI tx is in flight the cutoff is Database.CurrentTransactionCommitId so every finalized HV becomes collectible. Chains that lose their only HV AND aren't IsDeletedLive AND have no in-flight WriterTx are removed from the dict entirely; chains with non-null WriterTx are skipped (pending HVs marked with VersionStore.PendingXmax must not be disturbed mid-tx). Oldest-active is computed by walking ActiveSnapshotTxs and finding the min SnapshotXid; new helper TrimHistory(head, cutoff) walks newest-first and clips at the first node with Xmax > cutoff. **DMVs**: new VersionStoreDmvs.cs provides three enumerators registered as sys.dm_tran_version_store / sys.dm_tran_version_store_space_usage / sys.dm_tran_active_snapshot_database_transactions in BuiltInResources.cs's catalog-view dict, each with probe-confirmed column shapes from SQL Server 2025 (2026-05-14 — after the user granted VIEW SERVER STATE). sys.dm_tran_version_store yields one row per finalized HistoricalVersion across every chain — transaction_sequence_num = HV.Xmax (the commit Xid that retired the version), version_sequence_num synthesized per-tx counter from result-order grouping, record_image_first_part the raw byte[] payload, second-part NULL since the simulator stores payloads as a single allocation, database_id / rowset_id (= table.ObjectId) / status (0) / min_length_in_bytes / record_length_first_part_in_bytes matching probed types + ordinals exactly. sys.dm_tran_version_store_space_usage aggregates one row per database — reserved_space_kb = ceil(total_bytes / 1024), reserved_page_count = ceil(total_bytes / 8192) — always yielding a row (matches probe: empty stores show as zeroes, not row-empty). sys.dm_tran_active_snapshot_database_transactions projects Database.ActiveSnapshotTxs with transaction_sequence_num = tx.SnapshotXid, session_id = tx.connection.Spid, is_snapshot = true, commit_sequence_num / first_snapshot_sequence_num NULL (tx still in flight), max_version_chain_traversed / average_version_chain_traversed / elapsed_time_seconds = 0 (not instrumented). **Tests**: 11 new MvccObservabilityTests.cs cover: no-versioning → empty version_store; UPDATE-under-SI populates 3 HVs while reader holds snapshot; reader commits → GC drops all HVs; DELETE-under-SI appears in the store; transaction_sequence_num is a commit Xid > 0; space_usage always yields one row; reserved_space_kb scales with store contents; active_snapshot_db_tx lists the holding SI session and drains on commit; session_id matches @@spid; RCSI per-statement snapshot doesn't appear; GC respects an older still-active reader's HVs. Total: 3956 main (+11 new) + 227 internal + 328 EFCore + 58 analyzers, all green Debug + Release. CLAUDE.md "Phase-3 remaining limitations" rewrites — version-store GC + the three DMVs added to the shipped paragraph (with implementation pointers including VersionStore.RunGarbageCollection, Database.ActiveSnapshotTxs, and VersionStoreDmvs); only multi-update-within-one-tx history collapse remains in the limitations list. docs/claude/locking.md gains new "MVCC observability" and "Version-store garbage collection" sections documenting the three DMVs' column rules + the GC trigger / chain-removal logic; the "Known phase-3 limitations" section shrinks to just the multi-update item. Probe-confirmed exact column names + types of all three DMVs against SQL Server 2025 post-GRANT.1 parent b7e4d37 commit f50b48e
9 files changed
Lines changed: 586 additions & 12 deletions
File tree
- SqlServerSimulator.Tests
- SqlServerSimulator
- Parser
- Storage
- docs/claude
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
739 | 739 | | |
740 | 740 | | |
741 | 741 | | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
742 | 789 | | |
743 | 790 | | |
744 | 791 | | |
| |||
761 | 808 | | |
762 | 809 | | |
763 | 810 | | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
764 | 814 | | |
765 | 815 | | |
766 | 816 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
145 | 158 | | |
146 | 159 | | |
147 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
697 | 697 | | |
698 | 698 | | |
699 | 699 | | |
700 | | - | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
701 | 705 | | |
702 | 706 | | |
703 | 707 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
| 150 | + | |
150 | 151 | | |
151 | 152 | | |
| 153 | + | |
| 154 | + | |
152 | 155 | | |
153 | 156 | | |
154 | 157 | | |
| |||
158 | 161 | | |
159 | 162 | | |
160 | 163 | | |
| 164 | + | |
161 | 165 | | |
162 | 166 | | |
163 | 167 | | |
164 | 168 | | |
| 169 | + | |
| 170 | + | |
165 | 171 | | |
166 | 172 | | |
167 | 173 | | |
| |||
177 | 183 | | |
178 | 184 | | |
179 | 185 | | |
| 186 | + | |
180 | 187 | | |
181 | 188 | | |
182 | 189 | | |
| 190 | + | |
| 191 | + | |
183 | 192 | | |
184 | 193 | | |
185 | 194 | | |
186 | 195 | | |
187 | 196 | | |
188 | 197 | | |
189 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
190 | 205 | | |
191 | 206 | | |
192 | 207 | | |
| |||
0 commit comments