[disk] Replace custom cached I/O with standard buffered readers and writers - #1396
Open
Wei Wu (wuw92) wants to merge 1 commit into
Open
Wei Wu (wuw92) wants to merge 1 commit into
Wei Wu (wuw92) wants to merge 1 commit into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The partition test must flush its BufWriter before the dataset is read.
Pull request overview
This PR replaces custom cached I/O with standard buffered readers and writers across disk index construction, partitioning, and graph merging.
Changes:
- Adds bounded
BufReadercreation and updates buffer sizes tousize. - Uses
read_exact,write_all, seeking, and explicit flushing. - Removes the obsolete
CachedReaderandCachedWriterimplementations.
File summaries
| File | Description |
|---|---|
diskann-providers/src/utils/sampling.rs |
Updates buffer-capacity usage. |
diskann-providers/src/utils/mod.rs |
Changes the shared block-size constant to usize. |
diskann-disk/src/utils/partition.rs |
Migrates partition I/O to standard buffering. |
diskann-disk/src/storage/mod.rs |
Adds a bounded buffered-reader helper and test. |
diskann-disk/src/storage/disk_index_writer.rs |
Migrates disk-layout I/O and header rewriting. |
diskann-disk/src/storage/cached_writer.rs |
Removes the obsolete cached writer. |
diskann-disk/src/storage/cached_reader.rs |
Removes the obsolete cached reader. |
diskann-disk/src/build/builder/core.rs |
Migrates shard and graph-merge I/O. |
Review details
Suppressed comments (1)
diskann-disk/src/utils/partition.rs:480
- This test now wraps the dataset writer in
BufWriter, but it drops the writer at the end of the scope without flushing it.BufWriterdiscards buffered bytes on drop, so the dataset is empty and the subsequent call toshard_data_into_clusters_only_idsfails while reading its header; flush the writer after the nested loops.
dataset_writer.write_all(&val.to_le_bytes()).unwrap();
- Files reviewed: 8/8 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1396 +/- ##
==========================================
- Coverage 92.65% 91.54% -1.12%
==========================================
Files 527 526 -1
Lines 103254 103057 -197
==========================================
- Hits 95674 94339 -1335
- Misses 7580 8718 +1138
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reference Issues/PRs
N/A.
What does this implement/fix? Briefly explain your changes.
Replace
CachedReaderandCachedWriterwithstd::io::BufReaderandBufWriterin disk index construction, partitioning, and graph merging, removing the hand-maintained buffering implementation without adding dependencies.open_buf_readerhelper caps reader capacity at file length, with a focused test for that policy. Buffer-size values useusize.read_exactandwrite_allfor complete transfers. Reuse the disk-layout writer to rewind and fill its header instead of reopening the file; explicitly flush completed production outputs to propagate write errors.Any other comments?
This removes the publicly re-exported
CachedReader/CachedWritertypes and changesREAD_WRITE_BLOCK_SIZEfromu64tousize, so downstream source compatibility is not preserved. Truncated reads now follow standard I/O error handling rather than the custom cached-reader EOF diagnostic; initial reads are lazy rather than performed during construction.