Repository navigation
options: expose direct-IO setters for the SST writer and reader - #856
Conversation
TiKV's SST importer writes ingested SSTs buffered and then reads each one back in full, also buffered, to verify checksums. During a large ADD INDEX ingest that streams the entire index through the OS page cache twice and evicts the foreground read working set: reads that were page-cache hits (~50us) become device reads (~400us), degrading foreground p99 by ~2x. See tikv/tikv#19917 for the full analysis. Fixing that in TiKV needs two knobs this crate does not currently expose: - EnvOptions::set_use_direct_writes, so SstFileWriter can write without populating the page cache. RocksDB uses O_DIRECT on Linux and fcntl(F_NOCACHE) on macOS. - ColumnFamilyOptions::set_use_direct_reads, so a standalone SstFileReader can read the same way. use_direct_reads is a DB-level RocksDB option and DBOptions already exposes it here, but SstFileReader::new only accepts ColumnFamilyOptions; in crocksdb both wrap the same underlying Options object, so the setter is added there as well. Neither setter changes any default: both are false unless explicitly set. The test writes an SST with direct writes, reads it back with direct reads, and then reads it again buffered to confirm the alignment padding O_DIRECT requires does not leak into the file format. Ref: tikv/tikv#19917 Signed-off-by: Sanket Kedia <kediasanket11121993@gmail.com>
|
Hi @sanketkedia. Thanks for your PR. I'm waiting for a tikv member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
Welcome @sanketkedia! |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughAdds a C and Rust FFI setter for direct writes. Updates direct-I/O documentation. Expands SST tests to cover direct and buffered reads and writes, checksum validation, iteration, and database ingestion. ChangesDirect I/O option support
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant RustAPI
participant RocksDBOptions
participant SSTFile
participant Database
RustAPI->>RocksDBOptions: configure direct writes
RocksDBOptions->>SSTFile: write direct or buffered SST
RustAPI->>SSTFile: read with direct or buffered options
SSTFile->>RustAPI: return checksum and key/value results
RustAPI->>Database: ingest direct-written SST
Database->>RustAPI: return buffered reads and iteration results
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The direct-I/O bindings and expanded SST compatibility coverage introduce no actionable merge-blocking risk. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Warning Some tools did not complete. Review the errors below. 🔧 Clippy (1.98.0)Clippy execution failed 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
🤖 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_options.rs`:
- Around line 1492-1501: Update the public documentation for
set_use_direct_reads and the corresponding DBOptions setter to replace
platform-specific “O_DIRECT” wording with “direct I/O,” while preserving the
existing explanation of bypassing the OS page cache.
🪄 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 Plus
Run ID: 9b84651c-38cf-40e3-8bac-60966ef818dc
📒 Files selected for processing (5)
librocksdb_sys/crocksdb/c.cclibrocksdb_sys/crocksdb/crocksdb/c.hlibrocksdb_sys/src/lib.rssrc/rocksdb_options.rstests/cases/test_ingest_external_file.rs
AndreMouche
left a comment
There was a problem hiding this comment.
LGTM @Connor1996 Please take a look
[LGTM Timeline notifier]Timeline:
|
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: AndreMouche 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 |
|
Although the internal RocksDB read/write APIs are designed to guarantee forward and backward compatibility when writes use 1. Buffered write -> Direct I/O readThe current test covers "direct-write" -> "buffered-read", which is the important “disable Direct I/O after writing” compatibility case. Direct I/O is an I/O mode rather than an SST format attribute, so this should work without any format metadata or migration. Adding this case would make the compatibility matrix explicit and protect both directions when users toggle the option. 2. Direct I/O write -> ingest -> normal DB readCould we also extend the test to ingest a directly-written SST into a DB and read the ingested keys through the normal buffered DB read path? Reopening the external SST with a buffered |
Address review feedback on the direct-IO setters: - Test buffered write -> direct read in addition to direct write -> direct/buffered read, making the compatibility matrix explicit. - Ingest a directly-written SST into a DB and verify it serves normal buffered point and iterator reads, covering TiKV's full lifecycle. - Say "direct I/O" instead of "O_DIRECT" in the setter docs, since RocksDB uses fcntl(F_NOCACHE) on macOS. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Signed-off-by: Sanket Kedia <kediasanket11121993@gmail.com>
|
I've addressed your comments. Please take a look again. thank you! |
…ngest
An ImportSST.Write writes each SST buffered and then reads it back in full,
also buffered, to verify checksums. For a large ADD INDEX with DXF + global
sort, that streams the whole index through the OS page cache twice and evicts
the working set that concurrent foreground reads depend on: reads that were
page-cache hits (~50us) become device reads (~400us), and foreground p99
degrades ~2x while throughput falls to 0.72x of baseline.
Add import.use-direct-io-for-ingest. When set, DDL-sourced ingest writes its
SSTs with direct I/O and verifies them with direct I/O too, so ingested data
never enters the page cache. Off by default: direct I/O needs a data directory
on a filesystem that supports it, so enabling it is an explicit operator
decision.
Both halves are required. Applying direct I/O only to the writer is a measured
no-op, because the mandatory verification read immediately repopulates the
cache with the data the write kept out of it.
Scoped to DDL-sourced writes because that is the only workload measured. The
discriminator already arrives on the RPC: request_source is
{external|internal}_{tidb_req_source}_{source_task_name}, TiDB's DDL ingest
backend tags its writes internal_lightning_ddl, and the trailing component is
the same task name resource control already matches on. No protocol or
TiDB-side change is needed.
The new trait methods SstReader::open_for_one_shot_read and
SstWriterBuilder::set_use_direct_writes both default to ignoring the flag, so
no other engine implementation has to change.
Cargo.toml temporarily patches rocksdb to the branch behind
tikv/rust-rocksdb#856, which adds the two setters this needs. That must be
removed, and replaced with `cargo update -p rocksdb`, before this can merge.
ref tikv#19917
Signed-off-by: Sanket Kedia <kediasanket11121993@gmail.com>
…ngest
An ImportSST.Write writes each SST buffered and then reads it back in full,
also buffered, to verify checksums. For a large ADD INDEX with DXF + global
sort, that streams the whole index through the OS page cache twice and evicts
the working set that concurrent foreground reads depend on: reads that were
page-cache hits (~50us) become device reads (~400us), and foreground p99
degrades ~2x while throughput falls to 0.72x of baseline.
Add import.use-direct-io-for-ingest. When set, DDL-sourced ingest writes its
SSTs with direct I/O and verifies them with direct I/O too, so ingested data
never enters the page cache. Off by default: direct I/O needs a data directory
on a filesystem that supports it, so enabling it is an explicit operator
decision.
Both halves are required. Applying direct I/O only to the writer is a measured
no-op, because the mandatory verification read immediately repopulates the
cache with the data the write kept out of it.
Scoped to DDL-sourced writes because that is the only workload measured. The
discriminator already arrives on the RPC: request_source is
{external|internal}_{tidb_req_source}_{source_task_name}, TiDB's DDL ingest
backend tags its writes internal_lightning_ddl, and the trailing component is
the same task name resource control already matches on. No protocol or
TiDB-side change is needed.
The new trait methods SstReader::open_for_one_shot_read and
SstWriterBuilder::set_use_direct_writes both default to ignoring the flag, so
no other engine implementation has to change.
Cargo.toml temporarily patches rocksdb to the branch behind
tikv/rust-rocksdb#856, which adds the two setters this needs. That must be
removed, and replaced with `cargo update -p rocksdb`, before this can merge.
ref tikv#19917
Signed-off-by: Sanket Kedia <kediasanket11121993@gmail.com>
What is changed and how it works?
See tikv/tikv#19917 for full context. Exposes two direct-IO setters that TiKV needs in order to stop its SST importer from polluting the OS page cache:
EnvOptions::set_use_direct_writes— letsSstFileWriterwrite an SST withoutpopulating the page cache. Adds the missing
crocksdb_envoptions_set_use_direct_writesshim; RocksDB already supports the underlying
EnvOptions::use_direct_writes, usingO_DIRECTon Linux andfcntl(F_NOCACHE)on macOS.ColumnFamilyOptions::set_use_direct_reads— lets a standaloneSstFileReaderread anSST the same way. Rust-only wrapper; it reuses the existing
crocksdb_options_set_use_direct_readsFFI, so there is no new C code on this path.Neither setter changes any default — both are
falseunless explicitly set, so existingusers are unaffected.
Check List
Tests
test_sst_direct_iointests/cases/test_ingest_external_file.rs: writesan SST with direct writes, reads it back with direct reads and verifies checksum +
contents, then reads it once more buffered to confirm the alignment padding
O_DIRECTrequires does not leak into the file format.Side effects
No behaviour change unless a caller opts in.
Related changes
tikv/tikvimplementing the importer fix; that PR is blockedon this one landing, since TiKV pins
rocksdbby git.Summary by CodeRabbit
New Features
Documentation
Tests