Reduce refresh when lookup term in FollowingEngine (#39184)
Today we always refresh when looking up the primary term in FollowingEngine. This is not necessary for we can simply return none for operations before the global checkpoint.
This commit is contained in:
parent
cdec11c4eb
commit
a96df5d209
|
@ -151,14 +151,12 @@ public final class FollowingEngine extends InternalEngine {
|
|||
}
|
||||
|
||||
private OptionalLong lookupPrimaryTerm(final long seqNo) throws IOException {
|
||||
refreshIfNeeded("lookup_primary_term", seqNo);
|
||||
try (Searcher engineSearcher = acquireSearcher("lookup_primary_term", SearcherScope.INTERNAL)) {
|
||||
// We have to acquire a searcher before execute this check to ensure that the requesting seq_no is always found in the else
|
||||
// branch. If the operation is at most the global checkpoint, we should not look up its term as we may have merged away the
|
||||
// operation. Moreover, we won't need to replicate this operation to replicas since it was processed on every copies already.
|
||||
// Don't need to look up term for operations before the global checkpoint for they were processed on every copies already.
|
||||
if (seqNo <= engineConfig.getGlobalCheckpointSupplier().getAsLong()) {
|
||||
return OptionalLong.empty();
|
||||
} else {
|
||||
}
|
||||
refreshIfNeeded("lookup_primary_term", seqNo);
|
||||
try (Searcher engineSearcher = acquireSearcher("lookup_primary_term", SearcherScope.INTERNAL)) {
|
||||
final DirectoryReader reader = Lucene.wrapAllDocsLive(engineSearcher.getDirectoryReader());
|
||||
final IndexSearcher searcher = new IndexSearcher(reader);
|
||||
searcher.setQueryCache(null);
|
||||
|
@ -177,6 +175,9 @@ public final class FollowingEngine extends InternalEngine {
|
|||
return OptionalLong.of(primaryTermDV.longValue());
|
||||
}
|
||||
}
|
||||
if (seqNo <= engineConfig.getGlobalCheckpointSupplier().getAsLong()) {
|
||||
return OptionalLong.empty(); // we have merged away the looking up operation.
|
||||
} else {
|
||||
assert false : "seq_no[" + seqNo + "] does not have primary_term, total_hits=[" + topDocs.totalHits + "]";
|
||||
throw new IllegalStateException("seq_no[" + seqNo + "] does not have primary_term (total_hits=" + topDocs.totalHits + ")");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue