|
35 | 35 | import org.elasticsearch.common.bytes.BytesArray;
|
36 | 36 | import org.elasticsearch.common.settings.Settings;
|
37 | 37 | import org.elasticsearch.common.xcontent.XContentType;
|
| 38 | +import org.elasticsearch.core.internal.io.IOUtils; |
38 | 39 | import org.elasticsearch.index.engine.Engine;
|
39 | 40 | import org.elasticsearch.index.engine.NoOpEngine;
|
40 | 41 | import org.elasticsearch.index.mapper.SourceToParse;
|
|
60 | 61 | import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO;
|
61 | 62 | import static org.hamcrest.Matchers.empty;
|
62 | 63 | import static org.hamcrest.Matchers.equalTo;
|
| 64 | +import static org.hamcrest.Matchers.sameInstance; |
63 | 65 |
|
64 | 66 | public class PeerRecoveryTargetServiceTests extends IndexShardTestCase {
|
65 | 67 |
|
@@ -285,4 +287,32 @@ public void testResetStartingSeqNoIfLastCommitCorrupted() throws Exception {
|
285 | 287 | recoveryTarget.decRef();
|
286 | 288 | closeShards(shard);
|
287 | 289 | }
|
| 290 | + |
| 291 | + public void testResetStartRequestIfTranslogIsCorrupted() throws Exception { |
| 292 | + DiscoveryNode pNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), |
| 293 | + Collections.emptyMap(), Collections.emptySet(), Version.CURRENT); |
| 294 | + DiscoveryNode rNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(), |
| 295 | + Collections.emptyMap(), Collections.emptySet(), Version.CURRENT); |
| 296 | + IndexShard shard = newStartedShard(false); |
| 297 | + final SeqNoStats seqNoStats = populateRandomData(shard); |
| 298 | + shard.close("test", false); |
| 299 | + if (randomBoolean()) { |
| 300 | + shard.store().associateIndexWithNewTranslog(UUIDs.randomBase64UUID()); |
| 301 | + } else if (randomBoolean()) { |
| 302 | + Translog.createEmptyTranslog( |
| 303 | + shard.shardPath().resolveTranslog(), seqNoStats.getGlobalCheckpoint(), shard.shardId(), shard.getOperationPrimaryTerm()); |
| 304 | + } else { |
| 305 | + IOUtils.rm(shard.shardPath().resolveTranslog()); |
| 306 | + } |
| 307 | + shard = reinitShard(shard, ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.PeerRecoverySource.INSTANCE)); |
| 308 | + shard.markAsRecovering("peer recovery", new RecoveryState(shard.routingEntry(), pNode, rNode)); |
| 309 | + shard.prepareForIndexRecovery(); |
| 310 | + RecoveryTarget recoveryTarget = new RecoveryTarget(shard, null, null); |
| 311 | + StartRecoveryRequest request = PeerRecoveryTargetService.getStartRecoveryRequest( |
| 312 | + logger, rNode, recoveryTarget, randomNonNegativeLong()); |
| 313 | + assertThat(request.startingSeqNo(), equalTo(UNASSIGNED_SEQ_NO)); |
| 314 | + assertThat(request.metadataSnapshot(), sameInstance(Store.MetadataSnapshot.EMPTY)); |
| 315 | + recoveryTarget.decRef(); |
| 316 | + closeShards(shard); |
| 317 | + } |
288 | 318 | }
|
0 commit comments