Skip to content

Commit 5e3b82a

Browse files
committed
Address comments
Signed-off-by: Lakshya Taragi <lakshya.taragi@gmail.com>
1 parent 33c3cd2 commit 5e3b82a

File tree

7 files changed

+107
-264
lines changed

7 files changed

+107
-264
lines changed

server/src/internalClusterTest/java/org/opensearch/remotemigration/RemoteStoreMigrationAllocationIT.java

+18-48
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class RemoteStoreMigrationAllocationIT extends MigrationBaseTestCase {
5050

5151
// tests for primary shard copy allocation with MIXED mode and REMOTE_STORE direction
5252

53-
public void testDontAllocateNewPrimaryShardOnNonRemoteNodeForMixedModeAndRemoteStoreDirection() throws Exception {
53+
public void testAllocateNewPrimaryShardForMixedModeAndRemoteStoreDirection() throws Exception {
5454
logger.info(" --> initialize cluster");
5555
initializeCluster(false);
5656

@@ -71,59 +71,29 @@ public void testDontAllocateNewPrimaryShardOnNonRemoteNodeForMixedModeAndRemoteS
7171
setDirection(REMOTE_STORE.direction);
7272

7373
Decision decision = getDecisionForTargetNode(nonRemoteNode, true, true, false);
74-
Decision.Type type = Decision.Type.NO;
75-
assertEquals(type, decision.type());
74+
assertEquals(Decision.Type.NO, decision.type());
7675
assertEquals(
7776
"[remote_store migration_direction]: primary shard copy can not be allocated to a non-remote node",
7877
decision.getExplanation().toLowerCase(Locale.ROOT)
7978
);
8079

81-
logger.info(" --> attempt allocation");
80+
logger.info(" --> attempt allocation on non-remote node");
8281
attemptAllocation(nonRemoteNodeName);
8382

84-
logger.info(" --> verify non-allocation of primary shard");
83+
logger.info(" --> verify non-allocation of primary shard on non-remote node");
8584
assertNonAllocation(true);
86-
}
87-
88-
public void testAllocateNewPrimaryShardOnRemoteNodeForMixedModeAndRemoteStoreDirection() throws Exception {
89-
logger.info(" --> initialize cluster");
90-
initializeCluster(false);
91-
92-
logger.info(" --> add remote and non-remote nodes");
93-
setClusterMode(MIXED.mode);
94-
addRemote = true;
95-
String remoteNodeName = internalCluster().startNode();
96-
addRemote = false;
97-
String nonRemoteNodeName = internalCluster().startNode();
98-
internalCluster().validateClusterFormed();
99-
DiscoveryNode remoteNode = assertNodeInCluster(remoteNodeName);
100-
DiscoveryNode nonRemoteNode = assertNodeInCluster(nonRemoteNodeName);
10185

10286
logger.info(" --> verify expected decision for allocating a new primary shard on a remote node");
103-
prepareIndexWithoutReplica(Optional.empty());
104-
105-
logger.info(" --> set remote_store direction");
106-
setDirection(REMOTE_STORE.direction);
107-
108-
Decision decision = getDecisionForTargetNode(remoteNode, true, true, false);
87+
prepareDecisions();
88+
decision = getDecisionForTargetNode(remoteNode, true, true, false);
10989
assertEquals(Decision.Type.YES, decision.type());
11090
assertEquals(
11191
"[remote_store migration_direction]: primary shard copy can be allocated to a remote node",
11292
decision.getExplanation().toLowerCase(Locale.ROOT)
11393
);
11494

115-
logger.info(" --> attempt allocation");
116-
client.admin()
117-
.indices()
118-
.prepareUpdateSettings(TEST_INDEX)
119-
.setSettings(
120-
Settings.builder()
121-
.put("index.routing.allocation.include._name", allNodesExcept(null))
122-
.put("index.routing.allocation.exclude._name", "")
123-
)
124-
.execute()
125-
.actionGet();
126-
95+
logger.info(" --> attempt allocation on remote node");
96+
attemptAllocation(remoteNodeName);
12797
ensureGreen(TEST_INDEX);
12898

12999
logger.info(" --> verify allocation of primary shard");
@@ -236,11 +206,11 @@ public void testAllocateNewReplicaShardOnNonRemoteNodeIfPrimaryShardOnNonRemoteN
236206
logger.info(" --> verify expected decision for replica shard");
237207
prepareDecisions();
238208
Decision decision = getDecisionForTargetNode(nonRemoteNode2, false, true, false);
239-
Decision.Type type = Decision.Type.YES;
240-
String reason = "[remote_store migration_direction]: replica shard copy can be allocated to a non-remote node";
209+
Decision.Type expectedType = Decision.Type.YES;
210+
String expectedReason = "[remote_store migration_direction]: replica shard copy can be allocated to a non-remote node";
241211

242-
assertEquals(type, decision.type());
243-
assertEquals(reason, decision.getExplanation().toLowerCase(Locale.ROOT));
212+
assertEquals(expectedType, decision.type());
213+
assertEquals(expectedReason, decision.getExplanation().toLowerCase(Locale.ROOT));
244214

245215
logger.info(" --> allocate replica shard on the other non-remote node");
246216
attemptAllocation(nonRemoteNodeName2);
@@ -276,8 +246,8 @@ public void testAllocateNewReplicaShardOnNonRemoteNodeIfPrimaryShardOnRemoteNode
276246
prepareDecisions();
277247
Decision decision = getDecisionForTargetNode(nonRemoteNode, false, true, false);
278248

279-
Decision.Type type = Decision.Type.YES;
280-
assertEquals(type, decision.type());
249+
Decision.Type expectedType = Decision.Type.YES;
250+
assertEquals(expectedType, decision.type());
281251
assertEquals(
282252
"[remote_store migration_direction]: replica shard copy can be allocated to a non-remote node",
283253
decision.getExplanation().toLowerCase(Locale.ROOT)
@@ -352,13 +322,13 @@ public void testAlwaysAllocateNewShardForStrictMode() throws Exception {
352322
prepareDecisions();
353323
Decision decision = getDecisionForTargetNode(targetNode, !isReplicaAllocation, true, false);
354324
assertEquals(Decision.Type.YES, decision.type());
355-
String reason = String.format(
325+
String expectedReason = String.format(
356326
Locale.ROOT,
357327
"[remote_store migration_direction]: %s shard copy can be allocated to a %s node for strict compatibility mode",
358328
(isReplicaAllocation ? "replica" : "primary"),
359329
(isRemoteCluster ? "remote" : "non-remote")
360330
);
361-
assertEquals(reason, decision.getExplanation().toLowerCase(Locale.ROOT));
331+
assertEquals(expectedReason, decision.getExplanation().toLowerCase(Locale.ROOT));
362332

363333
logger.info(" --> attempt allocation");
364334
attemptAllocation(targetNode.getName());
@@ -410,12 +380,12 @@ public void testDontAllocateToNonRemoteNodeForRemoteStoreBackedIndex() throws Ex
410380
prepareDecisions();
411381
Decision decision = getDecisionForTargetNode(nonRemoteNode, !isReplicaAllocation, false, false);
412382
assertEquals(Decision.Type.NO, decision.type());
413-
String reason = String.format(
383+
String expectedReason = String.format(
414384
Locale.ROOT,
415385
"[remote_store migration_direction]: %s shard copy can not be allocated to a non-remote node because a remote store backed index's shard copy can only be allocated to a remote node",
416386
(isReplicaAllocation ? "replica" : "primary")
417387
);
418-
assertEquals(reason, decision.getExplanation().toLowerCase(Locale.ROOT));
388+
assertEquals(expectedReason, decision.getExplanation().toLowerCase(Locale.ROOT));
419389

420390
logger.info(" --> attempt allocation of shard on non-remote node");
421391
attemptAllocation(nonRemoteNodeName);

server/src/internalClusterTest/java/org/opensearch/remotemigration/RemoteStoreMigrationSettingsUpdateIT.java

+4-75
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@
1010

1111
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
1212
import org.opensearch.client.Client;
13-
import org.opensearch.cluster.metadata.IndexMetadata;
1413
import org.opensearch.common.settings.Settings;
1514
import org.opensearch.common.settings.SettingsException;
1615
import org.opensearch.core.rest.RestStatus;
1716
import org.opensearch.index.IndexSettings;
1817
import org.opensearch.indices.replication.common.ReplicationType;
19-
import org.opensearch.snapshots.SnapshotInfo;
20-
import org.opensearch.snapshots.SnapshotState;
2118
import org.opensearch.test.InternalTestCluster;
2219
import org.opensearch.test.OpenSearchIntegTestCase;
2320

24-
import java.nio.file.Path;
2521
import java.util.Optional;
2622

2723
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_REMOTE_SEGMENT_STORE_REPOSITORY;
@@ -38,7 +34,6 @@
3834
import static org.opensearch.remotemigration.RemoteStoreMigrationAllocationIT.prepareIndexWithoutReplica;
3935
import static org.opensearch.remotemigration.RemoteStoreMigrationAllocationIT.setClusterMode;
4036
import static org.opensearch.remotemigration.RemoteStoreMigrationAllocationIT.setDirection;
41-
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
4237

4338
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false)
4439
public class RemoteStoreMigrationSettingsUpdateIT extends MigrationBaseTestCase {
@@ -56,9 +51,9 @@ public void testNewIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMixedMode()
5651

5752
logger.info(" --> add non-remote node");
5853
addRemote = false;
59-
String remoteNodeName = internalCluster().startNode();
54+
String nonRemoteNodeName = internalCluster().startNode();
6055
internalCluster().validateClusterFormed();
61-
assertNodeInCluster(remoteNodeName);
56+
assertNodeInCluster(nonRemoteNodeName);
6257

6358
logger.info(" --> create an index");
6459
prepareIndexWithoutReplica(Optional.of(indexName1));
@@ -72,9 +67,9 @@ public void testNewIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMixedMode()
7267

7368
logger.info(" --> add remote node");
7469
addRemote = true;
75-
String nonRemoteNodeName = internalCluster().startNode();
70+
String remoteNodeName = internalCluster().startNode();
7671
internalCluster().validateClusterFormed();
77-
assertNodeInCluster(nonRemoteNodeName);
72+
assertNodeInCluster(remoteNodeName);
7873

7974
logger.info(" --> create another index");
8075
prepareIndexWithoutReplica(Optional.of(indexName2));
@@ -83,72 +78,6 @@ public void testNewIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMixedMode()
8378
assertRemoteStoreBackedIndex(indexName2);
8479
}
8580

86-
public void testNewRestoredIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMixedMode() throws Exception {
87-
logger.info(" --> initialize cluster: gives non remote cluster manager");
88-
initializeCluster(false);
89-
90-
logger.info(" --> add remote and non-remote nodes");
91-
setClusterMode(MIXED.mode);
92-
addRemote = false;
93-
String nonRemoteNodeName = internalCluster().startNode();
94-
addRemote = true;
95-
String remoteNodeName = internalCluster().startNode();
96-
internalCluster().validateClusterFormed();
97-
assertNodeInCluster(nonRemoteNodeName);
98-
assertNodeInCluster(remoteNodeName);
99-
100-
logger.info(" --> create a non remote-backed index");
101-
client.admin()
102-
.indices()
103-
.prepareCreate(TEST_INDEX)
104-
.setSettings(
105-
Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build()
106-
)
107-
.get();
108-
109-
logger.info(" --> verify that non remote stored backed index is created");
110-
assertNonRemoteStoreBackedIndex(TEST_INDEX);
111-
112-
logger.info(" --> create repository");
113-
String snapshotName = "test-snapshot";
114-
String snapshotRepoName = "test-restore-snapshot-repo";
115-
Path snapshotRepoNameAbsolutePath = randomRepoPath().toAbsolutePath();
116-
assertAcked(
117-
clusterAdmin().preparePutRepository(snapshotRepoName)
118-
.setType("fs")
119-
.setSettings(Settings.builder().put("location", snapshotRepoNameAbsolutePath))
120-
);
121-
122-
logger.info(" --> create snapshot of non remote stored backed index");
123-
124-
SnapshotInfo snapshotInfo = client().admin()
125-
.cluster()
126-
.prepareCreateSnapshot(snapshotRepoName, snapshotName)
127-
.setIndices(TEST_INDEX)
128-
.setWaitForCompletion(true)
129-
.get()
130-
.getSnapshotInfo();
131-
132-
assertEquals(SnapshotState.SUCCESS, snapshotInfo.state());
133-
assertTrue(snapshotInfo.successfulShards() > 0);
134-
assertEquals(0, snapshotInfo.failedShards());
135-
136-
logger.info(" --> restore index from snapshot under NONE direction");
137-
String restoredIndexName1 = TEST_INDEX + "-restored1";
138-
restoreSnapshot(snapshotRepoName, snapshotName, restoredIndexName1);
139-
140-
logger.info(" --> verify that restored index is non remote-backed");
141-
assertNonRemoteStoreBackedIndex(restoredIndexName1);
142-
143-
logger.info(" --> restore index from snapshot under REMOTE_STORE direction");
144-
setDirection(REMOTE_STORE.direction);
145-
String restoredIndexName2 = TEST_INDEX + "-restored2";
146-
restoreSnapshot(snapshotRepoName, snapshotName, restoredIndexName2);
147-
148-
logger.info(" --> verify that restored index is non remote-backed");
149-
assertRemoteStoreBackedIndex(restoredIndexName2);
150-
}
151-
15281
// compatibility mode setting test
15382

15483
public void testSwitchToStrictMode() throws Exception {

server/src/main/java/org/opensearch/action/admin/cluster/settings/TransportClusterUpdateSettingsAction.java

+16-13
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161
import org.opensearch.transport.TransportService;
6262

6363
import java.io.IOException;
64-
import java.util.Map;
64+
import java.util.ArrayList;
65+
import java.util.List;
66+
import java.util.Optional;
6567

6668
/**
6769
* Transport action for updating cluster settings
@@ -268,21 +270,22 @@ public ClusterState execute(final ClusterState currentState) {
268270
);
269271
}
270272

271-
private void validateCompatibilityModeSettingRequest(ClusterUpdateSettingsRequest request, ClusterState state) {
273+
/**
274+
* Verifies that while trying to switch to STRICT compatibility mode, all nodes must be of the
275+
* same type (all remote or all non-remote). If not, it throws SettingsException error
276+
* @param request cluster settings update request, for settings to be updated and new values
277+
* @param clusterState current state of cluster, for information on nodes
278+
*/
279+
private void validateCompatibilityModeSettingRequest(ClusterUpdateSettingsRequest request, ClusterState clusterState) {
272280
if (RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING.exists(request.persistentSettings())) {
273281
String value = request.persistentSettings().get(RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey());
274282
if (value.equals(RemoteStoreNodeService.CompatibilityMode.STRICT.mode)) {
275-
boolean hasRemoteNode = false, hasNonRemoteNode = false;
276-
Map<String, DiscoveryNode> nodes = state.nodes().getNodes();
277-
for (Map.Entry<String, DiscoveryNode> entry : nodes.entrySet()) {
278-
DiscoveryNode node = entry.getValue();
279-
if (node.isRemoteStoreNode()) {
280-
hasRemoteNode = true;
281-
continue;
282-
}
283-
hasNonRemoteNode = true;
284-
}
285-
if (hasRemoteNode && hasNonRemoteNode) {
283+
List<DiscoveryNode> discoveryNodeList = new ArrayList<>(clusterState.nodes().getNodes().values());
284+
Optional<DiscoveryNode> remoteNode = discoveryNodeList.stream().filter(DiscoveryNode::isRemoteStoreNode).findFirst();
285+
Optional<DiscoveryNode> nonRemoteNode = discoveryNodeList.stream()
286+
.filter(dn -> dn.isRemoteStoreNode() == false)
287+
.findFirst();
288+
if (remoteNode.isPresent() && nonRemoteNode.isPresent()) {
286289
throw new SettingsException(
287290
"can not switch to STRICT compatibility mode when the cluster contains both remote and non-remote nodes"
288291
);

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

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ public Iterator<Setting<?>> settings() {
319319
Property.Final
320320
);
321321

322+
public static final String SETTING_REMOTE_STORE_PREFIX = "index.remote_store.";
323+
322324
public static final String SETTING_REMOTE_STORE_ENABLED = "index.remote_store.enabled";
323325

324326
public static final String SETTING_REMOTE_SEGMENT_STORE_REPOSITORY = "index.remote_store.segment.repository";

0 commit comments

Comments
 (0)