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

Speed up DataTierAllocationDecider #78075

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -160,7 +161,7 @@ private Decision shouldIndexPreferTier(IndexMetadata indexMetadata, Set<Discover
String tierName = tier.get();
// The OpType doesn't actually matter here, because we have
// selected only a single tier as our "preferred" tier
joegallo marked this conversation as resolved.
Show resolved Hide resolved
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 {
Expand All @@ -175,11 +176,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
Expand Down Expand Up @@ -209,25 +205,37 @@ static boolean tierNodesPresent(String singleTier, DiscoveryNodes nodes) {
}


private static boolean allocationAllowed(OpType opType, String tierSetting, Set<DiscoveryNodeRole> roles) {
private static boolean allocationAllowed(String tierSetting, Set<DiscoveryNodeRole> roles) {
String[] values = parseTierList(tierSetting);
joegallo marked this conversation as resolved.
Show resolved Hide resolved
for (String value : values) {
Set<String> roleNames = null;
if (values.length == 0) {
return true;
}
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;
}
if (values.length == 1) {
final String value = values[0];
for (DiscoveryNodeRole role : roles) {
if (value.equals(role.roleName())) {
return true;
}
} else {
if (opType == OpType.AND) {
return false;
}
}
}
if (opType == OpType.OR) {
return false;
} else {
return true;
for (String value : values) {
if (roleNames == null) {
roleNames = new HashSet<>(roles.size());
for (DiscoveryNodeRole role : roles) {
roleNames.add(role.roleName());
}
}
if (roleNames.contains(value) == false) {
return false;
}
}
}
return true;
}
}