-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Allow indices lookup to be built lazily #78745
Conversation
by adding a flag to Metadata.Builder.build() method that controls when to build indices lookup. Relates to elastic#77466
918d7a4
to
0ea5c7e
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.
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; |
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.
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.
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.
if (indicesLookup != null) { | ||
return indicesLookup; | ||
} | ||
synchronized (this) { |
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.
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.
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.
aliasToIndices.compute(aliasMetadata.getAlias(), (aliasName, indices) -> { | ||
if (indices == null) { | ||
indices = new ArrayList<>(); | ||
aliasToIndices.compute(aliasMetadata.getAlias(), (aliasName, val) -> { |
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.
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)
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.
Pinging @elastic/es-data-management (Team:Data Management) |
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! Thanks Martijn
return indicesLookup; | ||
if (indicesLookup != null) { | ||
return indicesLookup; | ||
} else { |
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.
NIT: can unwrap the else I guess :)
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.
return build(true); | ||
} | ||
|
||
public Metadata build(boolean builtIndicesLookupEagerly) { |
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.
I think this one deserves a little Javadoc :)
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.
💔 Backport failed
You can use sqren/backport to manually backport by running |
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
…' 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) ...
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
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