Search in sources :

Example 56 with PartitionReplica

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

the class PartitionStateManager method replaceMember.

int replaceMember(Member oldMember, Member newMember) {
    if (!initialized) {
        return 0;
    }
    PartitionReplica oldReplica = PartitionReplica.from(oldMember);
    PartitionReplica newReplica = PartitionReplica.from(newMember);
    int count = 0;
    for (InternalPartitionImpl partition : partitions) {
        if (partition.replaceReplica(oldReplica, newReplica) > -1) {
            count++;
        }
    }
    if (count > 0) {
        node.getNodeExtension().onPartitionStateChange();
        logger.info("Replaced " + oldMember + " with " + newMember + " in partition table in " + count + " partitions.");
    }
    return count;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 57 with PartitionReplica

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

the class PartitionReplicaManager method triggerPartitionReplicaSync.

/**
 * This method is called on a backup node (replica). Given all conditions are satisfied, this method initiates a replica sync
 * operation and registers it to replicaSyncRequest. The operation is scheduled for a future execution if :
 * <ul>
 * <li>the {@code delayMillis} is greater than 0</li>
 * <li>if a migration is not allowed (during repartitioning or a node joining the cluster)</li>
 * <li>the partition is currently migrating</li>
 * <li>another sync request has already been sent</li>
 * <li>the maximum number of parallel synchronizations has already been reached</li>
 * </ul>
 *
 * @param partitionId  the partition which is being synchronized
 * @param namespaces   namespaces of partition replica fragments
 * @param replicaIndex the index of the replica which is being synchronized
 * @throws IllegalArgumentException if the replica index is not between 0 and {@link InternalPartition#MAX_REPLICA_COUNT}
 */
public void triggerPartitionReplicaSync(int partitionId, Collection<ServiceNamespace> namespaces, int replicaIndex) {
    assert replicaIndex >= 0 && replicaIndex < InternalPartition.MAX_REPLICA_COUNT : "Invalid replica index! partitionId=" + partitionId + ", replicaIndex=" + replicaIndex;
    PartitionReplica target = checkAndGetPrimaryReplicaOwner(partitionId, replicaIndex);
    if (target == null) {
        return;
    }
    if (!partitionService.areMigrationTasksAllowed()) {
        logger.finest("Cannot send sync replica request for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + namespaces + ". Sync is not allowed.");
        return;
    }
    InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId);
    if (partition.isMigrating()) {
        logger.finest("Cannot send sync replica request for partitionId=" + partitionId + ", replicaIndex=" + replicaIndex + ", namespaces=" + namespaces + ". Partition is already migrating.");
        return;
    }
    sendSyncReplicaRequest(partitionId, namespaces, replicaIndex, target);
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 58 with PartitionReplica

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

the class PartitionStateGeneratorImpl method updatePartitionState.

private void updatePartitionState(PartitionReplica[][] state, Collection<NodeGroup> groups, int index) {
    for (NodeGroup group : groups) {
        group.postProcessPartitionTable(index);
        for (PartitionReplica replica : group.getReplicas()) {
            PartitionTable table = group.getPartitionTable(replica);
            Set<Integer> set = table.getPartitions(index);
            for (Integer partitionId : set) {
                state[partitionId][index] = replica;
            }
        }
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 59 with PartitionReplica

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

the class PartitionStateGeneratorImpl method initialize.

private void initialize(InternalPartition[] currentState, PartitionReplica[][] state, Collection<Integer> partitions) {
    int partitionCount = currentState.length;
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        InternalPartition p = currentState[partitionId];
        PartitionReplica[] replicas = state[partitionId];
        boolean empty = true;
        for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
            replicas[index] = p.getReplica(index);
            empty &= replicas[index] == null;
        }
        if (empty || partitions != null && !partitions.contains(partitionId)) {
            continue;
        }
        // auto shift-up colder replicas to hotter replicas to fill the empty gaps
        int maxReplicaIndex = InternalPartition.MAX_REPLICA_COUNT - 1;
        for (int index = 0; index < InternalPartition.MAX_REPLICA_COUNT; index++) {
            if (replicas[index] == null) {
                for (int k = maxReplicaIndex; k > index; k--) {
                    if (replicas[k] != null) {
                        replicas[index] = replicas[k];
                        replicas[k] = null;
                        maxReplicaIndex = k - 1;
                        break;
                    }
                }
            }
        }
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 60 with PartitionReplica

use of com.hazelcast.internal.partition.PartitionReplica 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)

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