Skip to content

Commit

Permalink
Run assertAcked(...) requests in parallel in some spots (elastic#118980)
Browse files Browse the repository at this point in the history
Similar to how we sped up search tests we can parallelize a lot on
`assertAcked` calls when those aren't logically dependant on one another.
This speeds up tests quite a bit in some cases by avoiding unbatched CS updates
or at least allowing for more parallelism.
Also, this gives a bit more coverage as far as stressing the system with concurrent
transport requests goes.
  • Loading branch information
original-brownbear authored Dec 19, 2024
1 parent 103d29f commit 91835ec
Show file tree
Hide file tree
Showing 23 changed files with 184 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,12 @@ public void setUp() throws Exception {
.setSettings(
settings.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), IndexVersions.NEW_INDEXVERSION_FORMAT).build()
)
.setMapping(mapping)
.get()
);

assertAcked(
.setMapping(mapping),
indicesAdmin().prepareCreate(afterIndex)
.setSettings(
settings.put(IndexMetadata.SETTING_INDEX_VERSION_CREATED.getKey(), IndexVersions.TIME_SERIES_ID_HASHING).build()
)
.setMapping(mapping)
.get()
);

final TimeSeriesDataset timeSeriesDataset = new TimeSeriesDataset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.elasticsearch.action.admin.indices.cache.clear.TransportClearIndicesCacheAction;
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction;
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction;
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
Expand Down Expand Up @@ -157,9 +158,11 @@ public void setup() {
for (int i = 0; i < numIndices; i++) {
indices.add("test" + i);
}
for (String index : indices) {
assertAcked(prepareCreate(index).addAlias(new Alias(index + "-alias")));
}
assertAcked(
indices.stream()
.map(index -> prepareCreate(index).addAlias(new Alias(index + "-alias")))
.toArray(CreateIndexRequestBuilder[]::new)
);
ensureGreen();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ public void testEmptyMappings() throws Exception {
}

public void testTwoEmptyEqualMappings() throws Exception {
assertAcked(prepareCreate("test1"));
assertAcked(prepareCreate("test2").setMapping(XContentFactory.jsonBuilder().startObject().endObject()));
assertAcked(prepareCreate("test1"), prepareCreate("test2").setMapping(XContentFactory.jsonBuilder().startObject().endObject()));
FieldCapabilitiesRequest fieldCapsReq1 = new FieldCapabilitiesRequest();
fieldCapsReq1.indices("test1");
fieldCapsReq1.fields("*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -649,9 +649,11 @@ public void testRolloverWithClosedIndexInAlias() {
final String openNonwriteIndex = "open-index-nonwrite";
final String closedIndex = "closed-index-nonwrite";
final String writeIndexPrefix = "write-index-";
assertAcked(prepareCreate(openNonwriteIndex).addAlias(new Alias(aliasName)).get());
assertAcked(prepareCreate(closedIndex).addAlias(new Alias(aliasName)).get());
assertAcked(prepareCreate(writeIndexPrefix + "000001").addAlias(new Alias(aliasName).writeIndex(true)).get());
assertAcked(
prepareCreate(openNonwriteIndex).addAlias(new Alias(aliasName)),
prepareCreate(closedIndex).addAlias(new Alias(aliasName)),
prepareCreate(writeIndexPrefix + "000001").addAlias(new Alias(aliasName).writeIndex(true))
);
ensureGreen();

index(closedIndex, null, "{\"foo\": \"bar\"}");
Expand All @@ -674,17 +676,18 @@ public void testRolloverWithClosedWriteIndex() throws Exception {
final String openNonwriteIndex = "open-index-nonwrite";
final String closedIndex = "closed-index-nonwrite";
final String writeIndexPrefix = "write-index-";
assertAcked(prepareCreate(openNonwriteIndex).addAlias(new Alias(aliasName)).get());
assertAcked(prepareCreate(closedIndex).addAlias(new Alias(aliasName)).get());
assertAcked(prepareCreate(writeIndexPrefix + "000001").addAlias(new Alias(aliasName).writeIndex(true)).get());
assertAcked(
prepareCreate(openNonwriteIndex).addAlias(new Alias(aliasName)),
prepareCreate(closedIndex).addAlias(new Alias(aliasName)),
prepareCreate(writeIndexPrefix + "000001").addAlias(new Alias(aliasName).writeIndex(true))
);
ensureGreen(openNonwriteIndex, closedIndex, writeIndexPrefix + "000001");
index(closedIndex, null, "{\"foo\": \"bar\"}");
index(aliasName, null, "{\"foo\": \"bar\"}");
index(aliasName, null, "{\"foo\": \"bar\"}");
refresh(aliasName);

assertAcked(indicesAdmin().prepareClose(closedIndex).get());
assertAcked(indicesAdmin().prepareClose(writeIndexPrefix + "000001").get());
assertAcked(indicesAdmin().prepareClose(closedIndex, writeIndexPrefix + "000001").get());
ensureGreen(aliasName);

RolloverResponse rolloverResponse = indicesAdmin().prepareRolloverIndex(aliasName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,15 @@ public void testFinalReduce() throws ExecutionException, InterruptedException {

public void testWaitForRefreshIndexValidation() throws Exception {
int numberOfShards = randomIntBetween(3, 10);
assertAcked(prepareCreate("test1").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards)));
assertAcked(prepareCreate("test2").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards)));
assertAcked(prepareCreate("test3").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards)));
indicesAdmin().prepareAliases().addAlias("test1", "testAlias").get();
indicesAdmin().prepareAliases().addAlias(new String[] { "test2", "test3" }, "testFailedAlias").get();
assertAcked(
prepareCreate("test1").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards)),
prepareCreate("test2").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards)),
prepareCreate("test3").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards))
);
assertAcked(
indicesAdmin().prepareAliases().addAlias("test1", "testAlias"),
indicesAdmin().prepareAliases().addAlias(new String[] { "test2", "test3" }, "testFailedAlias")
);

