|
53 | 53 | import org.opensearch.common.Priority;
|
54 | 54 | import org.opensearch.common.inject.Inject;
|
55 | 55 | import org.opensearch.common.settings.ClusterSettings;
|
| 56 | +import org.opensearch.common.settings.SettingsException; |
56 | 57 | import org.opensearch.core.action.ActionListener;
|
57 | 58 | import org.opensearch.core.common.io.stream.StreamInput;
|
| 59 | +import org.opensearch.node.remotestore.RemoteStoreNodeService; |
58 | 60 | import org.opensearch.threadpool.ThreadPool;
|
59 | 61 | import org.opensearch.transport.TransportService;
|
60 | 62 |
|
61 | 63 | import java.io.IOException;
|
| 64 | +import java.util.ArrayList; |
| 65 | +import java.util.List; |
| 66 | +import java.util.Optional; |
62 | 67 |
|
63 | 68 | /**
|
64 | 69 | * Transport action for updating cluster settings
|
@@ -137,6 +142,7 @@ protected void clusterManagerOperation(
|
137 | 142 | final ClusterState state,
|
138 | 143 | final ActionListener<ClusterUpdateSettingsResponse> listener
|
139 | 144 | ) {
|
| 145 | + validateCompatibilityModeSettingRequest(request, state); |
140 | 146 | final SettingsUpdater updater = new SettingsUpdater(clusterSettings);
|
141 | 147 | clusterService.submitStateUpdateTask(
|
142 | 148 | "cluster_update_settings",
|
@@ -264,4 +270,27 @@ public ClusterState execute(final ClusterState currentState) {
|
264 | 270 | );
|
265 | 271 | }
|
266 | 272 |
|
| 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 | + } |
267 | 296 | }
|
0 commit comments