-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathRoutingPool.java
63 lines (56 loc) · 2.4 KB
/
RoutingPool.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/
package org.opensearch.cluster.routing;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.node.DiscoveryNode;
import org.opensearch.cluster.routing.allocation.RoutingAllocation;
/**
* {@link RoutingPool} defines the different node types based on the assigned capabilities. The methods
* help decide the capabilities of a specific node as well as an index or shard based on the index configuration.
* These methods help with allocation decisions and determining shard classification with the allocation process.
*
* @opensearch.internal
*/
public enum RoutingPool {
LOCAL_ONLY,
REMOTE_CAPABLE;
/**
* Helps to determine the appropriate {@link RoutingPool} for a given node from the {@link RoutingNode}
*/
public static RoutingPool getNodePool(RoutingNode node) {
return getNodePool(node.node());
}
/**
* Helps to determine the appropriate {@link RoutingPool} for a given node from the {@link DiscoveryNode}
*/
public static RoutingPool getNodePool(DiscoveryNode node) {
if (node.isSearchNode()) {
return REMOTE_CAPABLE;
}
return LOCAL_ONLY;
}
/**
* Can determine the appropriate {@link RoutingPool} for a given shard using the {@link IndexMetadata} for the
* index using the {@link RoutingAllocation}.
* @param shard the shard routing for which {@link RoutingPool} has to be determined.
* @param allocation the current allocation of the cluster
* @return {@link RoutingPool} for the given shard.
*/
public static RoutingPool getShardPool(ShardRouting shard, RoutingAllocation allocation) {
IndexMetadata indexMetadata = allocation.metadata().getIndexSafe(shard.index());
return getIndexPool(indexMetadata);
}
/**
* Can determine the appropriate {@link RoutingPool} for a given index using the {@link IndexMetadata}.
* @param indexMetadata the index metadata object for which {@link RoutingPool} has to be determined.
* @return {@link RoutingPool} for the given index.
*/
public static RoutingPool getIndexPool(IndexMetadata indexMetadata) {
return indexMetadata.isRemoteSnapshot() ? REMOTE_CAPABLE : LOCAL_ONLY;
}
}