librocksdb_sys: Implement a writable file interface#851
Conversation
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds end-to-end WritableFile support: C API wrappers, librocksdb_sys FFI bindings, a safe Rust WritableFile type implementing io::Write with close/Drop, crate re-export, and integration tests that create/write/flush/close/read/delete files. ChangesWritableFile Support Stack
Sequence DiagramsequenceDiagram
participant Caller
participant Env
participant RustWrapper as WritableFile (Rust)
participant FFI as librocksdb_sys FFI
participant C_API as RocksDB C API
Caller->>Env: new_writable_file(path, opts)
Env->>FFI: crocksdb_writable_file_create(path, opts, err)
FFI->>C_API: Env::NewWritableFile -> rocksdb::WritableFile*
C_API-->>FFI: WritableFile* / Status
FFI-->>RustWrapper: DBWritableFile pointer or err
Caller->>RustWrapper: write(data)
RustWrapper->>FFI: crocksdb_writable_file_append(data, len, err)
FFI->>C_API: WritableFile::Append -> Status
C_API-->>FFI: Status (OK/error)
FFI-->>RustWrapper: ok / err
Caller->>RustWrapper: flush()
RustWrapper->>FFI: crocksdb_writable_file_flush(err)
RustWrapper->>FFI: crocksdb_writable_file_close(err)
RustWrapper->>FFI: crocksdb_writable_file_destroy()
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
librocksdb_sys/crocksdb/crocksdb/c.h (1)
1797-1809: ⚡ Quick winConsider consistent naming between typedef and function prefix.
The typedef is
crocksdb_writablefile_t(no underscore between "writable" and "file") but the functions usecrocksdb_writable_file_*(with underscore). This differs from the existing pattern where typedef and function names match—for example,crocksdb_sequential_file_tusescrocksdb_sequential_file_*functions, andcrocksdb_readoptions_tusescrocksdb_readoptions_*functions.For consistency, either:
- Change the typedef to
crocksdb_writable_file_t, or- Change function names to
crocksdb_writablefile_*This mismatch could confuse API users and lead to typos when calling these functions.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@librocksdb_sys/crocksdb/crocksdb/c.h` around lines 1797 - 1809, The typedef name crocksdb_writablefile_t is inconsistent with the function family crocksdb_writable_file_*; rename the typedef to crocksdb_writable_file_t (and any struct/tag declarations and all references) so it matches the functions crocksdb_writable_file_create, crocksdb_writable_file_append, crocksdb_writable_file_flush, crocksdb_writable_file_close, and crocksdb_writable_file_destroy; update all usages and forward declarations in the codebase and headers to the new typedef name to maintain the established naming pattern.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/rocksdb.rs`:
- Around line 2923-2983: The WritableFile Drop currently calls
crocksdb_writable_file_destroy directly and can leak an un-closed file; make
close() idempotent and have Drop attempt a best-effort close before destroy. Add
a closed: bool (or closed: AtomicBool if multithreaded) field to WritableFile,
initialize it in WritableFile::new, update close(&mut self) to return early if
closed is true and otherwise call crocksdb_writable_file_close and set closed =
true (preserve the existing Result<String> behavior), and change Drop::drop to
call close() in an unsafe, ignored-error way and then call
crocksdb_writable_file_destroy only once (set inner = ptr::null_mut() after
destroy to avoid double-destroy).
---
Nitpick comments:
In `@librocksdb_sys/crocksdb/crocksdb/c.h`:
- Around line 1797-1809: The typedef name crocksdb_writablefile_t is
inconsistent with the function family crocksdb_writable_file_*; rename the
typedef to crocksdb_writable_file_t (and any struct/tag declarations and all
references) so it matches the functions crocksdb_writable_file_create,
crocksdb_writable_file_append, crocksdb_writable_file_flush,
crocksdb_writable_file_close, and crocksdb_writable_file_destroy; update all
usages and forward declarations in the codebase and headers to the new typedef
name to maintain the established naming pattern.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9566ac32-74df-4993-8e01-857df1b6c77f
📒 Files selected for processing (5)
librocksdb_sys/crocksdb/c.cclibrocksdb_sys/crocksdb/crocksdb/c.hlibrocksdb_sys/src/lib.rssrc/lib.rssrc/rocksdb.rs
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
Signed-off-by: Jianjun Liao <jianjun.liao@outlook.com>
[LGTM Timeline notifier]Timeline:
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: glorv, YuJuncen The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/ok-to-test |
|
/retest |
Implement a writable file interface to enable SST data streaming via memory-copy level writes instead of KV-level writes.
The implementation is modeled after
sequential_fileSummary by CodeRabbit
New Features
Tests