|
52 | 52 | import org.elasticsearch.index.engine.InternalEngineFactory; |
53 | 53 | import org.elasticsearch.index.fieldvisitor.FieldsVisitor; |
54 | 54 | import org.elasticsearch.index.mapper.SeqNoFieldMapper; |
| 55 | +import org.elasticsearch.index.mapper.SourceFieldMapper; |
55 | 56 | import org.elasticsearch.index.mapper.SourceToParse; |
56 | 57 | import org.elasticsearch.index.seqno.RetentionLeaseSyncer; |
57 | 58 | import org.elasticsearch.index.seqno.SeqNoStats; |
@@ -149,6 +150,55 @@ public void testSourceIncomplete() throws IOException { |
149 | 150 | closeShards(shard); |
150 | 151 | } |
151 | 152 |
|
| 153 | + public void testSourceIncompleteSyntheticSourceNoDoc() throws IOException { |
| 154 | + ShardRouting shardRouting = shardRoutingBuilder( |
| 155 | + new ShardId("index", "_na_", 0), |
| 156 | + randomAlphaOfLength(10), |
| 157 | + true, |
| 158 | + ShardRoutingState.INITIALIZING |
| 159 | + ).withRecoverySource(RecoverySource.EmptyStoreRecoverySource.INSTANCE).build(); |
| 160 | + Settings settings = Settings.builder() |
| 161 | + .put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current()) |
| 162 | + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) |
| 163 | + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) |
| 164 | + .put(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "synthetic") |
| 165 | + .build(); |
| 166 | + IndexMetadata metadata = IndexMetadata.builder(shardRouting.getIndexName()).settings(settings).primaryTerm(0, primaryTerm).build(); |
| 167 | + IndexShard shard = newShard(shardRouting, metadata, null, new InternalEngineFactory()); |
| 168 | + recoverShardFromStore(shard); |
| 169 | + SnapshotId snapshotId = new SnapshotId("test", "test"); |
| 170 | + IndexId indexId = new IndexId(shard.shardId().getIndexName(), shard.shardId().getIndex().getUUID()); |
| 171 | + SourceOnlySnapshotRepository repository = new SourceOnlySnapshotRepository(createRepository()); |
| 172 | + repository.start(); |
| 173 | + try (Engine.IndexCommitRef snapshotRef = shard.acquireLastIndexCommit(true)) { |
| 174 | + IndexShardSnapshotStatus indexShardSnapshotStatus = IndexShardSnapshotStatus.newInitializing(new ShardGeneration(-1L)); |
| 175 | + final PlainActionFuture<ShardSnapshotResult> future = new PlainActionFuture<>(); |
| 176 | + runAsSnapshot( |
| 177 | + shard.getThreadPool(), |
| 178 | + () -> repository.snapshotShard( |
| 179 | + new SnapshotShardContext( |
| 180 | + shard.store(), |
| 181 | + shard.mapperService(), |
| 182 | + snapshotId, |
| 183 | + indexId, |
| 184 | + new SnapshotIndexCommit(snapshotRef), |
| 185 | + null, |
| 186 | + indexShardSnapshotStatus, |
| 187 | + IndexVersion.current(), |
| 188 | + randomMillisUpToYear9999(), |
| 189 | + future |
| 190 | + ) |
| 191 | + ) |
| 192 | + ); |
| 193 | + IllegalStateException illegalStateException = expectThrows(IllegalStateException.class, future::actionGet); |
| 194 | + assertEquals( |
| 195 | + "Can't snapshot _source only on an index that has incomplete source ie. has _source disabled or filters the source", |
| 196 | + illegalStateException.getMessage() |
| 197 | + ); |
| 198 | + } |
| 199 | + closeShards(shard); |
| 200 | + } |
| 201 | + |
152 | 202 | public void testIncrementalSnapshot() throws IOException { |
153 | 203 | IndexShard shard = newStartedShard(); |
154 | 204 | for (int i = 0; i < 10; i++) { |
|
0 commit comments