Skip to content

Commit

Permalink
Refactoring the code
Browse files Browse the repository at this point in the history
Signed-off-by: Shubh Sahu <[email protected]>
  • Loading branch information
Shubh Sahu committed Apr 4, 2024
1 parent 2789f8c commit da459ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}

Expand Down Expand Up @@ -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"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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")
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit da459ae

Please sign in to comment.