-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Speed up InternalEngine#resolveDocVersion(...) method #122374
Speed up InternalEngine#resolveDocVersion(...) method #122374
Conversation
Use reference manager to get index reader instead of acquire a searcher. The latter involved creating an index searcher, which is not used and expensive as part og resolveDocVersion() method.
Hi @martijnvg, I've created a changelog YAML for you. |
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
Pinging @elastic/es-distributed-indexing (Team:Distributed Indexing) |
final VersionsAndSeqNoResolver.DocIdAndVersion docIdAndVersion; | ||
try (Searcher searcher = acquireSearcher("load_version", SearcherScope.INTERNAL)) { | ||
var indexReader = referenceManager.acquire(); |
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 think we need to hold a reference to the store before acquiring the referenceManager.
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.
Strange that no test then failed.
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 pushed: 8072907
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 think it's very unlikely and might even be impossible to run into a closed store here?
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.
Yes, resolveDocVersion is executed while holding a ref on the engine (preventing the engine to be closed and in turn the store to be closed too).
c0a0199
to
8072907
Compare
I swapped the enhancement label with non-issue label. After further analysis the reason why constructing an This is still the right change, the |
/* Acquire order here is store -> manager since we need | ||
* to make sure that the store is not closed before | ||
* the searcher is acquired. */ | ||
if (store.tryIncRef() == false) { |
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.
Ah see @tlrx, we don't need to ever acquire a store because we are guaranteed to have an engine reference here?
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 see, so we can just change that into an assertion?
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 think so yes, assertion should be enough :)
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 think so 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.
pushed: b81fa73
} | ||
} | ||
|
||
abstract static class DirectoryReaderSupplier implements Releasable { |
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.
This is only extended once, we can make this one class for the reader supplier can't we? Or better yet, maybe just inline the logic to save some cycles? :)
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 pushed: 1ee2699
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 for the iterations Martijn!
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 Martijn!
Use reference manager to get index reader instead of acquiring a searcher. The latter involves creating an index searcher, which is not used and expensive as part of the `resolveDocVersion(...)` method, because this method is invoked for each document that gets indexed.
Use reference manager to get index reader instead of acquiring a searcher. The latter involves creating an index searcher, which is not used and expensive as part of the `resolveDocVersion(...)` method, because this method is invoked for each document that gets indexed.
Checking whether we need to refresh does not require a searcher so we can simplify this to just work based on the reader and avoid lots of contention etc. for setting up the searcher. relates #122374
Checking whether we need to refresh does not require a searcher so we can simplify this to just work based on the reader and avoid lots of contention etc. for setting up the searcher. relates elastic#122374
Use reference manager to get index reader instead of acquire a searcher. The latter involves creating an index searcher, which is not used and expensive as part of the
resolveDocVersion(...)
method. This method is invoked for each document that gets indexed.