Skip to content

Commit 50bd584

Browse files
authored
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
1 parent e8a6d4a commit 50bd584

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

server/src/main/java/org/elasticsearch/indices/recovery/RecoverySourceHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ void phase1(IndexCommit snapshot, long startingSeqNo, IntSupplier translogOps, A
555555
}
556556
}
557557

558-
private void createRetentionLease(final long startingSeqNo, ActionListener<RetentionLease> listener) {
558+
void createRetentionLease(final long startingSeqNo, ActionListener<RetentionLease> listener) {
559559
runUnderPrimaryPermit(() -> {
560560
// Clone the peer recovery retention lease belonging to the source shard. We are retaining history between the the local
561561
// checkpoint of the safe commit we're creating and this lease's retained seqno with the retention lock, and by cloning an

server/src/test/java/org/elasticsearch/indices/recovery/RecoverySourceHandlerTests.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.elasticsearch.index.mapper.SeqNoFieldMapper;
6565
import org.elasticsearch.index.mapper.Uid;
6666
import org.elasticsearch.index.seqno.ReplicationTracker;
67+
import org.elasticsearch.index.seqno.RetentionLease;
6768
import org.elasticsearch.index.seqno.RetentionLeases;
6869
import org.elasticsearch.index.seqno.SeqNoStats;
6970
import org.elasticsearch.index.seqno.SequenceNumbers;
@@ -628,7 +629,6 @@ public void writeFileChunk(StoreFileMetaData md, long position, BytesReference c
628629
store.close();
629630
}
630631

631-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/50424")
632632
public void testCancelRecoveryDuringPhase1() throws Exception {
633633
Store store = newStore(createTempDir("source"), false);
634634
IndexShard shard = mock(IndexShard.class);
@@ -677,8 +677,16 @@ public void cleanFiles(int totalTranslogOps, long globalCheckpoint, Store.Metada
677677
}
678678
}
679679
};
680+
final StartRecoveryRequest startRecoveryRequest = getStartRecoveryRequest();
680681
final RecoverySourceHandler handler = new RecoverySourceHandler(
681-
shard, recoveryTarget, threadPool, getStartRecoveryRequest(), between(1, 16), between(1, 4));
682+
shard, recoveryTarget, threadPool, startRecoveryRequest, between(1, 16), between(1, 4)) {
683+
@Override
684+
void createRetentionLease(long startingSeqNo, ActionListener<RetentionLease> listener) {
685+
final String leaseId = ReplicationTracker.getPeerRecoveryRetentionLeaseId(startRecoveryRequest.targetNode().getId());
686+
listener.onResponse(new RetentionLease(leaseId, startingSeqNo, threadPool.absoluteTimeInMillis(),
687+
ReplicationTracker.PEER_RECOVERY_RETENTION_LEASE_SOURCE));
688+
}
689+
};
682690
cancelRecovery.set(() -> handler.cancel("test"));
683691
final StepListener<RecoverySourceHandler.SendFileResult> phase1Listener = new StepListener<>();
684692
try {

0 commit comments

Comments
 (0)