Skip to content

Commit

Permalink
Fix testCancelRecoveryDuringPhase1 (#50449)
Browse files Browse the repository at this point in the history
testCancelRecoveryDuringPhase1 uses a mock of IndexShard, which can't
create retention leases. We need to stub method createRetentionLease.

Relates #50351 
Closes #50424
  • Loading branch information
dnhatn committed Dec 26, 2019
1 parent ef467cc commit 7713221
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ void phase1(IndexCommit snapshot, long startingSeqNo, IntSupplier translogOps, A
}
}

private void createRetentionLease(final long startingSeqNo, ActionListener<RetentionLease> listener) {
void createRetentionLease(final long startingSeqNo, ActionListener<RetentionLease> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
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;
Expand Down Expand Up @@ -629,7 +630,6 @@ public void writeFileChunk(StoreFileMetaData md, long position, BytesReference c
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);
Expand Down Expand Up @@ -678,8 +678,16 @@ public void cleanFiles(int totalTranslogOps, long globalCheckpoint, Store.Metada
}
}
};
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<RetentionLease> 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<RecoverySourceHandler.SendFileResult> phase1Listener = new StepListener<>();
try {
Expand Down

0 comments on commit 7713221

Please sign in to comment.