Search in sources :

Example 31 with ServiceNamespace

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

the class FinalizeMigrationOperation method commitSource.

/**
 * Updates the replica versions on the migration source if the replica index has changed.
 */
private void commitSource() {
    int partitionId = getPartitionId();
    InternalPartitionServiceImpl partitionService = getService();
    PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
    ILogger logger = getLogger();
    int sourceNewReplicaIndex = migrationInfo.getSourceNewReplicaIndex();
    if (sourceNewReplicaIndex < 0) {
        clearPartitionReplicaVersions(partitionId);
        if (logger.isFinestEnabled()) {
            logger.finest("Replica versions are cleared in source after migration. partitionId=" + partitionId);
        }
    } else if (migrationInfo.getSourceCurrentReplicaIndex() != sourceNewReplicaIndex && sourceNewReplicaIndex > 1) {
        for (ServiceNamespace namespace : replicaManager.getNamespaces(partitionId)) {
            long[] versions = updatePartitionReplicaVersions(replicaManager, partitionId, namespace, sourceNewReplicaIndex - 1);
            if (logger.isFinestEnabled()) {
                logger.finest("Replica versions are set after SHIFT DOWN 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)

Example 32 with ServiceNamespace

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

the class FinalizeMigrationOperation method clearPartitionReplicaVersions.

private void clearPartitionReplicaVersions(int partitionId) {
    InternalPartitionServiceImpl partitionService = getService();
    PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
    for (ServiceNamespace namespace : replicaManager.getNamespaces(partitionId)) {
        replicaManager.clearPartitionReplicaVersions(partitionId, namespace);
    }
}
Also used : InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) PartitionReplicaManager(com.hazelcast.internal.partition.impl.PartitionReplicaManager)

Example 33 with ServiceNamespace

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

the class MigrationOperation method afterMigrate.

private void afterMigrate() {
    ILogger logger = getLogger();
    if (success) {
        InternalPartitionServiceImpl partitionService = getService();
        PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
        int destinationNewReplicaIndex = migrationInfo.getDestinationNewReplicaIndex();
        int replicaOffset = Math.max(destinationNewReplicaIndex, 1);
        Map<ServiceNamespace, long[]> namespaceVersions = fragmentMigrationState.getNamespaceVersionMap();
        for (Entry<ServiceNamespace, long[]> e : namespaceVersions.entrySet()) {
            ServiceNamespace namespace = e.getKey();
            long[] replicaVersions = e.getValue();
            replicaManager.setPartitionReplicaVersions(migrationInfo.getPartitionId(), namespace, replicaVersions, replicaOffset);
            if (logger.isFinestEnabled()) {
                logger.finest("ReplicaVersions are set after migration. " + migrationInfo + ", namespace=" + namespace + ", replicaVersions=" + Arrays.toString(replicaVersions));
            }
        }
    } else if (logger.isFinestEnabled()) {
        logger.finest("ReplicaVersions are not set since migration failed. " + migrationInfo);
    }
}
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)

Example 34 with ServiceNamespace

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

the class PartitionBackupReplicaAntiEntropyOperation method readInternal.

@Override
protected void readInternal(ObjectDataInput in) throws IOException {
    int len = in.readInt();
    versions = new HashMap<>(len);
    for (int i = 0; i < len; i++) {
        ServiceNamespace ns = in.readObject();
        long v = in.readLong();
        versions.put(ns, v);
    }
    returnResponse = in.readBoolean();
}
Also used : ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace)

Example 35 with ServiceNamespace

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

the class PartitionBackupReplicaAntiEntropyOperation method run.

@Override
public void run() {
    if (!isNodeStartCompleted()) {
        response = false;
        return;
    }
    InternalPartitionServiceImpl partitionService = getService();
    int partitionId = getPartitionId();
    int replicaIndex = getReplicaIndex();
    InternalPartitionImpl partition = partitionService.getPartitionStateManager().getPartitionImpl(partitionId);
    int currentReplicaIndex = partition.getReplicaIndex(PartitionReplica.from(getNodeEngine().getLocalMember()));
    ILogger logger = getLogger();
    if (replicaIndex != currentReplicaIndex) {
        logger.fine("Anti-entropy operation for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + " is received, but this node is not the expected backup replica!" + " Current replicaIndex=" + currentReplicaIndex);
        response = false;
        return;
    }
    Address ownerAddress = partition.getOwnerOrNull();
    if (!getCallerAddress().equals(ownerAddress)) {
        logger.fine("Anti-entropy operation for partitionId=" + getPartitionId() + ", replicaIndex=" + getReplicaIndex() + " is received from " + getCallerAddress() + ", but it's not the known primary replica owner: " + ownerAddress);
        response = false;
        return;
    }
    PartitionReplicaManager replicaManager = partitionService.getReplicaManager();
    replicaManager.retainNamespaces(partitionId, versions.keySet());
    if (logger.isFinestEnabled()) {
        logger.finest("Retained namespaces for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ". Namespaces=" + replicaManager.getNamespaces(partitionId));
    }
    Iterator<Map.Entry<ServiceNamespace, Long>> iter = versions.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry<ServiceNamespace, Long> entry = iter.next();
        ServiceNamespace ns = entry.getKey();
        long primaryVersion = entry.getValue();
        long[] currentVersions = replicaManager.getPartitionReplicaVersions(partitionId, ns);
        long currentVersion = currentVersions[replicaIndex - 1];
        if (replicaManager.isPartitionReplicaVersionDirty(partitionId, ns) || currentVersion != primaryVersion) {
            logBackupVersionMismatch(ns, currentVersion, primaryVersion);
            continue;
        }
        iter.remove();
    }
    if (!versions.isEmpty()) {
        replicaManager.triggerPartitionReplicaSync(partitionId, versions.keySet(), replicaIndex);
        response = false;
    }
}
Also used : Address(com.hazelcast.cluster.Address) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) PartitionReplicaManager(com.hazelcast.internal.partition.impl.PartitionReplicaManager) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) ILogger(com.hazelcast.logging.ILogger) HashMap(java.util.HashMap) Map(java.util.Map)

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