Always use DirectoryReader for realtime get from translog#74722
Merged
ywelsch merged 7 commits intoelastic:masterfrom Jul 1, 2021
Merged
Always use DirectoryReader for realtime get from translog#74722ywelsch merged 7 commits intoelastic:masterfrom
ywelsch merged 7 commits intoelastic:masterfrom
Conversation
ywelsch
commented
Jun 30, 2021
| IndexReader.CacheHelper cacheHelper = reader.getReaderCacheHelper(); // this one takes deletes into account | ||
| if (cacheHelper == null) { | ||
| throw new IllegalStateException("Reader " + reader + " does not support caching"); | ||
| return computeNumDocs(reader, roleQueryBits); |
Contributor
Author
There was a problem hiding this comment.
This change was necessary as DocumentSubsetReader was a bad citizen. It required the leafreader that it wrapped to have a readerCacheHelper, but then at the same time did not expose a reader cache helper by its own wrapping leafreader, so essentially double-standards.
I don't see a reason for this reader not to work when caching isn't available (single-document case)
Collaborator
|
Pinging @elastic/es-distributed (Team:Distributed) |
dnhatn
approved these changes
Jun 30, 2021
server/src/main/java/org/elasticsearch/index/mapper/DocumentLeafReader.java
Outdated
Show resolved
Hide resolved
henningandersen
approved these changes
Jul 1, 2021
Contributor
henningandersen
left a comment
There was a problem hiding this comment.
LGTM.
All comments below are optional at your discretion.
server/src/main/java/org/elasticsearch/index/engine/Engine.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/engine/TranslogDirectoryReader.java
Show resolved
Hide resolved
ywelsch
added a commit
that referenced
this pull request
Jul 1, 2021
Reading from translog during a realtime get requires special handling in some higher level components, e.g. ShardGetService, where we're doing a bunch of tricks to extract other stored fields from the source. Another issue with the current approach relates to #74227 where we introduce a new "field usage tracking" directory wrapper that's always applied, and we want to make sure that we can still quickly do realtime gets from translog without creating an in-memory index of the document, even when this directory wrapper exists. This PR introduces a directory reader that contains a single translog indexing operation. This can be used during a realtime get to access documents that haven't been refreshed yet. In the normal case, all information relevant to resolve the realtime get is mocked out to provide fast access to _id and _source. In case where more values are requested (e.g. access to other stored fields) etc., this reader will index the document into an in-memory Lucene segment that is created on-demand. Relates #64504
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reading from translog during a realtime get requires special handling in some higher level components, e.g.
ShardGetService, where we're doing a bunch of tricks to extract other stored fields from the source. Another issue with the current approach relates to #74227 where we introduce a new "field usage tracking" directory wrapper that's always applied, and we want to make sure that we can still quickly do realtime gets from translog without creating an in-memory index of the document, even when this directory wrapper exists.This PR introduces a directory reader that contains a single translog indexing operation. This can be used during a realtime get to access documents that haven't been refreshed yet. In the normal case, all information relevant to resolve the realtime get is mocked out to provide fast access to _id and _source. In case where more values are requested (e.g. access to other stored fields) etc., this reader will index the document into an in-memory Lucene segment that is created on-demand.
Relates #64504