|
@@ -35,6 +35,7 @@ import org.elasticsearch.common.UUIDs;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.xcontent.XContentType;
|
|
|
+import org.elasticsearch.core.internal.io.IOUtils;
|
|
|
import org.elasticsearch.index.engine.Engine;
|
|
|
import org.elasticsearch.index.engine.NoOpEngine;
|
|
|
import org.elasticsearch.index.mapper.SourceToParse;
|
|
@@ -60,6 +61,7 @@ import java.util.stream.LongStream;
|
|
|
import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO;
|
|
|
import static org.hamcrest.Matchers.empty;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.sameInstance;
|
|
|
|
|
|
public class PeerRecoveryTargetServiceTests extends IndexShardTestCase {
|
|
|
|
|
@@ -286,4 +288,32 @@ public class PeerRecoveryTargetServiceTests extends IndexShardTestCase {
|
|
|
recoveryTarget.decRef();
|
|
|
closeShards(shard);
|
|
|
}
|
|
|
+
|
|
|
+ public void testResetStartRequestIfTranslogIsCorrupted() throws Exception {
|
|
|
+ DiscoveryNode pNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(),
|
|
|
+ Collections.emptyMap(), Collections.emptySet(), Version.CURRENT);
|
|
|
+ DiscoveryNode rNode = new DiscoveryNode("foo", buildNewFakeTransportAddress(),
|
|
|
+ Collections.emptyMap(), Collections.emptySet(), Version.CURRENT);
|
|
|
+ IndexShard shard = newStartedShard(false);
|
|
|
+ final SeqNoStats seqNoStats = populateRandomData(shard);
|
|
|
+ shard.close("test", false);
|
|
|
+ if (randomBoolean()) {
|
|
|
+ shard.store().associateIndexWithNewTranslog(UUIDs.randomBase64UUID());
|
|
|
+ } else if (randomBoolean()) {
|
|
|
+ Translog.createEmptyTranslog(
|
|
|
+ shard.shardPath().resolveTranslog(), seqNoStats.getGlobalCheckpoint(), shard.shardId(), shard.getOperationPrimaryTerm());
|
|
|
+ } else {
|
|
|
+ IOUtils.rm(shard.shardPath().resolveTranslog());
|
|
|
+ }
|
|
|
+ shard = reinitShard(shard, ShardRoutingHelper.initWithSameId(shard.routingEntry(), RecoverySource.PeerRecoverySource.INSTANCE));
|
|
|
+ shard.markAsRecovering("peer recovery", new RecoveryState(shard.routingEntry(), pNode, rNode));
|
|
|
+ shard.prepareForIndexRecovery();
|
|
|
+ RecoveryTarget recoveryTarget = new RecoveryTarget(shard, null, null);
|
|
|
+ StartRecoveryRequest request = PeerRecoveryTargetService.getStartRecoveryRequest(
|
|
|
+ logger, rNode, recoveryTarget, randomNonNegativeLong());
|
|
|
+ assertThat(request.startingSeqNo(), equalTo(UNASSIGNED_SEQ_NO));
|
|
|
+ assertThat(request.metadataSnapshot(), sameInstance(Store.MetadataSnapshot.EMPTY));
|
|
|
+ recoveryTarget.decRef();
|
|
|
+ closeShards(shard);
|
|
|
+ }
|
|
|
}
|