Skip to content

Commit 1f019eb

Browse files
authored
Don't mark shard as refreshPending on stats fetching (#40458)
Completion and DocStats are pulled from internal readers instead of external since #33835 and #33847 which doesn't require us to refresh after a stats call since refreshes will happen internally anyhow and that will cause updated stats on ongoing indexing.
1 parent 3ecfd9b commit 1f019eb

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -947,9 +947,7 @@ public FlushStats flushStats() {
947947

948948
public DocsStats docStats() {
949949
readAllowed();
950-
DocsStats docsStats = getEngine().docStats();
951-
markSearcherAccessed();
952-
return docsStats;
950+
return getEngine().docStats();
953951
}
954952

955953
/**
@@ -1028,11 +1026,7 @@ public TranslogStats translogStats() {
10281026
public CompletionStats completionStats(String... fields) {
10291027
readAllowed();
10301028
try {
1031-
CompletionStats stats = getEngine().completionStats(fields);
1032-
// we don't wait for a pending refreshes here since it's a stats call instead we mark it as accessed only which will cause
1033-
// the next scheduled refresh to go through and refresh the stats as well
1034-
markSearcherAccessed();
1035-
return stats;
1029+
return getEngine().completionStats(fields);
10361030
} catch (IOException e) {
10371031
throw new UncheckedIOException(e);
10381032
}

server/src/test/java/org/elasticsearch/index/shard/IndexShardTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,7 +2767,7 @@ public void testCompletionStatsMarksSearcherAccessed() throws Exception {
27672767
});
27682768
long prevAccessTime = shard.getLastSearcherAccess();
27692769
indexShard.completionStats();
2770-
assertThat("searcher was not marked as accessed", shard.getLastSearcherAccess(), greaterThan(prevAccessTime));
2770+
assertThat("searcher was marked as accessed", shard.getLastSearcherAccess(), equalTo(prevAccessTime));
27712771
} finally {
27722772
closeShards(indexShard);
27732773
}
@@ -2797,7 +2797,7 @@ public void testDocStats() throws Exception {
27972797
});
27982798
long prevAccessTime = shard.getLastSearcherAccess();
27992799
final DocsStats docsStats = indexShard.docStats();
2800-
assertThat("searcher was not marked as accessed", shard.getLastSearcherAccess(), greaterThan(prevAccessTime));
2800+
assertThat("searcher was marked as accessed", shard.getLastSearcherAccess(), equalTo(prevAccessTime));
28012801
assertThat(docsStats.getCount(), equalTo(numDocs));
28022802
try (Engine.Searcher searcher = indexShard.acquireSearcher("test")) {
28032803
assertTrue(searcher.reader().numDocs() <= docsStats.getCount());

0 commit comments

Comments
 (0)