Search in sources :

Example 6 with ShardResponse

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();
    }
}
Also used : ShardRequest(io.crate.executor.transport.ShardRequest) BulkCreateIndicesRequest(org.elasticsearch.action.admin.indices.create.BulkCreateIndicesRequest) ShardId(org.elasticsearch.index.shard.ShardId) ShardResponse(io.crate.executor.transport.ShardResponse) NotSerializableExceptionWrapper(org.elasticsearch.common.io.stream.NotSerializableExceptionWrapper)

Example 7 with ShardResponse

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));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Reference(io.crate.metadata.Reference) Test(org.junit.Test) TableIdent(io.crate.metadata.TableIdent) UUID(java.util.UUID) SettableFuture(com.google.common.util.concurrent.SettableFuture) CrateUnitTest(io.crate.test.integration.CrateUnitTest) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) RowGranularity(io.crate.metadata.RowGranularity) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) DataTypes(io.crate.types.DataTypes) TimeValue(org.elasticsearch.common.unit.TimeValue) ShardResponse(io.crate.executor.transport.ShardResponse) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ReferenceIdent(io.crate.metadata.ReferenceIdent) EsExecutors.daemonThreadFactory(org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadFactory) ActionListener(org.elasticsearch.action.ActionListener) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ShardResponse(io.crate.executor.transport.ShardResponse) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 8 with ShardResponse

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());
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Reference(io.crate.metadata.Reference) Test(org.junit.Test) TableIdent(io.crate.metadata.TableIdent) UUID(java.util.UUID) SettableFuture(com.google.common.util.concurrent.SettableFuture) CrateUnitTest(io.crate.test.integration.CrateUnitTest) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) RowGranularity(io.crate.metadata.RowGranularity) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) DataTypes(io.crate.types.DataTypes) TimeValue(org.elasticsearch.common.unit.TimeValue) ShardResponse(io.crate.executor.transport.ShardResponse) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ReferenceIdent(io.crate.metadata.ReferenceIdent) EsExecutors.daemonThreadFactory(org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadFactory) ActionListener(org.elasticsearch.action.ActionListener) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ShardResponse(io.crate.executor.transport.ShardResponse) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 9 with ShardResponse

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();
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) Reference(io.crate.metadata.Reference) Test(org.junit.Test) TableIdent(io.crate.metadata.TableIdent) UUID(java.util.UUID) SettableFuture(com.google.common.util.concurrent.SettableFuture) CrateUnitTest(io.crate.test.integration.CrateUnitTest) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Matchers.any(org.mockito.Matchers.any) CountDownLatch(java.util.concurrent.CountDownLatch) Mockito(org.mockito.Mockito) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) RowGranularity(io.crate.metadata.RowGranularity) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) DataTypes(io.crate.types.DataTypes) TimeValue(org.elasticsearch.common.unit.TimeValue) ShardResponse(io.crate.executor.transport.ShardResponse) ThreadPool(org.elasticsearch.threadpool.ThreadPool) ReferenceIdent(io.crate.metadata.ReferenceIdent) EsExecutors.daemonThreadFactory(org.elasticsearch.common.util.concurrent.EsExecutors.daemonThreadFactory) ActionListener(org.elasticsearch.action.ActionListener) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) ShardUpsertRequest(io.crate.executor.transport.ShardUpsertRequest) ThreadPool(org.elasticsearch.threadpool.ThreadPool) CountDownLatch(java.util.concurrent.CountDownLatch) ShardResponse(io.crate.executor.transport.ShardResponse) ActionListener(org.elasticsearch.action.ActionListener) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

ShardResponse (io.crate.executor.transport.ShardResponse)9 ShardUpsertRequest (io.crate.executor.transport.ShardUpsertRequest)7 CrateUnitTest (io.crate.test.integration.CrateUnitTest)7 ActionListener (org.elasticsearch.action.ActionListener)7 EsRejectedExecutionException (org.elasticsearch.common.util.concurrent.EsRejectedExecutionException)7 ShardId (org.elasticsearch.index.shard.ShardId)7 Test (org.junit.Test)7 Reference (io.crate.metadata.Reference)6 ReferenceIdent (io.crate.metadata.ReferenceIdent)6 RowGranularity (io.crate.metadata.RowGranularity)6 TableIdent (io.crate.metadata.TableIdent)6 DataTypes (io.crate.types.DataTypes)6 UUID (java.util.UUID)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 ThreadPool (org.elasticsearch.threadpool.ThreadPool)6 Matchers.any (org.mockito.Matchers.any)6 SettableFuture (com.google.common.util.concurrent.SettableFuture)3 java.util.concurrent (java.util.concurrent)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutorService (java.util.concurrent.ExecutorService)3