long[] validCheckpoints = new long[numberOfShards];
Arrays.fill(validCheckpoints, SequenceNumbers.UNASSIGNED_SEQ_NO);
Expand Down Expand Up @@ -376,8 +380,10 @@ public void testShardCountLimit() throws Exception {
try {
final int numPrimaries1 = randomIntBetween(2, 10);
final int numPrimaries2 = randomIntBetween(1, 10);
assertAcked(prepareCreate("test1").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numPrimaries1)));
assertAcked(prepareCreate("test2").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numPrimaries2)));
assertAcked(
prepareCreate("test1").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numPrimaries1)),
prepareCreate("test2").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numPrimaries2))
);

// no exception
prepareSearch("test1").get().decRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,8 +531,10 @@ private void checkBrownFoxTermVector(Fields fields, String fieldName, boolean wi
public void testDuelWithAndWithoutTermVectors() throws IOException, ExecutionException, InterruptedException {
// setup indices
String[] indexNames = new String[] { "with_tv", "without_tv" };
assertAcked(prepareCreate(indexNames[0]).setMapping("field1", "type=text,term_vector=with_positions_offsets,analyzer=keyword"));
assertAcked(prepareCreate(indexNames[1]).setMapping("field1", "type=text,term_vector=no,analyzer=keyword"));
assertAcked(
prepareCreate(indexNames[1]).setMapping("field1", "type=text,term_vector=no,analyzer=keyword"),
prepareCreate(indexNames[0]).setMapping("field1", "type=text,term_vector=with_positions_offsets,analyzer=keyword")
);
ensureGreen();

// index documents with and without term vectors
Expand Down Expand Up @@ -1074,9 +1076,7 @@ public void testWithKeywordAndNormalizer() throws IOException, ExecutionExceptio
"type=text,term_vector=with_positions_offsets,analyzer=my_analyzer",
"field2",
"type=text,term_vector=with_positions_offsets,analyzer=keyword"
)
);
assertAcked(
),
prepareCreate(indexNames[1]).setSettings(builder.build())
.setMapping("field1", "type=keyword,normalizer=my_normalizer", "field2", "type=keyword")
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,8 @@ public void testSearchingFilteringAliasesSingleIndex() throws Exception {
}

