-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Speed up DataTierAllocationDecider #78075
Merged
original-brownbear
merged 9 commits into
elastic:master
from
original-brownbear:speed-up-data-tier-allocation-decider
Sep 22, 2021
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e2a2fb9
Speed up DataTierAllocationDecider
original-brownbear 29ce6c8
logic is hard
original-brownbear bebb1c2
Merge remote-tracking branch 'elastic/master' into speed-up-data-tier…
original-brownbear 142eb28
incorporate review
original-brownbear 9ca47b0
Remove outdated comment
joegallo d4668a8
Internal refactor
joegallo a99b975
Merge branch 'master' into speed-up-data-tier-allocation-decider
elasticmachine dfa6eb5
Merge remote-tracking branch 'elastic/master' into speed-up-data-tier…
original-brownbear 80c7221
CR: comments
original-brownbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -158,9 +158,7 @@ private Decision shouldIndexPreferTier(IndexMetadata indexMetadata, Set<Discover | |||||
Optional<String> tier = preferredTierFunction.apply(tierPreference, allocation.nodes()); | ||||||
if (tier.isPresent()) { | ||||||
String tierName = tier.get(); | ||||||
// The OpType doesn't actually matter here, because we have | ||||||
// selected only a single tier as our "preferred" tier | ||||||
if (allocationAllowed(OpType.AND, tierName, roles)) { | ||||||
if (allocationAllowed(tierName, roles)) { | ||||||
return allocation.decision(Decision.YES, NAME, | ||||||
"index has a preference for tiers [%s] and node has tier [%s]", tierPreference, tierName); | ||||||
} else { | ||||||
|
@@ -175,11 +173,6 @@ private Decision shouldIndexPreferTier(IndexMetadata indexMetadata, Set<Discover | |||||
return null; | ||||||
} | ||||||
|
||||||
private enum OpType { | ||||||
AND, | ||||||
OR | ||||||
} | ||||||
|
||||||
/** | ||||||
* Given a string of comma-separated prioritized tiers (highest priority | ||||||
* first) and an allocation, find the highest priority tier for which nodes | ||||||
|
@@ -192,7 +185,12 @@ public static Optional<String> preferredAvailableTier(String prioritizedTiers, D | |||||
} | ||||||
|
||||||
public static String[] parseTierList(String tiers) { | ||||||
return Strings.tokenizeToStringArray(tiers, ","); | ||||||
if (Strings.hasLength(tiers) == false) { | ||||||
// avoid parsing overhead in the null/empty string case | ||||||
return Strings.EMPTY_ARRAY; | ||||||
} else { | ||||||
return Strings.tokenizeToStringArray(tiers, ","); | ||||||
} | ||||||
} | ||||||
|
||||||
static boolean tierNodesPresent(String singleTier, DiscoveryNodes nodes) { | ||||||
|
@@ -209,25 +207,19 @@ static boolean tierNodesPresent(String singleTier, DiscoveryNodes nodes) { | |||||
} | ||||||
|
||||||
|
||||||
private static boolean allocationAllowed(OpType opType, String tierSetting, Set<DiscoveryNodeRole> roles) { | ||||||
String[] values = parseTierList(tierSetting); | ||||||
for (String value : values) { | ||||||
private static boolean allocationAllowed(String tierName, Set<DiscoveryNodeRole> roles) { | ||||||
assert Strings.hasLength(tierName) : "tierName must be not null and non-empty, but was [" + tierName + "]"; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here,
Suggested change
|
||||||
|
||||||
if (roles.contains(DiscoveryNodeRole.DATA_ROLE)) { | ||||||
// generic "data" roles are considered to have all tiers | ||||||
if (roles.contains(DiscoveryNodeRole.DATA_ROLE) || | ||||||
roles.stream().map(DiscoveryNodeRole::roleName).collect(Collectors.toSet()).contains(value)) { | ||||||
if (opType == OpType.OR) { | ||||||
return true; | ||||||
} else { | ||||||
for (DiscoveryNodeRole role : roles) { | ||||||
if (tierName.equals(role.roleName())) { | ||||||
return true; | ||||||
} | ||||||
} else { | ||||||
if (opType == OpType.AND) { | ||||||
return false; | ||||||
} | ||||||
} | ||||||
} | ||||||
if (opType == OpType.OR) { | ||||||
return false; | ||||||
} else { | ||||||
return true; | ||||||
} | ||||||
} | ||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
To avoid an array like
[" "]
(not that we expect that), maybe we should use: