Skip to content

Commit 7e28535

Browse files
committedFeb 21, 2024
Warn about index.mapper.dynamic usage instead of erroring
When migrating from older versions of OpenSearch index.mapper.dynamic could be present, use the deprecation system to warn about this state and ignore this legacy setting so the index is usable. Signed-off-by: Peter Nied <petern@amazon.com>
1 parent e97bee8 commit 7e28535

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
126126
- Add a system property to configure YamlParser codepoint limits ([#12298](https://github.com/opensearch-project/OpenSearch/pull/12298))
127127
- Prevent read beyond slice boundary in ByteArrayIndexInput ([#10481](https://github.com/opensearch-project/OpenSearch/issues/10481))
128128
- Fix the "highlight.max_analyzer_offset" request parameter with "plain" highlighter ([#10919](https://github.com/opensearch-project/OpenSearch/pull/10919))
129+
- Warn about deprecated and ignored index.mapper.dynamic index setting ([#11193](https://github.com/opensearch-project/OpenSearch/pull/11193))
129130

130131
### Security
131132

‎server/src/main/java/org/opensearch/index/mapper/MapperService.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public MapperService(
237237
ScriptService scriptService
238238
) {
239239
super(indexSettings);
240+
240241
this.indexVersionCreated = indexSettings.getIndexVersionCreated();
241242
this.indexAnalyzers = indexAnalyzers;
242243
this.documentParser = new DocumentMapperParser(
@@ -261,7 +262,12 @@ public MapperService(
261262
this.idFieldDataEnabled = idFieldDataEnabled;
262263

263264
if (INDEX_MAPPER_DYNAMIC_SETTING.exists(indexSettings.getSettings())) {
264-
throw new IllegalArgumentException("Setting " + INDEX_MAPPER_DYNAMIC_SETTING.getKey() + " was removed after version 6.0.0");
265+
deprecationLogger.deprecate(
266+
index().getName() + INDEX_MAPPER_DYNAMIC_SETTING.getKey(),
267+
"Index [{}] has setting [{}] that is not supported in OpenSearch, its value will be ignored.",
268+
index().getName(),
269+
INDEX_MAPPER_DYNAMIC_SETTING.getKey()
270+
);
265271
}
266272
}
267273

‎server/src/test/java/org/opensearch/index/mapper/MapperServiceTests.java

+24
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
import java.util.Arrays;
6464
import java.util.Collection;
6565
import java.util.Collections;
66+
import java.util.List;
6667
import java.util.Map;
68+
import java.util.function.Function;
6769

6870
import static org.hamcrest.CoreMatchers.containsString;
6971
import static org.hamcrest.CoreMatchers.is;
@@ -541,6 +543,28 @@ public void testReloadSearchAnalyzers() throws IOException {
541543
);
542544
}
543545

546+
public void testMapperDynamicAllowedIgnored() {
547+
final List<Function<Settings.Builder, Settings.Builder>> scenarios = List.of(
548+
(builder) -> builder.putNull(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey()),
549+
(builder) -> builder.put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), true),
550+
(builder) -> builder.put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), false)
551+
);
552+
553+
for (int i = 0; i < scenarios.size(); i++) {
554+
final Settings.Builder defaultSettingsBuilder = Settings.builder()
555+
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
556+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1);
557+
558+
final Settings settings = scenarios.get(i).apply(defaultSettingsBuilder).build();
559+
560+
createIndex("test" + i, settings).mapperService();
561+
}
562+
563+
assertWarnings(
564+
"[index.mapper.dynamic] setting was deprecated in OpenSearch and will be removed in a future release! See the breaking changes documentation for the next major version."
565+
);
566+
}
567+
544568
private boolean assertSameContainedFilters(TokenFilterFactory[] originalTokenFilter, NamedAnalyzer updatedAnalyzer) {
545569
ReloadableCustomAnalyzer updatedReloadableAnalyzer = (ReloadableCustomAnalyzer) updatedAnalyzer.analyzer();
546570
TokenFilterFactory[] newTokenFilters = updatedReloadableAnalyzer.getComponents().getTokenFilters();

0 commit comments

Comments
 (0)