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 @@ -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 {
Expand All @@ -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
Expand All @@ -192,7 +185,12 @@ public static Optional<String> preferredAvailableTier(String prioritizedTiers, D
}

public static String[] parseTierList(String tiers) {
return Strings.tokenizeToStringArray(tiers, ",");
if (Strings.hasText(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) {
Expand All @@ -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.hasText(tierName) : "tierName must be not null and non-empty, but was [" + tierName + "]";

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;
}
}
}