Skip to content

Commit 584df17

Browse files
Fix Concurrent Index Auto Create Failing Bulk Requests (#82541)
Batching these requests introduced a bug where auto-create requests for system indices would fail because system indices are always auto-created and thus throw resource-already-exists if multiple equal ones are batched together even though the index doesn't yet exist in the cluster state but only in the intermediary task executor state. This leads to bulk requests ignoring the exeception (thinking that the index already exists) in their auto-create callback when the request doesn't yet exist. Fixed by deduplicating these requests for now, added a TODO to do it a little nicer down the road but this fix is somewhat urgent as it breaks ML integ tests.
1 parent 62db2ae commit 584df17

File tree

2 files changed

+189
-133
lines changed

2 files changed

+189
-133
lines changed

server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/create/CreateSystemIndicesIT.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.elasticsearch.action.admin.indices.create;
1010

11+
import org.elasticsearch.action.ActionListener;
1112
import org.elasticsearch.action.admin.indices.alias.Alias;
1213
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesRequest;
1314
import org.elasticsearch.action.admin.indices.alias.get.GetAliasesResponse;
@@ -17,7 +18,11 @@
1718
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
1819
import org.elasticsearch.action.admin.indices.template.delete.DeleteComposableIndexTemplateAction;
1920
import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction;
21+
import org.elasticsearch.action.bulk.BulkRequest;
22+
import org.elasticsearch.action.bulk.BulkResponse;
23+
import org.elasticsearch.action.index.IndexRequest;
2024
import org.elasticsearch.action.support.IndicesOptions;
25+
import org.elasticsearch.client.internal.Client;
2126
import org.elasticsearch.cluster.metadata.AliasMetadata;
2227
import org.elasticsearch.cluster.metadata.ComposableIndexTemplate;
2328
import org.elasticsearch.cluster.metadata.MappingMetadata;
@@ -40,6 +45,8 @@
4045
import java.util.List;
4146
import java.util.Map;
4247
import java.util.Set;
48+
import java.util.concurrent.CountDownLatch;
49+
import java.util.concurrent.TimeUnit;
4350
import java.util.stream.Collectors;
4451

4552
import static org.elasticsearch.indices.TestSystemIndexDescriptor.INDEX_NAME;
@@ -201,6 +208,31 @@ private void doCreateTest(Runnable runnable, String concreteIndex) {
201208
assertAliases(concreteIndex);
202209
}
203210

211+
public void testConcurrentAutoCreates() throws InterruptedException {
212+
internalCluster().startNodes(3);
213+
214+
final Client client = client();
215+
final int count = randomIntBetween(5, 30);
216+
final CountDownLatch latch = new CountDownLatch(count);
217+
final ActionListener<BulkResponse> listener = new ActionListener<>() {
218+
@Override
219+
public void onResponse(BulkResponse o) {
220+
latch.countDown();
221+
assertFalse(o.hasFailures());
222+
}
223+
224+
@Override
225+
public void onFailure(Exception e) {
226+
latch.countDown();
227+
throw new AssertionError(e);
228+
}
229+
};
230+
for (int i = 0; i < count; i++) {
231+
client.bulk(new BulkRequest().add(new IndexRequest(INDEX_NAME).source(Map.of("foo", "bar"))), listener);
232+
}
233+
assertTrue(latch.await(30L, TimeUnit.SECONDS));
234+
}
235+
204236
/**
205237
* Make sure that aliases are created hidden
206238
*/

0 commit comments

Comments
 (0)