Skip to content

Commit f1eac4c

Browse files
authored
[8.x] Fix synthetic recovery source version validation. (#118942)
* Fix synthetic recovery source version validation. (#118924) The validation didn't work as expected, because created version was always 0 (which is created version default value). Moving the validation to a place that does have access to the index version. * fixed compile error after cherry picking * iter
1 parent 19fd296 commit f1eac4c

File tree

5 files changed

+58
-41
lines changed

5 files changed

+58
-41
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.create/20_synthetic_source.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,3 +2012,43 @@ synthetic_source with copy_to pointing inside dynamic object:
20122012
hits.hits.2.fields:
20132013
c.copy.keyword: [ "hello", "zap" ]
20142014

2015+
---
2016+
create index with use_synthetic_source:
2017+
- requires:
2018+
cluster_features: ["mapper.synthetic_recovery_source"]
2019+
reason: requires synthetic recovery source
2020+
2021+
- do:
2022+
indices.create:
2023+
index: test
2024+
body:
2025+
settings:
2026+
index:
2027+
recovery:
2028+
use_synthetic_source: true
2029+
mapping:
2030+
source:
2031+
mode: synthetic
2032+
2033+
- do:
2034+
indices.get_settings: {}
2035+
- match: { test.settings.index.mapping.source.mode: synthetic}
2036+
- is_true: test.settings.index.recovery.use_synthetic_source
2037+
2038+
- do:
2039+
bulk:
2040+
index: test
2041+
refresh: true
2042+
body:
2043+
- '{ "create": { } }'
2044+
- '{ "field": "aaaa" }'
2045+
- '{ "create": { } }'
2046+
- '{ "field": "bbbb" }'
2047+
2048+
- do:
2049+
indices.disk_usage:
2050+
index: test
2051+
run_expensive_tasks: true
2052+
flush: false
2053+
- gt: { test.store_size_in_bytes: 0 }
2054+
- is_false: test.fields._recovery_source

server/src/main/java/org/elasticsearch/index/IndexSettings.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -688,25 +688,11 @@ public void validate(Boolean enabled, Map<Setting<?>, Object> settings) {
688688
);
689689
}
690690
}
691-
692-
// Verify that all nodes can handle this setting
693-
var version = (IndexVersion) settings.get(SETTING_INDEX_VERSION_CREATED);
694-
if (version.before(IndexVersions.USE_SYNTHETIC_SOURCE_FOR_RECOVERY_BACKPORT)) {
695-
throw new IllegalArgumentException(
696-
String.format(
697-
Locale.ROOT,
698-
"The setting [%s] is unavailable on this cluster because some nodes are running older "
699-
+ "versions that do not support it. Please upgrade all nodes to the latest version "
700-
+ "and try again.",
701-
RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey()
702-
)
703-
);
704-
}
705691
}
706692

707693
@Override
708694
public Iterator<Setting<?>> settings() {
709-
List<Setting<?>> res = List.of(INDEX_MAPPER_SOURCE_MODE_SETTING, SETTING_INDEX_VERSION_CREATED, MODE);
695+
List<Setting<?>> res = List.of(INDEX_MAPPER_SOURCE_MODE_SETTING, MODE);
710696
return res.iterator();
711697
}
712698
},
@@ -1049,6 +1035,20 @@ public IndexSettings(final IndexMetadata indexMetadata, final Settings nodeSetti
10491035
indexMappingSourceMode = scopedSettings.get(INDEX_MAPPER_SOURCE_MODE_SETTING);
10501036
recoverySourceEnabled = RecoverySettings.INDICES_RECOVERY_SOURCE_ENABLED_SETTING.get(nodeSettings);
10511037
recoverySourceSyntheticEnabled = scopedSettings.get(RECOVERY_USE_SYNTHETIC_SOURCE_SETTING);
1038+
if (recoverySourceSyntheticEnabled) {
1039+
// Verify that all nodes can handle this setting
1040+
if (version.before(IndexVersions.USE_SYNTHETIC_SOURCE_FOR_RECOVERY_BACKPORT)) {
1041+
throw new IllegalArgumentException(
1042+
String.format(
1043+
Locale.ROOT,
1044+
"The setting [%s] is unavailable on this cluster because some nodes are running older "
1045+
+ "versions that do not support it. Please upgrade all nodes to the latest version "
1046+
+ "and try again.",
1047+
RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey()
1048+
)
1049+
);
1050+
}
1051+
}
10521052

10531053
scopedSettings.addSettingsUpdateConsumer(
10541054
MergePolicyConfig.INDEX_COMPOUND_FORMAT_SETTING,

server/src/main/java/org/elasticsearch/index/mapper/MapperFeatures.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public Set<NodeFeature> getTestFeatures() {
7070
DocumentParser.FIX_PARSING_SUBOBJECTS_FALSE_DYNAMIC_FALSE,
7171
CONSTANT_KEYWORD_SYNTHETIC_SOURCE_WRITE_FIX,
7272
META_FETCH_FIELDS_ERROR_CODE_CHANGED,
73-
SPARSE_VECTOR_STORE_SUPPORT
73+
SPARSE_VECTOR_STORE_SUPPORT,
74+
SourceFieldMapper.SYNTHETIC_RECOVERY_SOURCE
7475
);
7576
}
7677
}

server/src/main/java/org/elasticsearch/index/mapper/SourceFieldMapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class SourceFieldMapper extends MetadataFieldMapper {
5555
"mapper.source.remove_synthetic_source_only_validation"
5656
);
5757
public static final NodeFeature SOURCE_MODE_FROM_INDEX_SETTING = new NodeFeature("mapper.source.mode_from_index_setting");
58+
public static final NodeFeature SYNTHETIC_RECOVERY_SOURCE = new NodeFeature("mapper.synthetic_recovery_source");
5859

5960
public static final String NAME = "_source";
6061
public static final String RECOVERY_SOURCE_NAME = "_recovery_source";

server/src/test/java/org/elasticsearch/index/mapper/SourceFieldMapperTests.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -465,31 +465,6 @@ public void testRecoverySourceWitInvalidSettings() {
465465
)
466466
);
467467
}
468-
{
469-
Settings settings = Settings.builder()
470-
.put(SourceFieldMapper.INDEX_MAPPER_SOURCE_MODE_SETTING.getKey(), SourceFieldMapper.Mode.SYNTHETIC.toString())
471-
.put(IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey(), true)
472-
.build();
473-
IllegalArgumentException exc = expectThrows(
474-
IllegalArgumentException.class,
475-
() -> createMapperService(
476-
IndexVersionUtils.randomPreviousCompatibleVersion(random(), IndexVersions.USE_SYNTHETIC_SOURCE_FOR_RECOVERY_BACKPORT),
477-
settings,
478-
() -> false,
479-
topMapping(b -> {})
480-
)
481-
);
482-
assertThat(
483-
exc.getMessage(),
484-
containsString(
485-
String.format(
486-
Locale.ROOT,
487-
"The setting [%s] is unavailable on this cluster",
488-
IndexSettings.RECOVERY_USE_SYNTHETIC_SOURCE_SETTING.getKey()
489-
)
490-
)
491-
);
492-
}
493468
}
494469

495470
public void testRecoverySourceWithSyntheticSource() throws IOException {

0 commit comments

Comments
 (0)