public void testSearchingFilteringAliasesTwoIndices() throws Exception {
logger.info("--> creating index [test1]");
assertAcked(prepareCreate("test1").setMapping("name", "type=text"));
logger.info("--> creating index [test2]");
assertAcked(prepareCreate("test2").setMapping("name", "type=text"));
logger.info("--> creating indices [test1, test2]");
assertAcked(prepareCreate("test1").setMapping("name", "type=text"), prepareCreate("test2").setMapping("name", "type=text"));
ensureGreen();

logger.info("--> adding filtering aliases to index [test1]");
Expand Down Expand Up @@ -525,8 +523,7 @@ public void testSearchingFilteringAliasesMultipleIndices() throws Exception {

public void testDeletingByQueryFilteringAliases() throws Exception {
logger.info("--> creating index [test1] and [test2");
assertAcked(prepareCreate("test1").setMapping("name", "type=text"));
assertAcked(prepareCreate("test2").setMapping("name", "type=text"));
assertAcked(prepareCreate("test1").setMapping("name", "type=text"), prepareCreate("test2").setMapping("name", "type=text"));
ensureGreen();

logger.info("--> adding filtering aliases to index [test1]");
Expand Down Expand Up @@ -580,8 +577,7 @@ public void testDeletingByQueryFilteringAliases() throws Exception {

public void testDeleteAliases() throws Exception {
logger.info("--> creating index [test1] and [test2]");
assertAcked(prepareCreate("test1").setMapping("name", "type=text"));
assertAcked(prepareCreate("test2").setMapping("name", "type=text"));
assertAcked(prepareCreate("test1").setMapping("name", "type=text"), prepareCreate("test2").setMapping("name", "type=text"));
ensureGreen();

logger.info("--> adding filtering aliases to index [test1]");
Expand Down Expand Up @@ -619,8 +615,7 @@ public void testDeleteAliases() throws Exception {
}

logger.info("--> creating index [foo_foo] and [bar_bar]");
assertAcked(prepareCreate("foo_foo"));
assertAcked(prepareCreate("bar_bar"));
assertAcked(prepareCreate("foo_foo"), prepareCreate("bar_bar"));
ensureGreen();

logger.info("--> adding [foo] alias to [foo_foo] and [bar_bar]");
Expand Down Expand Up @@ -1163,13 +1158,15 @@ public void testAliasesWithBlocks() {
}
}

public void testAliasActionRemoveIndex() throws InterruptedException, ExecutionException {
assertAcked(prepareCreate("foo_foo"));
assertAcked(prepareCreate("bar_bar"));
assertAliasesVersionIncreases(new String[] { "foo_foo", "bar_bar" }, () -> {
assertAcked(indicesAdmin().prepareAliases().addAlias("foo_foo", "foo"));
assertAcked(indicesAdmin().prepareAliases().addAlias("bar_bar", "foo"));
});
public void testAliasActionRemoveIndex() {
assertAcked(prepareCreate("foo_foo"), prepareCreate("bar_bar"));
assertAliasesVersionIncreases(
new String[] { "foo_foo", "bar_bar" },
() -> assertAcked(
indicesAdmin().prepareAliases().addAlias("bar_bar", "foo"),
indicesAdmin().prepareAliases().addAlias("foo_foo", "foo")
)
);

IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, indicesAdmin().prepareAliases().removeIndex("foo"));
assertEquals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public void testEnableRebalance() {
// we test with 2 shards since otherwise it's pretty fragile if there are difference in the num or shards such that
// all shards are relocated to the second node which is not what we want here. It's solely a test for the settings to take effect
final int numShards = 2;
assertAcked(prepareCreate("test").setSettings(indexSettings(numShards, 0)));
assertAcked(prepareCreate("test_1").setSettings(indexSettings(numShards, 0)));
assertAcked(
prepareCreate("test").setSettings(indexSettings(numShards, 0)),
prepareCreate("test_1").setSettings(indexSettings(numShards, 0))
);
ensureGreen();
assertAllShardsOnNodes("test", firstNode);
assertAllShardsOnNodes("test_1", firstNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,11 @@ public void testQueryRewriteDates() throws Exception {
public void testQueryRewriteDatesWithNow() throws Exception {
Client client = client();
Settings settings = indexSettings(1, 0).put(IndicesRequestCache.INDEX_CACHE_REQUEST_ENABLED_SETTING.getKey(), true).build();
assertAcked(indicesAdmin().prepareCreate("index-1").setMapping("d", "type=date").setSettings(settings).get());
assertAcked(indicesAdmin().prepareCreate("index-2").setMapping("d", "type=date").setSettings(settings).get());
assertAcked(indicesAdmin().prepareCreate("index-3").setMapping("d", "type=date").setSettings(settings).get());
assertAcked(
indicesAdmin().prepareCreate("index-1").setMapping("d", "type=date").setSettings(settings),
indicesAdmin().prepareCreate("index-2").setMapping("d", "type=date").setSettings(settings),
indicesAdmin().prepareCreate("index-3").setMapping("d", "type=date").setSettings(settings)
);
ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
DateFormatter formatter = DateFormatter.forPattern("strict_date_optional_time");
indexRandom(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ private XContentBuilder getMappingForType() throws IOException {
}

public void testGetFieldMappings() throws Exception {

assertAcked(prepareCreate("indexa").setMapping(getMappingForType()));
assertAcked(indicesAdmin().prepareCreate("indexb").setMapping(getMappingForType()));
assertAcked(
prepareCreate("indexa").setMapping(getMappingForType()),
indicesAdmin().prepareCreate("indexb").setMapping(getMappingForType())
);

// Get mappings by full name
GetFieldMappingsResponse response = indicesAdmin().prepareGetFieldMappings("indexa").setFields("field1", "obj.subfield").get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ public void testPrimaryDocumentRejectionMetricsArePublishing() {
plugin.resetMeter();

final int numberOfShards = randomIntBetween(1, 5);
assertAcked(prepareCreate("test-one", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards)).get());
assertAcked(prepareCreate("test-two", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)).get());
assertAcked(
prepareCreate("test-one", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards)),
prepareCreate("test-two", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1))
);

final BulkRequest bulkRequestOne = new BulkRequest();
final int batchCountOne = randomIntBetween(50, 100);
Expand Down Expand Up @@ -397,8 +399,10 @@ public void testPrimaryDocumentRejectionMetricsFluctuatingOverTime() throws Exce
ensureStableCluster(2);

// for simplicity do not mix small and big documents in single index/shard
assertAcked(prepareCreate("test-index-one", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)).get());
assertAcked(prepareCreate("test-index-two", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)).get());
assertAcked(
prepareCreate("test-index-one", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)),
prepareCreate("test-index-two", Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1))
);

final TestTelemetryPlugin plugin = internalCluster().getInstance(PluginsService.class, dataNode)
.filterPlugins(TestTelemetryPlugin.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public static String randomExecutionHint() {

@Override
public void setupSuiteScopeCluster() throws Exception {
assertAcked(prepareCreate("idx").setMapping(TERMS_AGGS_FIELD, "type=keyword", "text", "type=text,store=true"));
assertAcked(prepareCreate("field-collapsing").setMapping("group", "type=keyword"));
createIndex("empty");
assertAcked(
prepareCreate("idx").setMapping(TERMS_AGGS_FIELD, "type=keyword", "text", "type=text,store=true"),
prepareCreate("field-collapsing").setMapping("group", "type=keyword"),
prepareCreate("empty"),
prepareCreate("articles").setMapping(
jsonBuilder().startObject()
.startObject("_doc")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ public void testResolvedIndices_TransportSearchAction() {
public void testResolvedIndices_TransportExplainAction() {
final String[] indices = { "test1", "test2" };
createIndex(indices);
assertAcked(indicesAdmin().prepareAliases().addAlias("test1", "alias1"));
assertAcked(indicesAdmin().prepareAliases().addAlias(indices, "alias2"));
assertAcked(
indicesAdmin().prepareAliases().addAlias("test1", "alias1"),
indicesAdmin().prepareAliases().addAlias(indices, "alias2")
);

assertResolvedIndices(client().prepareExplain("test1", "1"), Set.of("test1"), Set.of("test1"), r -> {});
assertResolvedIndices(client().prepareExplain("alias1", "1"), Set.of("alias1"), Set.of("test1"), r -> {});
Expand Down
Loading

0 comments on commit 91835ec

Please sign in to comment.