Search in sources :

Example 6 with PartitionReplica

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

the class PartitionPrimaryReplicaAntiEntropyTask method run.

@Override
public void run() {
    try {
        InternalPartition partition = partitionService.getPartition(partitionId, false);
        if (!partition.isLocal() || partition.isMigrating()) {
            return;
        }
        Collection<ServiceNamespace> namespaces = retainAndGetNamespaces();
        for (int index = 1; index < MAX_REPLICA_COUNT; index++) {
            PartitionReplica replica = partition.getReplica(index);
            if (replica != null) {
                invokePartitionBackupReplicaAntiEntropyOp(index, replica, namespaces, null);
            }
        }
    } finally {
        if (afterRun != null) {
            afterRun.run();
        }
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ServiceNamespace(com.hazelcast.internal.services.ServiceNamespace) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 7 with PartitionReplica

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

the class PartitionReplicaManager method checkAndGetPrimaryReplicaOwner.

/**
 * Checks preconditions for replica sync - if we don't know the owner yet, if this node is the owner or not a replica
 */
PartitionReplica checkAndGetPrimaryReplicaOwner(int partitionId, int replicaIndex) {
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    PartitionReplica owner = partition.getOwnerReplicaOrNull();
    if (owner == null) {
        logger.info("Sync replica target is null, no need to sync -> partitionId=" + partitionId + ", replicaIndex=" + replicaIndex);
        return null;
    }
    PartitionReplica localReplica = PartitionReplica.from(nodeEngine.getLocalMember());
    if (owner.equals(localReplica)) {
        if (logger.isFinestEnabled()) {
            logger.finest("This node is now owner of partition, cannot sync replica -> partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", partition-info=" + partitionStateManager.getPartitionImpl(partitionId));
        }
        return null;
    }
    if (!partition.isOwnerOrBackup(localReplica)) {
        if (logger.isFinestEnabled()) {
            logger.finest("This node is not backup replica of partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + " anymore.");
        }
        return null;
    }
    return owner;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 8 with PartitionReplica

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

the class PartitionStateGeneratorImpl method initializeGroupPartitions.

private void initializeGroupPartitions(PartitionReplica[][] state, Queue<NodeGroup> groups, int replicaCount, boolean aggressive, Collection<Integer> toBeArrangedPartitions) {
    // reset partition before reuse
    for (NodeGroup nodeGroup : groups) {
        nodeGroup.resetPartitions();
    }
    for (int partitionId = 0; partitionId < state.length; partitionId++) {
        PartitionReplica[] replicas = state[partitionId];
        for (int replicaIndex = 0; replicaIndex < InternalPartition.MAX_REPLICA_COUNT; replicaIndex++) {
            if (replicaIndex >= replicaCount) {
                replicas[replicaIndex] = null;
                continue;
            }
            PartitionReplica owner = replicas[replicaIndex];
            boolean valid = false;
            if (owner != null) {
                valid = partitionOwnerAvailable(groups, partitionId, replicaIndex, owner);
            }
            if (!valid) {
                replicas[replicaIndex] = null;
            } else if (aggressive && replicaIndex < AGGRESSIVE_INDEX_THRESHOLD && (toBeArrangedPartitions == null || toBeArrangedPartitions.contains(partitionId))) {
                for (int i = AGGRESSIVE_INDEX_THRESHOLD; i < replicaCount; i++) {
                    replicas[i] = null;
                }
            }
        }
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 9 with PartitionReplica

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

the class PartitionReplicaSyncResponse method nodeNotOwnsBackup.

/**
 * Fail all replication operations with the exception that this node is no longer the replica with the sent index
 */
private void nodeNotOwnsBackup(InternalPartitionImpl partition) {
    int partitionId = getPartitionId();
    int replicaIndex = getReplicaIndex();
    NodeEngine nodeEngine = getNodeEngine();
    ILogger logger = getLogger();
    if (logger.isFinestEnabled()) {
        int currentReplicaIndex = partition.getReplicaIndex(PartitionReplica.from(nodeEngine.getLocalMember()));
        logger.finest("This node is not backup replica of partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + " anymore. current replicaIndex=" + currentReplicaIndex);
    }
    if (operations != null) {
        PartitionReplica replica = partition.getReplica(replicaIndex);
        Member targetMember = null;
        if (replica != null) {
            ClusterServiceImpl clusterService = (ClusterServiceImpl) nodeEngine.getClusterService();
            targetMember = clusterService.getMember(replica.address(), replica.uuid());
        }
        Throwable throwable = new WrongTargetException(nodeEngine.getLocalMember(), targetMember, partitionId, replicaIndex, getClass().getName());
        for (Operation op : operations) {
            prepareOperation(op);
            onOperationFailure(op, throwable);
        }
    }
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) ILogger(com.hazelcast.logging.ILogger) Operation(com.hazelcast.spi.impl.operationservice.Operation) PartitionAwareOperation(com.hazelcast.spi.impl.operationservice.PartitionAwareOperation) UrgentSystemOperation(com.hazelcast.spi.impl.operationservice.UrgentSystemOperation) BackupOperation(com.hazelcast.spi.impl.operationservice.BackupOperation) Member(com.hazelcast.cluster.Member) WrongTargetException(com.hazelcast.spi.exception.WrongTargetException)

Example 10 with PartitionReplica

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

the class InternalPartitionImpl method replaceReplica.

int replaceReplica(PartitionReplica oldReplica, PartitionReplica newReplica) {
    for (int i = 0; i < MAX_REPLICA_COUNT; i++) {
        PartitionReplica currentReplica = replicas[i];
        if (currentReplica == null) {
            break;
        }
        if (currentReplica.equals(oldReplica)) {
            PartitionReplica[] newReplicas = copyOf(replicas, MAX_REPLICA_COUNT);
            newReplicas[i] = newReplica;
            replicas = newReplicas;
            onReplicaChange(i, oldReplica, newReplica);
            return i;
        }
    }
    return -1;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Aggregations

PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)103 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)51 QuickTest (com.hazelcast.test.annotation.QuickTest)51 Test (org.junit.Test)51 Address (com.hazelcast.cluster.Address)44 InternalPartition (com.hazelcast.internal.partition.InternalPartition)17 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)17 ArrayList (java.util.ArrayList)10 Member (com.hazelcast.cluster.Member)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)7 PartitionTableView (com.hazelcast.internal.partition.PartitionTableView)6 ReadonlyInternalPartition (com.hazelcast.internal.partition.ReadonlyInternalPartition)6 ClusterState (com.hazelcast.cluster.ClusterState)5 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 NodeEngine (com.hazelcast.spi.impl.NodeEngine)4 Operation (com.hazelcast.spi.impl.operationservice.Operation)4 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 MemberLeftException (com.hazelcast.core.MemberLeftException)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3