-
Notifications
You must be signed in to change notification settings - Fork 694
fix: update index template settings only when they change #37217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9849cf6
to
70585e9
Compare
834d109
to
3aeb344
Compare
3aeb344
to
89223b6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM would just like th logic to be easier to understand
@@ -483,33 +491,46 @@ utils.new SchemaSettingsAppender(templateFile) | |||
} | |||
} | |||
|
|||
private PutIndexTemplateRequest updateTemplateSettings( | |||
private Optional<PutIndexTemplateRequest> buildTemplateSettingsUpdateRequestIfChanged( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔧 A bit hard to understand I would prefer it be split up
private Optional<PutIndexTemplateRequest> buildTemplateSettingsUpdateRequestIfChanged(
final IndexTemplateDescriptor templateDescriptor,
final IndexConfiguration configuredSettings) {
try (final var templateFile = getResourceAsStream(templateDescriptor.getMappingsClasspathFilename())) {
final var currentTemplate = getIndexTemplateState(templateDescriptor);
final var configuredPriority = convertValue(configuredSettings.getTemplatePriority(), Long::valueOf);
final var newSettings = utils.new SchemaSettingsAppender(templateFile)
.withNumberOfShards(configuredSettings.getNumberOfShards())
.withNumberOfReplicas(configuredSettings.getNumberOfReplicas());
if (areTemplateSettingsEqualToConfigured(currentTemplate, configuredPriority, newSettings)) {
LOG.debug("Index template settings for [{}] are already up to date", templateDescriptor.getTemplateName());
return Optional.empty();
}
return Optional.of(buildPutIndexTemplateRequest(templateDescriptor, currentTemplate, newSettings, configuredPriority));
} catch (final IOException e) {
throw new SearchEngineException(
"Failed to load file " + templateDescriptor.getMappingsClasspathFilename() + " from classpath.", e);
}
}
private boolean areTemplateSettingsEqualToConfigured(IndexTemplateState currentTemplate, Long configuredPriority, SchemaSettingsAppender newSettings) {
return Objects.equals(configuredPriority, currentTemplate.priority())
&& newSettings.equalsSettings(serializeAsMap(currentTemplate.template().settings()));
}
private PutIndexTemplateRequest buildPutIndexTemplateRequest(
IndexTemplateDescriptor templateDescriptor,
IndexTemplateState currentTemplate,
SchemaSettingsAppender settingsAppender,
Long priority) {
final var updatedSettings = deserializeJson(IndexTemplateMapping._DESERIALIZER, settingsAppender.build()).settings();
LOG.debug("Applying to index template [{}]: settings={}, priority={}",
templateDescriptor.getTemplateName(), updatedSettings, priority);
return new PutIndexTemplateRequest.Builder()
.name(templateDescriptor.getTemplateName())
.indexPatterns(templateDescriptor.getIndexPattern())
.template(t -> t
.settings(updatedSettings)
.mappings(currentTemplate.template().mappings())
.aliases(currentTemplate.template().aliases()))
.priority(priority)
.build();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also do the same for OS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the hint, I tired to make it clearer now
I did not add though
private PutIndexTemplateRequest buildPutIndexTemplateRequest(
IndexTemplateDescriptor templateDescriptor,
IndexTemplateState currentTemplate,
SchemaSettingsAppender settingsAppender,
Long priority) {
I feel it is very specific and it is not reusable, I think it is clear enough now
fdca237
to
ac327bc
Compare
Successfully created backport PR for |
Description
Skip redundant index template settings PUTs for Elasticsearch/OpenSearch.
Adds parallel execution of index settings updates to cut overhead.
Problem
Every startup overwrote template settings (priority, shards, replicas) even when unchanged. This wasted requests, bumped ES/OS cluster.
Solution
Effects
Checklist
Related issues
closes #37240