Skip to content

Commit 556a185

Browse files
Fix Incorrect Cast in Bulk Handler Failure Handling (#69773) (#69783)
We need to cast the cause and not the original exception here.
1 parent 1db660a commit 556a185

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

server/src/internalClusterTest/java/org/elasticsearch/action/bulk/BulkProcessorClusterSettingsIT.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88

99
package org.elasticsearch.action.bulk;
1010

11+
import org.elasticsearch.action.support.AutoCreateIndex;
1112
import org.elasticsearch.common.settings.Settings;
1213
import org.elasticsearch.common.xcontent.XContentType;
14+
import org.elasticsearch.index.IndexNotFoundException;
1315
import org.elasticsearch.test.ESIntegTestCase;
1416
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
1517
import org.elasticsearch.test.ESIntegTestCase.Scope;
1618

19+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
1720
import static org.hamcrest.Matchers.equalTo;
21+
import static org.hamcrest.Matchers.instanceOf;
1822

1923
@ClusterScope(scope = Scope.TEST, numDataNodes = 0)
2024
public class BulkProcessorClusterSettingsIT extends ESIntegTestCase {
@@ -41,4 +45,12 @@ public void testBulkProcessorAutoCreateRestrictions() throws Exception {
4145
equalTo("[wontwork] IndexNotFoundException[no such index [wontwork] and [action.auto_create_index] is [false]]"));
4246
assertFalse("Operation on existing index should succeed", responses[2].isFailed());
4347
}
48+
49+
public void testIndexWithDisabledAutoCreateIndex() {
50+
assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.builder()
51+
.put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), randomFrom("-*", "+.*")).build()).get());
52+
final BulkItemResponse itemResponse =
53+
client().prepareBulk().add(client().prepareIndex("test-index", "type1").setSource("foo", "bar")).get().getItems()[0];
54+
assertThat(itemResponse.getFailure().getCause(), instanceOf(IndexNotFoundException.class));
55+
}
4456
}

server/src/main/java/org/elasticsearch/action/bulk/TransportBulkAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ protected void doRun() {
260260
public void onFailure(Exception e) {
261261
final Throwable cause = ExceptionsHelper.unwrapCause(e);
262262
if (cause instanceof IndexNotFoundException) {
263-
indicesThatCannotBeCreated.put(index, (IndexNotFoundException) e);
263+
indicesThatCannotBeCreated.put(index, (IndexNotFoundException) cause);
264264
}
265265
else if ((cause instanceof ResourceAlreadyExistsException) == false) {
266266
// fail all requests involving this index, if create didn't work

0 commit comments

Comments
 (0)