use of org.elasticsearch.common.settings.AbstractScopedSettings.ARCHIVED_SETTINGS_PREFIX in project crate by crate.
the class IndexTemplateUpgrader method archiveUnknownOrInvalidSettings.
/**
* Filter out all unknown/old/invalid settings. Archiving them *only* is not working as they would be "un-archived"
* by {@link IndexTemplateMetadata.Builder#fromXContent} logic to prefix all settings with `index.` when applying
* the new cluster state.
*/
private HashMap<String, IndexTemplateMetadata> archiveUnknownOrInvalidSettings(Map<String, IndexTemplateMetadata> templates) {
HashMap<String, IndexTemplateMetadata> upgradedTemplates = new HashMap<>(templates.size());
for (Map.Entry<String, IndexTemplateMetadata> entry : templates.entrySet()) {
IndexTemplateMetadata templateMetadata = entry.getValue();
Settings.Builder settingsBuilder = Settings.builder().put(templateMetadata.settings());
String templateName = entry.getKey();
// only process partition table templates
if (IndexParts.isPartitioned(templateName) == false) {
upgradedTemplates.put(templateName, templateMetadata);
continue;
}
Settings settings = DEFAULT_SCOPED_SETTINGS.archiveUnknownOrInvalidSettings(settingsBuilder.build(), e -> {
}, (e, ex) -> {
}).filter(k -> k.startsWith(ARCHIVED_SETTINGS_PREFIX) == false);
IndexTemplateMetadata.Builder builder = IndexTemplateMetadata.builder(templateName).patterns(templateMetadata.patterns()).order(templateMetadata.order()).settings(settings);
try {
for (ObjectObjectCursor<String, CompressedXContent> cursor : templateMetadata.getMappings()) {
var mappingSource = XContentHelper.toMap(cursor.value.compressedReference(), XContentType.JSON);
Object defaultMapping = mappingSource.get("default");
if (defaultMapping instanceof Map && ((Map<?, ?>) defaultMapping).containsKey("_all")) {
Map<?, ?> mapping = (Map<?, ?>) defaultMapping;
// Support for `_all` was removed (in favour of `copy_to`.
// We never utilized this but always set `_all: {enabled: false}` if you created a table using SQL in earlier version, so we can safely drop it.
mapping.remove("_all");
builder.putMapping(cursor.key, new CompressedXContent(BytesReference.bytes(XContentFactory.jsonBuilder().value(mappingSource))));
} else {
builder.putMapping(cursor.key, cursor.value);
}
}
} catch (IOException e) {
logger.error("Error while trying to upgrade template '" + templateName + "'", e);
continue;
}
for (ObjectObjectCursor<String, AliasMetadata> container : templateMetadata.aliases()) {
builder.putAlias(container.value);
}
upgradedTemplates.put(templateName, builder.build());
}
return upgradedTemplates;
}
use of org.elasticsearch.common.settings.AbstractScopedSettings.ARCHIVED_SETTINGS_PREFIX in project crate by crate.
the class SettingsUpdater method partitionKnownAndValidSettings.
/**
* Partitions the settings into those that are known and valid versus those that are unknown or invalid. The resulting tuple contains
* the known and valid settings in the first component and the unknown or invalid settings in the second component. Note that archived
* settings contained in the settings to partition are included in the first component.
*
* @param settings the settings to partition
* @param settingsType a string to identify the settings (for logging)
* @param logger a logger to sending warnings to
* @return the partitioned settings
*/
private Tuple<Settings, Settings> partitionKnownAndValidSettings(final Settings settings, final String settingsType, final Logger logger) {
final Settings existingArchivedSettings = settings.filter(k -> k.startsWith(ARCHIVED_SETTINGS_PREFIX));
final Settings settingsExcludingExistingArchivedSettings = settings.filter(k -> k.startsWith(ARCHIVED_SETTINGS_PREFIX) == false);
final Settings settingsWithUnknownOrInvalidArchived = clusterSettings.archiveUnknownOrInvalidSettings(settingsExcludingExistingArchivedSettings, e -> logUnknownSetting(settingsType, e, logger), (e, ex) -> logInvalidSetting(settingsType, e, ex, logger));
return Tuple.tuple(Settings.builder().put(settingsWithUnknownOrInvalidArchived.filter(k -> k.startsWith(ARCHIVED_SETTINGS_PREFIX) == false)).put(existingArchivedSettings).build(), settingsWithUnknownOrInvalidArchived.filter(k -> k.startsWith(ARCHIVED_SETTINGS_PREFIX)));
}
Aggregations