Skip to content

Commit

Permalink
fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Arpit Bandejiya <abandeji@amazon.com>
  • Loading branch information
Arpit-Bandejiya committed Nov 3, 2022
1 parent b962344 commit 3dfc228
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,50 +237,58 @@ 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();

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();

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public int maxAwarenessAttributes() {

public Optional<String> 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()
+ "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3dfc228

Please sign in to comment.