Search in sources :

Example 6 with PartitionReplicationEvent

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

the class PartitionReplicaSyncRequestOffloadable 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());
        // It is only safe to read replica versions before
        // preparing replication operations. Reasoning: even
        // though partition is already marked as migrating,
        // operations may be already queued in partition thread.
        // If we read replica versions after replication operation
        // is prepared, we may read updated replica versions
        // but replication op may have stale data -> future
        // backup sync checks will not detect the stale data.
        readReplicaVersions();
        final 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 = createFragmentReplicationOperationsOffload(event, namespace);
                }
            }
            // operations failed due to interruption
            if (isNotEmpty(operations) || isNotEmpty(chunkSuppliers)) {
                // TODO why using new CopyOnWriteArrayList<>(chunkSuppliers)?
                sendOperationsOnPartitionThread(new CopyOnWriteArrayList<>(operations), new CopyOnWriteArrayList<>(chunkSuppliers), namespace);
                while (hasRemainingChunksToSend(chunkSuppliers)) {
                    sendOperationsOnPartitionThread(new CopyOnWriteArrayList<>(operations), new CopyOnWriteArrayList<>(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) PartitionReplicationEvent(com.hazelcast.internal.partition.PartitionReplicationEvent)

Aggregations

PartitionReplicationEvent (com.hazelcast.internal.partition.PartitionReplicationEvent)6 Operation (com.hazelcast.spi.impl.operationservice.Operation)5 NonFragmentedServiceNamespace (com.hazelcast.internal.partition.NonFragmentedServiceNamespace)4 ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)4 UrgentSystemOperation (com.hazelcast.spi.impl.operationservice.UrgentSystemOperation)3 ChunkSupplier (com.hazelcast.internal.partition.ChunkSupplier)2 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)2 FragmentedMigrationAwareService (com.hazelcast.internal.partition.FragmentedMigrationAwareService)1 MigrationCycleOperation (com.hazelcast.internal.partition.MigrationCycleOperation)1 ILogger (com.hazelcast.logging.ILogger)1 PartitionAwareOperation (com.hazelcast.spi.impl.operationservice.PartitionAwareOperation)1 HashSet (java.util.HashSet)1