Search in sources :

Example 1 with ChunkSupplier

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

the class PartitionReplicaSyncRequest method sendOperationsForNamespaces.

/**
 * Send responses for first number of {@code permits} namespaces and remove them from the list.
 */
protected void sendOperationsForNamespaces(int permits) {
    InternalPartitionServiceImpl partitionService = getService();
    try {
        PartitionReplicationEvent event = new PartitionReplicationEvent(getCallerAddress(), partitionId(), getReplicaIndex());
        Iterator<ServiceNamespace> iterator = namespaces.iterator();
        for (int i = 0; i < permits; i++) {
            ServiceNamespace namespace = iterator.next();
            Collection<Operation> operations = Collections.emptyList();
            Collection<ChunkSupplier> chunkSuppliers = Collections.emptyList();
            if (NonFragmentedServiceNamespace.INSTANCE.equals(namespace)) {
                operations = createNonFragmentedReplicationOperations(event);
            } else {
                chunkSuppliers = isChunkedMigrationEnabled() ? collectChunkSuppliers(event, namespace) : chunkSuppliers;
                if (isEmpty(chunkSuppliers)) {
                    operations = createFragmentReplicationOperations(event, namespace);
                }
            }
            sendOperations(operations, chunkSuppliers, namespace);
            while (hasRemainingChunksToSend(chunkSuppliers)) {
                sendOperations(operations, chunkSuppliers, namespace);
            }
            iterator.remove();
        }
    } finally {
        partitionService.getReplicaManager().releaseReplicaSyncPermits(permits);
    }
}
Also used : ChunkSupplier(com.hazelcast.internal.partition.ChunkSupplier) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Operation(com.hazelcast.spi.impl.operationservice.Operation) MigrationCycleOperation(com.hazelcast.internal.partition.MigrationCycleOperation) PartitionAwareOperation(com.hazelcast.spi.impl.operationservice.PartitionAwareOperation) PartitionReplicationEvent(com.hazelcast.internal.partition.PartitionReplicationEvent)

Example 2 with ChunkSupplier

use of com.hazelcast.internal.partition.ChunkSupplier 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)

Example 3 with ChunkSupplier

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

the class AbstractPartitionOperation method collectChunkSuppliers.

@Nonnull
final Collection<ChunkSupplier> collectChunkSuppliers(PartitionReplicationEvent event, Collection<String> serviceNames, ServiceNamespace namespace) {
    ILogger logger = getLogger();
    logger.fine("Collecting chunk suppliers...");
    Collection<ChunkSupplier> chunkSuppliers = emptyList();
    NodeEngine nodeEngine = getNodeEngine();
    for (String serviceName : serviceNames) {
        Object service = nodeEngine.getService(serviceName);
        if (!(service instanceof ChunkedMigrationAwareService)) {
            // skip not chunked services
            continue;
        }
        chunkSuppliers = collectChunkSuppliers(event, namespace, isRunningOnPartitionThread(), chunkSuppliers, ((ChunkedMigrationAwareService) service));
        if (logger.isFineEnabled()) {
            logger.fine(String.format("Created chunk supplier:[%s, partitionId:%d]", namespace, event.getPartitionId()));
        }
    }
    return chunkSuppliers;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) ChunkedMigrationAwareService(com.hazelcast.internal.partition.ChunkedMigrationAwareService) ChunkSupplier(com.hazelcast.internal.partition.ChunkSupplier) ILogger(com.hazelcast.logging.ILogger) Nonnull(javax.annotation.Nonnull)

Example 4 with ChunkSupplier

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

the class AbstractPartitionOperation method collectChunkSuppliers.

@Nonnull
final Collection<ChunkSupplier> collectChunkSuppliers(PartitionReplicationEvent event, ServiceNamespace ns) {
    assert !(ns instanceof NonFragmentedServiceNamespace) : ns + " should be used only for chunked migrations enabled services!";
    ILogger logger = getLogger();
    logger.fine("Collecting chunk chunk suppliers...");
    Collection<ChunkSupplier> chunkSuppliers = Collections.emptyList();
    NodeEngine nodeEngine = getNodeEngine();
    Collection<ChunkedMigrationAwareService> services = nodeEngine.getServices(ChunkedMigrationAwareService.class);
    for (ChunkedMigrationAwareService service : services) {
        if (!service.isKnownServiceNamespace(ns)) {
            continue;
        }
        chunkSuppliers = collectChunkSuppliers(event, ns, isRunningOnPartitionThread(), chunkSuppliers, service);
        if (logger.isFineEnabled()) {
            logger.fine(String.format("Created chunk supplier:[%s, partitionId:%d]", ns, event.getPartitionId()));
        }
    }
    return chunkSuppliers;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) ChunkedMigrationAwareService(com.hazelcast.internal.partition.ChunkedMigrationAwareService) ChunkSupplier(com.hazelcast.internal.partition.ChunkSupplier) ILogger(com.hazelcast.logging.ILogger) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) Nonnull(javax.annotation.Nonnull)

Example 5 with ChunkSupplier

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

the class AbstractPartitionOperation method prepareAndAppendNewChunkSupplier.

private Collection<ChunkSupplier> prepareAndAppendNewChunkSupplier(PartitionReplicationEvent event, ServiceNamespace ns, ChunkedMigrationAwareService service, Collection<ChunkSupplier> chunkSuppliers) {
    ChunkSupplier supplier = service.newChunkSupplier(event, singleton(ns));
    if (supplier == null) {
        return chunkSuppliers;
    }
    if (isEmpty(chunkSuppliers)) {
        chunkSuppliers = newSetOf(chunkSuppliers);
    }
    chunkSuppliers.add(supplier);
    return chunkSuppliers;
}
Also used : ChunkSupplier(com.hazelcast.internal.partition.ChunkSupplier)

Aggregations

ChunkSupplier (com.hazelcast.internal.partition.ChunkSupplier)7 NonFragmentedServiceNamespace (com.hazelcast.internal.partition.NonFragmentedServiceNamespace)4 ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)3 ChunkedMigrationAwareService (com.hazelcast.internal.partition.ChunkedMigrationAwareService)2 PartitionReplicationEvent (com.hazelcast.internal.partition.PartitionReplicationEvent)2 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)2 ILogger (com.hazelcast.logging.ILogger)2 NodeEngine (com.hazelcast.spi.impl.NodeEngine)2 Operation (com.hazelcast.spi.impl.operationservice.Operation)2 Nonnull (javax.annotation.Nonnull)2 MigrationCycleOperation (com.hazelcast.internal.partition.MigrationCycleOperation)1 OffloadedReplicationPreparation (com.hazelcast.internal.partition.OffloadedReplicationPreparation)1 PartitionAwareOperation (com.hazelcast.spi.impl.operationservice.PartitionAwareOperation)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 Nullable (javax.annotation.Nullable)1