-
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
Cache DiscoveryNode#trimTier
Result
#80179
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.BiConsumer; | ||
import java.util.stream.Collectors; | ||
|
||
public class DiscoveryNodeFilters { | ||
|
||
|
@@ -66,9 +65,13 @@ public static DiscoveryNodeFilters buildFromKeyValue(OpType opType, Map<String, | |
|
||
private final OpType opType; | ||
|
||
@Nullable | ||
private final DiscoveryNodeFilters trimmed; | ||
|
||
DiscoveryNodeFilters(OpType opType, Map<String, String[]> filters) { | ||
this.opType = opType; | ||
this.filters = filters; | ||
this.filters = Map.copyOf(filters); | ||
this.trimmed = doTrim(this); | ||
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. Nit: could we avoid even calling this when constructing the trimmed filters? Seems unnecessary to walk the filters twice just to check that trimming actually worked. 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. Actually ... we can just avoid that walk altogether in |
||
} | ||
|
||
private boolean matchByIP(String[] values, @Nullable String hostIp, @Nullable String publishIp) { | ||
|
@@ -89,18 +92,24 @@ private boolean matchByIP(String[] values, @Nullable String hostIp, @Nullable St | |
*/ | ||
@Nullable | ||
public static DiscoveryNodeFilters trimTier(@Nullable DiscoveryNodeFilters original) { | ||
if (original == null) { | ||
return null; | ||
} | ||
return original == null ? null : original.trimmed; | ||
} | ||
|
||
Map<String, String[]> newFilters = original.filters.entrySet() | ||
.stream() | ||
// Remove all entries that use "_tier_preference", as these will be handled elsewhere | ||
.filter(entry -> { | ||
String attr = entry.getKey(); | ||
return attr != null && attr.equals("_tier_preference") == false; | ||
}) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
private static DiscoveryNodeFilters doTrim(DiscoveryNodeFilters original) { | ||
boolean filtered = false; | ||
final Map<String, String[]> newFilters = new HashMap<>(original.filters.size()); | ||
// Remove all entries that use "_tier_preference", as these will be handled elsewhere | ||
for (Map.Entry<String, String[]> entry : original.filters.entrySet()) { | ||
String attr = entry.getKey(); | ||
if (attr != null && attr.equals("_tier_preference") == false) { | ||
newFilters.put(entry.getKey(), entry.getValue()); | ||
} else { | ||
filtered = true; | ||
} | ||
} | ||
if (filtered == false) { | ||
return original; | ||
} | ||
|
||
if (newFilters.size() == 0) { | ||
return null; | ||
|
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.
Naming nit: would be good to mention that it's the tier preference that was trimmed -
withoutTierPreferences
or similar perhaps?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.
++ sounds good, renamed