Search in sources :

Example 26 with ServiceNamespace

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

the class NameSpaceUtil method getAllNamespaces.

/**
 * @param containers      collection of all containers in a partition
 * @param containerFilter allows only matching containers
 * @param toNamespace     returns {@link ObjectNamespace} for a container
 *
 * @return all service namespaces after functions are applied
 */
public static <T> Collection<ServiceNamespace> getAllNamespaces(Map<?, T> containers, Predicate<T> containerFilter, Function<T, ObjectNamespace> toNamespace) {
    if (MapUtil.isNullOrEmpty(containers)) {
        return Collections.emptySet();
    }
    Collection<ServiceNamespace> collection = Collections.emptySet();
    for (T container : containers.values()) {
        if (!containerFilter.test(container)) {
            continue;
        }
        ObjectNamespace namespace = toNamespace.apply(container);
        if (collection.isEmpty()) {
            collection = singleton(namespace);
            continue;
        }
        if (collection.size() == 1) {
            // previous is an immutable singleton set
            collection = new HashSet<>(collection);
            collection.add(namespace);
            continue;
        }
        collection.add(namespace);
    }
    return collection;
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) ObjectNamespace(com.hazelcast.internal.services.ObjectNamespace)

Example 27 with ServiceNamespace

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

the class CheckPartitionReplicaVersionTask method run.

@Override
public void run() {
    InternalPartition partition = partitionService.getPartition(partitionId);
    if (!partition.isLocal() || partition.isMigrating()) {
        callback.accept(false, null);
        return;
    }
    Collection<ServiceNamespace> namespaces = retainAndGetNamespaces();
    PartitionReplica target = partition.getReplica(replicaIndex);
    if (target == null) {
        callback.accept(false, null);
        return;
    }
    invokePartitionBackupReplicaAntiEntropyOp(replicaIndex, target, namespaces, callback);
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 28 with ServiceNamespace

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

the class ReplicaFragmentMigrationState method readData.

@Override
public void readData(ObjectDataInput in) throws IOException {
    int namespaceSize = in.readInt();
    namespaces = new HashMap<>(namespaceSize);
    for (int i = 0; i < namespaceSize; i++) {
        ServiceNamespace namespace = in.readObject();
        long[] replicaVersions = in.readLongArray();
        namespaces.put(namespace, replicaVersions);
    }
    int migrationOperationSize = in.readInt();
    migrationOperations = new ArrayList<>(migrationOperationSize);
    for (int i = 0; i < migrationOperationSize; i++) {
        Operation migrationOperation = in.readObject();
        migrationOperations.add(migrationOperation);
    }
    migrationOperations = readChunkedOperations(in, migrationOperations);
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) Operation(com.hazelcast.spi.impl.operationservice.Operation)

Example 29 with ServiceNamespace

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

the class AbstractPartitionPrimaryReplicaAntiEntropyTask method invokePartitionBackupReplicaAntiEntropyOp.

final void invokePartitionBackupReplicaAntiEntropyOp(int replicaIndex, PartitionReplica target, Collection<ServiceNamespace> namespaces, BiConsumer<Object, Throwable> callback) {
    if (skipSendingToTarget(target)) {
        return;
    }
    PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
    Map<ServiceNamespace, Long> versionMap = new HashMap<>();
    for (ServiceNamespace ns : namespaces) {
        long[] versions = replicaManager.getPartitionReplicaVersions(partitionId, ns);
        long currentReplicaVersion = versions[replicaIndex - 1];
        versionMap.put(ns, currentReplicaVersion);
    }
    boolean hasCallback = (callback != null);
    Operation op = new PartitionBackupReplicaAntiEntropyOperation(versionMap, hasCallback);
    op.setPartitionId(partitionId).setReplicaIndex(replicaIndex).setServiceName(SERVICE_NAME);
    ILogger logger = nodeEngine.getLogger(getClass());
    if (logger.isFinestEnabled()) {
        logger.finest("Sending anti-entropy operation to " + target + " for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + versionMap);
    }
    OperationService operationService = nodeEngine.getOperationService();
    if (hasCallback) {
        operationService.createInvocationBuilder(SERVICE_NAME, op, target.address()).setTryCount(OPERATION_TRY_COUNT).setTryPauseMillis(OPERATION_TRY_PAUSE_MILLIS).invoke().whenCompleteAsync(callback);
    } else {
        operationService.send(op, target.address());
    }
}
Also used : HashMap(java.util.HashMap) PartitionBackupReplicaAntiEntropyOperation(com.hazelcast.internal.partition.operation.PartitionBackupReplicaAntiEntropyOperation) NonFragmentedServiceNamespace(com.hazelcast.internal.partition.NonFragmentedServiceNamespace) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) ILogger(com.hazelcast.logging.ILogger) PartitionBackupReplicaAntiEntropyOperation(com.hazelcast.internal.partition.operation.PartitionBackupReplicaAntiEntropyOperation) UrgentSystemOperation(com.hazelcast.spi.impl.operationservice.UrgentSystemOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService)

Example 30 with ServiceNamespace

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

the class FinalizeMigrationOperation method rollbackDestination.

/**
 * Updates the replica versions on the migration destination.
 */
private void rollbackDestination() {
    int partitionId = getPartitionId();
    InternalPartitionServiceImpl partitionService = getService();
    PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
    ILogger logger = getLogger();
    int destinationCurrentReplicaIndex = migrationInfo.getDestinationCurrentReplicaIndex();
    if (destinationCurrentReplicaIndex == -1) {
        clearPartitionReplicaVersions(partitionId);
        if (logger.isFinestEnabled()) {
            logger.finest("Replica versions are cleared in destination after failed migration. partitionId=" + partitionId);
        }
    } else {
        int replicaOffset = Math.max(migrationInfo.getDestinationCurrentReplicaIndex(), 1);
        for (ServiceNamespace namespace : replicaManager.getNamespaces(partitionId)) {
            long[] versions = updatePartitionReplicaVersions(replicaManager, partitionId, namespace, replicaOffset - 1);
            if (logger.isFinestEnabled()) {
                logger.finest("Replica versions are rolled back in destination after failed migration. partitionId=" + partitionId + " namespace: " + namespace + " replica versions=" + Arrays.toString(versions));
            }
        }
    }
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) PartitionReplicaManager(com.hazelcast.internal.partition.impl.PartitionReplicaManager) ILogger(com.hazelcast.logging.ILogger) MigrationEndpoint(com.hazelcast.internal.partition.MigrationEndpoint)

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