Skip to content

Commit

Permalink
Add RolloverIT tests
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 Dec 27, 2022
1 parent 65a1d52 commit 10e54d9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
import org.opensearch.ResourceAlreadyExistsException;
import org.opensearch.action.admin.indices.alias.Alias;
import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse;
import org.opensearch.action.admin.indices.template.delete.DeleteIndexTemplateRequestBuilder;
import org.opensearch.action.admin.indices.template.put.PutIndexTemplateRequestBuilder;
import org.opensearch.cluster.ClusterState;
import org.opensearch.cluster.metadata.AutoExpandReplicas;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.metadata.Template;
import org.opensearch.cluster.routing.allocation.AllocationService;
import org.opensearch.common.settings.Settings;
import org.opensearch.common.time.DateFormatter;
Expand Down Expand Up @@ -299,6 +301,34 @@ public void testRolloverWithIndexSettingsBalancedReplica() throws Exception {
manageReplicaBalanceSetting(false);
}

public void testRolloverWithIndexSettingsBalancedWithUseZoneForReplicaDefaultCount() throws Exception {
DeleteIndexTemplateRequestBuilder deleteTemplate = client().admin().indices()
.prepareDeleteTemplate("random_index_template");
assertAcked(deleteTemplate.execute().actionGet());

Alias testAlias = new Alias("test_alias");
boolean explicitWriteIndex = randomBoolean();
if (explicitWriteIndex) {
testAlias.writeIndex(true);
}
assertAcked(prepareCreate("test_index-2").addAlias(testAlias).get());
manageUseZoneForReplicaSetting(true);
index("test_index-2", "type1", "1", "field", "value");
flush("test_index-2");

final Settings settings = Settings.builder()
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3)
.build();
client().admin().indices().prepareRolloverIndex("test_alias").settings(settings).alias(new Alias("extra_alias")).get();

final ClusterState state = client().admin().cluster().prepareState().get().getState();
final IndexMetadata newIndex = state.metadata().index("test_index-000003");
assertThat(newIndex.getNumberOfShards(), equalTo(3));
assertThat(newIndex.getNumberOfReplicas(), equalTo(2));
manageUseZoneForReplicaSetting(false);
randomIndexTemplate();
}

public void testRolloverWithIndexSettingsWithoutPrefix() throws Exception {
Alias testAlias = new Alias("test_alias");
boolean explicitWriteIndex = randomBoolean();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@

import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_REPLICAS;
import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_NUMBER_OF_SHARDS;
import static org.opensearch.cluster.routing.allocation.AwarenessReplicaBalance.USE_FORCE_ZONE_FOR_REPLICA_SETTING;
import static org.opensearch.common.unit.TimeValue.timeValueMillis;
import static org.opensearch.common.util.CollectionUtils.eagerPartition;
import static org.opensearch.discovery.DiscoveryModule.DISCOVERY_SEED_PROVIDERS_SETTING;
Expand Down Expand Up @@ -408,7 +409,7 @@ private void printTestMessage(String message) {
* Creates a randomized index template. This template is used to pass in randomized settings on a
* per index basis. Allows to enable/disable the randomization for number of shards and replicas
*/
private void randomIndexTemplate() {
protected void randomIndexTemplate() {

// TODO move settings for random directory etc here into the index based randomized settings.
if (cluster().size() > 0) {
Expand Down Expand Up @@ -734,10 +735,6 @@ public Settings indexSettings() {
if (numberOfShards > 0) {
builder.put(SETTING_NUMBER_OF_SHARDS, numberOfShards).build();
}
int numberOfReplicas = numberOfReplicas();
if (numberOfReplicas >= 0) {
builder.put(SETTING_NUMBER_OF_REPLICAS, numberOfReplicas).build();
}
// 30% of the time
if (randomInt(9) < 3) {
final String dataPath = randomAlphaOfLength(10);
Expand Down Expand Up @@ -2402,4 +2399,26 @@ public void manageReplicaBalanceSetting(boolean apply) {
updateSettingsRequest.persistentSettings(settings);
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
}

public void manageUseZoneForReplicaSetting(boolean apply) {
Settings settings;
if (apply) {
settings = Settings.builder()
.put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.getKey(), "zone")
.put(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "zone.values", "a, b, c")
.put(AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING.getKey(), true)
.put(AwarenessReplicaBalance.USE_FORCE_ZONE_FOR_REPLICA_SETTING.getKey(), true)
.build();
} else {
settings = Settings.builder()
.putNull(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_ATTRIBUTE_SETTING.getKey())
.putNull(AwarenessAllocationDecider.CLUSTER_ROUTING_ALLOCATION_AWARENESS_FORCE_GROUP_SETTING.getKey() + "zone.values")
.putNull(AwarenessReplicaBalance.CLUSTER_ROUTING_ALLOCATION_AWARENESS_BALANCE_SETTING.getKey())
.putNull(AwarenessReplicaBalance.USE_FORCE_ZONE_FOR_REPLICA_SETTING.getKey())
.build();
}
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
updateSettingsRequest.persistentSettings(settings);
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
}
}

0 comments on commit 10e54d9

Please sign in to comment.