Skip to content

Commit 4a0c8f9

Browse files
committed
No refresh on shard activation needed (#28013)
A shard is fully baked when it moves to POST_RECOVERY. There is no need to do an extra refresh on shard activation again as the shard has already been refreshed when it moved to POST_RECOVERY.
1 parent f6934dd commit 4a0c8f9

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: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,7 @@ public void updateShardState(final ShardRouting newRouting,
403403

404404
if (state == IndexShardState.POST_RECOVERY && newRouting.active()) {
405405
assert currentRouting.active() == false : "we are in POST_RECOVERY, but our shard routing is active " + currentRouting;
406-
// we want to refresh *before* we move to internal STARTED state
407-
try {
408-
getEngine().refresh("cluster_state_started");
409-
} catch (Exception e) {
410-
logger.debug("failed to refresh due to move to cluster wide started", e);
411-
}
412-
406+
413407
if (newRouting.primary()) {
414408
final DiscoveryNode recoverySourceNode = recoveryState.getSourceNode();
415409
final Engine engine = getEngine();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,14 +1168,14 @@ public void testShardStats() throws IOException {
11681168

11691169
public void testRefreshMetric() throws IOException {
11701170
IndexShard shard = newStartedShard();
1171-
assertThat(shard.refreshStats().getTotal(), equalTo(3L)); // refresh on: finalize, end of recovery and on starting shard
1171+
assertThat(shard.refreshStats().getTotal(), equalTo(2L)); // refresh on: finalize and end of recovery
11721172
long initialTotalTime = shard.refreshStats().getTotalTimeInMillis();
11731173
// check time advances
11741174
for (int i = 1; shard.refreshStats().getTotalTimeInMillis() == initialTotalTime; i++) {
11751175
indexDoc(shard, "test", "test");
1176-
assertThat(shard.refreshStats().getTotal(), equalTo(3L + i - 1));
1176+
assertThat(shard.refreshStats().getTotal(), equalTo(2L + i - 1));
11771177
shard.refresh("test");
1178-
assertThat(shard.refreshStats().getTotal(), equalTo(3L + i));
1178+
assertThat(shard.refreshStats().getTotal(), equalTo(2L + i));
11791179
assertThat(shard.refreshStats().getTotalTimeInMillis(), greaterThanOrEqualTo(initialTotalTime));
11801180
}
11811181
long refreshCount = shard.refreshStats().getTotal();

0 commit comments

Comments
 (0)