|
@@ -21,7 +21,6 @@ package org.elasticsearch.index.shard;
|
|
|
import org.apache.logging.log4j.Logger;
|
|
import org.apache.logging.log4j.Logger;
|
|
|
import org.apache.lucene.index.CorruptIndexException;
|
|
import org.apache.lucene.index.CorruptIndexException;
|
|
|
import org.apache.lucene.index.DirectoryReader;
|
|
import org.apache.lucene.index.DirectoryReader;
|
|
|
-import org.apache.lucene.index.IndexCommit;
|
|
|
|
|
import org.apache.lucene.index.IndexableField;
|
|
import org.apache.lucene.index.IndexableField;
|
|
|
import org.apache.lucene.index.Term;
|
|
import org.apache.lucene.index.Term;
|
|
|
import org.apache.lucene.search.IndexSearcher;
|
|
import org.apache.lucene.search.IndexSearcher;
|
|
@@ -46,8 +45,6 @@ import org.elasticsearch.action.index.IndexRequest;
|
|
|
import org.elasticsearch.action.support.PlainActionFuture;
|
|
import org.elasticsearch.action.support.PlainActionFuture;
|
|
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
|
|
-import org.elasticsearch.cluster.metadata.MetaData;
|
|
|
|
|
-import org.elasticsearch.cluster.metadata.RepositoryMetaData;
|
|
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
|
import org.elasticsearch.cluster.routing.AllocationId;
|
|
import org.elasticsearch.cluster.routing.AllocationId;
|
|
|
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
|
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
|
@@ -62,7 +59,6 @@ import org.elasticsearch.common.UUIDs;
|
|
|
import org.elasticsearch.common.breaker.CircuitBreaker;
|
|
import org.elasticsearch.common.breaker.CircuitBreaker;
|
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
import org.elasticsearch.common.bytes.BytesArray;
|
|
|
import org.elasticsearch.common.collect.Tuple;
|
|
import org.elasticsearch.common.collect.Tuple;
|
|
|
-import org.elasticsearch.common.component.AbstractLifecycleComponent;
|
|
|
|
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
import org.elasticsearch.common.io.stream.StreamInput;
|
|
|
import org.elasticsearch.common.lease.Releasable;
|
|
import org.elasticsearch.common.lease.Releasable;
|
|
@@ -107,7 +103,6 @@ import org.elasticsearch.index.mapper.Uid;
|
|
|
import org.elasticsearch.index.mapper.VersionFieldMapper;
|
|
import org.elasticsearch.index.mapper.VersionFieldMapper;
|
|
|
import org.elasticsearch.index.seqno.SeqNoStats;
|
|
import org.elasticsearch.index.seqno.SeqNoStats;
|
|
|
import org.elasticsearch.index.seqno.SequenceNumbers;
|
|
import org.elasticsearch.index.seqno.SequenceNumbers;
|
|
|
-import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
|
|
|
|
|
import org.elasticsearch.index.store.Store;
|
|
import org.elasticsearch.index.store.Store;
|
|
|
import org.elasticsearch.index.store.StoreStats;
|
|
import org.elasticsearch.index.store.StoreStats;
|
|
|
import org.elasticsearch.index.store.StoreUtils;
|
|
import org.elasticsearch.index.store.StoreUtils;
|
|
@@ -121,12 +116,8 @@ import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
|
|
import org.elasticsearch.indices.recovery.RecoveryState;
|
|
import org.elasticsearch.indices.recovery.RecoveryState;
|
|
|
import org.elasticsearch.indices.recovery.RecoveryTarget;
|
|
import org.elasticsearch.indices.recovery.RecoveryTarget;
|
|
|
import org.elasticsearch.repositories.IndexId;
|
|
import org.elasticsearch.repositories.IndexId;
|
|
|
-import org.elasticsearch.repositories.Repository;
|
|
|
|
|
-import org.elasticsearch.repositories.RepositoryData;
|
|
|
|
|
import org.elasticsearch.snapshots.Snapshot;
|
|
import org.elasticsearch.snapshots.Snapshot;
|
|
|
import org.elasticsearch.snapshots.SnapshotId;
|
|
import org.elasticsearch.snapshots.SnapshotId;
|
|
|
-import org.elasticsearch.snapshots.SnapshotInfo;
|
|
|
|
|
-import org.elasticsearch.snapshots.SnapshotShardFailure;
|
|
|
|
|
import org.elasticsearch.test.CorruptionUtils;
|
|
import org.elasticsearch.test.CorruptionUtils;
|
|
|
import org.elasticsearch.test.DummyShardLock;
|
|
import org.elasticsearch.test.DummyShardLock;
|
|
|
import org.elasticsearch.test.FieldMaskingReader;
|
|
import org.elasticsearch.test.FieldMaskingReader;
|
|
@@ -143,7 +134,6 @@ import java.nio.file.attribute.BasicFileAttributes;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
-import java.util.HashMap;
|
|
|
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -174,7 +164,6 @@ import static org.elasticsearch.common.lucene.Lucene.cleanLuceneIndex;
|
|
|
import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
|
|
import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
|
|
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|
|
import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO;
|
|
import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO;
|
|
|
-import static org.elasticsearch.repositories.RepositoryData.EMPTY_REPO_GEN;
|
|
|
|
|
import static org.elasticsearch.test.hamcrest.RegexMatcher.matches;
|
|
import static org.elasticsearch.test.hamcrest.RegexMatcher.matches;
|
|
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
|
import static org.hamcrest.Matchers.containsInAnyOrder;
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
import static org.hamcrest.Matchers.containsString;
|
|
@@ -2159,9 +2148,12 @@ public class IndexShardTests extends IndexShardTestCase {
|
|
|
|
|
|
|
|
public void testRestoreShard() throws IOException {
|
|
public void testRestoreShard() throws IOException {
|
|
|
final IndexShard source = newStartedShard(true);
|
|
final IndexShard source = newStartedShard(true);
|
|
|
- IndexShard target = newStartedShard(true);
|
|
|
|
|
|
|
+ IndexShard target = newStartedShard(true, Settings.builder()
|
|
|
|
|
+ .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), source.indexSettings().isSoftDeleteEnabled()).build());
|
|
|
|
|
|
|
|
indexDoc(source, "_doc", "0");
|
|
indexDoc(source, "_doc", "0");
|
|
|
|
|
+ EngineTestCase.generateNewSeqNo(source.getEngine()); // create a gap in the history
|
|
|
|
|
+ indexDoc(source, "_doc", "2");
|
|
|
if (randomBoolean()) {
|
|
if (randomBoolean()) {
|
|
|
source.refresh("test");
|
|
source.refresh("test");
|
|
|
}
|
|
}
|
|
@@ -2197,16 +2189,18 @@ public class IndexShardTests extends IndexShardTestCase {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}));
|
|
}));
|
|
|
- assertThat(target.getLocalCheckpoint(), equalTo(0L));
|
|
|
|
|
- assertThat(target.seqNoStats().getMaxSeqNo(), equalTo(0L));
|
|
|
|
|
- assertThat(target.getReplicationTracker().getGlobalCheckpoint(), equalTo(0L));
|
|
|
|
|
|
|
+ assertThat(target.getLocalCheckpoint(), equalTo(2L));
|
|
|
|
|
+ assertThat(target.seqNoStats().getMaxSeqNo(), equalTo(2L));
|
|
|
|
|
+ assertThat(target.seqNoStats().getGlobalCheckpoint(), equalTo(0L));
|
|
|
IndexShardTestCase.updateRoutingEntry(target, routing.moveToStarted());
|
|
IndexShardTestCase.updateRoutingEntry(target, routing.moveToStarted());
|
|
|
assertThat(target.getReplicationTracker().getTrackedLocalCheckpointForShard(
|
|
assertThat(target.getReplicationTracker().getTrackedLocalCheckpointForShard(
|
|
|
- target.routingEntry().allocationId().getId()).getLocalCheckpoint(), equalTo(0L));
|
|
|
|
|
|
|
+ target.routingEntry().allocationId().getId()).getLocalCheckpoint(), equalTo(2L));
|
|
|
|
|
+ assertThat(target.seqNoStats().getGlobalCheckpoint(), equalTo(2L));
|
|
|
|
|
|
|
|
- assertDocs(target, "0");
|
|
|
|
|
|
|
+ assertDocs(target, "0", "2");
|
|
|
|
|
|
|
|
- closeShards(source, target);
|
|
|
|
|
|
|
+ closeShard(source, false);
|
|
|
|
|
+ closeShards(target);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void testSearcherWrapperIsUsed() throws IOException {
|
|
public void testSearcherWrapperIsUsed() throws IOException {
|
|
@@ -3131,107 +3125,6 @@ public class IndexShardTests extends IndexShardTestCase {
|
|
|
return new Result(localCheckpoint, max);
|
|
return new Result(localCheckpoint, max);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /** A dummy repository for testing which just needs restore overridden */
|
|
|
|
|
- private abstract static class RestoreOnlyRepository extends AbstractLifecycleComponent implements Repository {
|
|
|
|
|
- private final String indexName;
|
|
|
|
|
-
|
|
|
|
|
- RestoreOnlyRepository(String indexName) {
|
|
|
|
|
- this.indexName = indexName;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void doStart() {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void doStop() {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- protected void doClose() {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public RepositoryMetaData getMetadata() {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public SnapshotInfo getSnapshotInfo(SnapshotId snapshotId) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public MetaData getSnapshotGlobalMetaData(SnapshotId snapshotId) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public IndexMetaData getSnapshotIndexMetaData(SnapshotId snapshotId, IndexId index) throws IOException {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public RepositoryData getRepositoryData() {
|
|
|
|
|
- Map<IndexId, Set<SnapshotId>> map = new HashMap<>();
|
|
|
|
|
- map.put(new IndexId(indexName, "blah"), emptySet());
|
|
|
|
|
- return new RepositoryData(EMPTY_REPO_GEN, Collections.emptyMap(), Collections.emptyMap(), map, Collections.emptyList());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void initializeSnapshot(SnapshotId snapshotId, List<IndexId> indices, MetaData metaData) {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public SnapshotInfo finalizeSnapshot(SnapshotId snapshotId, List<IndexId> indices, long startTime, String failure,
|
|
|
|
|
- int totalShards, List<SnapshotShardFailure> shardFailures, long repositoryStateId,
|
|
|
|
|
- boolean includeGlobalState) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId) {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public long getSnapshotThrottleTimeInNanos() {
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public long getRestoreThrottleTimeInNanos() {
|
|
|
|
|
- return 0;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public String startVerification() {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void endVerification(String verificationToken) {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean isReadOnly() {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void snapshotShard(IndexShard shard, Store store, SnapshotId snapshotId, IndexId indexId, IndexCommit snapshotIndexCommit,
|
|
|
|
|
- IndexShardSnapshotStatus snapshotStatus) {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, Version version, IndexId indexId, ShardId shardId) {
|
|
|
|
|
- return null;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void verify(String verificationToken, DiscoveryNode localNode) {
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
public void testIsSearchIdle() throws Exception {
|
|
public void testIsSearchIdle() throws Exception {
|
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
|
Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
|
|
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
|
|
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
|