feat(fs): simplify dyn Fs object safety for per-level routing#109
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughRemoved Fs associated types to make Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
This PR simplifies the filesystem abstraction to make Arc<dyn Fs> ergonomic for per-level filesystem routing by removing Fs trait associated types and type-erasing returned handles/dir listings.
Changes:
- Remove
File/ReadDirassociated types fromFs, making it directly object-safe asdyn Fs. - Change
Fs::open()to returnBox<dyn FsFile>andFs::read_dir()to returnVec<FsDirEntry>. - Update
StdFsimplementation and tests accordingly, removing the now-unneededStdReadDirtype.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/fs/mod.rs | Updates the Fs trait API to be object-safe without associated types and adjusts docs/signatures for boxed file handles and eager directory listing. |
| src/fs/std_fs.rs | Implements the new Fs API for StdFs, inlines directory-entry mapping, and updates tests to use the new return types. |
37805e6 to
99f65f9
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
4d8c9f9 to
718a56d
Compare
a1ac3f6 to
44832fd
Compare
94a1a77 to
ce60753
Compare
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'lsm-tree db_bench'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.15.
| Benchmark suite | Current: ee9a0ee | Previous: c1f5511 | Ratio |
|---|---|---|---|
readseq |
2291224.4054624946 ops/sec |
3035687.9728046074 ops/sec |
1.32 |
prefixscan |
182812.71589896103 ops/sec |
220381.37949769635 ops/sec |
1.21 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @polaz
Copilot correctly noted that hardcoded timing figures (~50ns vs ~5μs) are specific to syscall-backed implementations, not universal for all Fs backends (e.g., in-memory FS). Reword to qualify the claim.
Add the directory path and offending OsString to the error message so callers can identify which directory contains the problematic entry.
Add inline comments explaining: - Box<dyn FsFile> is intentionally 'static (owned handles, not borrowed) - Eager collect fail-fast on bad entries is intentional (corruption signal)
Use path.display() for Path and suppress unnecessary_debug_formatting for OsString which has no Display impl.
Cover the error path in StdFs::read_dir that rejects non-UTF-8 filenames. Only runs on Linux — macOS/APFS rejects invalid UTF-8 at the filesystem level. Also clarify Box<dyn FsFile> lifetime comment wording.
Add explicit note that Vec<FsDirEntry> order is unspecified and callers must sort if needed.
Move #[expect(clippy::unnecessary_debug_formatting)] from the let binding to the format! macro where the lint actually fires.
Some Linux filesystems (overlay, container mounts) reject invalid byte sequences at file creation. Skip the test gracefully instead of panicking on environments that don't support the test scenario.
Strengthen doc comment to clarify that Vec is chosen because LSM directory sizes are bounded (level count), not unbounded.
Directory sizes are bounded by segment count, not level count. Simplify to "expected to remain small" which is accurate.
Simplify the guard to skip on any write error, not just InvalidInput. Container/overlay mounts may return various error kinds when rejecting non-UTF-8 filenames.
Move rationale from adjacent comment into the expect attribute's reason field, matching the pattern used elsewhere in the crate.
Replace unwrap() with ? and unwrap_err() with match to comply with crate-wide #![deny(clippy::unwrap_used)].
b0f7fde to
ee9a0ee
Compare
|
@coderabbitai re-review |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 28986
✅ Object safety
✅
|
Replace generic FS: Fs type parameters with Arc<dyn Fs> / &dyn Fs throughout Writer, MultiWriter, and helpers, following the Fs trait simplification in #109 that removed associated types in favor of Box<dyn FsFile> returns.
Replace generic FS: Fs type parameters with Arc<dyn Fs> / &dyn Fs throughout Writer, MultiWriter, and helpers, following the Fs trait simplification in #109 that removed associated types in favor of Box<dyn FsFile> returns.
Summary
Remove associated types (
File,ReadDir) from theFstrait so thatArc<dyn Fs>works without specifying type parameters — enabling ergonomic per-level filesystem routing.Fs::open()now returnsBox<dyn FsFile>(allocation overhead is negligible for syscall-backed implementations likeStdFs)Fs::read_dir()now returnsVec<FsDirEntry>(cold-path only: recovery, compaction file listing)StdReadDirpublic type (logic inlined intoStdFs::read_dir)Before:
Arc<dyn Fs<File = std::fs::File, ReadDir = StdReadDir>>After:
Arc<dyn Fs>Changes
src/fs/mod.rs— removetype Fileandtype ReadDirassociated types, update method signatures and object-safety docsrc/fs/std_fs.rs— updateStdFsimpl, removeStdReadDir, update testsTesting
All 429 unit tests + integration tests pass. Object-safety test updated to assert simple
Arc<dyn Fs>.Closes #92