Skip to content

Commit

Permalink
Fix testCancelRecoveryDuringPhase1 (elastic#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 elastic#50351 
Closes elastic#50424
  • Loading branch information
dnhatn authored and SivagurunathanV committed Jan 21, 2020
1 parent 85a3808 commit 6b5ee4d
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 @@ -555,7 +555,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 @@ -628,7 +629,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 @@ -677,8 +677,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 6b5ee4d

Please sign in to comment.