Skip to content

Commit 8e55204

Browse files
committed
Split changes
Signed-off-by: Lakshya Taragi <lakshya.taragi@gmail.com>
1 parent 5e3b82a commit 8e55204

File tree

4 files changed

+132
-76
lines changed

4 files changed

+132
-76
lines changed

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

-14
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,6 @@ public void testAllocateNewReplicaShardOnRemoteNodeIfPrimaryShardOnRemoteNodeFor
171171
"[remote_store migration_direction]: replica shard copy can be allocated to a remote node since primary shard copy has been migrated to remote",
172172
decision.getExplanation().toLowerCase(Locale.ROOT)
173173
);
174-
175-
logger.info(" --> attempt allocation of replica shard the other remote node");
176-
attemptAllocation(remoteNodeName2);
177-
ensureGreen(TEST_INDEX);
178-
179-
logger.info(" --> verify allocation of replica shard");
180-
assertAllocation(false, remoteNode2);
181174
}
182175

183176
public void testAllocateNewReplicaShardOnNonRemoteNodeIfPrimaryShardOnNonRemoteNodeForMixedModeAndRemoteStoreDirection()
@@ -252,13 +245,6 @@ public void testAllocateNewReplicaShardOnNonRemoteNodeIfPrimaryShardOnRemoteNode
252245
"[remote_store migration_direction]: replica shard copy can be allocated to a non-remote node",
253246
decision.getExplanation().toLowerCase(Locale.ROOT)
254247
);
255-
256-
logger.info(" --> allocate replica shard on non-remote node");
257-
attemptAllocation(nonRemoteNodeName);
258-
ensureGreen(TEST_INDEX);
259-
260-
logger.info(" --> verify allocation of replica shard");
261-
assertAllocation(false, nonRemoteNode);
262248
}
263249

264250
// test for STRICT mode

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

-33
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@
1111
import org.opensearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
1212
import org.opensearch.client.Client;
1313
import org.opensearch.common.settings.Settings;
14-
import org.opensearch.common.settings.SettingsException;
1514
import org.opensearch.core.rest.RestStatus;
1615
import org.opensearch.index.IndexSettings;
1716
import org.opensearch.indices.replication.common.ReplicationType;
18-
import org.opensearch.test.InternalTestCluster;
1917
import org.opensearch.test.OpenSearchIntegTestCase;
2018

2119
import java.util.Optional;
@@ -78,37 +76,6 @@ public void testNewIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMixedMode()
7876
assertRemoteStoreBackedIndex(indexName2);
7977
}
8078

