|
30 | 30 | import org.elasticsearch.action.bulk.BulkShardRequest; |
31 | 31 | import org.elasticsearch.action.delete.DeleteRequest; |
32 | 32 | import org.elasticsearch.action.index.IndexRequest; |
| 33 | +import org.elasticsearch.action.support.PlainActionFuture; |
| 34 | +import org.elasticsearch.action.support.replication.ReplicationResponse; |
33 | 35 | import org.elasticsearch.cluster.metadata.IndexMetaData; |
34 | 36 | import org.elasticsearch.cluster.node.DiscoveryNode; |
35 | 37 | import org.elasticsearch.cluster.routing.ShardRouting; |
@@ -135,24 +137,23 @@ public void testRecoveryOfDisconnectedReplica() throws Exception { |
135 | 137 | final int missingOnReplica = shards.indexDocs(randomInt(5)); |
136 | 138 | docs += missingOnReplica; |
137 | 139 |
|
138 | | - final boolean translogTrimmed; |
| 140 | + final boolean peerRecoveryRetentionLeaseExpired; |
139 | 141 | 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(); |
146 | 147 | } |
147 | 148 | } else { |
148 | | - translogTrimmed = false; |
| 149 | + peerRecoveryRetentionLeaseExpired = false; |
149 | 150 | } |
150 | 151 | originalReplica.close("disconnected", false); |
151 | 152 | IOUtils.close(originalReplica.store()); |
152 | 153 | final IndexShard recoveredReplica = |
153 | 154 | shards.addReplicaWithExistingPath(originalReplica.shardPath(), originalReplica.routingEntry().currentNodeId()); |
154 | 155 | shards.recoverReplica(recoveredReplica); |
155 | | - if (translogTrimmed && missingOnReplica > 0) { |
| 156 | + if (peerRecoveryRetentionLeaseExpired && missingOnReplica > 0) { |
156 | 157 | // replica has something to catch up with, but since we trimmed the primary translog, we should fall back to full recovery |
157 | 158 | assertThat(recoveredReplica.recoveryState().getIndex().fileDetails(), not(empty())); |
158 | 159 | } else { |
|
0 commit comments