-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Refactor index engines to manage readers instead of searchers #43860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit changes the way we manage refreshes in the index engines. Instead of relying on a SearcherManager, this change uses a ReaderManager that creates ElasticsearchDirectoryReader when needed. Searchers are now created on-demand (when acquireSearcher is called) from the current ElasticsearchDirectoryReader. It also slightly changes the Engine.Searcher to extend IndexSearcher in order to simplify the usage in the consumer.
|
Pinging @elastic/es-distributed |
|
Pinging @elastic/es-search |
s1monw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, left some minors
| private final Closeable onClose; | ||
|
|
||
| public Searcher(String source, IndexSearcher searcher, Closeable onClose) { | ||
| public Searcher(String source, IndexReader reader, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any chance we can make this ElasticsearchDirectoryReader instead of IndexReader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ElasticsearchDirectoryReader can be wrapped by plugins so we'd need to move/recreate one when we create the Searcher. I agree that it would be simpler to always force the ElasticsearchDirectoryReader at the top though so I'll give it a try.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot the TranslogLeafReader that is used for get requests so this would require a bigger change and more refactoring. Maybe better to do this in a follow up ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure ++ no rush I didn't anticipate this one either
| return searcher.getIndexReader(); | ||
| } | ||
|
|
||
| public DirectoryReader getDirectoryReader() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we can move to a concrete reader then we can make this a hard cast to ElasticsearchDirectoryReader
| } | ||
| } | ||
|
|
||
| private void notifyListener(ElasticsearchDirectoryReader reader, ElasticsearchDirectoryReader previousReader) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move the reference stealing into this method too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then we can also do this return incrementAndNotify(acquire, referenceToRefresh)
|
|
||
| private void notifyListener(ElasticsearchDirectoryReader reader, ElasticsearchDirectoryReader previousReader) throws IOException { | ||
| boolean success = false; | ||
| try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can maybe do this:
reader.incRef(); // steal the reference
try (Closeable c = reader::decRef) {
refreshListener.accept(reader, previousReader);
reader.incRef(); // double inc-ref if we were successful
return reader;
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++ thanks
| if (renewed) { | ||
| // refresh outside of the write lock | ||
| // we have to refresh internal searcher here to ensure we release unreferenced segments. | ||
| // we have to refresh internal readr here to ensure we release unreferenced segments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/readr/reader
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ta
|
@s1monw , the |
s1monw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
Thanks @s1monw |
This commit changes the way we manage refreshes in the index engines. Instead of relying on a SearcherManager, this change uses a ReaderManager that creates ElasticsearchDirectoryReader when needed. Searchers are now created on-demand (when acquireSearcher is called) from the current ElasticsearchDirectoryReader. It also slightly changes the Engine.Searcher to extend IndexSearcher in order to simplify the usage in the consumer.
This commit changes the way we manage refreshes in the index engines.
Instead of relying on a SearcherManager, this change uses a ReaderManager that
creates ElasticsearchDirectoryReader when needed. Searchers are now created on-demand
(when acquireSearcher is called) from the current ElasticsearchDirectoryReader.
It also slightly changes the Engine.Searcher to extend IndexSearcher in order
to simplify the usage in the consumer.