81-
// compatibility mode setting test
82-
83-
public void testSwitchToStrictMode() throws Exception {
84-
logger.info(" --> initialize cluster");
85-
initializeCluster(false);
86-
87-
logger.info(" --> create a mixed mode cluster");
88-
setClusterMode(MIXED.mode);
89-
addRemote = true;
90-
String remoteNodeName = internalCluster().startNode();
91-
addRemote = false;
92-
String nonRemoteNodeName = internalCluster().startNode();
93-
internalCluster().validateClusterFormed();
94-
assertNodeInCluster(remoteNodeName);
95-
assertNodeInCluster(nonRemoteNodeName);
96-
97-
logger.info(" --> attempt switching to strict mode");
98-
SettingsException exception = assertThrows(SettingsException.class, () -> setClusterMode(STRICT.mode));
99-
assertEquals(
100-
"can not switch to STRICT compatibility mode when the cluster contains both remote and non-remote nodes",
101-
exception.getMessage()
102-
);
103-
104-
logger.info(" --> stop remote node");
105-
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(remoteNodeName));
106-
ensureStableCluster(2);
107-
108-
logger.info(" --> attempt switching to strict mode");
109-
setClusterMode(STRICT.mode);
110-
}
111-
11279
// verify that the created index is not remote store backed
11380
private void assertNonRemoteStoreBackedIndex(String indexName) {
11481
Settings indexSettings = client.admin().indices().prepareGetIndex().execute().actionGet().getSettings().get(indexName);

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

-29
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,12 @@
5353
import org.opensearch.common.Priority;
5454
import org.opensearch.common.inject.Inject;
5555
import org.opensearch.common.settings.ClusterSettings;
56-
import org.opensearch.common.settings.SettingsException;
5756
import org.opensearch.core.action.ActionListener;
5857
import org.opensearch.core.common.io.stream.StreamInput;
59-
import org.opensearch.node.remotestore.RemoteStoreNodeService;
6058
import org.opensearch.threadpool.ThreadPool;
6159
import org.opensearch.transport.TransportService;
6260

6361
import java.io.IOException;
64-
import java.util.ArrayList;
65-
import java.util.List;
66-
import java.util.Optional;
6762

6863
/**
6964
* Transport action for updating cluster settings
@@ -142,7 +137,6 @@ protected void clusterManagerOperation(
142137
final ClusterState state,
143138
final ActionListener<ClusterUpdateSettingsResponse> listener
144139
) {
145-
validateCompatibilityModeSettingRequest(request, state);
146140
final SettingsUpdater updater = new SettingsUpdater(clusterSettings);
147141
clusterService.submitStateUpdateTask(
148142
"cluster_update_settings",
@@ -270,27 +264,4 @@ public ClusterState execute(final ClusterState currentState) {
270264
);
271265
}
272266

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) {
280-
if (RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING.exists(request.persistentSettings())) {
281-
String value = request.persistentSettings().get(RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey());
282-
if (value.equals(RemoteStoreNodeService.CompatibilityMode.STRICT.mode)) {
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()) {
289-
throw new SettingsException(
290-
"can not switch to STRICT compatibility mode when the cluster contains both remote and non-remote nodes"
291-
);
292-
}
293-
}
294-
}
295-
}
296267
}

server/src/test/java/org/opensearch/cluster/metadata/MetadataCreateIndexServiceTests.java

+132
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@
5555
import org.opensearch.cluster.routing.allocation.decider.AwarenessAllocationDecider;
5656
import org.opensearch.cluster.routing.allocation.decider.MaxRetryAllocationDecider;
5757
import org.opensearch.cluster.service.ClusterService;
58+
import org.opensearch.common.UUIDs;
5859
import org.opensearch.common.compress.CompressedXContent;
5960
import org.opensearch.common.settings.ClusterSettings;
6061
import org.opensearch.common.settings.IndexScopedSettings;
6162
import org.opensearch.common.settings.Setting;
6263
import org.opensearch.common.settings.Settings;
6364
import org.opensearch.common.unit.TimeValue;
6465
import org.opensearch.common.util.BigArrays;
66+
import org.opensearch.common.util.FeatureFlags;
6567
import org.opensearch.common.xcontent.XContentFactory;
6668
import org.opensearch.core.index.Index;
6769
import org.opensearch.core.xcontent.NamedXContentRegistry;
@@ -81,6 +83,7 @@
8183
import org.opensearch.indices.SystemIndexDescriptor;
8284
import org.opensearch.indices.SystemIndices;
8385
import org.opensearch.indices.replication.common.ReplicationType;
86+
import org.opensearch.node.remotestore.RemoteStoreNodeService;
8487
import org.opensearch.snapshots.EmptySnapshotsInfoService;
8588
import org.opensearch.test.ClusterServiceUtils;
8689
import org.opensearch.test.OpenSearchTestCase;
@@ -135,6 +138,7 @@
135138
import static org.opensearch.cluster.metadata.MetadataCreateIndexService.getIndexNumberOfRoutingShards;
136139
import static org.opensearch.cluster.metadata.MetadataCreateIndexService.parseV1Mappings;
137140
import static org.opensearch.cluster.metadata.MetadataCreateIndexService.resolveAndValidateAliases;
141+
import static org.opensearch.common.util.FeatureFlags.REMOTE_STORE_MIGRATION_EXPERIMENTAL;
138142
import static org.opensearch.index.IndexModule.INDEX_STORE_TYPE_SETTING;
139143
import static org.opensearch.index.IndexSettings.INDEX_REFRESH_INTERVAL_SETTING;
140144
import static org.opensearch.index.IndexSettings.INDEX_REMOTE_TRANSLOG_BUFFER_INTERVAL_SETTING;
@@ -149,6 +153,8 @@
149153
import static org.opensearch.node.Node.NODE_ATTRIBUTES;
150154
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY;
151155
import static org.opensearch.node.remotestore.RemoteStoreNodeAttribute.REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY;
156+
import static org.opensearch.node.remotestore.RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING;
157+
import static org.opensearch.node.remotestore.RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING;
152158
import static org.hamcrest.Matchers.containsString;
153159
import static org.hamcrest.Matchers.endsWith;
154160
import static org.hamcrest.Matchers.equalTo;
@@ -1550,6 +1556,132 @@ public void testRemoteStoreOverrideTranslogRepoIndexSettings() {
15501556
}));
15511557
}
15521558

1559+
public void testNewIndexIsRemoteStoreBackedForRemoteStoreDirectionAndMixedMode() {
1560+
FeatureFlags.initializeFeatureFlags(Settings.builder().put(REMOTE_STORE_MIGRATION_EXPERIMENTAL, "true").build());
1561+
1562+
// non-remote cluster manager node
1563+
DiscoveryNode nonRemoteClusterManagerNode = new DiscoveryNode(
1564+
UUIDs.base64UUID(),
1565+
buildNewFakeTransportAddress(),
1566+
emptyMap(),
1567+
singleton(DiscoveryNodeRole.CLUSTER_MANAGER_ROLE),
1568+
Version.CURRENT
1569+
);
1570+
1571+
DiscoveryNodes discoveryNodes = DiscoveryNodes.builder()
1572+
.add(nonRemoteClusterManagerNode)
1573+
.localNodeId(nonRemoteClusterManagerNode.getId())
1574+
.build();
1575+
1576+
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).nodes(discoveryNodes).build();
1577+
1578+
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
1579+
1580+
request = new CreateIndexClusterStateUpdateRequest("create index", "test", "test");
1581+
1582+
Settings indexSettings = aggregateIndexSettings(
1583+
clusterState,
1584+
request,
1585+
Settings.EMPTY,
1586+
null,
1587+
Settings.EMPTY,
1588+
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
1589+
randomShardLimitService(),
1590+
Collections.emptySet(),
1591+
clusterSettings
1592+
);
1593+
1594+
verifyRemoteStoreIndexSettings(
1595+
indexSettings,
1596+
null,
1597+
null,
1598+
null,
1599+
ReplicationType.DOCUMENT.toString(),
1600+
IndexSettings.DEFAULT_REMOTE_TRANSLOG_BUFFER_INTERVAL
1601+
);
1602+
1603+
// remote data node
1604+
Map<String, String> attributes = new HashMap<>();
1605+
attributes.put(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-segment-repo-1");
1606+
attributes.put(REMOTE_STORE_TRANSLOG_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-translog-repo-1");
1607+
DiscoveryNode remoteDataNode = new DiscoveryNode(
1608+
UUIDs.base64UUID(),
1609+
buildNewFakeTransportAddress(),
1610+
attributes,
1611+
Set.of(DiscoveryNodeRole.INGEST_ROLE, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE, DiscoveryNodeRole.DATA_ROLE),
1612+
Version.CURRENT
1613+
);
1614+
1615+
discoveryNodes = DiscoveryNodes.builder(discoveryNodes).add(remoteDataNode).localNodeId(remoteDataNode.getId()).build();
1616+
1617+
clusterState = ClusterState.builder(ClusterName.DEFAULT).nodes(discoveryNodes).build();
1618+
1619+
Settings remoteStoreMigrationSettings = Settings.builder()
1620+
.put(REMOTE_STORE_COMPATIBILITY_MODE_SETTING.getKey(), RemoteStoreNodeService.CompatibilityMode.MIXED)
1621+
.put(MIGRATION_DIRECTION_SETTING.getKey(), RemoteStoreNodeService.Direction.REMOTE_STORE)
1622+
.build();
1623+
1624+
clusterSettings = new ClusterSettings(remoteStoreMigrationSettings, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
1625+
1626+
indexSettings = aggregateIndexSettings(
1627+
clusterState,
1628+
request,
1629+
Settings.EMPTY,
1630+
null,
1631+
Settings.EMPTY,
1632+
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
1633+
randomShardLimitService(),
1634+
Collections.emptySet(),
1635+
clusterSettings
1636+
);
1637+
1638+
verifyRemoteStoreIndexSettings(
1639+
indexSettings,
1640+
"true",
1641+
"my-segment-repo-1",
1642+
"my-translog-repo-1",
1643+
ReplicationType.SEGMENT.toString(),
1644+
IndexSettings.DEFAULT_REMOTE_TRANSLOG_BUFFER_INTERVAL
1645+
);
1646+
1647+
Map<String, String> missingTranslogAttribute = Map.of(REMOTE_STORE_SEGMENT_REPOSITORY_NAME_ATTRIBUTE_KEY, "my-segment-repo-1");
1648+
1649+
DiscoveryNodes finalDiscoveryNodes = DiscoveryNodes.builder()
1650+
.add(nonRemoteClusterManagerNode)
1651+
.add(
1652+
new DiscoveryNode(
1653+
UUIDs.base64UUID(),
1654+
buildNewFakeTransportAddress(),
1655+
missingTranslogAttribute,
1656+
Set.of(DiscoveryNodeRole.INGEST_ROLE, DiscoveryNodeRole.REMOTE_CLUSTER_CLIENT_ROLE, DiscoveryNodeRole.DATA_ROLE),
1657+
Version.CURRENT
1658+
)
1659+
)
1660+
.build();
1661+
1662+
ClusterState finalClusterState = ClusterState.builder(ClusterName.DEFAULT).nodes(finalDiscoveryNodes).build();
1663+
ClusterSettings finalClusterSettings = clusterSettings;
1664+
1665+
final IndexCreationException error = expectThrows(IndexCreationException.class, () -> {
1666+
aggregateIndexSettings(
1667+
finalClusterState,
1668+
request,
1669+
Settings.EMPTY,
1670+
null,
1671+
Settings.EMPTY,
1672+
IndexScopedSettings.DEFAULT_SCOPED_SETTINGS,
1673+
randomShardLimitService(),
1674+
Collections.emptySet(),
1675+
finalClusterSettings
1676+
);
1677+
});
1678+
1679+
assertThat(
1680+
error.getCause().getMessage(),
1681+
containsString("Cluster is migrating to remote store but no remote node found, failing index creation")
1682+
);
1683+
}
1684+
15531685
public void testBuildIndexMetadata() {
15541686
IndexMetadata sourceIndexMetadata = IndexMetadata.builder("parent")
15551687
.settings(Settings.builder().put("index.version.created", Version.CURRENT).build())

0 commit comments

Comments
 (0)