Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrik-es committed Oct 31, 2024
1 parent 3fb4258 commit 3a58939
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 443 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,6 @@
- is_false: test_index.mappings.properties.foo.meta.bar
- match: { test_index.mappings.properties.foo.meta.baz: "quux" }

---
"disabling synthetic source fails":
- requires:
cluster_features: ["gte_v8.4.0"]
reason: "Added in 8.4.0"

- do:
indices.create:
index: test_index
body:
settings:
index:
mapping.source.mode: synthetic

- do:
catch: /Cannot update parameter \[mode\] from \[synthetic\] to \[stored\]/
indices.put_mapping:
index: test_index
body:
_source:
mode: stored

---
"enabling synthetic source from explicit succeeds":
- requires:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ force_synthetic_source_ok:
body:
settings:
index:
mapping.source.mode: synthetic
mapping.source.mode: stored
mappings:
properties:
obj:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ setup:
index_options: positions
vectors:
type: text
store: false
term_vector: with_positions_offsets
positions:
type: text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ force_synthetic_source_ok:
body:
settings:
index:
mapping.source.mode: synthetic
mapping.source.mode: stored
mappings:
properties:
obj:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ stored source is supported:
time_series:
start_time: 2021-04-28T00:00:00Z
end_time: 2021-04-29T00:00:00Z
mapping:
source.mode: stored
mappings:
properties:
"@timestamp":
Expand Down Expand Up @@ -508,6 +510,8 @@ disabled source is not supported:
time_series:
start_time: 2021-04-28T00:00:00Z
end_time: 2021-04-29T00:00:00Z
mapping:
source.mode: disabled
mappings:
properties:
"@timestamp":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public SourceFieldMapper build() {
}

private Mode resolveSourceMode() {
// If the `index.mapper.source.mode` exists it takes precedence to determine the source mode for `_source`
// If the `index.mapping.source.mode` exists it takes precedence to determine the source mode for `_source`
// otherwise the mode is determined according to `_source.mode`.
if (INDEX_MAPPER_SOURCE_MODE_SETTING.exists(settings)) {
return INDEX_MAPPER_SOURCE_MODE_SETTING.get(settings);
Expand Down Expand Up @@ -439,6 +439,10 @@ public static boolean isSynthetic(IndexSettings indexSettings) {
return INDEX_MAPPER_SOURCE_MODE_SETTING.get(indexSettings.getSettings()) == SourceFieldMapper.Mode.SYNTHETIC;
}

public static boolean isStored(IndexSettings indexSettings) {
return INDEX_MAPPER_SOURCE_MODE_SETTING.get(indexSettings.getSettings()) == Mode.STORED;
}

public boolean isDisabled() {
return mode == Mode.DISABLED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.elasticsearch.index.engine.EngineFactory;
import org.elasticsearch.index.engine.ReadOnlyEngine;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.translog.TranslogStats;
import org.elasticsearch.repositories.FilterRepository;
Expand Down Expand Up @@ -134,8 +135,9 @@ private static Metadata metadataToSnapshot(Collection<IndexId> indices, Metadata
@Override
public void snapshotShard(SnapshotShardContext context) {
final MapperService mapperService = context.mapperService();
if (mapperService.documentMapper() != null // if there is no mapping this is null
&& mapperService.documentMapper().sourceMapper().isComplete() == false) {
if ((mapperService.documentMapper() != null // if there is no mapping this is null
&& mapperService.documentMapper().sourceMapper().isComplete() == false)
|| (mapperService.documentMapper() == null && SourceFieldMapper.isStored(mapperService.getIndexSettings()) == false)) {
context.onFailure(
new IllegalStateException(
"Can't snapshot _source only on an index that has incomplete source ie. has _source disabled or filters the source"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.elasticsearch.index.engine.InternalEngineFactory;
import org.elasticsearch.index.fieldvisitor.FieldsVisitor;
import org.elasticsearch.index.mapper.SeqNoFieldMapper;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.mapper.SourceToParse;
import org.elasticsearch.index.seqno.RetentionLeaseSyncer;
import org.elasticsearch.index.seqno.SeqNoStats;
Expand Down Expand Up @@ -150,6 +151,55 @@ public void testSourceIncomplete() throws IOException {
closeShards(shard);
}

public void testSourceIncompleteSyntheticSourceNoDoc() throws IOException {
ShardRouting shardRouting = shardRoutingBuilder(
new ShardId("index", "_na_", 0),
randomAlphaOfLength(10),
true,
ShardRoutingState.INITIALIZING
).withRecoverySource(RecoverySource.EmptyStoreRecoverySource.INSTANCE).build();
Settings settings = Settings.builder()
.put(IndexMetadata.SETTING_VERSION_CREATED, IndexVersion.current())
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "synthetic")
.build();
IndexMetadata metadata = IndexMetadata.builder(shardRouting.getIndexName()).settings(settings).primaryTerm(0, primaryTerm).build();
IndexShard shard = newShard(shardRouting, metadata, null, new InternalEngineFactory());
recoverShardFromStore(shard);
SnapshotId snapshotId = new SnapshotId("test", "test");
IndexId indexId = new IndexId(shard.shardId().getIndexName(), shard.shardId().getIndex().getUUID());
SourceOnlySnapshotRepository repository = new SourceOnlySnapshotRepository(createRepository());
repository.start();
try (Engine.IndexCommitRef snapshotRef = shard.acquireLastIndexCommit(true)) {
IndexShardSnapshotStatus indexShardSnapshotStatus = IndexShardSnapshotStatus.newInitializing(new ShardGeneration(-1L));
final PlainActionFuture<ShardSnapshotResult> future = new PlainActionFuture<>();
runAsSnapshot(
shard.getThreadPool(),
() -> repository.snapshotShard(
new SnapshotShardContext(
shard.store(),
shard.mapperService(),
snapshotId,
indexId,
new SnapshotIndexCommit(snapshotRef),
null,
indexShardSnapshotStatus,
IndexVersion.current(),
randomMillisUpToYear9999(),
future
)
)
);
IllegalStateException illegalStateException = expectThrows(IllegalStateException.class, future::actionGet);
assertEquals(
"Can't snapshot _source only on an index that has incomplete source ie. has _source disabled or filters the source",
illegalStateException.getMessage()
);
}
closeShards(shard);
}

public void testIncrementalSnapshot() throws IOException {
IndexShard shard = newStartedShard();
for (int i = 0; i < 10; i++) {
Expand Down
Loading

0 comments on commit 3a58939

Please sign in to comment.