use of org.elasticsearch.threadpool.ThreadPool 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 org.elasticsearch.threadpool.ThreadPool 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 org.elasticsearch.threadpool.ThreadPool 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();
}
use of org.elasticsearch.threadpool.ThreadPool in project elasticsearch-indexing-proxy by codelibs.
the class IndexingProxyService method launchRequestSender.
private void launchRequestSender(final String index, final long filePosition, final long version, final ActionListener<Map<String, Object>> listener) {
if (logger.isDebugEnabled()) {
logger.debug("Launching RequestSender(" + index + ")");
}
final Map<String, Object> source = new HashMap<>();
source.put(IndexingProxyPlugin.NODE_NAME, nodeName());
source.put(IndexingProxyPlugin.FILE_POSITION, filePosition);
source.put(IndexingProxyPlugin.TIMESTAMP, new Date());
source.put(DOC_TYPE, "index");
final IndexRequestBuilder builder = client.prepareIndex(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, index).setSource(source).setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
if (version > 0) {
builder.setVersion(version);
} else {
builder.setCreate(true);
}
builder.execute(wrap(res -> {
if (res.getResult() == Result.CREATED || res.getResult() == Result.UPDATED) {
final RequestSender sender = new RequestSender(settings, client, threadPool, namedWriteableRegistry, nodeName(), dataPath, index, dataFileFormat, docSenderMap, logger);
final RequestSender oldSender = docSenderMap.put(index, sender);
if (oldSender != null) {
oldSender.terminate();
}
threadPool.schedule(TimeValue.ZERO, Names.GENERIC, sender);
listener.onResponse(source);
} else {
listener.onFailure(new ElasticsearchException("Failed to update .idxproxy index: " + res));
}
}, listener::onFailure));
}
use of org.elasticsearch.threadpool.ThreadPool in project crate by crate.
the class Node method awaitClose.
/**
* Wait for this node to be effectively closed.
*/
// synchronized to prevent running concurrently with close()
public synchronized boolean awaitClose(long timeout, TimeUnit timeUnit) throws InterruptedException {
if (lifecycle.closed() == false) {
// closed yet.
throw new IllegalStateException("Call close() first");
}
ThreadPool threadPool = injector.getInstance(ThreadPool.class);
final boolean terminated = ThreadPool.terminate(threadPool, timeout, timeUnit);
if (terminated) {
// that run on shards run in the threadpool, indices should be effectively closed by now.
if (nodeService.awaitClose(0, TimeUnit.MILLISECONDS) == false) {
throw new IllegalStateException("Some shards are still open after the threadpool terminated. " + "Something is leaking index readers or store references.");
}
}
return terminated;
}
Aggregations