Skip to content

Commit 98cf7bd

Browse files
committed
Only run retention lease actions on active primary (#40386)
In some cases, a request to perform a retention lease action can arrive on a primary shard before it is active. In this case, the primary shard would not yet be in primary mode, tripping an assertion in the replication tracker. Instead, we should not attempt to perform such actions on an initializing shard. This commit addresses this by not returning the primary shard in the single shard iterator if the primary shard is not yet active.
1 parent 8ea08df commit 98cf7bd

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

server/src/main/java/org/elasticsearch/index/seqno/RetentionLeaseActions.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.elasticsearch.client.ElasticsearchClient;
3131
import org.elasticsearch.cluster.ClusterState;
3232
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
33+
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
34+
import org.elasticsearch.cluster.routing.PlainShardIterator;
3335
import org.elasticsearch.cluster.routing.ShardsIterator;
3436
import org.elasticsearch.cluster.service.ClusterService;
3537
import org.elasticsearch.common.inject.Inject;
@@ -45,6 +47,7 @@
4547
import org.elasticsearch.transport.TransportService;
4648

4749
import java.io.IOException;
50+
import java.util.Collections;
4851
import java.util.Objects;
4952
import java.util.function.Supplier;
5053

@@ -89,10 +92,14 @@ abstract static class TransportRetentionLeaseAction<T extends Request<T>> extend
8992

9093
@Override
9194
protected ShardsIterator shards(final ClusterState state, final InternalRequest request) {
92-
return state
95+
final IndexShardRoutingTable shardRoutingTable = state
9396
.routingTable()
94-
.shardRoutingTable(request.concreteIndex(), request.request().getShardId().id())
95-
.primaryShardIt();
97+
.shardRoutingTable(request.concreteIndex(), request.request().getShardId().id());
98+
if (shardRoutingTable.primaryShard().active()) {
99+
return shardRoutingTable.primaryShardIt();
100+
} else {
101+
return new PlainShardIterator(request.request().getShardId(), Collections.emptyList());
102+
}
96103
}
97104

98105
@Override

x-pack/plugin/ccr/src/test/java/org/elasticsearch/xpack/ccr/CcrRetentionLeaseIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.elasticsearch.plugins.Plugin;
4444
import org.elasticsearch.snapshots.RestoreInfo;
4545
import org.elasticsearch.snapshots.RestoreService;
46-
import org.elasticsearch.test.junit.annotations.TestLogging;
4746
import org.elasticsearch.test.transport.MockTransportService;
4847
import org.elasticsearch.transport.ConnectTransportException;
4948
import org.elasticsearch.transport.RemoteTransportException;
@@ -614,7 +613,7 @@ public void testRetentionLeaseAdvancesWhileFollowing() throws Exception {
614613
});
615614
}
616615

617-
@TestLogging(value = "org.elasticsearch.xpack.ccr:trace")
616+
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/39509")
618617
public void testRetentionLeaseRenewalIsCancelledWhenFollowingIsPaused() throws Exception {
619618
final String leaderIndex = "leader";
620619
final String followerIndex = "follower";

0 commit comments

Comments
 (0)