Skip to content

Commit

Permalink
Fix _host based require filters (#38173)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ywelsch authored Feb 1, 2019
1 parent da6269b commit 025bf28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,7 @@ public boolean match(DiscoveryNode node) {
}
} else if ("_host".equals(attr)) {
for (String value : values) {
if (Regex.simpleMatch(value, node.getHostName())) {
if (opType == OpType.OR) {
return true;
}
} else {
if (opType == OpType.AND) {
return false;
}
}
if (Regex.simpleMatch(value, node.getHostAddress())) {
if (Regex.simpleMatch(value, node.getHostName()) || Regex.simpleMatch(value, node.getHostAddress())) {
if (opType == OpType.OR) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,26 @@ public void testIpPublishFilteringMatchingOr() {
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() {
Settings settings = shuffleSettings(Settings.builder()
.put("xxx.tag", "A")
Expand Down

0 comments on commit 025bf28

Please sign in to comment.