Skip to content

Commit

Permalink
Dry up more index settings logic in internal cluster tests (#94199)
Browse files Browse the repository at this point in the history
Drying up the last remaining spots that I found.
  • Loading branch information
original-brownbear committed Mar 1, 2023
1 parent aa354a6 commit 044afe0
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1139,11 +1139,7 @@ public void testUpdateIndexSettingsViaDataStream() throws Exception {
assertThat(getSettingsResponse.getSetting(backingIndex1, "index.number_of_replicas"), equalTo("1"));
assertThat(getSettingsResponse.getSetting(backingIndex2, "index.number_of_replicas"), equalTo("1"));

client().admin()
.indices()
.prepareUpdateSettings("logs-foobar")
.setSettings(Settings.builder().put("index.number_of_replicas", 0))
.get();
setReplicaCount(0, "logs-foobar");
getSettingsResponse = client().admin().indices().prepareGetSettings("logs-foobar").get();
assertThat(getSettingsResponse.getIndexToSettings().size(), equalTo(2));
assertThat(getSettingsResponse.getSetting(backingIndex1, "index.number_of_replicas"), equalTo("0"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ public void testMigrateIndexWithWriteBlock() throws Exception {
createSystemIndexForDescriptor(INTERNAL_UNMANAGED);

String indexName = INTERNAL_UNMANAGED.getIndexPattern().replace("*", "old");

client().admin().indices().prepareUpdateSettings(indexName).setSettings(Settings.builder().put("index.blocks.write", true)).get();

updateIndexSettings(Settings.builder().put("index.blocks.write", true), indexName);
ensureGreen();

client().execute(PostFeatureUpgradeAction.INSTANCE, new PostFeatureUpgradeRequest()).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,10 @@ public void testCreateShrinkWithIndexSort() throws Exception {
assertSortedSegments("source", expectedIndexSort);

// relocate all shards to one node such that we can merge it.
client().admin()
.indices()
.prepareUpdateSettings("source")
.setSettings(Settings.builder().put("index.routing.allocation.require._name", mergeNode).put("index.blocks.write", true))
.get();
updateIndexSettings(
Settings.builder().put("index.routing.allocation.require._name", mergeNode).put("index.blocks.write", true),
"source"
);
ensureGreen();

// check that index sort cannot be set on the target index
Expand Down Expand Up @@ -545,15 +544,10 @@ public void testShrinkCommitsMergeOnIdle() throws Exception {
// to the require._name below.
ensureGreen();
// relocate all shards to one node such that we can merge it.
client().admin()
.indices()
.prepareUpdateSettings("source")
.setSettings(
Settings.builder()
.put("index.routing.allocation.require._name", discoveryNodes[0].getName())
.put("index.blocks.write", true)
)
.get();
updateIndexSettings(
Settings.builder().put("index.routing.allocation.require._name", discoveryNodes[0].getName()).put("index.blocks.write", true),
"source"
);
ensureGreen();
IndicesSegmentResponse sourceStats = client().admin().indices().prepareSegments("source").get();

Expand Down Expand Up @@ -636,15 +630,12 @@ public void testShrinkThenSplitWithFailedNode() throws Exception {
).get();
client().admin().indices().prepareFlush("original").get();
ensureGreen();
client().admin()
.indices()
.prepareUpdateSettings("original")
.setSettings(
Settings.builder()
.put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getConcreteSettingForNamespace("_name").getKey(), shrinkNode)
.put(IndexMetadata.SETTING_BLOCKS_WRITE, true)
)
.get();
updateIndexSettings(
Settings.builder()
.put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getConcreteSettingForNamespace("_name").getKey(), shrinkNode)
.put(IndexMetadata.SETTING_BLOCKS_WRITE, true),
"original"
);
ensureGreen();

assertAcked(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -148,12 +147,7 @@ public void testBulkProcessor2WaitOnClose() throws Exception {

public void testBulkProcessor2ConcurrentRequestsReadOnlyIndex() throws Exception {
createIndex("test-ro");
assertAcked(
client().admin()
.indices()
.prepareUpdateSettings("test-ro")
.setSettings(Settings.builder().put(IndexMetadata.SETTING_BLOCKS_WRITE, true))
);
updateIndexSettings(Settings.builder().put(IndexMetadata.SETTING_BLOCKS_WRITE, true), "test-ro");
ensureGreen();

int bulkActions = randomIntBetween(10, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.apache.lucene.util.Constants;
import org.elasticsearch.action.ActionFuture;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
Expand Down Expand Up @@ -354,14 +353,7 @@ public void testHealthOnMasterFailover() throws Exception {
internalCluster().restartNode(internalCluster().getMasterName(), InternalTestCluster.EMPTY_CALLBACK);
}
if (withIndex) {
assertAcked(
client().admin()
.indices()
.updateSettings(
new UpdateSettingsRequest("test").settings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0))
)
.get()
);
setReplicaCount(0, "test");
}
for (ActionFuture<ClusterHealthResponse> responseFuture : responseFutures) {
assertSame(responseFuture.get().getStatus(), ClusterHealthStatus.GREEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,7 @@ public void testShardCreation() throws Exception {

// new replicas get the SEARCH_ONLY role
routingTableWatcher.numReplicas += 1;
assertAcked(
client().admin()
.indices()
.prepareUpdateSettings("test")
.setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, routingTableWatcher.numReplicas))
);
setReplicaCount(routingTableWatcher.numReplicas, "test");

ensureGreen(INDEX_NAME);
assertEngineTypes();
Expand All @@ -327,12 +322,7 @@ public void testShardCreation() throws Exception {
// removing replicas drops SEARCH_ONLY copies first
while (routingTableWatcher.numReplicas > 0) {
routingTableWatcher.numReplicas -= 1;
assertAcked(
client().admin()
.indices()
.prepareUpdateSettings("test")
.setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, routingTableWatcher.numReplicas))
);
setReplicaCount(routingTableWatcher.numReplicas, "test");
}

// restoring the index from a snapshot may change the number of indexing replicas because the routing table is created afresh
Expand Down Expand Up @@ -412,12 +402,7 @@ public void testRelocation() {
createIndex(INDEX_NAME, routingTableWatcher.getIndexSettings());

for (String nodeName : internalCluster().getNodeNames()) {
assertAcked(
client().admin()
.indices()
.prepareUpdateSettings("test")
.setSettings(Settings.builder().put(IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_PREFIX + "._name", nodeName))
);
updateIndexSettings(Settings.builder().put(IndexMetadata.INDEX_ROUTING_EXCLUDE_GROUP_PREFIX + "._name", nodeName), "test");
ensureGreen(INDEX_NAME);
}
} finally {
Expand All @@ -442,13 +427,7 @@ public void testPromotion() {
ensureGreen(INDEX_NAME);
assertEngineTypes();

assertAcked(
client().admin()
.indices()
.prepareUpdateSettings("test")
.setSettings(Settings.builder().put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._name", "not-a-node"))
);

updateIndexSettings(Settings.builder().put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._name", "not-a-node"), "test");
AllocationCommand cancelPrimaryCommand;
while ((cancelPrimaryCommand = getCancelPrimaryCommand()) != null) {
client().admin().cluster().prepareReroute().add(cancelPrimaryCommand).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,7 @@ public void beforeIndexCreated(Index index, Settings indexSettings) {
}
});
}
assertAcked(
client().admin()
.indices()
.prepareUpdateSettings("index1")
.setSettings(Settings.builder().put(INDEX_ROUTING_EXCLUDE_GROUP_PREFIX + "._name", node1))
);
updateIndexSettings(Settings.builder().put(INDEX_ROUTING_EXCLUDE_GROUP_PREFIX + "._name", node1), "index1");
ensureGreen("index1");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package org.elasticsearch.xpack.autoscaling.storage;

import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.index.IndexRequestBuilder;
Expand Down Expand Up @@ -139,14 +138,7 @@ private void testScaleFromEmptyWarm(boolean allocatable) throws Exception {
assertThat(capacity().results().get("warm").requiredCapacity().total().storage().getBytes(), equalTo(0L));
assertThat(capacity().results().get("warm").requiredCapacity().node().storage().getBytes(), equalTo(0L));

assertAcked(
client().admin()
.indices()
.updateSettings(
new UpdateSettingsRequest(indexName).settings(Settings.builder().put(DataTier.TIER_PREFERENCE, "data_warm,data_hot"))
)
.actionGet()
);
updateIndexSettings(Settings.builder().put(DataTier.TIER_PREFERENCE, "data_warm,data_hot"), indexName);
if (allocatable == false) {
refresh();
}
Expand Down Expand Up @@ -207,15 +199,9 @@ public void testScaleFromEmptyLegacy() {
assertThat(capacity().results().get("cold").requiredCapacity().total().storage().getBytes(), equalTo(0L));
assertThat(capacity().results().get("cold").requiredCapacity().node().storage().getBytes(), equalTo(0L));

assertAcked(
client().admin()
.indices()
.updateSettings(
new UpdateSettingsRequest(indexName).settings(
Settings.builder().put(IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "data_tier", "warm")
)
)
.actionGet()
updateIndexSettings(
Settings.builder().put(IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING.getKey() + "data_tier", "warm"),
indexName
);

assertThat(capacity().results().get("warm").requiredCapacity().total().storage().getBytes(), Matchers.greaterThan(0L));
Expand Down Expand Up @@ -297,16 +283,7 @@ public void testScaleWhileShrinking() throws Exception {
String filterKey = randomFrom(IndexMetadata.INDEX_ROUTING_INCLUDE_GROUP_SETTING, IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING)
.getKey() + filter.v1();

assertAcked(
client().admin()
.indices()
.updateSettings(
new UpdateSettingsRequest(indexName).settings(
Settings.builder().put(filterKey, filter.v2()).put("index.blocks.write", true)
)
)
.actionGet()
);
updateIndexSettings(Settings.builder().put(filterKey, filter.v2()).put("index.blocks.write", true), indexName);

long shrinkSpace = used + LOW_WATERMARK_BYTES;

Expand Down Expand Up @@ -445,13 +422,7 @@ public void testScaleDuringSplitOrClone() throws Exception {
equalTo(used + LOW_WATERMARK_BYTES + ReactiveStorageDeciderService.NODE_DISK_OVERHEAD)
);

assertAcked(
client().admin()
.indices()
.updateSettings(new UpdateSettingsRequest(indexName).settings(Settings.builder().put("index.blocks.write", true)))
.actionGet()
);

updateIndexSettings(Settings.builder().put("index.blocks.write", true), indexName);
ResizeType resizeType = randomFrom(ResizeType.CLONE, ResizeType.SPLIT);
String cloneName = "clone-" + indexName;
int resizedShardCount = resizeType == ResizeType.CLONE ? 1 : between(2, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.desirednodes.UpdateDesiredNodesAction;
import org.elasticsearch.action.admin.cluster.desirednodes.UpdateDesiredNodesRequest;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.action.admin.indices.shrink.ResizeType;
import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
Expand All @@ -37,7 +36,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_AUTO_EXPAND_REPLICAS_SETTING;
Expand Down Expand Up @@ -466,10 +464,7 @@ public void testIllegalOnFrozen() {
}

private void updatePreference(String tier) {
client().admin()
.indices()
.updateSettings(new UpdateSettingsRequest(index).settings(Map.of(DataTier.TIER_PREFERENCE, tier)))
.actionGet();
updateIndexSettings(Settings.builder().put(DataTier.TIER_PREFERENCE, tier), index);
}

private DataTiersFeatureSetUsage getUsage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainRequest;
import org.elasticsearch.action.admin.cluster.allocation.ClusterAllocationExplainResponse;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest;
import org.elasticsearch.cluster.node.DiscoveryNodeRole;
import org.elasticsearch.cluster.routing.ShardRoutingState;
import org.elasticsearch.cluster.routing.allocation.DataTier;
Expand Down Expand Up @@ -194,9 +193,7 @@ public void testUserOptsOutOfTierMigration() throws Exception {
assertReplicaIsUnassigned();
}, 30, TimeUnit.SECONDS);

Settings removeTierRoutingSetting = Settings.builder().putNull(DataTier.TIER_PREFERENCE).build();
UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(managedIndex).settings(removeTierRoutingSetting);
assertAcked(client().admin().indices().updateSettings(updateSettingsRequest).actionGet());
updateIndexSettings(Settings.builder().putNull(DataTier.TIER_PREFERENCE), managedIndex);

// the index should successfully allocate on any nodes
ensureGreen(managedIndex);
Expand All @@ -216,7 +213,7 @@ public void testUserOptsOutOfTierMigration() throws Exception {
}, 30, TimeUnit.SECONDS);

// remove the tier routing setting again
assertAcked(client().admin().indices().updateSettings(updateSettingsRequest).actionGet());
updateIndexSettings(Settings.builder().putNull(DataTier.TIER_PREFERENCE), managedIndex);

// wait for lifecycle to complete in the cold phase
assertBusy(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ public void testCannotRemoveWriteBlock() throws ExecutionException, InterruptedE
assertNotNull(iae.getCause());
assertThat(iae.getCause().getMessage(), containsString("Cannot remove write block from archive index"));

client().admin()
.indices()
.prepareUpdateSettings(indexName)
.setSettings(Settings.builder().put(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey(), true))
.get();
updateIndexSettings(Settings.builder().put(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey(), true), indexName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ public void testCannotRemoveWriteBlock() {
assertNotNull(iae.getCause());
assertThat(iae.getCause().getMessage(), containsString("Cannot remove write block from searchable snapshot index"));

client().admin()
.indices()
.prepareUpdateSettings(indexName)
.setSettings(Settings.builder().put(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey(), true))
.get();
updateIndexSettings(Settings.builder().put(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey(), true), indexName);
}

}

0 comments on commit 044afe0

Please sign in to comment.