Skip to content

feat: Improve on-disk cache init - #87

Open
Darkheir wants to merge 3 commits into
sekoiafrom
feat/on_disk_init_performances
Open

feat: Improve on-disk cache init#87
Darkheir wants to merge 3 commits into
sekoiafrom
feat/on_disk_init_performances

Conversation

@Darkheir

@Darkheir Darkheir commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Fix a potential race condition that would make on-disk footers not accounted for
  • Improve the on-disk cache init time by splitting the work between multiple threads
    • Since a big part is IO bound I think we can have a number of threads greater than the number of CPUs the searcher has.

There is one last potential optimization that would help the searcher start faster:
Make the init return immediately (before the cache has been warmed up) and always check the disk on cache miss during this warm up phase.
Do you think the added complexity is worth it ?

How was this PR tested?

Added test

…read

Signed-off-by: Darkheir <raphael.cohen@sekoia.io>
Signed-off-by: Darkheir <raphael.cohen@sekoia.io>
Copilot AI lite review requested due to automatic review settings September 4, 2026 12:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are localized, add targeted tests for the new behavior, and only minor robustness improvements were identified.

Pull request overview

This PR improves the DiskSizedCache startup path by parallelizing shard scanning to rebuild the LRU index faster, and it hardens cache accounting against a race where a failed disk read could incorrectly drop a newly re-inserted entry.

Changes:

  • Parallelize on-disk shard scanning during cache open, then globally sort by mtime to restore cross-shard recency.
  • Introduce per-entry “generation” tracking so missing-file cleanup won’t remove a concurrently replaced entry.
  • Add tests covering recency restoration across shards and ensuring vanished entries are removed from the index/capacity accounting.
File summaries
File Description
quickwit/quickwit-storage/src/cache/disk_sized_cache.rs Adds parallel shard scanning + generation-based index bookkeeping to speed open and avoid races when files disappear/are replaced.
Review details

Suppressed comments (1)

quickwit/quickwit-storage/src/cache/disk_sized_cache.rs:466

  • entries.into_inner().unwrap() will also panic if the mutex is poisoned. If the intent is to keep cache opening best-effort even under partial failures, it’s safer to recover the inner Vec on poison.
    entries.into_inner().unwrap()
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +460 to +462
let shard_entries = scan_shard(shard_path);
entries.lock().unwrap().extend(shard_entries);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don' think the lock can be poisoned here.

@Darkheir
Darkheir requested a review from rdettai-sk September 4, 2026 12:46
.min(shard_paths.len());
let next_shard_idx = AtomicUsize::new(0);
let entries = Mutex::new(Vec::new());
std::thread::scope(|scope| {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, I think using a rayon threadpool you make this a tiny bit easier to proofread

const SCAN_THREADS_PER_CPU: usize = 4;

/// Upper bound on the number of shard-scanning threads.
const MAX_SCAN_THREADS: usize = 128;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we maybe apply this parallelism limit to all blocking (spawn_blocking) tasks and use one thread pool for the entire disk sized cache?

@rdettai-sk

Copy link
Copy Markdown
Collaborator

Make the init return immediately (before the cache has been warmed up) and always check the disk on cache miss during this warm up phase.
Do you think the added complexity is worth it ?

I don't think so, this is already fairly complicated 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants