Skip to content

Commit

Permalink
Split changes
Browse files Browse the repository at this point in the history
Signed-off-by: Lakshya Taragi <[email protected]>
  • Loading branch information
ltaragi committed Apr 1, 2024
1 parent 5e3b82a commit 4c23b6b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,47 +139,6 @@ public void testDontAllocateNewReplicaShardOnRemoteNodeIfPrimaryShardOnNonRemote
assertNonAllocation(false);
}

public void testAllocateNewReplicaShardOnRemoteNodeIfPrimaryShardOnRemoteNodeForMixedModeAndRemoteStoreDirection() throws Exception {
logger.info(" --> initialize cluster");
initializeCluster(false);

logger.info(" --> set mixed cluster compatibility mode");
setClusterMode(MIXED.mode);

logger.info(" --> add remote and non-remote nodes");
addRemote = true;
String remoteNodeName1 = internalCluster().startNode();
String remoteNodeName2 = internalCluster().startNode();
addRemote = false;
String nonRemoteNodeName = internalCluster().startNode();
internalCluster().validateClusterFormed();
DiscoveryNode remoteNode1 = assertNodeInCluster(remoteNodeName1);
DiscoveryNode remoteNode2 = assertNodeInCluster(remoteNodeName2);
DiscoveryNode nonRemoteNode = assertNodeInCluster(nonRemoteNodeName);

logger.info(" --> allocate primary shard on remote node");
prepareIndexWithAllocatedPrimary(remoteNode1, Optional.empty());

logger.info(" --> set remote_store direction");
setDirection(REMOTE_STORE.direction);

logger.info(" --> verify expected decision for replica shard");
prepareDecisions();
Decision decision = getDecisionForTargetNode(remoteNode2, false, true, false);
assertEquals(Decision.Type.YES, decision.type());
assertEquals(
"[remote_store migration_direction]: replica shard copy can be allocated to a remote node since primary shard copy has been migrated to remote",
decision.getExplanation().toLowerCase(Locale.ROOT)
);

logger.info(" --> attempt allocation of replica shard the other remote node");
attemptAllocation(remoteNodeName2);
ensureGreen(TEST_INDEX);

logger.info(" --> verify allocation of replica shard");
assertAllocation(false, remoteNode2);
}

public void testAllocateNewReplicaShardOnNonRemoteNodeIfPrimaryShardOnNonRemoteNodeForMixedModeAndRemoteStoreDirection()
throws Exception {
logger.info(" --> initialize cluster");
Expand Down Expand Up @@ -220,47 +179,6 @@ public void testAllocateNewReplicaShardOnNonRemoteNodeIfPrimaryShardOnNonRemoteN
assertAllocation(false, nonRemoteNode2);
}

public void testAllocateNewReplicaShardOnNonRemoteNodeIfPrimaryShardOnRemoteNodeForMixedModeAndRemoteStoreDirection() throws Exception {
logger.info(" --> initialize cluster");
initializeCluster(false);

logger.info(" --> set mixed cluster compatibility mode");

logger.info(" --> add remote and non-remote nodes");
setClusterMode(MIXED.mode);
addRemote = false;
String nonRemoteNodeName = internalCluster().startNode();
addRemote = true;
String remoteNodeName = internalCluster().startNode();
internalCluster().validateClusterFormed();
DiscoveryNode nonRemoteNode = assertNodeInCluster(nonRemoteNodeName);
DiscoveryNode remoteNode = assertNodeInCluster(remoteNodeName);

logger.info(" --> allocate primary on remote node");
prepareIndexWithAllocatedPrimary(remoteNode, Optional.empty());

logger.info(" --> set remote_store direction");
setDirection(REMOTE_STORE.direction);

logger.info(" --> verify expected decision for replica shard");
prepareDecisions();
Decision decision = getDecisionForTargetNode(nonRemoteNode, false, true, false);

Decision.Type expectedType = Decision.Type.YES;
assertEquals(expectedType, decision.type());
assertEquals(
"[remote_store migration_direction]: replica shard copy can be allocated to a non-remote node",
decision.getExplanation().toLowerCase(Locale.ROOT)
);

logger.info(" --> allocate replica shard on non-remote node");
attemptAllocation(nonRemoteNodeName);
ensureGreen(TEST_INDEX);

logger.info(" --> verify allocation of replica shard");
assertAllocation(false, nonRemoteNode);
}

// test for STRICT mode

public void testAlwaysAllocateNewShardForStrictMode() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
import org.opensearch.client.Client;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.core.rest.RestStatus;
import org.opensearch.index.IndexSettings;
import org.opensearch.indices.replication.common.ReplicationType;
import org.opensearch.test.InternalTestCluster;
import org.opensearch.test.OpenSearchIntegTestCase;

import java.util.Optional;
Expand Down Expand Up @@ -78,37 +76,6 @@ public void testNewIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMixedMode()
assertRemoteStoreBackedIndex(indexName2);
}

// compatibility mode setting test

public void testSwitchToStrictMode() throws Exception {
logger.info(" --> initialize cluster");
initializeCluster(false);

logger.info(" --> create a mixed mode cluster");
setClusterMode(MIXED.mode);
addRemote = true;
String remoteNodeName = internalCluster().startNode();
addRemote = false;
String nonRemoteNodeName = internalCluster().startNode();
internalCluster().validateClusterFormed();
assertNodeInCluster(remoteNodeName);
assertNodeInCluster(nonRemoteNodeName);

logger.info(" --> attempt switching to strict mode");
SettingsException exception = assertThrows(SettingsException.class, () -> setClusterMode(STRICT.mode));
assertEquals(
"can not switch to STRICT compatibility mode when the cluster contains both remote and non-remote nodes",
exception.getMessage()
);

logger.info(" --> stop remote node");
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(remoteNodeName));
ensureStableCluster(2);

logger.info(" --> attempt switching to strict mode");
setClusterMode(STRICT.mode);
}

// verify that the created index is not remote store backed
private void assertNonRemoteStoreBackedIndex(String indexName) {
Settings indexSettings = client.admin().indices().prepareGetIndex().execute().actionGet().getSettings().get(indexName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,12 @@
import org.opensearch.common.Priority;
import org.opensearch.common.inject.Inject;
import org.opensearch.common.settings.ClusterSettings;
import org.opensearch.common.settings.SettingsException;
import org.opensearch.core.action.ActionListener;
import org.opensearch.core.common.io.stream.StreamInput;
import org.opensearch.node.remotestore.RemoteStoreNodeService;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.transport.TransportService;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
* Transport action for updating cluster settings
Expand Down Expand Up @@ -142,7 +137,6 @@ protected void clusterManagerOperation(
final ClusterState state,
final ActionListener<ClusterUpdateSettingsResponse> listener
) {
validateCompatibilityModeSettingRequest(request, state);
final SettingsUpdater updater = new SettingsUpdater(clusterSettings);
clusterService.submitStateUpdateTask(
"cluster_update_settings",
Expand Down Expand Up @@ -270,27 +264,4 @@ public ClusterState execute(final ClusterState currentState) {
);
}

/**
* Verifies that while trying to switch to STRICT compatibility mode, all nodes must be of the
* same type (all remote or all non-remote). If not, it throws SettingsException error
* @param request cluster settings update request, for settings to be updated and new values
* @param clusterState current state of cluster, for information on nodes
*/
private void validateCompatibilityModeSettingRequest(ClusterUpdateSettingsRequest request, ClusterState clusterState) {
if (RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING.exists(request.persistentSettings())) {
String value = request.persistentSettings().get(RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey());
if (value.equals(RemoteStoreNodeService.CompatibilityMode.STRICT.mode)) {
List<DiscoveryNode> discoveryNodeList = new ArrayList<>(clusterState.nodes().getNodes().values());
Optional<DiscoveryNode> remoteNode = discoveryNodeList.stream().filter(DiscoveryNode::isRemoteStoreNode).findFirst();
Optional<DiscoveryNode> nonRemoteNode = discoveryNodeList.stream()
.filter(dn -> dn.isRemoteStoreNode() == false)
.findFirst();
if (remoteNode.isPresent() && nonRemoteNode.isPresent()) {
throw new SettingsException(
"can not switch to STRICT compatibility mode when the cluster contains both remote and non-remote nodes"
);
}
}
}
}
}

0 comments on commit 4c23b6b

Please sign in to comment.