Skip to content

Replace caching onion - #7066

Open
PSeitz wants to merge 1 commit into
quickwit-oss:mainfrom
PSeitz:remove_caching_onion
Open

PSeitz wants to merge 1 commit into
quickwit-oss:mainfrom
PSeitz:remove_caching_onion

Conversation

@PSeitz

@PSeitz PSeitz commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Replaces the dynamic Directory and Storage wrapper stack on the search read path with three concrete types (SplitDirectory, SplitBundle, and SplitStorageReader) where every layer has a fixed position and caches no longer implement Storage.

Before (up to 10 nested Directory / Storage wrappers)

Tantivy
  ▼
HotDirectory                  (Directory — hotcache)
  ▼
CachingDirectory              (Directory — per-split short-lived cache + MemoryReserver)
  ▼
StorageDirectory              (Directory — Storage adapter + coalesced range streaming)
  ▼
BundleStorage                 (Storage — maps split files to byte ranges)
  ▼
FeuerStorage                  (Storage — node-wide slice cache)
  ▼
SplitCacheBackingStorage      (Storage — whole-split disk cache)
  ▼
TimeoutAndRetryStorage        (Storage — retry on timeout)
  ▼
CountingStorage               (Storage — download counters)
  ▼
DebouncedStorage              (Storage — in-flight dedup)
  ▼
S3 / GCS / Azure / LocalFile  (Storage)

Problems with this stack:

  • Caches and read helpers implemented Storage (or Directory), forcing them to forward or stub unrelated write, delete, and list methods.
  • Dynamic nesting allowed invalid layer orderings. TimeoutAndRetryStorage sat above DebouncedStorage, so a timed-out retry re-joined the same stalled Shared future instead of issuing a fresh backend request. DebouncedStorage sat below FeuerStorage even though feuer already deduplicates buffered misses.
  • Component scoping was implicit (DebouncedStorage was hidden inside storage factories; caches and counters were stacked ad-hoc at call sites).

After (3 concrete types with clear API boundaries)

Tantivy
  │  tantivy::Directory (read_bytes / read_bytes_async / stream_ranges)
  ▼
SplitDirectory  (quickwit-directories)
  ├── read_bytes (sync):
  │     1. hotcache (always checked first)
  │     2. per-split short-lived cache (ShortLivedCache::Disabled | Enabled { memory_reserver })
  │     3. miss -> unsupported-sync-read error
  ├── read_bytes_async:
  │     1. hotcache (always checked first)
  │     2. per-split short-lived cache (ShortLivedCache::Disabled | Enabled { memory_reserver })
  │     3. miss -> SplitBundle::get_slice
  └── stream_ranges:
        bypasses hotcache and short_lived_cache -> SplitBundle::stream_ranges
  │
  │  bundled file path + byte range(s) within that file
  ▼
SplitBundle  (quickwit-storage)
  └── maps logical file path -> byte range(s) inside `<split_id>.split`
  │
  │  split object path + byte range(s) in object storage
  ▼
SplitStorageReader  (quickwit-storage)
  ├── 1. storage_cache (feuer::Cache; checked per range in stream_ranges only when < 10 ranges, never inserts on stream misses)
  ├── 2. range coalescing (stream_ranges only, bridges nearby gaps up to 4 MiB)
  ├── 3. split_cache (SearchSplitCache, whole-split local disk cache)
  ├── 4. debouncer (StorageDebouncer, skipped on storage_cache buffered reads)
  ├── 5. timeout_policy (retries fresh backend calls inside debounced work)
  ├── 6. download_counters (per-reader backend download tracking)
  └── 7. backend: Arc<dyn Storage>  (S3 / GCS / Azure / LocalFile)

API boundaries:

  • Storage: object/file storage backends only (S3, GCS, Azure, LocalFile, RAM, PrefixStorage). Caches, debouncing, retries, counters, and split-bundle offset mapping no longer implement Storage.
  • SplitStorageReader: reads byte slices and coalesced range streams from immutable split objects with fixed ordering across storage_cache, range coalescing, split_cache, StorageDebouncer, StorageTimeoutPolicy, and DownloadCounters.
  • SplitBundle: translates logical bundled file paths into byte ranges on SplitStorageReader (used directly by SplitDirectory, list_fields, and split recovery).
  • SplitDirectory: the Tantivy Directory implementation for reading splits, owning hotcache lookup, the optional per-split ShortLivedCache, and forwarding stream_ranges (bypassing hotcache and short_lived_cache).

Wrapper Replacement Map

flowchart LR
    subgraph Before
        HotDirectory
        CachingDirectory
        StorageDirectory
        BundleStorage
        FeuerStorage
        SplitCacheBackingStorage
        TimeoutAndRetryStorage
        CountingStorage
        DebouncedStorage
    end

    subgraph After
        SplitDirectory
        SplitBundle
        SplitStorageReader
        StorageDebouncer
    end

    HotDirectory --> SplitDirectory
    CachingDirectory --> SplitDirectory
    StorageDirectory --> SplitDirectory
    BundleStorage --> SplitBundle
    FeuerStorage --> SplitStorageReader
    SplitCacheBackingStorage --> SplitStorageReader
    TimeoutAndRetryStorage --> SplitStorageReader
    CountingStorage --> SplitStorageReader
    DebouncedStorage --> StorageDebouncer
Loading

Also removed unused legacy code: quickwit-storage/src/cache/, DebugProxyDirectory, 7 dead quickwit_cache_virtual_* metrics, and unused crate dependencies (mini-moka, quick_cache, rustc-hash, proptest, time).

