Skip to content

Commit

Permalink
fix: move source mode setting to IndexSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
salvatore-campagna committed Jan 8, 2025
1 parent a7ba43a commit f6613d3
Show file tree
Hide file tree
Showing 20 changed files with 113 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.core.Nullable;
import org.elasticsearch.features.NodeFeature;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.xcontent.ToXContentFragment;
import org.elasticsearch.xcontent.XContentBuilder;

Expand Down Expand Up @@ -71,7 +71,7 @@ public static MappingStats of(Metadata metadata, Runnable ensureNotCancelled) {
}
AnalysisStats.countMapping(mappingCounts, indexMetadata);

var sourceMode = SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.get(indexMetadata.getSettings());
var sourceMode = IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.get(indexMetadata.getSettings());
sourceModeUsageCount.merge(sourceMode.toString().toLowerCase(Locale.ENGLISH), 1, Integer::sum);
}
final AtomicLong totalFieldCount = new AtomicLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.MapperService.MergeReason;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.shard.IndexLongFieldRange;
import org.elasticsearch.indices.IndexCreationException;
Expand Down Expand Up @@ -1590,7 +1589,7 @@ static void validateCloneIndex(

private static final Set<String> UNMODIFIABLE_SETTINGS_DURING_RESIZE = Set.of(
IndexSettings.MODE.getKey(),
SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(),
IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(),
IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey(),
IndexSortConfig.INDEX_SORT_FIELD_SETTING.getKey(),
IndexSortConfig.INDEX_SORT_ORDER_SETTING.getKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.elasticsearch.index.mapper.IgnoredSourceFieldMapper;
import org.elasticsearch.index.mapper.InferenceMetadataFieldsMapper;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.store.FsDirectoryFactory;
import org.elasticsearch.index.store.Store;
Expand Down Expand Up @@ -189,7 +188,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings {
FieldMapper.SYNTHETIC_SOURCE_KEEP_INDEX_SETTING,
IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_WRITE_SETTING,
IgnoredSourceFieldMapper.SKIP_IGNORED_SOURCE_READ_SETTING,
SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING,
IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING,
IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING,
InferenceMetadataFieldsMapper.USE_LEGACY_SEMANTIC_TEXT_FORMAT,

Expand Down
93 changes: 52 additions & 41 deletions server/src/main/java/org/elasticsearch/index/IndexSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_NESTED_DOCS_LIMIT_SETTING;
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_NESTED_FIELDS_LIMIT_SETTING;
import static org.elasticsearch.index.mapper.MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING;
import static org.elasticsearch.index.mapper.SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING;

/**
* This class encapsulates all index level settings and handles settings updates.
Expand Down Expand Up @@ -655,6 +654,58 @@ public Iterator<Setting<?>> settings() {
Property.Final
);

/**
* Returns <code>true</code> if TSDB encoding is enabled. The default is <code>true</code>
*/
public boolean isES87TSDBCodecEnabled() {
return es87TSDBCodecEnabled;
}

public static final Setting<Boolean> LOGSDB_ROUTE_ON_SORT_FIELDS = Setting.boolSetting(
"index.logsdb.route_on_sort_fields",
false,
Property.IndexScope,
Property.Final
);

/**
* The {@link IndexMode "mode"} of the index.
*/
public static final Setting<IndexMode> MODE = Setting.enumSetting(
IndexMode.class,
"index.mode",
IndexMode.STANDARD,
new Setting.Validator<>() {
@Override
public void validate(IndexMode value) {}

@Override
public void validate(IndexMode value, Map<Setting<?>, Object> settings) {
value.validateWithOtherSettings(settings);
}

@Override
public Iterator<Setting<?>> settings() {
return IndexMode.VALIDATE_WITH_SETTINGS.iterator();
}
},
Property.IndexScope,
Property.Final,
Property.ServerlessPublic
);

public static final Setting<SourceFieldMapper.Mode> INDEX_MAPPER_SOURCE_MODE_SETTING = Setting.enumSetting(
SourceFieldMapper.Mode.class,
settings -> {
final IndexMode indexMode = IndexSettings.MODE.get(settings);
return indexMode.defaultSourceMode().name();
},
"index.mapping.source.mode",
value -> {},
Setting.Property.Final,
Setting.Property.IndexScope
);

public static final Setting<Boolean> RECOVERY_USE_SYNTHETIC_SOURCE_SETTING = Setting.boolSetting(
"index.recovery.use_synthetic_source",
settings -> {
Expand Down Expand Up @@ -700,46 +751,6 @@ public Iterator<Setting<?>> settings() {
Property.Final
);

/**
* Returns <code>true</code> if TSDB encoding is enabled. The default is <code>true</code>
*/
public boolean isES87TSDBCodecEnabled() {
return es87TSDBCodecEnabled;
}

public static final Setting<Boolean> LOGSDB_ROUTE_ON_SORT_FIELDS = Setting.boolSetting(
"index.logsdb.route_on_sort_fields",
false,
Property.IndexScope,
Property.Final
);

/**
* The {@link IndexMode "mode"} of the index.
*/
public static final Setting<IndexMode> MODE = Setting.enumSetting(
IndexMode.class,
"index.mode",
IndexMode.STANDARD,
new Setting.Validator<>() {
@Override
public void validate(IndexMode value) {}

@Override
public void validate(IndexMode value, Map<Setting<?>, Object> settings) {
value.validateWithOtherSettings(settings);
}

@Override
public Iterator<Setting<?>> settings() {
return IndexMode.VALIDATE_WITH_SETTINGS.iterator();
}
},
Property.IndexScope,
Property.Final,
Property.ServerlessPublic
);

/**
* Legacy index setting, kept for 7.x BWC compatibility. This setting has no effect in 8.x. Do not use.
* TODO: Remove in 9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.elasticsearch.common.Explicit;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.core.Nullable;
Expand All @@ -37,7 +36,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -68,22 +66,6 @@ public class SourceFieldMapper extends MetadataFieldMapper {

public static final String LOSSY_PARAMETERS_ALLOWED_SETTING_NAME = "index.lossy.source-mapping-parameters";

public static final Setting<Mode> INDEX_MAPPER_SOURCE_MODE_SETTING = Setting.enumSetting(SourceFieldMapper.Mode.class, settings -> {
final IndexMode indexMode = IndexSettings.MODE.get(settings);
return indexMode.defaultSourceMode().name();
}, "index.mapping.source.mode", new Setting.Validator<>() {
@Override
public void validate(Mode value) {

}

@Override
public Iterator<Setting<?>> settings() {
List<Setting<?>> res = List.of(IndexSettings.MODE);
return res.iterator();
}
}, Setting.Property.Final, Setting.Property.IndexScope);

public static final String DEPRECATION_WARNING = "Configuring source mode in mappings is deprecated and will be removed "
+ "in future versions. Use [index.mapping.source.mode] index setting instead.";

Expand Down Expand Up @@ -273,8 +255,8 @@ public SourceFieldMapper build() {
private Mode resolveSourceMode() {
// 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);
if (IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.exists(settings)) {
return IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.get(settings);
}

// If `_source.mode` is not set we need to apply a default according to index mode.
Expand Down Expand Up @@ -306,7 +288,7 @@ private static SourceFieldMapper resolveStaticInstance(final Mode sourceMode) {
return DEFAULT;
}

final Mode settingSourceMode = INDEX_MAPPER_SOURCE_MODE_SETTING.get(c.getSettings());
final Mode settingSourceMode = IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.get(c.getSettings());
// Needed for bwc so that "mode" is not serialized in case of standard index with stored source.
if (indexMode == IndexMode.STANDARD && settingSourceMode == Mode.STORED) {
return DEFAULT;
Expand Down Expand Up @@ -491,11 +473,11 @@ public boolean isSynthetic() {
}

public static boolean isSynthetic(IndexSettings indexSettings) {
return INDEX_MAPPER_SOURCE_MODE_SETTING.get(indexSettings.getSettings()) == SourceFieldMapper.Mode.SYNTHETIC;
return IndexSettings.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;
return IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.get(indexSettings.getSettings()) == Mode.STORED;
}

public boolean isDisabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.Mapping;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.index.shard.IndexLongFieldRange;
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.shard.ShardId;
Expand Down Expand Up @@ -159,7 +158,7 @@ public final class RestoreService implements ClusterStateApplier {
SETTING_CREATION_DATE,
SETTING_HISTORY_UUID,
IndexSettings.MODE.getKey(),
SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(),
IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(),
IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey(),
IndexSortConfig.INDEX_SORT_FIELD_SETTING.getKey(),
IndexSortConfig.INDEX_SORT_ORDER_SETTING.getKey(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.Writeable.Reader;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.index.mapper.SourceFieldMapper;
import org.elasticsearch.script.Script;
import org.elasticsearch.tasks.TaskCancelledException;
import org.elasticsearch.test.AbstractWireSerializingTestCase;
Expand Down Expand Up @@ -586,15 +586,15 @@ public void testSourceModes() {
int numDisabledIndices = randomIntBetween(1, 5);
for (int i = 0; i < numSyntheticIndices; i++) {
IndexMetadata.Builder indexMetadata = new IndexMetadata.Builder("foo-synthetic-" + i).settings(
indexSettings(IndexVersion.current(), 4, 1).put(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "synthetic")
indexSettings(IndexVersion.current(), 4, 1).put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "synthetic")
);
builder.put(indexMetadata);
}
for (int i = 0; i < numStoredIndices; i++) {
IndexMetadata.Builder indexMetadata;
if (randomBoolean()) {
indexMetadata = new IndexMetadata.Builder("foo-stored-" + i).settings(
indexSettings(IndexVersion.current(), 4, 1).put(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "stored")
indexSettings(IndexVersion.current(), 4, 1).put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "stored")
);
} else {
indexMetadata = new IndexMetadata.Builder("foo-stored-" + i).settings(indexSettings(IndexVersion.current(), 4, 1));
Expand All @@ -603,7 +603,7 @@ public void testSourceModes() {
}
for (int i = 0; i < numDisabledIndices; i++) {
IndexMetadata.Builder indexMetadata = new IndexMetadata.Builder("foo-disabled-" + i).settings(
indexSettings(IndexVersion.current(), 4, 1).put(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "disabled")
indexSettings(IndexVersion.current(), 4, 1).put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), "disabled")
);
builder.put(indexMetadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

import java.io.IOException;

import static org.elasticsearch.index.mapper.SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING;

public class LuceneSyntheticSourceChangesSnapshotTests extends SearchBasedChangesSnapshotTests {
@Override
protected Settings indexSettings() {
return Settings.builder()
.put(super.indexSettings())
.put(INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC.name())
.put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC.name())
.put(IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey(), true)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@

import java.io.IOException;

import static org.elasticsearch.index.mapper.SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING;

public class TranslogOperationAsserterTests extends EngineTestCase {

@Override
protected Settings indexSettings() {
return Settings.builder()
.put(super.indexSettings())
.put(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true)
.put(INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC.name())
.put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC.name())
.put(IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey(), true)
.build();
}
Expand All @@ -57,10 +55,10 @@ EngineConfig engineConfig(boolean useSyntheticSource) {
EngineConfig config = engine.config();
Settings.Builder settings = Settings.builder().put(config.getIndexSettings().getSettings());
if (useSyntheticSource) {
settings.put(INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC.name());
settings.put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC.name());
settings.put(IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey(), true);
} else {
settings.put(INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.STORED.name());
settings.put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.STORED.name());
settings.put(IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey(), false);
}
IndexMetadata imd = IndexMetadata.builder(config.getIndexSettings().getIndexMetadata()).settings(settings).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.lucene.index.DirectoryReader;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.CheckedConsumer;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
Expand Down Expand Up @@ -130,7 +131,7 @@ private MapperService mapperServiceWithCustomSettings(
for (var entry : customSettings.entrySet()) {
settings.put(entry.getKey(), entry.getValue());
}
settings.put(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC);
settings.put(IndexSettings.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC);
return createMapperService(settings.build(), mapping(mapping));
}

Expand Down
Loading

0 comments on commit f6613d3

Please sign in to comment.