Skip to content

Commit 1c08c1d

Browse files
committed
fix the test
1 parent 66c507d commit 1c08c1d

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

server/src/test/java/org/elasticsearch/index/replication/RecoveryDuringReplicationTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.elasticsearch.action.bulk.BulkShardRequest;
3131
import org.elasticsearch.action.delete.DeleteRequest;
3232
import org.elasticsearch.action.index.IndexRequest;
33+
import org.elasticsearch.action.support.PlainActionFuture;
34+
import org.elasticsearch.action.support.replication.ReplicationResponse;
3335
import org.elasticsearch.cluster.metadata.IndexMetaData;
3436
import org.elasticsearch.cluster.node.DiscoveryNode;
3537
import org.elasticsearch.cluster.routing.ShardRouting;
@@ -135,24 +137,23 @@ public void testRecoveryOfDisconnectedReplica() throws Exception {
135137
final int missingOnReplica = shards.indexDocs(randomInt(5));
136138
docs += missingOnReplica;
137139

138-
final boolean translogTrimmed;
140+
final boolean peerRecoveryRetentionLeaseExpired;
139141
if (randomBoolean()) {
140-
shards.flush();
141-
translogTrimmed = randomBoolean();
142-
if (translogTrimmed) {
143-
final Translog translog = getTranslog(shards.getPrimary());
144-
translog.getDeletionPolicy().setRetentionAgeInMillis(0);
145-
translog.trimUnreferencedReaders();
142+
peerRecoveryRetentionLeaseExpired = randomBoolean();
143+
if (peerRecoveryRetentionLeaseExpired) {
144+
PlainActionFuture<ReplicationResponse> listener = new PlainActionFuture<>();
145+
shards.getPrimary().removePeerRecoveryRetentionLease(originalReplica.routingEntry().currentNodeId(), listener);
146+
listener.actionGet();
146147
}
147148
} else {
148-
translogTrimmed = false;
149+
peerRecoveryRetentionLeaseExpired = false;
149150
}
150151
originalReplica.close("disconnected", false);
151152
IOUtils.close(originalReplica.store());
152153
final IndexShard recoveredReplica =
153154
shards.addReplicaWithExistingPath(originalReplica.shardPath(), originalReplica.routingEntry().currentNodeId());
154155
shards.recoverReplica(recoveredReplica);
155-
if (translogTrimmed && missingOnReplica > 0) {
156+
if (peerRecoveryRetentionLeaseExpired && missingOnReplica > 0) {
156157
// replica has something to catch up with, but since we trimmed the primary translog, we should fall back to full recovery
157158
assertThat(recoveredReplica.recoveryState().getIndex().fileDetails(), not(empty()));
158159
} else {

0 commit comments

Comments
 (0)