User Impact & Breaking Changes

  • Timeout retry fix: Moving timeout-and-retry inside debounced work fixes timed-out reads re-joining the same stalled debounced future instead of issuing a fresh backend request.
  • Metrics: Removed 7 dead quickwit_cache_virtual_* metrics; updated quickwit_storage_object_storage_gets_total description.
  • Internal Rust crate APIs: Removed BundleStorage, CountingStorage, TimeoutAndRetryStorage, DebouncedStorage, AsyncDebouncer, ByteRangeCache, MemorySizedCache, StorageCache, MockStorageCache, wrap_storage_with_cache, and wrap_storage_with_storage_cache from quickwit-storage, and HotDirectory, CachingDirectory, StorageDirectory, DebugProxyDirectory, and ReadOperation from quickwit-directories.
  • Node configuration: CacheConfig keeps existing fields deserializable, so existing node configs remain valid.

Author Checklist

  • Reviewed PR diff
  • Defined the core constraints: caches do not implement Storage, static pipeline disallowing invalid layer orderings, hotcache always consulted first for read_bytes/read_bytes_async (bypassed for stream_ranges), and explicit component scoping
  • Kept storage_cache (feuer) and split_cache (SearchSplitCache) as separate fields rather than a combined cache enum, without adding config mutual-exclusion checks
  • Unified slice and stream debouncing into StorageDebouncer and made DownloadCounters unconditional on SplitStorageReader
  • Moved range coalescing (stream_ranges) from SplitDirectory into SplitStorageReader right above debouncer
  • Scoped per-range storage_cache lookups in stream_ranges to < 10 ranges and sanity-checked 1M-range iterators for zero cache lookups and no eager buffering
  • Verified ByteRangeCache / MemoryReserver role (SplitWarmupMemory) and confirmed CacheConfig deserialization compatibility while removing dead metrics and methods
  • Drove cleanup passes (removed ReadDebouncer, DebugProxyDirectory, SplitBundle::exists, legacy cache/ module, unused deps; flattened write_hotcache; made SplitBundle Arc-backed; folded SplitDirectory tests into split_directory.rs)
  • Reviewed PR description, layer diagrams, API boundaries, and CI lint fixes

Verification

  • make fmt
  • make metrics-inventory
  • RUSTDOCFLAGS="-Dwarnings -Arustdoc::private_intra_doc_links" cargo doc --no-deps
  • cargo check --workspace --tests
  • cargo clippy -p quickwit-config -p quickwit-storage -p quickwit-directories -p quickwit-search -p quickwit-cli -p quickwit-indexing --tests -- -D warnings
  • cargo nextest run -p quickwit-config -p quickwit-directories -p quickwit-search — 477 passed
  • cargo nextest run -p quickwit-storage --features testsuite,azure,gcs — 123 passed
  • cargo nextest run -p quickwit-indexing split_recovery_tests — 2 passed
  • Docker-backed integration tests (make test-all / REST API tests) run in CI.

@PSeitz
PSeitz requested a review from a team as a code owner November 29, 2026 09:26
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T16:10:49.093676Z a50c40c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a238bc1cbc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@datadog-official datadog-official Bot 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.

Bits Code Review: PASS

More details

Timeout retries now execute inside debounced work, allowing fresh backend calls after a timeout. The completed static review found no reportable defects in cache ordering, streaming, or migrated callers.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit a238bc1

@PSeitz PSeitz changed the title Replace dynamic storage/directory caching onion with static split read pipeline Remove caching onion Nov 29, 2026
@PSeitz PSeitz changed the title Remove caching onion Replace caching onion Nov 29, 2026
@PSeitz
PSeitz force-pushed the remove_caching_onion branch from 94d1699 to 40d3bee Compare November 29, 2026 10:23

@datadog-official datadog-official Bot 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.

Bits Code Review: PASS

More details

Static review identified no reportable defects in cache ordering, retry placement, stream sharing, memory reservations, or migrated callers. Runtime behavior was not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 40d3bee

@PSeitz
PSeitz force-pushed the remove_caching_onion branch from 40d3bee to 1586c21 Compare November 29, 2026 11:21

@datadog-official datadog-official Bot 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.

Bits Code Review: PASS

More details

Timeout retries now execute inside debounced work, allowing fresh backend calls instead of rejoining a stalled request. No reportable static concern remained; runtime behavior was not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 1586c21

@PSeitz
PSeitz force-pushed the remove_caching_onion branch from 1586c21 to 48c35c6 Compare November 29, 2026 12:40

@datadog-official datadog-official Bot 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.

Bits Code Review: PASS

More details

Static review found the consolidated read pipeline preserves the relevant cache and memory-reservation behavior. Runtime behavior was not tested.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 48c35c6

@PSeitz
PSeitz force-pushed the remove_caching_onion branch from 48c35c6 to a24960d Compare November 29, 2026 15:42

@datadog-official datadog-official Bot 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.

Bits Code Review: PASS

More details

Static tracing of the read, cache, streaming, and retry paths identified no actionable defects. The human PR discussion contained no comments or reviews requiring reconciliation.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit a24960d

@PSeitz
PSeitz force-pushed the remove_caching_onion branch from a24960d to a50c40c Compare November 29, 2026 16:05

@datadog-official datadog-official Bot 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.

Bits Code Review: PASS

More details

Timeout retries now run inside debounced work, allowing fresh backend requests instead of rejoining a stalled read. The completed static review identified no reportable defect; runtime behavior was not exercised.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit a50c40c

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a50c40c90d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +345 to +346
#[cfg(test)]
mod tests {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Split the new directory module below the 500-line limit

The previously reported standalone test file has been removed, but the tests are now inlined here and split_directory.rs is a newly added, 587-line file. This violates the root AGENTS.md requirement to keep new files under 500 lines; extracting this test module into a separate file would bring both files below the limit without removing coverage.

AGENTS.md reference: AGENTS.md:L136-L136

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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.

1 participant