← Back to Pull requests

sds/view, memtable: stop cloning rows on Get/Scan with immutability contract and debug mutation checking #194

Closed
unknown closed this pull request without merging on Oct 07, 2026 12:11 UTC
View on GitHub
unknown unknown commented on Oct 06, 2026 21:19 UTC
Author

Summary

Part of #97. Fixes #178.

Now that objectfs uses copy-on-write Inodes (CachedInode.mutate, #177), rows returned by and stored in sds/view and sds/memtable are treated as shared and immutable. This drops redundant proto.Clone calls 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, and pkg/sds/memtable that messages returned by Get/Scan and passed in changes (sds.Change.Row) are shared and must not be modified in place; callers requiring modifications must clone them first.
- Documented that before and after messages passed to StatsUpdateFunc are shared and read-only.
2. Cloning Removed on Read Paths:
- Removed proto.Clone from View.Get (overlay hits and read cache hits) and View.Scan.
- Removed proto.Clone from MemTable.Get, MemTable.Put, MemTable.Rows, and MemStore.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, and View.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, and ensureInodeChunksLoadedLocked, confirming that loaded rows are read-only and all modifications go through CachedInode.mutate or construct new messages.
- Added WithVolumeMutationCheck / WithVolumeViewOptions and WithServerMutationCheck / WithServerViewOptions.
5. Tests:
- Unit tests in pkg/sds/view verifying pointer preservation (zero cloning) and detecting illegal mutations on Get, Scan, ApplyChanges, cache eviction, and Close.
- Unit tests in pkg/sds/memtable verifying pointer preservation.
- Controller regression test TestMutationCheckCatchesInPlaceInodeModification and enabled mutation checking in TestOverlayEntryKeepsRowAsOfChange. Confirmed that reverting mutate to 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) | — |

Diff: 387 lines (+290 / -97) across 4 files Reviewer: justinsb Review duration: 891m
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
0.43
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 43% (MEDIUM) · Higher = larger blast radius
43%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 17% · Safe to merge
17%