Search in sources :

Example 1 with OffloadedReplicationPreparation

use of com.hazelcast.internal.partition.OffloadedReplicationPreparation in project hazelcast by hazelcast.

the class AbstractPartitionOperation method collectChunkSuppliers.

private Collection<ChunkSupplier> collectChunkSuppliers(PartitionReplicationEvent event, ServiceNamespace ns, boolean currentThreadIsPartitionThread, Collection<ChunkSupplier> chunkSuppliers, ChunkedMigrationAwareService service) {
    // request execution on partition or async executor thread.
    if (currentThreadIsPartitionThread ^ (service instanceof OffloadedReplicationPreparation && ((OffloadedReplicationPreparation) service).shouldOffload())) {
        return prepareAndAppendNewChunkSupplier(event, ns, service, chunkSuppliers);
    }
    if (currentThreadIsPartitionThread) {
        // migration aware service requested offload, but we
        // are on partition thread execute on async executor
        Future<ChunkSupplier> future = getNodeEngine().getExecutionService().submit(ExecutionService.ASYNC_EXECUTOR, () -> service.newChunkSupplier(event, singleton(ns)));
        try {
            ChunkSupplier supplier = future.get();
            return appendNewElement(chunkSuppliers, supplier);
        } catch (ExecutionException | CancellationException e) {
            ExceptionUtil.rethrow(e.getCause());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            ExceptionUtil.rethrow(e);
        }
    }
    // migration aware service did not request offload but
    // execution is not on partition thread must execute
    // chunk preparation on partition thread
    UrgentPartitionRunnable<ChunkSupplier> partitionThreadRunnable = new UrgentPartitionRunnable<>(event.getPartitionId(), () -> service.newChunkSupplier(event, singleton(ns)));
    getNodeEngine().getOperationService().execute(partitionThreadRunnable);
    ChunkSupplier supplier = partitionThreadRunnable.future.joinInternal();
    return appendNewElement(chunkSuppliers, supplier);
}
Also used : ChunkSupplier(com.hazelcast.internal.partition.ChunkSupplier) CancellationException(java.util.concurrent.CancellationException) OffloadedReplicationPreparation(com.hazelcast.internal.partition.OffloadedReplicationPreparation) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ChunkSupplier (com.hazelcast.internal.partition.ChunkSupplier)1 OffloadedReplicationPreparation (com.hazelcast.internal.partition.OffloadedReplicationPreparation)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1