-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Provide a getFromTranslog
method in ShardGetService
#95736
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
Provide a getFromTranslog
method in ShardGetService
#95736
Conversation
|
Pinging @elastic/es-distributed (Team:Distributed) |
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.
@henningandersen @Tim-Brooks @tlrx This is now cleaned up and I've added test too. Ready for review! :-)
@@ -754,59 +757,90 @@ public GetResult get( | |||
try (ReleasableLock ignored = readLock.acquire()) { | |||
ensureOpen(); | |||
if (get.realtime()) { | |||
final VersionValue versionValue; |
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.
All I've done here is to break this down into two pieces. Alternative would be probably a flag to shortcut this, but I'm not sure it makes this more readable. Open for suggestions.
// we need to lock here to access the version map to do this truly in RT | ||
versionValue = getVersionFromMap(get.uid().bytes()); | ||
var result = realtimeGetUnderLock(get, mappingLookup, documentParser, searcherWrapper); | ||
if (result != null) { |
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 normal get, as before, never returns null.
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/InternalEngine.java
Outdated
Show resolved
Hide resolved
} | ||
return null; |
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'd be fine to return an Optional.empty() here and in upstream methods; this would maybe help to distinguish the case when the doc is not found in the translog vs when it's found but deleted?
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.
Optional would be also an option! I just wanted to reduce non-essential changes to the Engine interface since that would change the return type in the upstream methods. The null return value is not affecting the normal Engine.get
path. I will add some asserts for it, to make sure. (Alternatively, we could change the return value of get and getFromTranslog to an Optional).
server/src/main/java/org/elasticsearch/index/get/ShardGetService.java
Outdated
Show resolved
Hide resolved
server/src/test/java/org/elasticsearch/index/shard/ShardGetServiceTests.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java
Outdated
Show resolved
Hide resolved
} | ||
assert versionValue.seqNo >= 0 : versionValue; | ||
refreshIfNeeded("realtime_get", versionValue.seqNo); |
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.
Is this refresh needed when the caller is getFromTranslog
? I have the impression that we could avoid it but maybe I am missing a point?
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 is needed since we read from the internal searcher and we need to reload the reader so we can serve the get. The branching is a bit awkward there, I admit. I'll try to improve that.
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.
…gine.java Co-authored-by: Tanguy Leroux <[email protected]>
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
@elasticmachine update branch |
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.
getFromTranslog
inShardGetService
that shortcuts a get once not found in the translog.InternalEngine
.These two together would be used in a
TransportGetFromTranslogAction
in the real-time get PR. The aim is to return either a result from the index shard's translog, or if not found, return the minimum segment generation that the search shard to wait for before handling the get request locally. Since the index shard might not have a result for the get in its translog due to being in the append-only mode (which the get request would temporarily disable), we need to return the generation where we have switched to a safe live version map.Relates ES-5999