Only call doCache one per request#6001
Only call doCache one per request#6001cwperks wants to merge 4 commits intoopensearch-project:mainfrom
Conversation
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6001 +/- ##
==========================================
- Coverage 73.82% 73.81% -0.02%
==========================================
Files 439 439
Lines 27087 27104 +17
Branches 4018 4022 +4
==========================================
+ Hits 19998 20007 +9
- Misses 5180 5189 +9
+ Partials 1909 1908 -1
🚀 New features to boost your workflow:
|
|
|
||
| @Override | ||
| public Weight doCache(Weight weight, QueryCachingPolicy policy) { | ||
| if (!indexSettings.getValue(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING)) { |
There was a problem hiding this comment.
I am not entirely sure if this setting is the correct one here. The method is a about the query cache, but this setting is index cache specific.
Maybe we can approach the issue by adding a cache to hasRestrictedRulesExplicit() to avoid recurring rule calculations. I can look into this.
There was a problem hiding this comment.
yea, I closed it because I'm not confident that I understand the different levels of caching deeply enough yet. I will re-open once I can take a deeper dive if it make sense.
There was a problem hiding this comment.
In my testing, I'm finding that doCache can be called multiple times per query. For the example below it would be called 5x for each clause:
{
"query": {
"bool": {
"filter": [
{ "term": { "field_b": "other_0" } },
{ "term": { "field_b": "other_1" } },
{ "term": { "field_b": "other_2" } },
{ "term": { "field_b": "other_3" } },
{ "term": { "field_b": "other_4" } }
]
}
}
}
I think we can do some caching of the first result and short-circuit accordingly.
There was a problem hiding this comment.
yea, i can take care of that.
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Description
We recently saw this method in the hotthreads output of a cluster that had many aliases pointing to the same concrete index.
On further investigation, I found that
doCachecan sometimes be called many times per query when I would expect it to run once per request. The changes in this PR ensure that its called once per request per shard, stores the result in the threadcontext and uses that for subsequent clauses.For instance, in the query below
doCachewould be called 5x per shardBug fix
Issues Resolved
To be filed
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.