Skip to content

Conversation

nielsbauman
Copy link
Contributor

@nielsbauman nielsbauman commented Sep 29, 2025

By moving component template normalization to the transport action, we can perform an equality check on the component template before creating a cluster state update task. This reduces the load on the master/cluster state update thread for no-op update requests. We still need to perform the equality check in the cluster state update task, as the cluster state could have been updated after we performed the check in the transport action. But avoiding a cluster state update task altogether in some cases is worth adding the check to the transport action.

Additionally, by making some small refactorings in MetadataIndexTemplateService#addComponentTemplate we avoid building some objects unnecessarily and improve readability.

The number of changed lines looks scary, but most "changed" lines are only moving tests from one class to another.

Also see #135457 for another (bigger) optimization in component templates.

By moving component template normalization to the transport action, we
can perform an equality check on the component template before creating
a cluster state update task. This reduces the load on the master/cluster
state update thread for no-op update requests. We still need to perform
the equality check in the cluster state update task, as the cluster
state could have been updated after we performed the check in the
transport action. But avoiding a cluster state update task altogether in
some cases is worth adding the check to the transport action.

Additionally, by making some small refactorings in
`MetadataIndexTemplateService#addComponentTemplate` we avoid building
some objects unnecessarily and improve readability.
@nielsbauman nielsbauman requested a review from a team as a code owner September 29, 2025 17:11
@nielsbauman nielsbauman added >enhancement :Data Management/Indices APIs APIs to create and manage indices and templates labels Sep 29, 2025
@elasticsearchmachine elasticsearchmachine added Team:Data Management Meta label for data/management team v9.2.0 labels Sep 29, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-data-management (Team:Data Management)

@elasticsearchmachine
Copy link
Collaborator

Hi @nielsbauman, I've created a changelog YAML for you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the added lines in this class are solely from moving the tests over from MetadataIndexTemplateServiceTests.

Comment on lines +365 to 369
// These two validation checks are only scoped to the component template itself (and don't depend on any other entities in the
// cluster state) and could thus be done in the transport action. However, since we're parsing mappings here, we shouldn't be doing
// it directly on the transport thread. Instead, we should fork to a different threadpool (management/generic).
validateTemplate(finalComponentTemplate.template().settings(), finalComponentTemplate.template().mappings(), indicesService);
validate(name, finalComponentTemplate.template(), List.of(), null);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented with moving these two validations to the transport action, but since the Distributed Coordination team advised running them on the management or generic threadpool, I decided to leave it as future work. In terms of overall processing, we wouldn't save much. The only/main win would be that we avoid adding a cluster state update task in case the validation fails.

Also worth noting is that we potentially do more (heavier) mappings validation in validateIndexTemplateV2 below. Although #135457 helps reduce that in a lot of cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Indices APIs APIs to create and manage indices and templates >enhancement Team:Data Management Meta label for data/management team v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants