use of io.crate.executor.transport.ShardResponse in project crate by crate.
the class BulkShardProcessor method executeRequests.
private void executeRequests() {
try {
executeLock.acquire();
for (Iterator<Map.Entry<ShardId, Request>> it = requestsByShard.entrySet().iterator(); it.hasNext(); ) {
if (failure.get() != null) {
return;
}
Map.Entry<ShardId, Request> entry = it.next();
final Request request = entry.getValue();
final ShardId shardId = entry.getKey();
requestExecutor.execute(request, new ActionListener<ShardResponse>() {
@Override
public void onResponse(ShardResponse response) {
processResponse(response);
}
@Override
public void onFailure(Throwable t) {
t = SQLExceptions.unwrap(t, throwable -> throwable instanceof RuntimeException);
if (t instanceof ClassCastException || t instanceof NotSerializableExceptionWrapper) {
// this is caused by passing mixed argument types into a bulk upsert.
// it can happen after an valid request already succeeded and data was written.
// so never bubble, but rather mark all items of this request as failed.
markItemsAsFailedAndReleaseRetryLock(request, Optional.absent());
LOGGER.warn("ShardUpsert: {} items failed", t, request.items().size());
return;
}
processFailure(t, shardId, request, Optional.absent());
}
});
it.remove();
}
} catch (InterruptedException e) {
Thread.interrupted();
} catch (Throwable e) {
setFailure(e);
} finally {
requestItemCounter.set(0);
executeLock.release();
}
}
use of io.crate.executor.transport.ShardResponse 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));
}
use of io.crate.executor.transport.ShardResponse in project crate by crate.
the class BulkRetryCoordinatorTest method testNoPendingOperationsOnFailedExecution.
@Test
public void testNoPendingOperationsOnFailedExecution() throws Exception {
ThreadPool threadPool = mock(ThreadPool.class);
BulkRetryCoordinator coordinator = new BulkRetryCoordinator(threadPool);
BulkRequestExecutor<ShardUpsertRequest> executor = (request, listener) -> {
listener.onFailure(new InterruptedException("Dummy execution failed"));
};
final SettableFuture<ShardResponse> future = SettableFuture.create();
coordinator.retry(shardRequest(), executor, new ActionListener<ShardResponse>() {
@Override
public void onResponse(ShardResponse shardResponse) {
}
@Override
public void onFailure(Throwable e) {
future.set(null);
}
});
ShardResponse response = future.get();
assertNull(response);
assertEquals(0, coordinator.numPendingOperations());
}
use of io.crate.executor.transport.ShardResponse in project crate by crate.
the class BulkRetryCoordinatorTest method testParallelSuccessfulExecution.
@Test
public void testParallelSuccessfulExecution() throws Exception {
ThreadPool threadPool = mock(ThreadPool.class);
final BulkRetryCoordinator coordinator = new BulkRetryCoordinator(threadPool);
final BulkRequestExecutor<ShardUpsertRequest> executor = (request, listener) -> {
listener.onResponse(new ShardResponse());
};
final CountDownLatch latch = new CountDownLatch(1000);
ExecutorService executorService = Executors.newFixedThreadPool(10, daemonThreadFactory("DummyThreadPool"));
for (int i = 0; i < 1000; i++) {
executorService.submit(new Runnable() {
@Override
public void run() {
coordinator.retry(shardRequest(), executor, new ActionListener<ShardResponse>() {
@Override
public void onResponse(ShardResponse shardResponse) {
latch.countDown();
}
@Override
public void onFailure(Throwable e) {
}
});
}
});
}
latch.await();
assertEquals(0, coordinator.numPendingOperations());
executorService.awaitTermination(5, TimeUnit.SECONDS);
executorService.shutdown();
}
Aggregations