Skip to content

Commit ca6d41c

Browse files
authored
Fail indexDocs() on rejection (elastic#111962)
In 9dc59e2 we relaxed the `indexDocs()` test utility to retry on rejections caused by exceeding the write queue length limit, but then we massively relaxed this limit in elastic#59559. We should not be seeing such rejections any more, so we can revert this special handling and strengthen the tests to assert that the indexing process encounters no failures at all.
1 parent d2e6670 commit ca6d41c

File tree

1 file changed

+2
-36
lines changed

1 file changed

+2
-36
lines changed

test/framework/src/main/java/org/elasticsearch/test/ESIntegTestCase.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.apache.lucene.search.Sort;
2222
import org.apache.lucene.search.TotalHits;
2323
import org.apache.lucene.tests.util.LuceneTestCase;
24-
import org.elasticsearch.ExceptionsHelper;
2524
import org.elasticsearch.action.ActionListener;
2625
import org.elasticsearch.action.ActionRequest;
2726
import org.elasticsearch.action.ActionResponse;
@@ -101,15 +100,13 @@
101100
import org.elasticsearch.common.unit.ByteSizeValue;
102101
import org.elasticsearch.common.util.Maps;
103102
import org.elasticsearch.common.util.MockBigArrays;
104-
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
105103
import org.elasticsearch.common.util.concurrent.ThreadContext;
106104
import org.elasticsearch.common.xcontent.ChunkedToXContent;
107105
import org.elasticsearch.common.xcontent.XContentHelper;
108106
import org.elasticsearch.core.IOUtils;
109107
import org.elasticsearch.core.Nullable;
110108
import org.elasticsearch.core.Releasable;
111109
import org.elasticsearch.core.TimeValue;
112-
import org.elasticsearch.core.Tuple;
113110
import org.elasticsearch.env.Environment;
114111
import org.elasticsearch.env.TestEnvironment;
115112
import org.elasticsearch.gateway.PersistedClusterStateService;
@@ -186,7 +183,6 @@
186183
import java.util.Random;
187184
import java.util.Set;
188185
import java.util.concurrent.Callable;
189-
import java.util.concurrent.CopyOnWriteArrayList;
190186
import java.util.concurrent.CountDownLatch;
191187
import java.util.concurrent.ExecutionException;
192188
import java.util.concurrent.Executor;
@@ -212,7 +208,6 @@
212208
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
213209
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoTimeout;
214210
import static org.hamcrest.Matchers.empty;
215-
import static org.hamcrest.Matchers.emptyIterable;
216211
import static org.hamcrest.Matchers.equalTo;
217212
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
218213
import static org.hamcrest.Matchers.is;
@@ -1735,7 +1730,6 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean ma
17351730
}
17361731
}
17371732
Collections.shuffle(builders, random());
1738-
final CopyOnWriteArrayList<Tuple<IndexRequestBuilder, Exception>> errors = new CopyOnWriteArrayList<>();
17391733
List<CountDownLatch> inFlightAsyncOperations = new ArrayList<>();
17401734
// If you are indexing just a few documents then frequently do it one at a time. If many then frequently in bulk.
17411735
final String[] indicesArray = indices.toArray(new String[] {});
@@ -1744,7 +1738,7 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean ma
17441738
logger.info("Index [{}] docs async: [{}] bulk: [{}]", builders.size(), true, false);
17451739
for (IndexRequestBuilder indexRequestBuilder : builders) {
17461740
indexRequestBuilder.execute(
1747-
new PayloadLatchedActionListener<>(indexRequestBuilder, newLatch(inFlightAsyncOperations), errors)
1741+
new LatchedActionListener<DocWriteResponse>(newLatch(inFlightAsyncOperations)).delegateResponse((l, e) -> fail(e))
17481742
);
17491743
postIndexAsyncActions(indicesArray, inFlightAsyncOperations, maybeFlush);
17501744
}
@@ -1771,19 +1765,8 @@ public void indexRandom(boolean forceRefresh, boolean dummyDocuments, boolean ma
17711765
}
17721766
}
17731767
for (CountDownLatch operation : inFlightAsyncOperations) {
1774-
operation.await();
1775-
}
1776-
final List<Exception> actualErrors = new ArrayList<>();
1777-
for (Tuple<IndexRequestBuilder, Exception> tuple : errors) {
1778-
Throwable t = ExceptionsHelper.unwrapCause(tuple.v2());
1779-
if (t instanceof EsRejectedExecutionException) {
1780-
logger.debug("Error indexing doc: " + t.getMessage() + ", reindexing.");
1781-
tuple.v1().get(); // re-index if rejected
1782-
} else {
1783-
actualErrors.add(tuple.v2());
1784-
}
1768+
safeAwait(operation);
17851769
}
1786-
assertThat(actualErrors, emptyIterable());
17871770
if (bogusIds.isEmpty() == false) {
17881771
// delete the bogus types again - it might trigger merges or at least holes in the segments and enforces deleted docs!
17891772
for (List<String> doc : bogusIds) {
@@ -1957,23 +1940,6 @@ protected void addError(Exception e) {}
19571940

19581941
}
19591942

1960-
private class PayloadLatchedActionListener<Response, T> extends LatchedActionListener<Response> {
1961-
private final CopyOnWriteArrayList<Tuple<T, Exception>> errors;
1962-
private final T builder;
1963-
1964-
PayloadLatchedActionListener(T builder, CountDownLatch latch, CopyOnWriteArrayList<Tuple<T, Exception>> errors) {
1965-
super(latch);
1966-
this.errors = errors;
1967-
this.builder = builder;
1968-
}
1969-
1970-
@Override
1971-
protected void addError(Exception e) {
1972-
errors.add(new Tuple<>(builder, e));
1973-
}
1974-
1975-
}
1976-
19771943
/**
19781944
* Clears the given scroll Ids
19791945
*/

0 commit comments

Comments
 (0)