Skip to content

Commit ddf33fb

Browse files
committed
Relax SearchReplicaAllocation decider
It doesn't make sense to require that search replicas be allocated to nodes with the search role if the cluster has no nodes with the search role. Signed-off-by: Michael Froh <[email protected]>
1 parent 4bef91a commit ddf33fb

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

server/src/main/java/org/opensearch/cluster/metadata/MetadataCreateIndexService.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,7 @@ public static void updateRemoteStoreSettings(
11791179
translogRepo = RemoteStoreNodeAttribute.getTranslogRepoName(remoteNode.get().getAttributes());
11801180
segmentRepo = RemoteStoreNodeAttribute.getSegmentRepoName(remoteNode.get().getAttributes());
11811181
if (segmentRepo != null) {
1182-
settingsBuilder.put(SETTING_REMOTE_STORE_ENABLED, true)
1183-
.put(SETTING_REMOTE_SEGMENT_STORE_REPOSITORY, segmentRepo);
1182+
settingsBuilder.put(SETTING_REMOTE_STORE_ENABLED, true).put(SETTING_REMOTE_SEGMENT_STORE_REPOSITORY, segmentRepo);
11841183
if (translogRepo != null) {
11851184
settingsBuilder.put(SETTING_REMOTE_TRANSLOG_STORE_REPOSITORY, translogRepo);
11861185
}

server/src/main/java/org/opensearch/cluster/routing/allocation/decider/SearchReplicaAllocationDecider.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,15 @@ public Decision canRemain(ShardRouting shardRouting, RoutingNode node, RoutingAl
3434

3535
private Decision canAllocate(ShardRouting shardRouting, DiscoveryNode node, RoutingAllocation allocation) {
3636
boolean isSearchReplica = shardRouting.isSearchOnly();
37+
boolean existSearchNodes = false;
38+
for (DiscoveryNode discoveryNode : allocation.nodes()) {
39+
if (discoveryNode.isSearchNode()) {
40+
existSearchNodes = true;
41+
}
42+
}
43+
boolean canAllocateSearchReplica = node.isSearchNode() || (existSearchNodes == false);
3744

38-
if ((node.isSearchNode() && isSearchReplica) || (node.isSearchNode() == false && isSearchReplica == false)) {
45+
if ((canAllocateSearchReplica && isSearchReplica) || (node.isSearchNode() == false && isSearchReplica == false)) {
3946
return allocation.decision(
4047
Decision.YES,
4148
NAME,

server/src/main/java/org/opensearch/indices/IndicesService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@
216216
import static org.opensearch.index.TieredMergePolicyProvider.MIN_DEFAULT_MAX_MERGE_AT_ONCE;
217217
import static org.opensearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder;
218218
import static org.opensearch.indices.IndicesRequestCache.INDICES_REQUEST_CACHE_MAX_SIZE_ALLOWED_IN_CACHE_SETTING;
219-
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.isRemoteDataAttributePresent;
220219
import static org.opensearch.search.SearchService.ALLOW_EXPENSIVE_QUERIES;
221220

222221
/**

server/src/main/java/org/opensearch/node/remotestore/RemoteStoreNodeAttribute.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,17 @@ private static Tuple<String, String> getValue(Map<String, String> attributes, Li
194194

195195
private Map<String, String> getValidatedRepositoryNames(DiscoveryNode node) {
196196
Set<Tuple<String, String>> repositoryNames = new HashSet<>();
197-
if (containsKey(node.getAttributes(), REMOTE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEYS) &&
198-
containsKey(node.getAttributes(), List.of(REMOTE_STORE_SEGMENTS_ONLY_ATTRIBUTE_KEY)) &&
199-
"true".equals(node.getAttributes().get(REMOTE_STORE_SEGMENTS_ONLY_ATTRIBUTE_KEY).toLowerCase(Locale.ROOT))) {
197+
if (containsKey(node.getAttributes(), REMOTE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEYS)
198+
&& containsKey(node.getAttributes(), List.of(REMOTE_STORE_SEGMENTS_ONLY_ATTRIBUTE_KEY))
199+
&& "true".equals(node.getAttributes().get(REMOTE_STORE_SEGMENTS_ONLY_ATTRIBUTE_KEY).toLowerCase(Locale.ROOT))) {
200200
repositoryNames.add(validateAttributeNonNull(node, REMOTE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEYS));
201201
} else if (containsKey(node.getAttributes(), REMOTE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEYS)
202202
|| containsKey(node.getAttributes(), REMOTE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEYS)) {
203-
repositoryNames.add(validateAttributeNonNull(node, REMOTE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEYS));
204-
repositoryNames.add(validateAttributeNonNull(node, REMOTE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEYS));
205-
} else if (containsKey(node.getAttributes(), REMOTE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEYS)) {
206-
repositoryNames.add(validateAttributeNonNull(node, REMOTE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEYS));
207-
}
203+
repositoryNames.add(validateAttributeNonNull(node, REMOTE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEYS));
204+
repositoryNames.add(validateAttributeNonNull(node, REMOTE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEYS));
205+
} else if (containsKey(node.getAttributes(), REMOTE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEYS)) {
206+
repositoryNames.add(validateAttributeNonNull(node, REMOTE_CLUSTER_STATE_REPOSITORY_NAME_ATTRIBUTE_KEYS));
207+
}
208208
if (containsKey(node.getAttributes(), REMOTE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEYS)) {
209209
repositoryNames.add(validateAttributeNonNull(node, REMOTE_ROUTING_TABLE_REPOSITORY_NAME_ATTRIBUTE_KEYS));
210210
}

0 commit comments

Comments
 (0)