|
@@ -38,6 +38,7 @@ import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
|
+import org.elasticsearch.common.UUIDs;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
|
import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.io.FileSystemUtils;
|
|
@@ -96,17 +97,9 @@ public class RecoverySourceHandlerTests extends ESTestCase {
|
|
|
|
|
|
public void testSendFiles() throws Throwable {
|
|
|
Settings settings = Settings.builder().put("indices.recovery.concurrent_streams", 1).
|
|
|
- put("indices.recovery.concurrent_small_file_streams", 1).build();
|
|
|
+ put("indices.recovery.concurrent_small_file_streams", 1).build();
|
|
|
final RecoverySettings recoverySettings = new RecoverySettings(settings, service);
|
|
|
- final StartRecoveryRequest request = new StartRecoveryRequest(
|
|
|
- shardId,
|
|
|
- null,
|
|
|
- new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
- new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
- null,
|
|
|
- randomBoolean(),
|
|
|
- randomNonNegativeLong(),
|
|
|
- randomBoolean() ? SequenceNumbers.UNASSIGNED_SEQ_NO : randomNonNegativeLong());
|
|
|
+ final StartRecoveryRequest request = getStartRecoveryRequest();
|
|
|
Store store = newStore(createTempDir());
|
|
|
RecoverySourceHandler handler = new RecoverySourceHandler(null, null, request,
|
|
|
recoverySettings.getChunkSize().bytesAsInt(), Settings.EMPTY);
|
|
@@ -151,19 +144,26 @@ public class RecoverySourceHandlerTests extends ESTestCase {
|
|
|
IOUtils.close(reader, store, targetStore);
|
|
|
}
|
|
|
|
|
|
- public void testSendSnapshotSendsOps() throws IOException {
|
|
|
- final RecoverySettings recoverySettings = new RecoverySettings(Settings.EMPTY, service);
|
|
|
- final int fileChunkSizeInBytes = recoverySettings.getChunkSize().bytesAsInt();
|
|
|
- final long startingSeqNo = randomBoolean() ? SequenceNumbers.UNASSIGNED_SEQ_NO : randomIntBetween(0, 16);
|
|
|
- final StartRecoveryRequest request = new StartRecoveryRequest(
|
|
|
+ public StartRecoveryRequest getStartRecoveryRequest() throws IOException {
|
|
|
+ Store.MetadataSnapshot metadataSnapshot = randomBoolean() ? Store.MetadataSnapshot.EMPTY :
|
|
|
+ new Store.MetadataSnapshot(Collections.emptyMap(),
|
|
|
+ Collections.singletonMap(Engine.HISTORY_UUID_KEY, UUIDs.randomBase64UUID()), randomIntBetween(0, 100));
|
|
|
+ return new StartRecoveryRequest(
|
|
|
shardId,
|
|
|
null,
|
|
|
new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
- null,
|
|
|
+ metadataSnapshot,
|
|
|
randomBoolean(),
|
|
|
randomNonNegativeLong(),
|
|
|
- randomBoolean() ? SequenceNumbers.UNASSIGNED_SEQ_NO : randomNonNegativeLong());
|
|
|
+ randomBoolean() || metadataSnapshot.getHistoryUUID() == null ?
|
|
|
+ SequenceNumbers.UNASSIGNED_SEQ_NO : randomNonNegativeLong());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testSendSnapshotSendsOps() throws IOException {
|
|
|
+ final RecoverySettings recoverySettings = new RecoverySettings(Settings.EMPTY, service);
|
|
|
+ final int fileChunkSizeInBytes = recoverySettings.getChunkSize().bytesAsInt();
|
|
|
+ final StartRecoveryRequest request = getStartRecoveryRequest();
|
|
|
final IndexShard shard = mock(IndexShard.class);
|
|
|
when(shard.state()).thenReturn(IndexShardState.STARTED);
|
|
|
final RecoveryTargetHandler recoveryTarget = mock(RecoveryTargetHandler.class);
|
|
@@ -181,6 +181,7 @@ public class RecoverySourceHandlerTests extends ESTestCase {
|
|
|
operations.add(new Translog.Index(index, new Engine.IndexResult(1, i - initialNumberOfDocs, true)));
|
|
|
}
|
|
|
operations.add(null);
|
|
|
+ final long startingSeqNo = randomBoolean() ? SequenceNumbers.UNASSIGNED_SEQ_NO : randomIntBetween(0, 16);
|
|
|
RecoverySourceHandler.SendSnapshotResult result = handler.sendSnapshot(startingSeqNo, new Translog.Snapshot() {
|
|
|
@Override
|
|
|
public void close() {
|
|
@@ -226,18 +227,9 @@ public class RecoverySourceHandlerTests extends ESTestCase {
|
|
|
|
|
|
public void testHandleCorruptedIndexOnSendSendFiles() throws Throwable {
|
|
|
Settings settings = Settings.builder().put("indices.recovery.concurrent_streams", 1).
|
|
|
- put("indices.recovery.concurrent_small_file_streams", 1).build();
|
|
|
+ put("indices.recovery.concurrent_small_file_streams", 1).build();
|
|
|
final RecoverySettings recoverySettings = new RecoverySettings(settings, service);
|
|
|
- final StartRecoveryRequest request =
|
|
|
- new StartRecoveryRequest(
|
|
|
- shardId,
|
|
|
- null,
|
|
|
- new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
- new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
- null,
|
|
|
- randomBoolean(),
|
|
|
- randomNonNegativeLong(),
|
|
|
- randomBoolean() ? SequenceNumbers.UNASSIGNED_SEQ_NO : 0L);
|
|
|
+ final StartRecoveryRequest request = getStartRecoveryRequest();
|
|
|
Path tempDir = createTempDir();
|
|
|
Store store = newStore(tempDir, false);
|
|
|
AtomicBoolean failedEngine = new AtomicBoolean(false);
|
|
@@ -268,8 +260,8 @@ public class RecoverySourceHandlerTests extends ESTestCase {
|
|
|
}
|
|
|
|
|
|
CorruptionUtils.corruptFile(random(), FileSystemUtils.files(tempDir, (p) ->
|
|
|
- (p.getFileName().toString().equals("write.lock") ||
|
|
|
- p.getFileName().toString().startsWith("extra")) == false));
|
|
|
+ (p.getFileName().toString().equals("write.lock") ||
|
|
|
+ p.getFileName().toString().startsWith("extra")) == false));
|
|
|
Store targetStore = newStore(createTempDir(), false);
|
|
|
try {
|
|
|
handler.sendFiles(store, metas.toArray(new StoreFileMetaData[0]), (md) -> {
|
|
@@ -296,18 +288,9 @@ public class RecoverySourceHandlerTests extends ESTestCase {
|
|
|
|
|
|
public void testHandleExceptinoOnSendSendFiles() throws Throwable {
|
|
|
Settings settings = Settings.builder().put("indices.recovery.concurrent_streams", 1).
|
|
|
- put("indices.recovery.concurrent_small_file_streams", 1).build();
|
|
|
+ put("indices.recovery.concurrent_small_file_streams", 1).build();
|
|
|
final RecoverySettings recoverySettings = new RecoverySettings(settings, service);
|
|
|
- final StartRecoveryRequest request =
|
|
|
- new StartRecoveryRequest(
|
|
|
- shardId,
|
|
|
- null,
|
|
|
- new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
- new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
- null,
|
|
|
- randomBoolean(),
|
|
|
- randomNonNegativeLong(),
|
|
|
- randomBoolean() ? SequenceNumbers.UNASSIGNED_SEQ_NO : 0L);
|
|
|
+ final StartRecoveryRequest request = getStartRecoveryRequest();
|
|
|
Path tempDir = createTempDir();
|
|
|
Store store = newStore(tempDir, false);
|
|
|
AtomicBoolean failedEngine = new AtomicBoolean(false);
|
|
@@ -363,17 +346,7 @@ public class RecoverySourceHandlerTests extends ESTestCase {
|
|
|
|
|
|
public void testThrowExceptionOnPrimaryRelocatedBeforePhase1Started() throws IOException {
|
|
|
final RecoverySettings recoverySettings = new RecoverySettings(Settings.EMPTY, service);
|
|
|
- final boolean attemptSequenceNumberBasedRecovery = randomBoolean();
|
|
|
- final StartRecoveryRequest request =
|
|
|
- new StartRecoveryRequest(
|
|
|
- shardId,
|
|
|
- null,
|
|
|
- new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
- new DiscoveryNode("b", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT),
|
|
|
- null,
|
|
|
- false,
|
|
|
- randomNonNegativeLong(),
|
|
|
- attemptSequenceNumberBasedRecovery ? randomNonNegativeLong() : SequenceNumbers.UNASSIGNED_SEQ_NO);
|
|
|
+ final StartRecoveryRequest request = getStartRecoveryRequest();
|
|
|
final IndexShard shard = mock(IndexShard.class);
|
|
|
when(shard.seqNoStats()).thenReturn(mock(SeqNoStats.class));
|
|
|
when(shard.segmentStats(anyBoolean())).thenReturn(mock(SegmentsStats.class));
|