Skip to content

Add hook for LRUQueryCache to allow custom population strategies - #15723

Merged
dnhatn merged 3 commits into
mainfrom
cache-strategy
Feb 19, 2026
Merged

dnhatn merged 3 commits into
mainfrom
cache-strategy

Conversation

@dnhatn

@dnhatn dnhatn commented Feb 19, 2026

Copy link
Copy Markdown
Member

In Elasticsearch, we execute intra-segment searches across multiple threads, which can trigger redundant, concurrent cache populations for the same segment. Since each slice-search targets a subset of the segment but cache population scans the entire segment, this amplification significantly wastes I/O and CPU for expensive queries. This PR introduces a hook in LRUQueryCache to allow custom population strategies, such as delegating to a background thread or skipping redundant populations. There is no change to the default behavior of LRUQueryCache.

@dnhatn dnhatn added this to the 10.5.0 milestone Feb 19, 2026
@dnhatn
dnhatn marked this pull request as ready for review February 19, 2026 01:05

@martijnvg martijnvg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@romseygeek romseygeek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

assertThat(reader.leaves(), hasSize(1));
LeafReaderContext singleLeaf = reader.leaves().get(0);

AtomicInteger visited = new AtomicInteger(0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It took me a while to work out what this test was actually doing (dividing up the document space into numThreads sections, and searching each section separately in its own thread) - maybe add some comments to make it a bit clearer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

++ added in 4f80ab0

@dnhatn

dnhatn commented Feb 19, 2026

Copy link
Copy Markdown
Member Author

@martijnvg @romseygeek Thank you!

@dnhatn
dnhatn merged commit e1879e4 into main Feb 19, 2026
13 checks passed
dnhatn added a commit that referenced this pull request Feb 19, 2026
)

In Elasticsearch, we execute intra-segment searches across multiple 
threads, which can trigger redundant, concurrent cache populations for
the same segment. Since each slice-search targets a subset of the
segment but cache population scans the entire segment, this
amplification significantly wastes I/O and CPU for expensive queries.
This PR introduces a hook in LRUQueryCache to allow custom population
strategies, such as delegating to a background thread or skipping
redundant populations. There is no change to the default behavior of
LRUQueryCache.
dnhatn added a commit that referenced this pull request Feb 19, 2026
In Elasticsearch, we execute intra-segment searches across multiple 
threads, which can trigger redundant, concurrent cache populations for
the same segment. Since each slice-search targets a subset of the
segment but cache population scans the entire segment, this
amplification significantly wastes I/O and CPU for expensive queries.
This PR introduces a hook in LRUQueryCache to allow custom population
strategies, such as delegating to a background thread or skipping
redundant populations. There is no change to the default behavior of
LRUQueryCache.

Backport of #15723 to 10.x
gmarouli pushed a commit to gmarouli/lucene that referenced this pull request Feb 20, 2026
…che#15723)

In Elasticsearch, we execute intra-segment searches across multiple 
threads, which can trigger redundant, concurrent cache populations for
the same segment. Since each slice-search targets a subset of the
segment but cache population scans the entire segment, this
amplification significantly wastes I/O and CPU for expensive queries.
This PR introduces a hook in LRUQueryCache to allow custom population
strategies, such as delegating to a background thread or skipping
redundant populations. There is no change to the default behavior of
LRUQueryCache.
dnhatn added a commit to elastic/elasticsearch that referenced this pull request Feb 20, 2026
This change forks LRUQueryCache to include apache/lucene#15723 so that 
we can override cache population behavior for intra-segment searches. 
With ES|QL doc_partitioning, each thread can independently populates the
query cache for the same segment. The actual changes will be in a
follow-up PR. Once Lucene 10.5 or 11 is released, we should remove this
fork.
PeteGillinElastic pushed a commit to PeteGillinElastic/elasticsearch that referenced this pull request Feb 23, 2026
This change forks LRUQueryCache to include apache/lucene#15723 so that 
we can override cache population behavior for intra-segment searches. 
With ES|QL doc_partitioning, each thread can independently populates the
query cache for the same segment. The actual changes will be in a
follow-up PR. Once Lucene 10.5 or 11 is released, we should remove this
fork.
jimczi added a commit to elastic/elasticsearch that referenced this pull request Jun 29, 2026
The fork existed only to backport apache/lucene#15723 (the
tryPopulateCache hook for intra-segment cache population). Lucene 10.5
ships that hook, so ElasticsearchLRUQueryCache extends the upstream
LRUQueryCache directly and the fork is deleted.
jimczi added a commit to elastic/elasticsearch that referenced this pull request Jun 29, 2026
Adds coverage for the intra-segment cache gate doc-partitioning relies on:
a query whose weight is an OptionalCachingWeight populates the cache only
when startCaching grants the claim, and falls back to an uncached scorer
otherwise. Guards the seam now served by Lucene 10.5 (apache/lucene#15723).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants