diff --git a/server/src/internalClusterTest/java/org/opensearch/remotemigration/ResizeIndexMigrationTestCase.java b/server/src/internalClusterTest/java/org/opensearch/remotemigration/ResizeIndexMigrationTestCase.java index fb64254ca8f85..d1122c1b2b109 100644 --- a/server/src/internalClusterTest/java/org/opensearch/remotemigration/ResizeIndexMigrationTestCase.java +++ b/server/src/internalClusterTest/java/org/opensearch/remotemigration/ResizeIndexMigrationTestCase.java @@ -115,12 +115,8 @@ public void testFailResizeIndexWhileDocRepToRemoteStoreMigration() throws Except ); assertEquals( ex.getMessage(), - "index Resizing for type [" - + resizeType - + "] is not allowed as Cluster mode is [Mixed]" - + " and migration direction is [REMOTE_STORE]" - + " and index's SETTING_REMOTE_STORE_ENABLED = " - + "false" + "Index " + resizeType +" is not allowed as remote migration mode is mixed" + + " and index is remote store disabled" ); } @@ -207,12 +203,8 @@ public void testFailResizeIndexWhileRemoteStoreToDocRepMigration() throws Except ); assertEquals( ex.getMessage(), - "index Resizing for type [" - + resizeType - + "] is not allowed as Cluster mode is [Mixed]" - + " and migration direction is [DOCREP]" - + " and index's SETTING_REMOTE_STORE_ENABLED = " - + "true" + "Index " + resizeType +" is not allowed as remote migration mode is mixed" + + " and index is remote store enabled" ); } } diff --git a/server/src/main/java/org/opensearch/action/admin/indices/shrink/TransportResizeAction.java b/server/src/main/java/org/opensearch/action/admin/indices/shrink/TransportResizeAction.java index 360bb2602efb0..47c4abb6624a8 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/shrink/TransportResizeAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/shrink/TransportResizeAction.java @@ -59,6 +59,8 @@ import org.opensearch.index.shard.DocsStats; import org.opensearch.index.store.StoreStats; import org.opensearch.node.remotestore.RemoteStoreNodeService; +import org.opensearch.node.remotestore.RemoteStoreNodeService.CompatibilityMode; +import org.opensearch.node.remotestore.RemoteStoreNodeService.Direction; import org.opensearch.threadpool.ThreadPool; import org.opensearch.transport.TransportService; @@ -235,7 +237,7 @@ static CreateIndexClusterStateUpdateRequest prepareCreateIndexRequest( if (metadata == null) { throw new IndexNotFoundException(sourceIndexName); } - validateClusterModeSettings(resizeRequest.getResizeType(), metadata, clusterSettings); + validateRemoteMigrationModeSettings(resizeRequest.getResizeType(), metadata, clusterSettings); final Settings.Builder targetIndexSettingsBuilder = Settings.builder() .put(targetIndex.settings()) .normalizePrefix(IndexMetadata.INDEX_SETTING_PREFIX); @@ -386,28 +388,22 @@ protected String getClusterManagerActionName(DiscoveryNode node) { * is false, then throw IllegalStateException. If migration direction is [DocRep] and * index's SETTING_REMOTE_STORE_ENABLED is true, then throw IllegalStateException. */ - private static void validateClusterModeSettings( + private static void validateRemoteMigrationModeSettings( final ResizeType type, IndexMetadata sourceIndexMetadata, ClusterSettings clusterSettings ) { - if (clusterSettings.get(RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING) - .equals(RemoteStoreNodeService.CompatibilityMode.MIXED)) { + CompatibilityMode compatibilityMode = clusterSettings.get(RemoteStoreNodeService.REMOTE_STORE_COMPATIBILITY_MODE_SETTING); + if (compatibilityMode == CompatibilityMode.MIXED) { boolean isRemoteStoreEnabled = sourceIndexMetadata.getSettings().getAsBoolean(SETTING_REMOTE_STORE_ENABLED, false); - if ((clusterSettings.get(RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING) - .equals(RemoteStoreNodeService.Direction.REMOTE_STORE) - && isRemoteStoreEnabled == false) - || (clusterSettings.get(RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING).equals(RemoteStoreNodeService.Direction.DOCREP) - && isRemoteStoreEnabled == true)) { + Direction migrationDirection = clusterSettings.get(RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING); + boolean invalidConfiguration = (migrationDirection == Direction.REMOTE_STORE && isRemoteStoreEnabled == false) + || (migrationDirection == Direction.DOCREP && isRemoteStoreEnabled); + if (invalidConfiguration) { throw new IllegalStateException( - "index Resizing for type [" - + type - + "] is not allowed as Cluster mode is [Mixed]" - + " and migration direction is [" - + clusterSettings.get(RemoteStoreNodeService.MIGRATION_DIRECTION_SETTING) - + "]" - + " and index's SETTING_REMOTE_STORE_ENABLED = " - + isRemoteStoreEnabled + "Index " + type +" is not allowed as remote migration mode is mixed" + + " and index is remote store " + + (isRemoteStoreEnabled ? "enabled" : "disabled") ); } } diff --git a/server/src/test/java/org/opensearch/action/admin/indices/shrink/TransportResizeActionTests.java b/server/src/test/java/org/opensearch/action/admin/indices/shrink/TransportResizeActionTests.java index 90ceace5c999a..8d4c0d7e7faf7 100644 --- a/server/src/test/java/org/opensearch/action/admin/indices/shrink/TransportResizeActionTests.java +++ b/server/src/test/java/org/opensearch/action/admin/indices/shrink/TransportResizeActionTests.java @@ -683,14 +683,9 @@ public void testResizeFailuresDuringMigration() { ); assertEquals( ise.getMessage(), - "index Resizing for type [" - + resizeType - + "] is not allowed as Cluster mode is [Mixed]" - + " and migration direction is [" - + migrationDirection - + "]" - + " and index's SETTING_REMOTE_STORE_ENABLED = " - + isRemoteStoreEnabled + "Index " + resizeType +" is not allowed as remote migration mode is mixed" + + " and index is remote store " + + (isRemoteStoreEnabled ? "enabled" : "disabled") ); } else { CreateIndexClusterStateUpdateRequest request = TransportResizeAction.prepareCreateIndexRequest(