use of org.elasticsearch.common.util.concurrent.EsRejectedExecutionException in project elasticsearch by elastic.
the class RejectionActionIT method testSimulatedSearchRejectionLoad.
public void testSimulatedSearchRejectionLoad() throws Throwable {
for (int i = 0; i < 10; i++) {
client().prepareIndex("test", "type", Integer.toString(i)).setSource("field", "1").get();
}
int numberOfAsyncOps = randomIntBetween(200, 700);
final CountDownLatch latch = new CountDownLatch(numberOfAsyncOps);
final CopyOnWriteArrayList<Object> responses = new CopyOnWriteArrayList<>();
for (int i = 0; i < numberOfAsyncOps; i++) {
client().prepareSearch("test").setSearchType(SearchType.QUERY_THEN_FETCH).setQuery(QueryBuilders.matchQuery("field", "1")).execute(new ActionListener<SearchResponse>() {
@Override
public void onResponse(SearchResponse searchResponse) {
responses.add(searchResponse);
latch.countDown();
}
@Override
public void onFailure(Exception e) {
responses.add(e);
latch.countDown();
}
});
}
latch.await();
// validate all responses
for (Object response : responses) {
if (response instanceof SearchResponse) {
SearchResponse searchResponse = (SearchResponse) response;
for (ShardSearchFailure failure : searchResponse.getShardFailures()) {
assertTrue("got unexpected reason..." + failure.reason(), failure.reason().toLowerCase(Locale.ENGLISH).contains("rejected"));
}
} else {
Exception t = (Exception) response;
Throwable unwrap = ExceptionsHelper.unwrapCause(t);
if (unwrap instanceof SearchPhaseExecutionException) {
SearchPhaseExecutionException e = (SearchPhaseExecutionException) unwrap;
for (ShardSearchFailure failure : e.shardFailures()) {
assertTrue("got unexpected reason..." + failure.reason(), failure.reason().toLowerCase(Locale.ENGLISH).contains("rejected"));
}
} else if ((unwrap instanceof EsRejectedExecutionException) == false) {
throw new AssertionError("unexpected failure", (Throwable) response);
}
}
}
assertThat(responses.size(), equalTo(numberOfAsyncOps));
}
use of org.elasticsearch.common.util.concurrent.EsRejectedExecutionException in project elasticsearch by elastic.
the class AsyncBulkByScrollActionTests method testThreadPoolRejectionsAbortRequest.
/**
* Mimicks a ThreadPool rejecting execution of the task.
*/
public void testThreadPoolRejectionsAbortRequest() throws Exception {
testTask.rethrottle(1);
setupClient(new TestThreadPool(getTestName()) {
@Override
public ScheduledFuture<?> schedule(TimeValue delay, String name, Runnable command) {
// While we're here we can check that the sleep made it through
assertThat(delay.nanos(), greaterThan(0L));
assertThat(delay.seconds(), lessThanOrEqualTo(10L));
((AbstractRunnable) command).onRejection(new EsRejectedExecutionException("test"));
return null;
}
});
ScrollableHitSource.Response response = new ScrollableHitSource.Response(false, emptyList(), 0, emptyList(), null);
simulateScrollResponse(new DummyAsyncBulkByScrollAction(), timeValueNanos(System.nanoTime()), 10, response);
ExecutionException e = expectThrows(ExecutionException.class, () -> listener.get());
assertThat(e.getMessage(), equalTo("EsRejectedExecutionException[test]"));
assertThat(client.scrollsCleared, contains(scrollId));
// When the task is rejected we don't increment the throttled timer
assertEquals(timeValueMillis(0), testTask.getStatus().getThrottled());
}
use of org.elasticsearch.common.util.concurrent.EsRejectedExecutionException in project crate by crate.
the class HttpBlobHandler method exceptionCaught.
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
Throwable ex = e.getCause();
if (ex instanceof ClosedChannelException) {
LOGGER.trace("channel closed: {}", ex.toString());
return;
} else if (ex instanceof IOException) {
String message = ex.getMessage();
if (message != null && message.contains("Connection reset by peer")) {
LOGGER.debug(message);
} else {
LOGGER.warn(message, e);
}
return;
}
HttpResponseStatus status;
String body = null;
if (ex instanceof DigestMismatchException || ex instanceof BlobsDisabledException || ex instanceof IllegalArgumentException) {
status = HttpResponseStatus.BAD_REQUEST;
body = String.format(Locale.ENGLISH, "Invalid request sent: %s", ex.getMessage());
} else if (ex instanceof DigestNotFoundException || ex instanceof IndexNotFoundException) {
status = HttpResponseStatus.NOT_FOUND;
} else if (ex instanceof EsRejectedExecutionException) {
status = TOO_MANY_REQUESTS;
body = String.format(Locale.ENGLISH, "Rejected execution: %s", ex.getMessage());
} else {
status = HttpResponseStatus.INTERNAL_SERVER_ERROR;
body = String.format(Locale.ENGLISH, "Unhandled exception: %s", ex);
}
if (body != null) {
LOGGER.debug(body);
}
simpleResponse(status, body);
}
use of org.elasticsearch.common.util.concurrent.EsRejectedExecutionException in project crate by crate.
the class NodeFetchOperation method doFetch.
private void doFetch(FetchContext fetchContext, SettableFuture<IntObjectMap<StreamBucket>> resultFuture, IntObjectMap<? extends IntContainer> toFetch) throws Exception {
final IntObjectHashMap<StreamBucket> fetched = new IntObjectHashMap<>(toFetch.size());
HashMap<TableIdent, TableFetchInfo> tableFetchInfos = getTableFetchInfos(fetchContext);
final AtomicReference<Throwable> lastThrowable = new AtomicReference<>(null);
final AtomicInteger threadLatch = new AtomicInteger(toFetch.size());
for (IntObjectCursor<? extends IntContainer> toFetchCursor : toFetch) {
final int readerId = toFetchCursor.key;
final IntContainer docIds = toFetchCursor.value;
TableIdent ident = fetchContext.tableIdent(readerId);
final TableFetchInfo tfi = tableFetchInfos.get(ident);
assert tfi != null : "tfi must not be null";
CollectRunnable runnable = new CollectRunnable(tfi.createCollector(readerId), docIds, fetched, readerId, lastThrowable, threadLatch, resultFuture, fetchContext.isKilled());
try {
executor.execute(runnable);
} catch (EsRejectedExecutionException | RejectedExecutionException e) {
runnable.run();
}
}
}
use of org.elasticsearch.common.util.concurrent.EsRejectedExecutionException in project crate by crate.
the class BulkRetryCoordinatorTest method testScheduleRetryAfterRejectedExecution.
@Test
public void testScheduleRetryAfterRejectedExecution() throws Exception {
ThreadPool threadPool = mock(ThreadPool.class);
BulkRetryCoordinator coordinator = new BulkRetryCoordinator(threadPool);
BulkRequestExecutor<ShardUpsertRequest> executor = (request, listener) -> {
listener.onFailure(new EsRejectedExecutionException("Dummy execution rejected"));
};
coordinator.retry(shardRequest(), executor, new ActionListener<ShardResponse>() {
@Override
public void onResponse(ShardResponse shardResponse) {
}
@Override
public void onFailure(Throwable e) {
}
});
verify(threadPool).schedule(eq(TimeValue.timeValueMillis(0)), eq(ThreadPool.Names.SAME), any(Runnable.class));
}
Aggregations