From 3dfc2281c6c5eb9363c72500ff493ea1789705d9 Mon Sep 17 00:00:00 2001 From: Arpit Bandejiya Date: Mon, 31 Oct 2022 22:26:16 +0530 Subject: [PATCH] fix lint errors Signed-off-by: Arpit Bandejiya --- .../admin/indices/rollover/RolloverIT.java | 50 +++++++++++-------- .../settings/UpdateNumberOfReplicasIT.java | 7 +-- .../snapshots/RestoreSnapshotIT.java | 14 +++--- .../cluster/metadata/AutoExpandReplicas.java | 2 + .../allocation/AwarenessReplicaBalance.java | 3 +- .../AwarenessReplicaBalanceTests.java | 11 ++-- 6 files changed, 48 insertions(+), 39 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/rollover/RolloverIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/rollover/RolloverIT.java index 770e81fee9dab..53870ffb12541 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/rollover/RolloverIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/rollover/RolloverIT.java @@ -237,14 +237,12 @@ public void testRolloverWithIndexSettingsBalancedReplica() throws Exception { containsString("expected total copies needs to be a multiple of total awareness attributes [2]") ); - client().admin() .indices() .prepareRolloverIndex("test_alias") - .settings(Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1) - .build()) + .settings( + Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 1).build() + ) .alias(new Alias("extra_alias")) .waitForActiveShards(0) .get(); @@ -252,11 +250,13 @@ public void testRolloverWithIndexSettingsBalancedReplica() throws Exception { client().admin() .indices() .prepareRolloverIndex("test_alias") - .settings(Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) - .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1") - .build()) + .settings( + Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) + .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1") + .build() + ) .alias(new Alias("extra_alias")) .waitForActiveShards(0) .get(); @@ -264,23 +264,31 @@ public void testRolloverWithIndexSettingsBalancedReplica() throws Exception { client().admin() .indices() .prepareRolloverIndex("test_alias") - .settings(Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) - .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-all") - .build()) + .settings( + Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) + .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-all") + .build() + ) .alias(new Alias("extra_alias")) .waitForActiveShards(0) .get(); - final IllegalArgumentException restoreError2 = expectThrows( IllegalArgumentException.class, - () -> client().admin().indices().prepareRolloverIndex("test_alias").settings(Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) - .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-0") - .build()).alias(new Alias("extra_alias")).get() + () -> client().admin() + .indices() + .prepareRolloverIndex("test_alias") + .settings( + Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) + .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-0") + .build() + ) + .alias(new Alias("extra_alias")) + .get() ); assertThat( diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/settings/UpdateNumberOfReplicasIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/settings/UpdateNumberOfReplicasIT.java index a3faed725d37f..9eb86b7d8df96 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/settings/UpdateNumberOfReplicasIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/settings/UpdateNumberOfReplicasIT.java @@ -626,9 +626,10 @@ public void testAwarenessReplicaBalance() { client().admin() .indices() .prepareUpdateSettings("aware-replica") - .setSettings(Settings.builder() - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) - .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1") + .setSettings( + Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2) + .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1") ) .execute() .actionGet(); diff --git a/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java b/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java index 841f34088ace2..49e89c7155942 100644 --- a/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/snapshots/RestoreSnapshotIT.java @@ -1004,10 +1004,9 @@ public void testRestoreBalancedReplica() { () -> clusterAdmin().prepareRestoreSnapshot("test-repo", "snapshot-0") .setRenamePattern("test-index") .setRenameReplacement("new-index") - .setIndexSettings(Settings.builder() - .put(SETTING_NUMBER_OF_REPLICAS, 1) - .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-2") - .build()) + .setIndexSettings( + Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, 1).put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-2").build() + ) .setIndices("test-index") .get() ); @@ -1038,10 +1037,9 @@ public void testRestoreBalancedReplica() { restoreSnapshotResponse = clusterAdmin().prepareRestoreSnapshot("test-repo", "snapshot-0") .setRenamePattern("test-index") .setRenameReplacement("new-index") - .setIndexSettings(Settings.builder() - .put(SETTING_NUMBER_OF_REPLICAS, 0) - .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1") - .build()) + .setIndexSettings( + Settings.builder().put(SETTING_NUMBER_OF_REPLICAS, 0).put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1").build() + ) .setWaitForCompletion(true) .setIndices("test-index") .execute() diff --git a/server/src/main/java/org/opensearch/cluster/metadata/AutoExpandReplicas.java b/server/src/main/java/org/opensearch/cluster/metadata/AutoExpandReplicas.java index 8b83e06284e1f..7c62ed87adec8 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/AutoExpandReplicas.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/AutoExpandReplicas.java @@ -137,9 +137,11 @@ int getMaxReplicas(int numDataNodes) { public int getMaxReplicas() { return maxReplicas; } + public boolean isEnabled() { return enabled; } + private OptionalInt getDesiredNumberOfReplicas(IndexMetadata indexMetadata, RoutingAllocation allocation) { if (enabled) { int numMatchingDataNodes = 0; diff --git a/server/src/main/java/org/opensearch/cluster/routing/allocation/AwarenessReplicaBalance.java b/server/src/main/java/org/opensearch/cluster/routing/allocation/AwarenessReplicaBalance.java index 9ea2db3134012..19601483d5607 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/allocation/AwarenessReplicaBalance.java +++ b/server/src/main/java/org/opensearch/cluster/routing/allocation/AwarenessReplicaBalance.java @@ -104,7 +104,8 @@ public int maxAwarenessAttributes() { public Optional validate(int replicaCount, AutoExpandReplicas autoExpandReplica) { if (autoExpandReplica.isEnabled()) { - if ((autoExpandReplica.getMaxReplicas() != Integer.MAX_VALUE) && ((autoExpandReplica.getMaxReplicas() + 1) % maxAwarenessAttributes() != 0)) { + if ((autoExpandReplica.getMaxReplicas() != Integer.MAX_VALUE) + && ((autoExpandReplica.getMaxReplicas() + 1) % maxAwarenessAttributes() != 0)) { String errorMessage = "expected max cap on auto expand to be a multiple of total awareness attributes [" + maxAwarenessAttributes() + "]"; diff --git a/server/src/test/java/org/opensearch/cluster/routing/allocation/AwarenessReplicaBalanceTests.java b/server/src/test/java/org/opensearch/cluster/routing/allocation/AwarenessReplicaBalanceTests.java index 2ea0ec0a653d3..f7b1b8694f91a 100644 --- a/server/src/test/java/org/opensearch/cluster/routing/allocation/AwarenessReplicaBalanceTests.java +++ b/server/src/test/java/org/opensearch/cluster/routing/allocation/AwarenessReplicaBalanceTests.java @@ -18,7 +18,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS; -import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS; public class AwarenessReplicaBalanceTests extends OpenSearchAllocationTestCase { @@ -30,7 +29,7 @@ public class AwarenessReplicaBalanceTests extends OpenSearchAllocationTestCase { public void testNoForcedAwarenessAttribute() { Settings settings = Settings.builder() .put("cluster.routing.allocation.awareness.attributes", "rack_id") - .put(SETTING_AUTO_EXPAND_REPLICAS,"0-1") + .put(SETTING_AUTO_EXPAND_REPLICAS, "0-1") .build(); AutoExpandReplicas autoExpandReplica = AutoExpandReplicas.SETTING.get(settings); AwarenessReplicaBalance awarenessReplicaBalance = new AwarenessReplicaBalance(settings, EMPTY_CLUSTER_SETTINGS); @@ -47,7 +46,7 @@ public void testForcedAwarenessAttribute() { .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "zone.values", "a, b") .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "rack.values", "c, d, e") .put(AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING.getKey(), true) - .put(SETTING_AUTO_EXPAND_REPLICAS,"0-2") + .put(SETTING_AUTO_EXPAND_REPLICAS, "0-2") .build(); AwarenessReplicaBalance awarenessReplicaBalance = new AwarenessReplicaBalance(settings, EMPTY_CLUSTER_SETTINGS); @@ -63,7 +62,7 @@ public void testForcedAwarenessAttribute() { .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "zone.values", "a, b") .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "rack.values", "c, d, e") .put(AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING.getKey(), true) - .put(SETTING_AUTO_EXPAND_REPLICAS,"0-all") + .put(SETTING_AUTO_EXPAND_REPLICAS, "0-all") .build(); awarenessReplicaBalance = new AwarenessReplicaBalance(settings, EMPTY_CLUSTER_SETTINGS); @@ -79,7 +78,7 @@ public void testForcedAwarenessAttribute() { .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "zone.values", "a, b") .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "rack.values", "c, d, e") .put(AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING.getKey(), true) - .put(SETTING_AUTO_EXPAND_REPLICAS,"0-1") + .put(SETTING_AUTO_EXPAND_REPLICAS, "0-1") .build(); awarenessReplicaBalance = new AwarenessReplicaBalance(settings, EMPTY_CLUSTER_SETTINGS); @@ -121,7 +120,7 @@ public void testForcedAwarenessAttributeDisabled() { Settings settings = Settings.builder() .put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.getKey(), "zone, rack") .put(AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING.getKey(), true) - .put(SETTING_AUTO_EXPAND_REPLICAS,"0-1") + .put(SETTING_AUTO_EXPAND_REPLICAS, "0-1") .build(); AwarenessReplicaBalance awarenessReplicaBalance = new AwarenessReplicaBalance(settings, EMPTY_CLUSTER_SETTINGS);