sds/view, memtable: stop cloning rows on Get/Scan with immutability contract and debug mutation checking #194
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 387 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.357
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #194"
general
weight: 0.35
justinsb
Summary
Part of #97. Fixes #178.
Now that objectfs uses copy-on-write Inodes (
CachedInode.mutate, #177), rows returned by and stored insds/viewandsds/memtableare treated as shared and immutable. This drops redundantproto.Clonecalls on the read path (View.Get,View.Scan,MemTable.Get,MemTable.Put,MemTable.Rows,MemStore.Scan).Changes
1. Contract & Documentation:
- Documented in
pkg/sds/view,View.Get,View.Scan,sds.LocalIndex, andpkg/sds/memtablethat messages returned byGet/Scanand passed in changes (sds.Change.Row) are shared and must not be modified in place; callers requiring modifications must clone them first.- Documented that
beforeandaftermessages passed toStatsUpdateFuncare shared and read-only.2. Cloning Removed on Read Paths:
- Removed
proto.ClonefromView.Get(overlay hits and read cache hits) andView.Scan.- Removed
proto.ClonefromMemTable.Get,MemTable.Put,MemTable.Rows, andMemStore.Scan.3. Mutation Check Debug Mode (
view.WithMutationCheck()):- Added debug assertion checker that tracks deterministic protobuf hashes keyed by pointer identity.
- Re-checks hashes on subsequent reads (
Get,Scan), cache evictions/replacements, stats recomputation, andView.Close().- Panics naming the type and key if an illegal in-place mutation is detected.
4. ObjectFS Readers Audit & Options:
- Audited
getSQLiteRowLocked,scanSQLiteRowsLocked,getOrLoadInodeLocked,getDirEntrySQLiteLocked, andensureInodeChunksLoadedLocked, confirming that loaded rows are read-only and all modifications go throughCachedInode.mutateor construct new messages.- Added
WithVolumeMutationCheck/WithVolumeViewOptionsandWithServerMutationCheck/WithServerViewOptions.5. Tests:
- Unit tests in
pkg/sds/viewverifying pointer preservation (zero cloning) and detecting illegal mutations onGet,Scan,ApplyChanges, cache eviction, andClose.- Unit tests in
pkg/sds/memtableverifying pointer preservation.- Controller regression test
TestMutationCheckCatchesInPlaceInodeModificationand enabled mutation checking inTestOverlayEntryKeepsRowAsOfChange. Confirmed that revertingmutateto in-place modification fails the controller tests with mutation check enabled.- Concurrency and race tests verified clean under
-race.Benchmark Comparison (mode=sqlite_cache_on, AMD EPYC 9B14)
| Operation | Before | After | Delta |
| :--- | :--- | :--- | :--- |
| Stat (GetAttr) | 9,224 ns/op (86 allocs, 3,744 B) | 8,473 ns/op (78 allocs, 3,248 B) | -8 allocs/op (-496 B/op) |
| Lookup | 10,518 ns/op (101 allocs, 4,208 B) | 9,618 ns/op (90 allocs, 3,600 B) | -11 allocs/op (-608 B/op) |
| ReadDir (100) | 1,312,444 ns/op (13,314 allocs, 495 KB) | 1,222,098 ns/op (12,311 allocs, 436 KB) | -1,003 allocs/op (-58.5 KB/op) |
| ReadDir (1k) | — | 13,018,971 ns/op (130,577 allocs, 4.57 MB) | — |
| ReadDir (10k) | — | 272,925,499 ns/op (2,082,091 allocs, 71.8 MB) | — |