|
19 | 19 |
|
20 | 20 | package org.elasticsearch.index.seqno;
|
21 | 21 |
|
| 22 | +import org.elasticsearch.ElasticsearchException; |
22 | 23 | import org.elasticsearch.action.ActionListener;
|
23 | 24 | import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
24 | 25 | import org.elasticsearch.action.support.replication.ReplicationResponse;
|
|
31 | 32 | import org.elasticsearch.index.shard.IndexShard;
|
32 | 33 | import org.elasticsearch.index.shard.ShardId;
|
33 | 34 | import org.elasticsearch.indices.IndicesService;
|
| 35 | +import org.elasticsearch.indices.recovery.PeerRecoveryTargetService; |
34 | 36 | import org.elasticsearch.plugins.Plugin;
|
35 | 37 | import org.elasticsearch.test.ESIntegTestCase;
|
| 38 | +import org.elasticsearch.test.transport.MockTransportService; |
36 | 39 | import org.elasticsearch.threadpool.ThreadPool;
|
| 40 | +import org.elasticsearch.transport.TransportService; |
37 | 41 |
|
38 | 42 | import java.io.Closeable;
|
39 | 43 | import java.util.ArrayList;
|
|
43 | 47 | import java.util.List;
|
44 | 48 | import java.util.Map;
|
45 | 49 | import java.util.concurrent.CountDownLatch;
|
| 50 | +import java.util.concurrent.Semaphore; |
46 | 51 | import java.util.concurrent.TimeUnit;
|
47 | 52 | import java.util.concurrent.atomic.AtomicBoolean;
|
48 | 53 | import java.util.concurrent.atomic.AtomicReference;
|
@@ -73,7 +78,7 @@ public List<Setting<?>> getSettings() {
|
73 | 78 | protected Collection<Class<? extends Plugin>> nodePlugins() {
|
74 | 79 | return Stream.concat(
|
75 | 80 | super.nodePlugins().stream(),
|
76 |
| - Stream.of(RetentionLeaseSyncIntervalSettingPlugin.class)) |
| 81 | + Stream.of(RetentionLeaseSyncIntervalSettingPlugin.class, MockTransportService.TestPlugin.class)) |
77 | 82 | .collect(Collectors.toList());
|
78 | 83 | }
|
79 | 84 |
|
@@ -355,6 +360,17 @@ public void testRetentionLeasesSyncOnRecovery() throws Exception {
|
355 | 360 | currentRetentionLeases.put(id, primary.renewRetentionLease(id, retainingSequenceNumber, source));
|
356 | 361 | }
|
357 | 362 |
|
| 363 | + // Cause some recoveries to fail to ensure that retention leases are handled properly when retrying a recovery |
| 364 | + final Semaphore recoveriesToDisrupt = new Semaphore(randomIntBetween(0, 4)); |
| 365 | + final MockTransportService transportService |
| 366 | + = (MockTransportService) internalCluster().getInstance(TransportService.class, primaryShardNodeName); |
| 367 | + transportService.addSendBehavior((connection, requestId, action, request, options) -> { |
| 368 | + if (action.equals(PeerRecoveryTargetService.Actions.FINALIZE) && recoveriesToDisrupt.tryAcquire()) { |
| 369 | + throw new ElasticsearchException("failing recovery for test"); |
| 370 | + } |
| 371 | + connection.sendRequest(requestId, action, request, options); |
| 372 | + }); |
| 373 | + |
358 | 374 | // now allow the replicas to be allocated and wait for recovery to finalize
|
359 | 375 | allowNodes("index", 1 + numberOfReplicas);
|
360 | 376 | ensureGreen("index");
|
|
0 commit comments