Bulk request which try and fail to create multiple indices may never return
This is caused by an NPE in the error handling code. All is well if only 1 index creation fails (or none). Closes #6436
This commit is contained in:
parent
724129e6ce
commit
b454f64c57
|
@ -134,7 +134,7 @@ public class TransportBulkAction extends TransportAction<BulkRequest, BulkRespon
|
||||||
// fail all requests involving this index, if create didnt work
|
// fail all requests involving this index, if create didnt work
|
||||||
for (int i = 0; i < bulkRequest.requests.size(); i++) {
|
for (int i = 0; i < bulkRequest.requests.size(); i++) {
|
||||||
ActionRequest request = bulkRequest.requests.get(i);
|
ActionRequest request = bulkRequest.requests.get(i);
|
||||||
if (setResponseFailureIfIndexMatches(responses, i, request, index, e)) {
|
if (request != null && setResponseFailureIfIndexMatches(responses, i, request, index, e)) {
|
||||||
bulkRequest.requests.set(i, null);
|
bulkRequest.requests.set(i, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.CyclicBarrier;
|
import java.util.concurrent.CyclicBarrier;
|
||||||
|
@ -624,10 +625,20 @@ public class BulkTests extends ElasticsearchIntegrationTest {
|
||||||
int bulkEntryCount = randomIntBetween(10, 50);
|
int bulkEntryCount = randomIntBetween(10, 50);
|
||||||
BulkRequestBuilder builder = client().prepareBulk();
|
BulkRequestBuilder builder = client().prepareBulk();
|
||||||
boolean[] expectedFailures = new boolean[bulkEntryCount];
|
boolean[] expectedFailures = new boolean[bulkEntryCount];
|
||||||
|
ArrayList<String> badIndexNames = new ArrayList<>();
|
||||||
|
for (int i = randomIntBetween(1, 5); i > 0; i--) {
|
||||||
|
badIndexNames.add("INVALID.NAME" + i);
|
||||||
|
}
|
||||||
boolean expectFailure = false;
|
boolean expectFailure = false;
|
||||||
for (int i = 0; i < bulkEntryCount; i++) {
|
for (int i = 0; i < bulkEntryCount; i++) {
|
||||||
expectFailure |= expectedFailures[i] = randomBoolean();
|
expectFailure |= expectedFailures[i] = randomBoolean();
|
||||||
builder.add(client().prepareIndex().setIndex(expectedFailures[i] ? "INVALID.NAME" : "test").setType("type1").setId("1").setSource("field", 1));
|
String name;
|
||||||
|
if (expectedFailures[i]) {
|
||||||
|
name = randomFrom(badIndexNames);
|
||||||
|
} else {
|
||||||
|
name = "test";
|
||||||
|
}
|
||||||
|
builder.add(client().prepareIndex().setIndex(name).setType("type1").setId("1").setSource("field", 1));
|
||||||
}
|
}
|
||||||
BulkResponse bulkResponse = builder.get();
|
BulkResponse bulkResponse = builder.get();
|
||||||
assertThat(bulkResponse.hasFailures(), is(expectFailure));
|
assertThat(bulkResponse.hasFailures(), is(expectFailure));
|
||||||
|
|
Loading…
Reference in New Issue