Skip to content

Commit df8346f

Browse files
committed
Do not intercept renew requests from other tests (#48833)
We might have some outstanding renew retention lease requests after a shard has unfollowed. If testRetentionLeaseIsAddedIfItDisappearsWhileFollowing intercepts a renew request from other tests then we will never unlatch and the test will time out. Closes #45192
1 parent a91f0f8 commit df8346f

File tree

1 file changed

+33
-35
lines changed

1 file changed

+33
-35
lines changed

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

Lines changed: 33 additions & 35 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;
@@ -87,9 +86,6 @@
8786
import static org.hamcrest.Matchers.greaterThan;
8887
import static org.hamcrest.Matchers.hasSize;
8988

90-
@TestLogging(
91-
// issue: https://github.com/elastic/elasticsearch/issues/45192
92-
value = "org.elasticsearch.xpack.ccr:trace,org.elasticsearch.indices.recovery:trace,org.elasticsearch.index.seqno:debug")
9389
public class CcrRetentionLeaseIT extends CcrIntegTestCase {
9490

9591
public static final class RetentionLeaseRenewIntervalSettingPlugin extends Plugin {
@@ -782,40 +778,42 @@ public void testRetentionLeaseIsAddedIfItDisappearsWhileFollowing() throws Excep
782778
(connection, requestId, action, request, options) -> {
783779
if (RetentionLeaseActions.Renew.ACTION_NAME.equals(action)
784780
|| TransportActionProxy.getProxyAction(RetentionLeaseActions.Renew.ACTION_NAME).equals(action)) {
785-
senderTransportService.clearAllRules();
786781
final RetentionLeaseActions.RenewRequest renewRequest = (RetentionLeaseActions.RenewRequest) request;
787782
final String retentionLeaseId = getRetentionLeaseId(followerIndex, leaderIndex);
788-
assertThat(retentionLeaseId, equalTo(renewRequest.getId()));
789-
logger.info("--> intercepting renewal request for retention lease [{}]", retentionLeaseId);
790-
final String primaryShardNodeId =
791-
getLeaderCluster()
792-
.clusterService()
793-
.state()
794-
.routingTable()
795-
.index(leaderIndex)
796-
.shard(renewRequest.getShardId().id())
797-
.primaryShard()
798-
.currentNodeId();
799-
final String primaryShardNodeName =
800-
getLeaderCluster().clusterService().state().nodes().get(primaryShardNodeId).getName();
801-
final IndexShard primary =
802-
getLeaderCluster()
803-
.getInstance(IndicesService.class, primaryShardNodeName)
804-
.getShardOrNull(renewRequest.getShardId());
805-
final CountDownLatch innerLatch = new CountDownLatch(1);
806-
// this forces the background renewal from following to face a retention lease not found exception
807-
logger.info("--> removing retention lease [{}] on the leader", retentionLeaseId);
808-
primary.removeRetentionLease(retentionLeaseId,
809-
ActionListener.wrap(r -> innerLatch.countDown(), e -> fail(e.toString())));
810-
logger.info("--> waiting for the removed retention lease [{}] to be synced on the leader", retentionLeaseId);
811-
try {
812-
innerLatch.await();
813-
} catch (final InterruptedException e) {
814-
Thread.currentThread().interrupt();
815-
fail(e.toString());
783+
if (retentionLeaseId.equals(renewRequest.getId())) {
784+
logger.info("--> intercepting renewal request for retention lease [{}]", retentionLeaseId);
785+
senderTransportService.clearAllRules();
786+
final String primaryShardNodeId =
787+
getLeaderCluster()
788+
.clusterService()
789+
.state()
790+
.routingTable()
791+
.index(leaderIndex)
792+
.shard(renewRequest.getShardId().id())
793+
.primaryShard()
794+
.currentNodeId();
795+
final String primaryShardNodeName =
796+
getLeaderCluster().clusterService().state().nodes().get(primaryShardNodeId).getName();
797+
final IndexShard primary =
798+
getLeaderCluster()
799+
.getInstance(IndicesService.class, primaryShardNodeName)
800+
.getShardOrNull(renewRequest.getShardId());
801+
final CountDownLatch innerLatch = new CountDownLatch(1);
802+
try {
803+
// this forces the background renewal from following to face a retention lease not found exception
804+
logger.info("--> removing retention lease [{}] on the leader", retentionLeaseId);
805+
primary.removeRetentionLease(retentionLeaseId,
806+
ActionListener.wrap(r -> innerLatch.countDown(), e -> fail(e.toString())));
807+
logger.info("--> waiting for the removed retention lease [{}] to be synced on the leader",
808+
retentionLeaseId);
809+
innerLatch.await();
810+
logger.info("--> removed retention lease [{}] on the leader", retentionLeaseId);
811+
} catch (final Exception e) {
812+
throw new AssertionError("failed to remove retention lease [" + retentionLeaseId + "] on the leader");
813+
} finally {
814+
latch.countDown();
815+
}
816816
}
817-
logger.info("--> removed retention lease [{}] on the leader", retentionLeaseId);
818-
latch.countDown();
819817
}
820818
connection.sendRequest(requestId, action, request, options);
821819
});

0 commit comments

Comments
 (0)