Skip to content

Commit

Permalink
Work around legacy issue
Browse files Browse the repository at this point in the history
  • Loading branch information
droberts195 committed Sep 27, 2023
1 parent 300dc3c commit 8acdedf
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ protected SystemIndexDescriptor(
if (settings.getAsInt(IndexMetadata.INDEX_FORMAT_SETTING.getKey(), 0) != indexFormat) {
throw new IllegalArgumentException("Descriptor index format does not match index format in managed settings");
}
this.mappingsNodeVersion = extractNodeVersionFromMappings(mappings, mappingsNodeVersionMetaKey);
this.mappingsNodeVersion = bestEffortExtractNodeVersionFromMappings(mappings, mappingsNodeVersionMetaKey);
this.mappingsVersion = extractVersionFromMappings(mappings);
assert mappingsVersion.version >= 0 : "The mappings version must not be negative";

Expand Down Expand Up @@ -953,6 +953,24 @@ private static MappingsVersion extractVersionFromMappings(String mappings) {
return new MappingsVersion(value, Objects.hash(properties));
}

/**
* An accurate node version is no longer required in system index mappings metadata.
* because the mappings version should be used to determine if an upgrade is required,
* not the node version. However, some parts of the code are still relying on
* <code>mappingsNodeVersion</code>. This method allows sections of the code to stop
* accurately setting node version in their mappings while other sections continue to
* use it. Once all uses of <code>mappingsNodeVersion</code> are removed this method
* can be removed too.
*/
@Deprecated
private static Version bestEffortExtractNodeVersionFromMappings(String mappings, String versionMetaKey) {
try {
return extractNodeVersionFromMappings(mappings, versionMetaKey);
} catch (Exception e) {
return null;
}
}

@SuppressWarnings("unchecked")
private static Version extractNodeVersionFromMappings(String mappings, String versionMetaKey) {
final Map<String, Object> mappingsMap = XContentHelper.convertToMap(XContentType.JSON.xContent(), mappings, false);
Expand Down

0 comments on commit 8acdedf

Please sign in to comment.