objectfs: SQLite as the controller's metadata store #152
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 532 lines diff across 6 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.376
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #152"
general
weight: 0.35
justinsb
Summary
This PR implements SQLite as the ObjectFS controller's metadata store behind the
--metadata-store=legacy|sqliteflag (defaulting tolegacyfor now), backed bypkg/sds/projection/sqlite.Key Changes & Optimizations
1. Cached MessageType Resolution (
pkg/sds/record):- Cached resolved
protoreflect.MessageTypeper type ID inrecord.Registrykeyed by type fingerprint, eliminating repetitive descriptor re-serialization, hashing, and dynamicpb construction.-
DB.Getdrops from ~50 µs to ~1.4–10 µs.2. Point Lookups & Direct Directory Operations (
pkg/objectfs/controller):- In SQLite mode,
Lookup,CreateFile,Mkdir,Unlink,Rmdir, andRenameperform primary-key lookups (Get) ofDirEntry(parent_ino, name)instead of scanning whole directories into memory.- For
Rmdir's emptiness check, usesScanLimit(ctx, typeName, prefixBytes, 1).-
ReadDiris the only operation that enumerates directory rows.- Completely eliminates the $O(N)$ directory scaling penalty (adding to a 10k-entry directory takes ~1.3 ms, same as an empty directory).
3. Pragmas via DSN & Exclusive Locking (
pkg/sds/projection/sqlite):- Configured pragmas directly in DSN so modernc applies them to every connection:
path + "?_pragma=locking_mode(EXCLUSIVE)&_pragma=journal_mode(WAL)&_pragma=synchronous(NORMAL)&_pragma=busy_timeout(5000)"- Single connection pool via
sqlDB.SetMaxOpenConns(1)withlocking_mode=EXCLUSIVE, keeping the WAL index in memory without POSIX advisory locks on-shm.4. Prepared Statement Caching & Hot-Path Contexts:
- Prepares and caches
*sql.Stmtper table forGet,Insert/Replace,Delete,Scan,ScanLimit, andCount.- Strips cancellable context wrappers via
context.WithoutCancel(ctx)on database hot paths to eliminate modernc'sinterruptOnDonegoroutines.5. Startup & Snapshot Recovery Hierarchy:
- Local SQLite DB: Reopened at position $P$ with stream replay from position $P$.
- Published SQLite Snapshot: Restored via
sqlite.RestoreSnapshotwith stream replay from snapshot position.- EROFS Snapshot: Loaded and imported into SQLite via
importErofsToSQLiteLockedwith stream replay.- Snapshot publishing during flush via
sqlite.PublishSnapshot(VACUUM INTO).6. End-to-End & POSIX Gates:
- Added
-mode=opstotests/bench/benchmark.gofor FUSE end-to-end benchmarking.- Configured
dev/tasks/fuse-startanddev/ci/presubmits/ap-posixto test both legacy and sqlite stores in CI.---
Benchmark Comparison (Before vs After Optimization)
Single-Client Latency
| Operation | Legacy (In-Memory LRU) | SQLite (Initial PR) | SQLite (Optimized) | Speedup vs Initial |
| :--- | :--- | :--- | :--- | :--- |
| Stat (GetAttr) | 0.34 µs | 126.4 µs | 10.6 µs | 12x faster |
| Lookup | 0.41 µs | 375.9 µs | 15.9 µs | 23x faster |
| ReadDir (100 entries) | 27.7 µs | 12.8 ms | 0.70 ms | 18x faster |
| Rename | 0.82 ms | 2.24 ms | 1.65 ms | 1.4x faster |
| Create | 0.82 ms | 2.02 ms | 1.68 ms | 1.2x faster |
| 64 KiB fsynced write | 1.15 ms | 2.53 ms | 1.85 ms | 1.4x faster |
Directory Entry Addition Scaling
| Scenario | Legacy Store | SQLite (Initial PR) | SQLite (Optimized) |
| :--- | :--- | :--- | :--- |
| Add to empty directory | 0.77 ms | 1.45 ms | 1.45 ms |
| Add to 10k entry directory | 0.99 ms | 11.23 ms | 1.42 ms |
Scale & Cache-Miss Latency (Exceeding Legacy 10,000 Inode LRU)
When the dataset exceeds the legacy in-memory cache capacity (tested with 15,000 files across directories):
| Scenario | Legacy Store (Disk/EROFS Miss) | SQLite Store | SQLite Advantage |
| :--- | :--- | :--- | :--- |
| Stat 1,000 evicted inodes | 353.4 ms (353.4 µs/op) | 8.7 ms (8.7 µs/op) | 40x faster |
| Lookup 10 dirs | 386.3 µs | 25.5 µs | 15x faster |
| Memory (HeapAlloc) | 16,998 KB | 7,599 KB | 55% less memory |
Cold Start Recovery Time (First Request Served)
---
Fixes #109