Skip to content

Commit e8c34c2

Browse files
committed
IndexShard - only flush on primary activation if it's a relocation target from an old node
#27580 added extra flushes when a shard transitions to primary to make sure that we never replay translog ops without seq# during recovery. The current logic causes an extra flush when a primary starts when it's recovering from the store. This is not needed as we also flush in the engine itself (to add sequence numbers info into the commit). This double flushing confuses tests and is unneeded. Fixes #27649
1 parent a7c2def commit e8c34c2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
import org.elasticsearch.common.util.BigArrays;
6767
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
6868
import org.elasticsearch.common.util.concurrent.AsyncIOProcessor;
69-
import org.elasticsearch.common.util.concurrent.ThreadContext;
7069
import org.elasticsearch.common.xcontent.XContentFactory;
7170
import org.elasticsearch.index.Index;
7271
import org.elasticsearch.index.IndexModule;
@@ -142,7 +141,6 @@
142141
import java.nio.channels.ClosedByInterruptException;
143142
import java.nio.charset.StandardCharsets;
144143
import java.util.ArrayList;
145-
import java.util.Arrays;
146144
import java.util.Collections;
147145
import java.util.EnumSet;
148146
import java.util.List;
@@ -408,10 +406,12 @@ public void updateShardState(final ShardRouting newRouting,
408406

409407
if (newRouting.primary()) {
410408
final DiscoveryNode recoverySourceNode = recoveryState.getSourceNode();
409+
final Engine engine = getEngine();
411410
if (currentRouting.isRelocationTarget() == false || recoverySourceNode.getVersion().before(Version.V_6_0_0_alpha1)) {
412411
// there was no primary context hand-off in < 6.0.0, need to manually activate the shard
413-
final Engine engine = getEngine();
414412
engine.seqNoService().activatePrimaryMode(getEngine().seqNoService().getLocalCheckpoint());
413+
}
414+
if (currentRouting.isRelocationTarget() == true && recoverySourceNode.getVersion().before(Version.V_6_0_0_alpha1)) {
415415
// Flush the translog as it may contain operations with no sequence numbers. We want to make sure those
416416
// operations will never be replayed as part of peer recovery to avoid an arbitrary mixture of operations with seq#
417417
// (due to active indexing) and operations without a seq# coming from the translog. We therefore flush

qa/full-cluster-restart/src/test/java/org/elasticsearch/upgrades/FullClusterRestartIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ public void testEmptyShard() throws IOException {
613613
* Tests recovery of an index with or without a translog and the
614614
* statistics we gather about that.
615615
*/
616-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/27649")
617616
public void testRecovery() throws IOException {
618617
int count;
619618
boolean shouldHaveTranslog;
@@ -694,8 +693,9 @@ public void testRecovery() throws IOException {
694693
fail("expected version to be one of [" + currentLuceneVersion + "," + bwcLuceneVersion + "] but was " + line);
695694
}
696695
}
697-
assertNotEquals("expected at least 1 current segment after translog recovery", 0, numCurrentVersion);
698-
assertNotEquals("expected at least 1 old segment", 0, numBwcVersion);}
696+
assertNotEquals("expected at least 1 current segment after translog recovery. segments:\n" + segmentsResponse,
697+
0, numCurrentVersion);
698+
assertNotEquals("expected at least 1 old segment. segments:\n" + segmentsResponse, 0, numBwcVersion);}
699699
}
700700
}
701701

0 commit comments

Comments
 (0)