Skip to content

Use hash of the cache key to limit in-memory heap overhead for large search requests - #6727

Open
ncoiffier-celonis wants to merge 1 commit into
mainfrom
hash-partial-request-cache-key
Open

Use hash of the cache key to limit in-memory heap overhead for large search requests#6727
ncoiffier-celonis wants to merge 1 commit into
mainfrom
hash-partial-request-cache-key

Conversation

@ncoiffier-celonis

@ncoiffier-celonis ncoiffier-celonis commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Description

Attempt to fix #5878 and #6719.

Store the hash of the cache key for the partial_request_cache; this is particularly problematic for LeafSearchCache which uses the (large) SearchRequest as a cahce key, including the whole query and for queries that mostly return zero-hit splits.

Hash collision can happen (for a 64MB cache size, the probability of collision is 1e-27). We're limiting the impact of collisions by ensuring that splits belong to the correct search request. In the case of collision, at least data isolation at the index level is preserved (worse case scenario, we would be seeing incorrect document id from the same split or some missing data).

How was this PR tested?

Unit tests only.

@ncoiffier-celonis
ncoiffier-celonis force-pushed the hash-partial-request-cache-key branch from be2b655 to 1490d85 Compare August 27, 2026 15:43
@ncoiffier-celonis
ncoiffier-celonis force-pushed the hash-partial-request-cache-key branch from 1490d85 to 22026c9 Compare August 27, 2026 15:44
@ncoiffier-celonis
ncoiffier-celonis marked this pull request as ready for review August 27, 2026 15:45
@ncoiffier-celonis
ncoiffier-celonis requested review from a team as code owners August 27, 2026 15:45

@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: 22026c9a6b

ℹ️ 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 +60 to +63
response
.partial_hits
.iter()
.all(|partial_hit| partial_hit.split_id == split_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Verify split identity for hitless responses

When a hash collision returns a response from another split with no partial_hits, this all check is vacuously true, so get accepts the response and can expose incorrect counts or aggregation data from another index. This is especially relevant to the zero-hit entries this change targets; store the split identity alongside the encoded response and verify it independently of the hits.

AGENTS.md reference: AGENTS.md:L21-L22

Useful? React with 👍 / 👎.

Comment on lines +285 to +286
let key = CacheKeyHash::of(&(split_id.as_str(), query_ast_json.as_str()));
let encoded_result = self.content.get(&key)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Verify predicate cache identity after hash lookup

When two (split_id, query_ast_json) keys collide, this returns the other entry without validating either original key. A same-split collision can therefore apply the wrong hit set because its segment ID still matches, while a cross-split collision with an empty hit set can make the term-absence path in leaf_search_single_split incorrectly prune the requested split without checking the returned segment ID. Preserve enough identity with the value to reject these collisions rather than treating them as cache hits.

AGENTS.md reference: AGENTS.md:L21-L22

Useful? React with 👍 / 👎.

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.

partial_request cache count keeps increasing

1 participant