Skip to content

Commit

Permalink
Add a new node role - remote searcher
Browse files Browse the repository at this point in the history
Signed-off-by: Tianli Feng <ftianli@amazon.com>
  • Loading branch information
Tianli Feng committed Oct 6, 2022
1 parent a17692d commit e51b0c9
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
7 changes: 7 additions & 0 deletions client/rest/src/main/java/org/opensearch/client/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ public boolean isIngest() {
return roles.contains("ingest");
}

/**
* Returns whether the node provides search capability for a remote shard.
*/
public boolean isRemoteSearcher() {
return roles.contains("remote_searcher");
}

@Override
public String toString() {
return String.join(",", roles);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
import static java.util.Collections.singletonMap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.equalTo;

public class NodeTests extends RestClientTestCase {
public void testToString() {
Expand Down Expand Up @@ -161,4 +163,9 @@ public void testEqualsAndHashCode() {
)
);
}

public void testIsRemoteSearcherNode() {
Roles remoteSearcherRole = new Roles(Collections.singleton("remote_searcher"));
assertThat(remoteSearcherRole.isRemoteSearcher(), equalTo(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public void testNodeCounts() {
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1);
expectedCounts.put(DiscoveryNodeRole.REMOTE_SEARCHER_ROLE.roleName(), 0);
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
int numNodes = randomIntBetween(1, 5);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,15 @@ public boolean isRemoteClusterClient() {
return roles.contains(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE);
}

/**
* Returns whether the node can provide search capability for a remote shard.
*
* @return true if the node contains remote_searcher role, false otherwise
*/
public boolean isRemoteSearcherNode() {
return roles.contains(DiscoveryNodeRole.REMOTE_SEARCHER_ROLE);
}

/**
* Returns a set of all the roles that the node has. The roles are returned in sorted order by the role name.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,33 @@ public Setting<Boolean> legacySetting() {

};

/**
* Represents the role for a remote searcher node.
*/
public static final DiscoveryNodeRole REMOTE_SEARCHER_ROLE = new DiscoveryNodeRole("remote_searcher", "s", true) {

@Override
public Setting<Boolean> legacySetting() {
// remote_searcher role is added in 2.4 so doesn't need to configure legacy setting
return null;
}

@Override
public DiscoveryNodeRole getCompatibilityRole(Version nodeVersion) {
if (nodeVersion.onOrAfter(Version.V_2_4_0)) {
return this;
} else {
return DiscoveryNodeRole.DATA_ROLE;
}
}

};

/**
* The built-in node roles.
*/
public static SortedSet<DiscoveryNodeRole> BUILT_IN_ROLES = Collections.unmodifiableSortedSet(
new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, CLUSTER_MANAGER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE))
new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, CLUSTER_MANAGER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE, REMOTE_SEARCHER_ROLE))
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.transport.TransportAddress;
import org.opensearch.test.NodeRoles;
import org.opensearch.test.OpenSearchTestCase;

import java.net.InetAddress;
Expand Down Expand Up @@ -204,4 +205,10 @@ public void testGetRoleFromRoleNameIsCaseInsensitive() {
assertEquals(dynamicRoleName.toLowerCase(Locale.ROOT), dynamicNodeRole.roleName());
assertEquals(dynamicRoleName.toLowerCase(Locale.ROOT), dynamicNodeRole.roleNameAbbreviation());
}

public void testDiscoveryNodeIsRemoteSearcherNode() {
final Settings settingWithRemoteSearcherRole = NodeRoles.onlyRole(DiscoveryNodeRole.REMOTE_SEARCHER_ROLE);
final DiscoveryNode node = DiscoveryNode.createLocal(settingWithRemoteSearcherRole, buildNewFakeTransportAddress(), "node");
assertThat(node.isRemoteSearcherNode(), equalTo(true));
}
}

0 comments on commit e51b0c9

Please sign in to comment.