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);
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations