Skip to content
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

Allow indices lookup to be built lazily #78745

Merged
merged 8 commits into from
Oct 7, 2021

Conversation

martijnvg
Copy link
Member

@martijnvg martijnvg commented Oct 6, 2021

Overloaded the Metadata.Builder.build() method by adding a parameter that controls when to build indices lookup.
By default the indices lookup is always build.

When cluster state updates are batched in ilm, then built the indices lookup lazily. Because during batching only the final cluster state is used, then for the many intermediate cluster states we avoids building the indices lookup, which in a cluster with many indices can improve the performance of publishing cluster states significantly.

Relates to #77466

by adding a flag to Metadata.Builder.build() method that controls when to build indices lookup.

Relates to elastic#77466
@martijnvg martijnvg force-pushed the lazily_built_indices_lookup2 branch from 918d7a4 to 0ea5c7e Compare October 6, 2021 11:16
Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

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

Looks good, thanks @martijnvg ! Just a few small things :)

@@ -189,7 +189,7 @@
private final String[] allClosedIndices;
private final String[] visibleClosedIndices;

private final SortedMap<String, IndexAbstraction> indicesLookup;
private volatile SortedMap<String, IndexAbstraction> indicesLookup;
Copy link
Member

Choose a reason for hiding this comment

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

No need for this to be volatile, this is just a best effort cache. No need to synchronize here. Especially when the only time this is null after construction is during the ILM task loop anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

if (indicesLookup != null) {
return indicesLookup;
}
synchronized (this) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here, let's not have any synchronization here. If this isn't set then it will be lazy set just fine in our task loops and otherwise it's set from the time of construction anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

aliasToIndices.compute(aliasMetadata.getAlias(), (aliasName, indices) -> {
if (indices == null) {
indices = new ArrayList<>();
aliasToIndices.compute(aliasMetadata.getAlias(), (aliasName, val) -> {
Copy link
Member

Choose a reason for hiding this comment

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

If we're changing this already (+1 to the name change btw), can't we just go for computeIfAbsent to make it look nicer? :) (and also faster because we don't need a capturing lambda then)

Copy link
Member Author

Choose a reason for hiding this comment

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

@martijnvg martijnvg marked this pull request as ready for review October 7, 2021 08:57
@martijnvg martijnvg added :Data Management/Indices APIs APIs to create and manage indices and templates >enhancement v7.16.0 labels Oct 7, 2021
@elasticmachine elasticmachine added the Team:Data Management Meta label for data/management team label Oct 7, 2021
@elasticmachine
Copy link
Collaborator

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

@martijnvg martijnvg added the :Data Management/ILM+SLM Index and Snapshot lifecycle management label Oct 7, 2021
@martijnvg martijnvg changed the title Lazily built indices lookup Allow indices lookup to be built lazily Oct 7, 2021
Copy link
Member

@original-brownbear original-brownbear left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks Martijn

return indicesLookup;
if (indicesLookup != null) {
return indicesLookup;
} else {
Copy link
Member

Choose a reason for hiding this comment

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

NIT: can unwrap the else I guess :)

Copy link
Member Author

Choose a reason for hiding this comment

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

return build(true);
}

public Metadata build(boolean builtIndicesLookupEagerly) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this one deserves a little Javadoc :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@martijnvg martijnvg merged commit 877e722 into elastic:master Oct 7, 2021
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
7.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 78745

martijnvg added a commit to martijnvg/elasticsearch that referenced this pull request Oct 7, 2021
Backport elastic#78745 to 7.x branch.

Overloaded the Metadata.Builder.build() method by adding a parameter that controls when to build indices lookup.
By default the indices lookup is always build.

When cluster state updates are batched in ilm, then built the indices lookup lazily. Because during batching only the final cluster state is used, then for the many intermediate cluster states we avoids building the indices lookup, which in a cluster with many indices can improve the performance of publishing cluster states significantly.

Relates to elastic#77466
wjp719 added a commit to wjp719/elasticsearch that referenced this pull request Oct 7, 2021
…' into feature/data_stream_support_routing

* wjp/feature/data_stream_support_routing: (44 commits)
  Revert "Adjust /_cat/templates not to request all metadata (elastic#78812)"
  Allow indices lookup to be built lazily (elastic#78745)
  [DOCS] Document default security in alpha2 (elastic#78227)
  Add cluster applier stats (elastic#77552)
  Fix failing URLDecodeProcessorTests::testProcessor test (elastic#78690)
  Upgrade to lucene snapshot ba75dc5e6bf (elastic#78817)
  Adjust /_cat/templates not to request all metadata (elastic#78812)
  Simplify build plugin license handling (elastic#77009)
  Fix SearchableSnapshotsBlobStoreCacheIntegTests.testBlobStoreCache (elastic#78616)
  Improve Docker image caching and testing (elastic#78552)
  Load knn vectors format with mmapfs (elastic#78724)
  Fix date math zone test to use negative minutes (elastic#78796)
  Changing name of shards field in node/stats api to shard_stats (elastic#78531)
  [DOCS] Fix system index refs in restore tutorial (elastic#78582)
  Add previously removed settings back for 8.0 (elastic#78784)
  TSDB: Fix template name in test
  Add a system property to forcibly format everything (elastic#78768)
  Revert "Adding config so that some tests will break if over-the-wire encryption fails (elastic#78409)" (elastic#78787)
  Must date math test failure
  Adding config so that some tests will break if over-the-wire encryption fails (elastic#78409)
  ...
elasticsearchmachine pushed a commit that referenced this pull request Oct 7, 2021
Backport #78745 to 7.x branch.

Overloaded the Metadata.Builder.build() method by adding a parameter that controls when to build indices lookup.
By default the indices lookup is always build.

When cluster state updates are batched in ilm, then built the indices lookup lazily. Because during batching only the final cluster state is used, then for the many intermediate cluster states we avoids building the indices lookup, which in a cluster with many indices can improve the performance of publishing cluster states significantly.

Relates to #77466
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/ILM+SLM Index and Snapshot lifecycle management :Data Management/Indices APIs APIs to create and manage indices and templates >enhancement Team:Data Management Meta label for data/management team v7.16.0 v8.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants