Skip to content

Commit

Permalink
Fixing javadocs
Browse files Browse the repository at this point in the history
Signed-off-by: Shourya Dutta Biswas <[email protected]>
  • Loading branch information
shourya035 committed Apr 20, 2024
1 parent f14e231 commit ca4b1d9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,6 @@ public List<ShardRouting> shardsMatchingPredicate(Predicate<ShardRouting> predic
return shards;
}

/**
* Returns <code>true</code> iff all shards for the index are started otherwise <code>false</code>
*/
public boolean allShardsStarted() {
for (IndexShardRoutingTable shardRoutingTable : this) {
if (shardRoutingTable.allShardsStarted() == false) {
return false;
}
}
return true;
}

public int shardsMatchingPredicateCount(Predicate<ShardRouting> predicate) {
int count = 0;
for (IndexShardRoutingTable shardRoutingTable : this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@ public static class RemoteMigrationClusterStateUtils {
* once all shards of an index have moved over to remote store enabled nodes
* <br>
* Also appends the requisite Remote Store Path based custom metadata to the existing index metadata
*
* @return Mutated {@link ClusterState} with the remote store based settings applied
*/
public static void maybeAddRemoteIndexSettings(
IndexMetadata indexMetadata,
Expand Down Expand Up @@ -227,15 +225,9 @@ public static void maybeAddRemoteIndexSettings(

/**
* Returns <code>true</code> iff all the below conditions are true:
* <li>
* All primary shards are in {@link ShardRoutingState#STARTED} state and are in remote store enabled nodes
* </li>
* <li>
* No replica shard in {@link ShardRoutingState#INITIALIZING} or {@link ShardRoutingState#RELOCATING} state
* </li>
* <li>
* All {@link ShardRoutingState#STARTED} replica shards are in remote store enabled nodes
* </li>
* - All primary shards are in {@link ShardRoutingState#STARTED} state and are in remote store enabled nodes
* - No replica shard in {@link ShardRoutingState#INITIALIZING} or {@link ShardRoutingState#RELOCATING} state
* - All {@link ShardRoutingState#STARTED} replica shards are in remote store enabled nodes
*
*
* @param indexRoutingTable current {@link IndexRoutingTable} from cluster state
Expand Down Expand Up @@ -322,18 +314,10 @@ public static boolean indexHasAllRemoteStoreRelatedMetadata(IndexMetadata indexM

/**
* Assert current index settings have:
* <li>
* <code>index.remote_store.enabled</code> is <code>true</code>
* </li>
* <li>
* <code>index.remote_store.segment.repository</code> is not <code>null</code>
* </li>
* <li>
* <code>index.remote_store.translog.repository</code> is not <code>null</code>
* </li>
* <li>
* <code>index.replication.type</code> is <code>SEGMENT</code>
* </li>
* - index.remote_store.enabled == true
* - index.remote_store.segment.repository != null
* - index.remote_store.translog.repository != null
* - index.replication.type == SEGMENT
*
* @param indexSettings Current index settings
* @return <code>true</code> if all above conditions match. <code>false</code> otherwise
Expand All @@ -348,12 +332,8 @@ public static boolean indexHasRemoteStoreSettings(Settings indexSettings) {
/**
* Asserts current index metadata customs has the {@link IndexMetadata#REMOTE_STORE_CUSTOM_KEY} key.
* If it does, checks if the following sub-keys are present
* <li>
* {@link RemoteStoreEnums.PathType#NAME)}
* </li>
* <li>
* {@link RemoteStoreEnums.PathHashAlgorithm#NAME)}
* </li>
* - path_type
* - path_hash_algorithm
*
* @param indexMetadata Current index metadata
* @return <code>true</code> if all above conditions match. <code>false</code> otherwise
Expand All @@ -364,7 +344,6 @@ public static boolean indexHasRemotePathMetadata(IndexMetadata indexMetadata) {
return Objects.nonNull(customMetadata.get(RemoteStoreEnums.PathType.NAME))
&& Objects.nonNull(customMetadata.get(RemoteStoreEnums.PathHashAlgorithm.NAME));
}
;
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
import org.opensearch.cluster.routing.UnassignedInfo;
import org.opensearch.common.settings.Settings;
import org.opensearch.core.index.shard.ShardId;
import org.opensearch.index.shard.IndexShardTestUtils;
import org.opensearch.node.remotestore.RemoteStoreNodeService;
import org.opensearch.test.OpenSearchTestCase;

import java.util.ArrayList;
Expand Down Expand Up @@ -244,7 +242,7 @@ public static ClusterState state(final int numberOfNodes, final String[] indices
discoBuilder.localNodeId(newNode(0).getId());
discoBuilder.clusterManagerNodeId(newNode(0).getId());
Metadata.Builder metadata = Metadata.builder();
Builder routingTable = RoutingTable.builder();
RoutingTable.Builder routingTable = RoutingTable.builder();
List<String> nodesList = new ArrayList<>(nodes);
int currentNodeToAssign = 0;
for (String index : indices) {
Expand Down Expand Up @@ -326,57 +324,20 @@ public static ClusterState stateWithAssignedPrimariesAndOneReplica(String index,
* Creates cluster state with several indexes, shards and replicas and all shards STARTED.
*/
public static ClusterState stateWithAssignedPrimariesAndReplicas(String[] indices, int numberOfShards, int numberOfReplicas) {
return stateWithDiscoveryNodesAndAssignedPrimariesAndReplicas(null, indices, numberOfShards, numberOfReplicas);
}

/**
* Creates cluster state with provided {@link DiscoveryNodes}, several indexes, shards and replicas and all shards STARTED.
* Generates {@link DiscoveryNodes} if none are provided
*/
public static ClusterState stateWithDiscoveryNodesAndAssignedPrimariesAndReplicas(
DiscoveryNodes discoveryNodes,
String[] indices,
int numberOfShards,
int numberOfReplicas
) {
return stateWithDiscoveryNodesAndPrimariesAndReplicas(
discoveryNodes,
indices,
numberOfShards,
numberOfReplicas,
ShardRoutingState.STARTED
);
}

/**
* Creates cluster state with provided {@link DiscoveryNodes}, several indexes, shards and replicas with specified {@link ShardRoutingState}.
* Generates {@link DiscoveryNodes} if none are provided
*/
public static ClusterState stateWithDiscoveryNodesAndPrimariesAndReplicas(
DiscoveryNodes discoveryNodes,
String[] indices,
int numberOfShards,
int numberOfReplicas,
ShardRoutingState shardRoutingState
) {
ClusterState.Builder state = ClusterState.builder(new ClusterName("test"));
// Generate fake nodes if none are provided
if (discoveryNodes == null) {
int numberOfDataNodes = numberOfReplicas + 1;
DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
for (int i = 0; i < numberOfDataNodes + 1; i++) {
final DiscoveryNode node = newNode(i);
discoBuilder = discoBuilder.add(node);
}
discoBuilder.localNodeId(newNode(0).getId());
discoBuilder.clusterManagerNodeId(newNode(numberOfDataNodes + 1).getId());
state.nodes(discoBuilder);
} else {
state.nodes(discoveryNodes);
int numberOfDataNodes = numberOfReplicas + 1;
DiscoveryNodes.Builder discoBuilder = DiscoveryNodes.builder();
for (int i = 0; i < numberOfDataNodes + 1; i++) {
final DiscoveryNode node = newNode(i);
discoBuilder = discoBuilder.add(node);
}
discoBuilder.localNodeId(newNode(0).getId());
discoBuilder.clusterManagerNodeId(newNode(numberOfDataNodes + 1).getId());
ClusterState.Builder state = ClusterState.builder(new ClusterName("test"));
state.nodes(discoBuilder);
Builder routingTableBuilder = RoutingTable.builder();

Metadata.Builder metadataBuilder = Metadata.builder();
org.opensearch.cluster.metadata.Metadata.Builder metadataBuilder = Metadata.builder();

for (String index : indices) {
IndexMetadata indexMetadata = IndexMetadata.builder(index)
Expand All @@ -394,11 +355,11 @@ public static ClusterState stateWithDiscoveryNodesAndPrimariesAndReplicas(
final ShardId shardId = new ShardId(index, "_na_", i);
IndexShardRoutingTable.Builder indexShardRoutingBuilder = new IndexShardRoutingTable.Builder(shardId);
indexShardRoutingBuilder.addShard(
TestShardRouting.newShardRouting(index, i, newNode(0).getId(), null, true, shardRoutingState)
TestShardRouting.newShardRouting(index, i, newNode(0).getId(), null, true, ShardRoutingState.STARTED)
);
for (int replica = 0; replica < numberOfReplicas; replica++) {
indexShardRoutingBuilder.addShard(
TestShardRouting.newShardRouting(index, i, newNode(replica + 1).getId(), null, false, shardRoutingState)
TestShardRouting.newShardRouting(index, i, newNode(replica + 1).getId(), null, false, ShardRoutingState.STARTED)
);
}
indexRoutingTableBuilder.addIndexShard(indexShardRoutingBuilder.build());
Expand Down Expand Up @@ -488,52 +449,6 @@ public static ClusterState state(DiscoveryNode localNode, DiscoveryNode clusterM
return state.build();
}

public static ClusterState stateWithMixedNodes(
int numberOfRemoteDataNodes,
int numberOfDocrepDataNodes,
boolean applyMixedModeSetting,
String[] indices,
int numberOfShards,
int numberOfReplicas,
ShardRoutingState shardRoutingState
) {
assert numberOfRemoteDataNodes > 1 && numberOfDocrepDataNodes > 1 : "Need at-least 2 nodes to create state for remote nodes";
DiscoveryNodes.Builder mixedNodes = new DiscoveryNodes.Builder();
for (int i = 0; i < numberOfRemoteDataNodes; i++) {
mixedNodes.add(newRemoteNodeWithName("remote_" + i));
}
for (int i = 0; i < numberOfDocrepDataNodes; i++) {
mixedNodes.add(newNode(i));
}
mixedNodes.localNodeId(newRemoteNode(numberOfRemoteDataNodes + numberOfDocrepDataNodes).getId());
mixedNodes.clusterManagerNodeId(newRemoteNode(numberOfRemoteDataNodes + numberOfDocrepDataNodes + 1).getId());
ClusterState initialState = stateWithDiscoveryNodesAndPrimariesAndReplicas(
mixedNodes.build(),
indices,
numberOfShards,
numberOfReplicas,
shardRoutingState
);
if (applyMixedModeSetting) {
ClusterState.Builder finalState = ClusterState.builder(initialState);
Metadata.Builder finalMetadata = Metadata.builder(initialState.metadata());
finalMetadata.persistentSettings(
Settings.builder()
.put(RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey(), "mixed")
.put(RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING.getKey(), "remote_store")
.build()
);
finalMetadata.transientSettings(
Settings.builder()
.put(RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey(), "mixed")
.put(RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING.getKey(), "remote_store")
.build()
);
return finalState.metadata(finalMetadata).build();
}
return initialState;
}

private static DiscoveryNode newNode(int nodeId) {
return new DiscoveryNode(
"node_" + nodeId,
Expand All @@ -544,14 +459,6 @@ private static DiscoveryNode newNode(int nodeId) {
);
}

private static DiscoveryNode newRemoteNode(int nodeId) {
return newRemoteNodeWithName(String.valueOf(nodeId));
}

private static DiscoveryNode newRemoteNodeWithName(String nodeId) {
return IndexShardTestUtils.getFakeRemoteEnabledNode("node_" + nodeId);
}

private static String selectAndRemove(Set<String> strings) {
String selection = randomFrom(strings.toArray(new String[0]));
strings.remove(selection);
Expand Down

0 comments on commit ca4b1d9

Please sign in to comment.