Skip to content

Commit c1272c1

Browse files
author
Tianli Feng
authored
Add a new node role 'search' which is dedicated to provide search capability (#4689)
Signed-off-by: Tianli Feng <ftianli@amazon.com>
1 parent cd8f0fa commit c1272c1

7 files changed

Lines changed: 47 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
3535
- Added precommit support for MacOS ([#4682](https://github.com/opensearch-project/OpenSearch/pull/4682))
3636
- Recommission API changes for service layer ([#4320](https://github.com/opensearch-project/OpenSearch/pull/4320))
3737
- Update GeoGrid base class access modifier to support extensibility ([#4572](https://github.com/opensearch-project/OpenSearch/pull/4572))
38+
- Add a new node role 'search' which is dedicated to provide search capability ([#4689](https://github.com/opensearch-project/OpenSearch/pull/4689))
3839

3940
### Dependencies
4041
- Bumps `log4j-core` from 2.18.0 to 2.19.0

client/rest/src/main/java/org/opensearch/client/Node.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ public boolean isIngest() {
239239
return roles.contains("ingest");
240240
}
241241

242+
/**
243+
* Returns whether the node is dedicated to provide search capability.
244+
*/
245+
public boolean isSearch() {
246+
return roles.contains("search");
247+
}
248+
242249
@Override
243250
public String toString() {
244251
return String.join(",", roles);

client/rest/src/test/java/org/opensearch/client/NodeTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
import static java.util.Collections.singletonMap;
4949
import static org.junit.Assert.assertEquals;
5050
import static org.junit.Assert.assertFalse;
51+
import static org.junit.Assert.assertThat;
5152
import static org.junit.Assert.assertTrue;
53+
import static org.hamcrest.CoreMatchers.equalTo;
5254

5355
public class NodeTests extends RestClientTestCase {
5456
public void testToString() {
@@ -161,4 +163,9 @@ public void testEqualsAndHashCode() {
161163
)
162164
);
163165
}
166+
167+
public void testIsSearchNode() {
168+
Roles searchRole = new Roles(Collections.singleton("search"));
169+
assertThat(searchRole.isSearch(), equalTo(true));
170+
}
164171
}

server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/stats/ClusterStatsIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public void testNodeCounts() {
8989
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
9090
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 1);
9191
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 1);
92+
expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0);
9293
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
9394
int numNodes = randomIntBetween(1, 5);
9495

@@ -160,6 +161,7 @@ public void testNodeCountsWithDeprecatedMasterRole() {
160161
expectedCounts.put(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE.roleName(), 1);
161162
expectedCounts.put(DiscoveryNodeRole.INGEST_ROLE.roleName(), 0);
162163
expectedCounts.put(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE.roleName(), 0);
164+
expectedCounts.put(DiscoveryNodeRole.SEARCH_ROLE.roleName(), 0);
163165
expectedCounts.put(ClusterStatsNodes.Counts.COORDINATING_ONLY, 0);
164166

165167
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();

server/src/main/java/org/opensearch/cluster/node/DiscoveryNode.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,15 @@ public boolean isRemoteClusterClient() {
460460
return roles.contains(DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE);
461461
}
462462

463+
/**
464+
* Returns whether the node is dedicated to provide search capability.
465+
*
466+
* @return true if the node contains search role, false otherwise
467+
*/
468+
public boolean isSearchNode() {
469+
return roles.contains(DiscoveryNodeRole.SEARCH_ROLE);
470+
}
471+
463472
/**
464473
* Returns a set of all the roles that the node has. The roles are returned in sorted order by the role name.
465474
* <p>

server/src/main/java/org/opensearch/cluster/node/DiscoveryNodeRole.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,24 @@ public Setting<Boolean> legacySetting() {
290290

291291
};
292292

293+
/**
294+
* Represents the role for a search node, which is dedicated to provide search capability.
295+
*/
296+
public static final DiscoveryNodeRole SEARCH_ROLE = new DiscoveryNodeRole("search", "s", true) {
297+
298+
@Override
299+
public Setting<Boolean> legacySetting() {
300+
// search role is added in 2.4 so doesn't need to configure legacy setting
301+
return null;
302+
}
303+
304+
};
305+
293306
/**
294307
* The built-in node roles.
295308
*/
296309
public static SortedSet<DiscoveryNodeRole> BUILT_IN_ROLES = Collections.unmodifiableSortedSet(
297-
new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, CLUSTER_MANAGER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE))
310+
new TreeSet<>(Arrays.asList(DATA_ROLE, INGEST_ROLE, CLUSTER_MANAGER_ROLE, REMOTE_CLUSTER_CLIENT_ROLE, SEARCH_ROLE))
298311
);
299312

300313
/**

server/src/test/java/org/opensearch/cluster/node/DiscoveryNodeTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.opensearch.common.settings.Setting;
4040
import org.opensearch.common.settings.Settings;
4141
import org.opensearch.common.transport.TransportAddress;
42+
import org.opensearch.test.NodeRoles;
4243
import org.opensearch.test.OpenSearchTestCase;
4344

4445
import java.net.InetAddress;
@@ -204,4 +205,10 @@ public void testGetRoleFromRoleNameIsCaseInsensitive() {
204205
assertEquals(dynamicRoleName.toLowerCase(Locale.ROOT), dynamicNodeRole.roleName());
205206
assertEquals(dynamicRoleName.toLowerCase(Locale.ROOT), dynamicNodeRole.roleNameAbbreviation());
206207
}
208+
209+
public void testDiscoveryNodeIsSearchNode() {
210+
final Settings settingWithSearchRole = NodeRoles.onlyRole(DiscoveryNodeRole.SEARCH_ROLE);
211+
final DiscoveryNode node = DiscoveryNode.createLocal(settingWithSearchRole, buildNewFakeTransportAddress(), "node");
212+
assertThat(node.isSearchNode(), equalTo(true));
213+
}
207214
}

0 commit comments

Comments
 (0)