Search in sources :

Example 36 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace 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)

Example 37 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class MigrationRequestOperation method createNextChunkedState.

@Nullable
private ReplicaFragmentMigrationState createNextChunkedState() {
    // if no current namespace exists, this is
    // the start of migration process, just return
    ServiceNamespace currentNS = namespacesContext.current();
    if (currentNS == null) {
        return null;
    }
    Collection<ChunkSupplier> chunkSuppliers = namespaceToSuppliers.get(currentNS);
    if (chunkSuppliers == null) {
        // migration, hence no chunk supplier.
        return null;
    }
    // remove finished suppliers for currentNS
    Iterator<ChunkSupplier> iterator = chunkSuppliers.iterator();
    while (iterator.hasNext()) {
        ChunkSupplier chunkSupplier = iterator.next();
        if (!chunkSupplier.hasNext()) {
            iterator.remove();
        }
    }
    if (isEmpty(chunkSuppliers)) {
        namespaceToSuppliers.remove(currentNS);
        return null;
    }
    // we still have unfinished suppliers
    return createReplicaFragmentMigrationState(singleton(currentNS), emptyList(), chunkSuppliers, maxTotalChunkedDataInBytes);
}
Also used : ChunkSupplier(com.hazelcast.internal.partition.ChunkSupplier) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Nullable(javax.annotation.Nullable)

Example 38 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class MigrationRequestOperation method invokeMigrationOperation.

/**
 * Invokes the {@link MigrationOperation} on the migration destination.
 */
private void invokeMigrationOperation(ReplicaFragmentMigrationState migrationState, boolean firstFragment) {
    assert ThreadUtil.isRunningOnPartitionThread() : "Migration operations must be invoked from a partition thread";
    boolean lastFragment = !namespacesContext.hasNext();
    Operation operation = new MigrationOperation(migrationInfo, firstFragment ? completedMigrations : Collections.emptyList(), partitionStateVersion, migrationState, firstFragment, lastFragment);
    ILogger logger = getLogger();
    if (logger.isFinestEnabled()) {
        Set<ServiceNamespace> namespaces = migrationState != null ? migrationState.getNamespaceVersionMap().keySet() : emptySet();
        logger.finest("Invoking MigrationOperation for namespaces " + namespaces + " and " + migrationInfo + ", firstFragment: " + firstFragment + ", lastFragment: " + lastFragment);
    }
    NodeEngine nodeEngine = getNodeEngine();
    InternalPartitionServiceImpl partitionService = getService();
    ExecutorService asyncExecutor = getNodeEngine().getExecutionService().getExecutor(ExecutionService.ASYNC_EXECUTOR);
    Address target = migrationInfo.getDestinationAddress();
    nodeEngine.getOperationService().createInvocationBuilder(InternalPartitionService.SERVICE_NAME, operation, target).setResultDeserialized(true).setCallTimeout(partitionService.getPartitionMigrationTimeout()).invoke().whenCompleteAsync(new MigrationCallback(), asyncExecutor);
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) Address(com.hazelcast.cluster.Address) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ExecutorService(java.util.concurrent.ExecutorService) ILogger(com.hazelcast.logging.ILogger) UrgentSystemOperation(com.hazelcast.spi.impl.operationservice.UrgentSystemOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 39 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class MigrationRequestOperation method createReplicaFragmentMigrationState.

private ReplicaFragmentMigrationState createReplicaFragmentMigrationState(Collection<ServiceNamespace> namespaces, Collection<Operation> operations, Collection<ChunkSupplier> suppliers, int maxTotalChunkedDataInBytes) {
    InternalPartitionService partitionService = getService();
    PartitionReplicaVersionManager versionManager = partitionService.getPartitionReplicaVersionManager();
    Map<ServiceNamespace, long[]> versions = new HashMap<>(namespaces.size());
    for (ServiceNamespace namespace : namespaces) {
        long[] v = versionManager.getPartitionReplicaVersions(getPartitionId(), namespace);
        versions.put(namespace, v);
    }
    return new ReplicaFragmentMigrationState(versions, operations, suppliers, chunkedMigrationEnabled, maxTotalChunkedDataInBytes, getLogger(), getPartitionId());
}
Also used : ReplicaFragmentMigrationState(com.hazelcast.internal.partition.ReplicaFragmentMigrationState) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) HashMap(java.util.HashMap) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Example 40 with ServiceNamespace

use of com.hazelcast.internal.services.ServiceNamespace in project hazelcast by hazelcast.

the class PartitionReplicaSyncRetryResponse method run.

@Override
public void run() throws Exception {
    final InternalPartitionServiceImpl partitionService = getService();
    final int partitionId = getPartitionId();
    final int replicaIndex = getReplicaIndex();
    PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
    for (ServiceNamespace namespace : namespaces) {
        replicaManager.clearReplicaSyncRequest(partitionId, namespace, replicaIndex);
    }
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) PartitionReplicaManager(com.hazelcast.internal.partition.impl.PartitionReplicaManager)

Aggregations

ServiceNamespace (com.hazelcast.internal.services.ServiceNamespace)40 InternalPartitionServiceImpl (com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl)11 NonFragmentedServiceNamespace (com.hazelcast.internal.partition.NonFragmentedServiceNamespace)10 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 ObjectNamespace (com.hazelcast.internal.services.ObjectNamespace)8 HashMap (java.util.HashMap)7 PartitionReplicaManager (com.hazelcast.internal.partition.impl.PartitionReplicaManager)6 ILogger (com.hazelcast.logging.ILogger)6 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 MigrationEndpoint (com.hazelcast.internal.partition.MigrationEndpoint)4 PartitionReplicaVersionManager (com.hazelcast.internal.partition.PartitionReplicaVersionManager)4 PartitionReplicationEvent (com.hazelcast.internal.partition.PartitionReplicationEvent)4 HashSet (java.util.HashSet)4 Address (com.hazelcast.cluster.Address)3 ChunkSupplier (com.hazelcast.internal.partition.ChunkSupplier)3 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 CachePartitionSegment (com.hazelcast.cache.impl.CachePartitionSegment)2 CacheService (com.hazelcast.cache.impl.CacheService)2 CacheConfig (com.hazelcast.config.CacheConfig)2