@@ -760,11 +760,9 @@ public GetResult get(
760
760
try (ReleasableLock ignored = readLock .acquire ()) {
761
761
ensureOpen ();
762
762
if (get .realtime ()) {
763
- var result = realtimeGetUnderLock (get , mappingLookup , documentParser , searcherWrapper );
764
- if (result != null ) {
765
- return result ;
766
- }
767
- return getFromSearcher (get , acquireSearcher ("realtime_get" , SearcherScope .INTERNAL , searcherWrapper ), false );
763
+ var result = realtimeGetUnderLock (get , mappingLookup , documentParser , searcherWrapper , true );
764
+ assert result != null : "real-time get result must not be null" ;
765
+ return result ;
768
766
} else {
769
767
// we expose what has been externally expose in a point in time snapshot via an explicit refresh
770
768
return getFromSearcher (get , acquireSearcher ("get" , SearcherScope .EXTERNAL , searcherWrapper ), false );
@@ -782,15 +780,20 @@ public GetResult getFromTranslog(
782
780
assert assertGetUsesIdField (get );
783
781
try (ReleasableLock ignored = readLock .acquire ()) {
784
782
ensureOpen ();
785
- return realtimeGetUnderLock (get , mappingLookup , documentParser , searcherWrapper );
783
+ return realtimeGetUnderLock (get , mappingLookup , documentParser , searcherWrapper , false );
786
784
}
787
785
}
788
786
787
+ /**
788
+ * @param getFromSearcher indicates whether we also try the internal searcher if not found in translog. In the case where
789
+ * we just started tracking locations in the translog, we always use the internal searcher.
790
+ */
789
791
protected GetResult realtimeGetUnderLock (
790
792
Get get ,
791
793
MappingLookup mappingLookup ,
792
794
DocumentParser documentParser ,
793
- Function <Engine .Searcher , Engine .Searcher > searcherWrapper
795
+ Function <Engine .Searcher , Engine .Searcher > searcherWrapper ,
796
+ boolean getFromSearcher
794
797
) {
795
798
assert readLock .isHeldByCurrentThread ();
796
799
assert get .realtime ();
@@ -799,6 +802,7 @@ protected GetResult realtimeGetUnderLock(
799
802
// we need to lock here to access the version map to do this truly in RT
800
803
versionValue = getVersionFromMap (get .uid ().bytes ());
801
804
}
805
+ boolean getFromSearcherIfNotInTranslog = getFromSearcher ;
802
806
if (versionValue != null ) {
803
807
if (versionValue .isDelete ()) {
804
808
return GetResult .NOT_EXISTS ;
@@ -836,14 +840,15 @@ protected GetResult realtimeGetUnderLock(
836
840
trackTranslogLocation .set (true );
837
841
// We need to start tracking translog locations in the live version map. Refresh and
838
842
// serve the get from the internal searcher even if we're supposed to only get from translog.
839
- assert versionValue .seqNo >= 0 : versionValue ;
840
- refreshIfNeeded ("realtime_get" , versionValue .seqNo );
841
- return getFromSearcher (get , acquireSearcher ("realtime_get" , SearcherScope .INTERNAL , searcherWrapper ), false );
843
+ getFromSearcherIfNotInTranslog = true ;
842
844
}
843
845
}
844
846
assert versionValue .seqNo >= 0 : versionValue ;
845
847
refreshIfNeeded ("realtime_get" , versionValue .seqNo );
846
848
}
849
+ if (getFromSearcherIfNotInTranslog ) {
850
+ return getFromSearcher (get , acquireSearcher ("realtime_get" , SearcherScope .INTERNAL , searcherWrapper ), false );
851
+ }
847
852
return null ;
848
853
}
849
854
0 commit comments