Provide a getFromTranslog method in ShardGetService#95736
Provide a getFromTranslog method in ShardGetService#95736elasticsearchmachine merged 15 commits intoelastic:mainfrom
getFromTranslog method in ShardGetService#95736Conversation
|
|
|
Pinging @elastic/es-distributed (Team:Distributed) |
pxsalehi
left a comment
There was a problem hiding this comment.
@henningandersen @Tim-Brooks @tlrx This is now cleaned up and I've added test too. Ready for review! :-)
| try (ReleasableLock ignored = readLock.acquire()) { | ||
| ensureOpen(); | ||
| if (get.realtime()) { | ||
| final VersionValue versionValue; |
There was a problem hiding this comment.
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.
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
| assert versionValue.seqNo >= 0 : versionValue; | ||
| refreshIfNeeded("realtime_get", versionValue.seqNo); | ||
| } | ||
| return null; |
There was a problem hiding this comment.
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.
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
| return getFromSearcher(get, acquireSearcher("get", SearcherScope.EXTERNAL, searcherWrapper), false); | ||
| } | ||
| assert versionValue.seqNo >= 0 : versionValue; | ||
| refreshIfNeeded("realtime_get", versionValue.seqNo); |
There was a problem hiding this comment.
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.
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.
…gine.java Co-authored-by: Tanguy Leroux <tlrx.dev@gmail.com>
|
@elasticmachine update branch |
getFromTransloginShardGetServicethat shortcuts a get once not found in the translog.InternalEngine.These two together would be used in a
TransportGetFromTranslogActionin 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