|
21 | 21 | import org.apache.logging.log4j.Logger;
|
22 | 22 | import org.apache.lucene.index.CorruptIndexException;
|
23 | 23 | import org.apache.lucene.index.DirectoryReader;
|
24 |
| -import org.apache.lucene.index.IndexCommit; |
25 | 24 | import org.apache.lucene.index.IndexableField;
|
26 | 25 | import org.apache.lucene.index.Term;
|
27 | 26 | import org.apache.lucene.search.IndexSearcher;
|
|
46 | 45 | import org.elasticsearch.action.support.PlainActionFuture;
|
47 | 46 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
48 | 47 | import org.elasticsearch.cluster.metadata.MappingMetaData;
|
49 |
| -import org.elasticsearch.cluster.metadata.MetaData; |
50 |
| -import org.elasticsearch.cluster.metadata.RepositoryMetaData; |
51 | 48 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
52 | 49 | import org.elasticsearch.cluster.routing.AllocationId;
|
53 | 50 | import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
|
|
62 | 59 | import org.elasticsearch.common.breaker.CircuitBreaker;
|
63 | 60 | import org.elasticsearch.common.bytes.BytesArray;
|
64 | 61 | import org.elasticsearch.common.collect.Tuple;
|
65 |
| -import org.elasticsearch.common.component.AbstractLifecycleComponent; |
66 | 62 | import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
67 | 63 | import org.elasticsearch.common.io.stream.StreamInput;
|
68 | 64 | import org.elasticsearch.common.lease.Releasable;
|
|
107 | 103 | import org.elasticsearch.index.mapper.VersionFieldMapper;
|
108 | 104 | import org.elasticsearch.index.seqno.SeqNoStats;
|
109 | 105 | import org.elasticsearch.index.seqno.SequenceNumbers;
|
110 |
| -import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus; |
111 | 106 | import org.elasticsearch.index.store.Store;
|
112 | 107 | import org.elasticsearch.index.store.StoreStats;
|
113 | 108 | import org.elasticsearch.index.store.StoreUtils;
|
|
121 | 116 | import org.elasticsearch.indices.recovery.RecoveryState;
|
122 | 117 | import org.elasticsearch.indices.recovery.RecoveryTarget;
|
123 | 118 | import org.elasticsearch.repositories.IndexId;
|
124 |
| -import org.elasticsearch.repositories.Repository; |
125 |
| -import org.elasticsearch.repositories.RepositoryData; |
126 | 119 | import org.elasticsearch.snapshots.Snapshot;
|
127 | 120 | import org.elasticsearch.snapshots.SnapshotId;
|
128 |
| -import org.elasticsearch.snapshots.SnapshotInfo; |
129 |
| -import org.elasticsearch.snapshots.SnapshotShardFailure; |
130 | 121 | import org.elasticsearch.test.CorruptionUtils;
|
131 | 122 | import org.elasticsearch.test.DummyShardLock;
|
132 | 123 | import org.elasticsearch.test.FieldMaskingReader;
|
|
143 | 134 | import java.util.ArrayList;
|
144 | 135 | import java.util.Arrays;
|
145 | 136 | import java.util.Collections;
|
146 |
| -import java.util.HashMap; |
147 | 137 | import java.util.HashSet;
|
148 | 138 | import java.util.Iterator;
|
149 | 139 | import java.util.List;
|
|
174 | 164 | import static org.elasticsearch.common.xcontent.ToXContent.EMPTY_PARAMS;
|
175 | 165 | import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
176 | 166 | import static org.elasticsearch.index.seqno.SequenceNumbers.UNASSIGNED_SEQ_NO;
|
177 |
| -import static org.elasticsearch.repositories.RepositoryData.EMPTY_REPO_GEN; |
178 | 167 | import static org.elasticsearch.test.hamcrest.RegexMatcher.matches;
|
179 | 168 | import static org.hamcrest.Matchers.containsInAnyOrder;
|
180 | 169 | import static org.hamcrest.Matchers.containsString;
|
@@ -2159,9 +2148,12 @@ public void testRecoveryFailsAfterMovingToRelocatedState() throws InterruptedExc
|
2159 | 2148 |
|
2160 | 2149 | public void testRestoreShard() throws IOException {
|
2161 | 2150 | final IndexShard source = newStartedShard(true);
|
2162 |
| - IndexShard target = newStartedShard(true); |
| 2151 | + IndexShard target = newStartedShard(true, Settings.builder() |
| 2152 | + .put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), source.indexSettings().isSoftDeleteEnabled()).build()); |
2163 | 2153 |
|
2164 | 2154 | indexDoc(source, "_doc", "0");
|
| 2155 | + EngineTestCase.generateNewSeqNo(source.getEngine()); // create a gap in the history |
| 2156 | + indexDoc(source, "_doc", "2"); |
2165 | 2157 | if (randomBoolean()) {
|
2166 | 2158 | source.refresh("test");
|
2167 | 2159 | }
|
@@ -2197,16 +2189,18 @@ public void restoreShard(IndexShard shard, SnapshotId snapshotId, Version versio
|
2197 | 2189 | }
|
2198 | 2190 | }
|
2199 | 2191 | }));
|
2200 |
| - assertThat(target.getLocalCheckpoint(), equalTo(0L)); |
2201 |
| - assertThat(target.seqNoStats().getMaxSeqNo(), equalTo(0L)); |
2202 |
| - assertThat(target.getReplicationTracker().getGlobalCheckpoint(), equalTo(0L)); |
| 2192 | + assertThat(target.getLocalCheckpoint(), equalTo(2L)); |
| 2193 | + assertThat(target.seqNoStats().getMaxSeqNo(), equalTo(2L)); |
| 2194 | + assertThat(target.seqNoStats().getGlobalCheckpoint(), equalTo(0L)); |
2203 | 2195 | IndexShardTestCase.updateRoutingEntry(target, routing.moveToStarted());
|
2204 | 2196 | assertThat(target.getReplicationTracker().getTrackedLocalCheckpointForShard(
|
2205 |
| - target.routingEntry().allocationId().getId()).getLocalCheckpoint(), equalTo(0L)); |
| 2197 | + target.routingEntry().allocationId().getId()).getLocalCheckpoint(), equalTo(2L)); |
| 2198 | + assertThat(target.seqNoStats().getGlobalCheckpoint(), equalTo(2L)); |
2206 | 2199 |
|
2207 |
| - assertDocs(target, "0"); |
| 2200 | + assertDocs(target, "0", "2"); |
2208 | 2201 |
|
2209 |
| - closeShards(source, target); |
| 2202 | + closeShard(source, false); |
| 2203 | + closeShards(target); |
2210 | 2204 | }
|
2211 | 2205 |
|
2212 | 2206 | public void testSearcherWrapperIsUsed() throws IOException {
|
@@ -3131,107 +3125,6 @@ private Result indexOnReplicaWithGaps(
|
3131 | 3125 | return new Result(localCheckpoint, max);
|
3132 | 3126 | }
|
3133 | 3127 |
|
3134 |
| - /** A dummy repository for testing which just needs restore overridden */ |
3135 |
| - private abstract static class RestoreOnlyRepository extends AbstractLifecycleComponent implements Repository { |
3136 |
| - private final String indexName; |
3137 |
| - |
3138 |
| - RestoreOnlyRepository(String indexName) { |
3139 |
| - this.indexName = indexName; |
3140 |
| - } |
3141 |
| - |
3142 |
| - @Override |
3143 |
| - protected void doStart() { |
3144 |
| - } |
3145 |
| - |
3146 |
| - @Override |
3147 |
| - protected void doStop() { |
3148 |
| - } |
3149 |
| - |
3150 |
| - @Override |
3151 |
| - protected void doClose() { |
3152 |
| - } |
3153 |
| - |
3154 |
| - @Override |
3155 |
| - public RepositoryMetaData getMetadata() { |
3156 |
| - return null; |
3157 |
| - } |
3158 |
| - |
3159 |
| - @Override |
3160 |
| - public SnapshotInfo getSnapshotInfo(SnapshotId snapshotId) { |
3161 |
| - return null; |
3162 |
| - } |
3163 |
| - |
3164 |
| - @Override |
3165 |
| - public MetaData getSnapshotGlobalMetaData(SnapshotId snapshotId) { |
3166 |
| - return null; |
3167 |
| - } |
3168 |
| - |
3169 |
| - @Override |
3170 |
| - public IndexMetaData getSnapshotIndexMetaData(SnapshotId snapshotId, IndexId index) throws IOException { |
3171 |
| - return null; |
3172 |
| - } |
3173 |
| - |
3174 |
| - @Override |
3175 |
| - public RepositoryData getRepositoryData() { |
3176 |
| - Map<IndexId, Set<SnapshotId>> map = new HashMap<>(); |
3177 |
| - map.put(new IndexId(indexName, "blah"), emptySet()); |
3178 |
| - return new RepositoryData(EMPTY_REPO_GEN, Collections.emptyMap(), Collections.emptyMap(), map, Collections.emptyList()); |
3179 |
| - } |
3180 |
| - |
3181 |
| - @Override |
3182 |
| - public void initializeSnapshot(SnapshotId snapshotId, List<IndexId> indices, MetaData metaData) { |
3183 |
| - } |
3184 |
| - |
3185 |
| - @Override |
3186 |
| - public SnapshotInfo finalizeSnapshot(SnapshotId snapshotId, List<IndexId> indices, long startTime, String failure, |
3187 |
| - int totalShards, List<SnapshotShardFailure> shardFailures, long repositoryStateId, |
3188 |
| - boolean includeGlobalState) { |
3189 |
| - return null; |
3190 |
| - } |
3191 |
| - |
3192 |
| - @Override |
3193 |
| - public void deleteSnapshot(SnapshotId snapshotId, long repositoryStateId) { |
3194 |
| - } |
3195 |
| - |
3196 |
| - @Override |
3197 |
| - public long getSnapshotThrottleTimeInNanos() { |
3198 |
| - return 0; |
3199 |
| - } |
3200 |
| - |
3201 |
| - @Override |
3202 |
| - public long getRestoreThrottleTimeInNanos() { |
3203 |
| - return 0; |
3204 |
| - } |
3205 |
| - |
3206 |
| - @Override |
3207 |
| - public String startVerification() { |
3208 |
| - return null; |
3209 |
| - } |
3210 |
| - |
3211 |
| - @Override |
3212 |
| - public void endVerification(String verificationToken) { |
3213 |
| - } |
3214 |
| - |
3215 |
| - @Override |
3216 |
| - public boolean isReadOnly() { |
3217 |
| - return false; |
3218 |
| - } |
3219 |
| - |
3220 |
| - @Override |
3221 |
| - public void snapshotShard(IndexShard shard, Store store, SnapshotId snapshotId, IndexId indexId, IndexCommit snapshotIndexCommit, |
3222 |
| - IndexShardSnapshotStatus snapshotStatus) { |
3223 |
| - } |
3224 |
| - |
3225 |
| - @Override |
3226 |
| - public IndexShardSnapshotStatus getShardSnapshotStatus(SnapshotId snapshotId, Version version, IndexId indexId, ShardId shardId) { |
3227 |
| - return null; |
3228 |
| - } |
3229 |
| - |
3230 |
| - @Override |
3231 |
| - public void verify(String verificationToken, DiscoveryNode localNode) { |
3232 |
| - } |
3233 |
| - } |
3234 |
| - |
3235 | 3128 | public void testIsSearchIdle() throws Exception {
|
3236 | 3129 | Settings settings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
|
3237 | 3130 | .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1)
|
|
0 commit comments