From 7713221733ddf229e84a878f880b6eb9609f3461 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 26 Dec 2019 08:56:00 -0500 Subject: [PATCH] Fix testCancelRecoveryDuringPhase1 (#50449) testCancelRecoveryDuringPhase1 uses a mock of IndexShard, which can't create retention leases. We need to stub method createRetentionLease. Relates #50351 Closes #50424 --- .../indices/recovery/RecoverySourceHandler.java | 2 +- .../indices/recovery/RecoverySourceHandlerTests.java | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java index 86e8106adcc..c1bcf0e2588 100644 --- a/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java +++ b/server/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java @@ -558,7 +558,7 @@ public class RecoverySourceHandler { } } - private void createRetentionLease(final long startingSeqNo, ActionListener listener) { + void createRetentionLease(final long startingSeqNo, ActionListener listener) { runUnderPrimaryPermit(() -> { // Clone the peer recovery retention lease belonging to the source shard. We are retaining history between the the local // checkpoint of the safe commit we're creating and this lease's retained seqno with the retention lock, and by cloning an diff --git a/server/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java b/server/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java index 141b22ab1c9..5123793efa3 100644 --- a/server/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java @@ -64,6 +64,7 @@ import org.elasticsearch.index.mapper.ParsedDocument; import org.elasticsearch.index.mapper.SeqNoFieldMapper; import org.elasticsearch.index.mapper.Uid; import org.elasticsearch.index.seqno.ReplicationTracker; +import org.elasticsearch.index.seqno.RetentionLease; import org.elasticsearch.index.seqno.RetentionLeases; import org.elasticsearch.index.seqno.SeqNoStats; import org.elasticsearch.index.seqno.SequenceNumbers; @@ -629,7 +630,6 @@ public class RecoverySourceHandlerTests extends ESTestCase { store.close(); } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50424") public void testCancelRecoveryDuringPhase1() throws Exception { Store store = newStore(createTempDir("source"), false); IndexShard shard = mock(IndexShard.class); @@ -678,8 +678,16 @@ public class RecoverySourceHandlerTests extends ESTestCase { } } }; + final StartRecoveryRequest startRecoveryRequest = getStartRecoveryRequest(); final RecoverySourceHandler handler = new RecoverySourceHandler( - shard, recoveryTarget, threadPool, getStartRecoveryRequest(), between(1, 16), between(1, 4)); + shard, recoveryTarget, threadPool, startRecoveryRequest, between(1, 16), between(1, 4)) { + @Override + void createRetentionLease(long startingSeqNo, ActionListener listener) { + final String leaseId = ReplicationTracker.getPeerRecoveryRetentionLeaseId(startRecoveryRequest.targetNode().getId()); + listener.onResponse(new RetentionLease(leaseId, startingSeqNo, threadPool.absoluteTimeInMillis(), + ReplicationTracker.PEER_RECOVERY_RETENTION_LEASE_SOURCE)); + } + }; cancelRecovery.set(() -> handler.cancel("test")); final StepListener phase1Listener = new StepListener<>(); try {