Use caching to avoid excessive creation of NonClosingReaderWrapper instances#20921
Use caching to avoid excessive creation of NonClosingReaderWrapper instances#20921kkewwei wants to merge 5 commits intoopensearch-project:mainfrom
Conversation
PR Reviewer Guide 🔍(Review updated until commit 31a701b)Here are some key observations to aid the review process:
|
|
@sgup432 Please help review in your spare time. |
PR Code Suggestions ✨Latest suggestions up to 31a701b Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit a72da36
Suggestions up to commit 1d4bbfa
Suggestions up to commit 9b78f3e
Suggestions up to commit 5f67c69
Suggestions up to commit 1f8febd
|
|
Persistent review updated to latest commit 1f8febd |
|
❌ Gradle check result for 1f8febd: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
Persistent review updated to latest commit 5f67c69 |
|
❌ Gradle check result for 5f67c69: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
❌ Gradle check result for 5f67c69: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
❌ Gradle check result for 5f67c69: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
org.opensearch.indices.IndicesRequestCacheIT.testCanCache #20920 |
| * @opensearch.internal | ||
| */ | ||
| private static final class NonClosingReaderWrapper extends FilterDirectoryReader { | ||
| @PublicApi(since = "3.6.0") |
There was a problem hiding this comment.
Why do we need to make this public?
There was a problem hiding this comment.
IndexReaderWrapperTests needs to reference NonClosingReaderWrapper, which requires the class to be exposed. However, I believe we can avoid this issue by using DirectoryReader externally instead.
| NonClosingReaderWrapper nonClosingReaderWrapper = new NonClosingReaderWrapper(engineSearcher.getDirectoryReader()); | ||
|
|
||
| NonClosingReaderWrapper nonClosingReaderWrapper; | ||
| if (readerWrapperCache == null) { |
There was a problem hiding this comment.
I guess this would never be null?
There was a problem hiding this comment.
Being a static function, wrapSearcher is invoked directly within InternalEngine. Since InternalEngine does not have access to the variables in the corresponding IndexShard, these variables will be set to null upon entry into this function.
|
|
||
| private final IndexingOperationListener indexingOperationListeners; | ||
| private final Runnable globalCheckpointSyncer; | ||
| private final ConcurrentHashMap<DirectoryReader, NonClosingReaderWrapper> readerWrapperCache = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Lets clear this map during IndexShard.close() as well? Though it would eventually clear it out when all underlying segments are closed, but still good to have?
|
Persistent review updated to latest commit 9b78f3e |
|
Persistent review updated to latest commit 1d4bbfa |
|
Persistent review updated to latest commit a72da36 |
…stances Signed-off-by: kkewwei <kewei.11@bytedance.com> Signed-off-by: kkewwei <kkewwei@163.com>
Signed-off-by: kkewwei <kewei.11@bytedance.com> Signed-off-by: kkewwei <kkewwei@163.com>
Signed-off-by: kkewwei <kewei.11@bytedance.com> Signed-off-by: kkewwei <kkewwei@163.com>
a72da36 to
e7344dd
Compare
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit e7344dd.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
Signed-off-by: kkewwei <kewei.11@bytedance.com> Signed-off-by: kkewwei <kkewwei@163.com>
e7344dd to
31a701b
Compare
|
Persistent review updated to latest commit 31a701b |
|
❌ Gradle check result for 31a701b: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
…stances
Description
Instead of creating a NonClosingReaderWrapper per query/update, we reuse the same NonClosingReaderWrapper by caching.
We can't reuse it in external plugin(like security plugin), in security plugin, the result may depend on conditions such as the user, so the same
NonClosingReaderWrappercannot be reused universally.Related Issues
Resolves #19175
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.