Fix _host based require filters (#38173)

Using index.routing.allocation.require._host does not correctly work because the boolean logic in
filter matching is broken (DiscoveryNodeFilters.match(...) will return false) when
opType ==OpType.AND
This commit is contained in:
Yannick Welsch 2019-02-01 16:02:37 +01:00 committed by GitHub
parent da6269b456
commit 025bf28405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 10 deletions

View File

@ -147,16 +147,7 @@ public class DiscoveryNodeFilters {
} }
} else if ("_host".equals(attr)) { } else if ("_host".equals(attr)) {
for (String value : values) { for (String value : values) {
if (Regex.simpleMatch(value, node.getHostName())) { if (Regex.simpleMatch(value, node.getHostName()) || Regex.simpleMatch(value, node.getHostAddress())) {
if (opType == OpType.OR) {
return true;
}
} else {
if (opType == OpType.AND) {
return false;
}
}
if (Regex.simpleMatch(value, node.getHostAddress())) {
if (opType == OpType.OR) { if (opType == OpType.OR) {
return true; return true;
} }

View File

@ -235,6 +235,26 @@ public class DiscoveryNodeFiltersTests extends ESTestCase {
assertThat(filters.match(node), equalTo(true)); assertThat(filters.match(node), equalTo(true));
} }
public void testHostNameFilteringMatchingAnd() {
Settings settings = shuffleSettings(Settings.builder()
.put("xxx._host", "A")
.build());
DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "A", "192.1.1.54", localAddress, emptyMap(), emptySet(), null);
assertThat(filters.match(node), equalTo(true));
}
public void testHostAddressFilteringMatchingAnd() {
Settings settings = shuffleSettings(Settings.builder()
.put("xxx._host", "192.1.1.54")
.build());
DiscoveryNodeFilters filters = buildFromSettings(AND, "xxx.", settings);
DiscoveryNode node = new DiscoveryNode("", "", "", "A", "192.1.1.54", localAddress, emptyMap(), emptySet(), null);
assertThat(filters.match(node), equalTo(true));
}
public void testIpPublishFilteringNotMatchingOr() { public void testIpPublishFilteringNotMatchingOr() {
Settings settings = shuffleSettings(Settings.builder() Settings settings = shuffleSettings(Settings.builder()
.put("xxx.tag", "A") .put("xxx.tag", "A")