Search in sources :

Example 61 with PartitionReplica

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

the class InternalPartitionImpl method setReplica.

void setReplica(int replicaIndex, PartitionReplica newReplica) {
    PartitionReplica[] newReplicas = copyOf(replicas, MAX_REPLICA_COUNT);
    PartitionReplica oldReplica = newReplicas[replicaIndex];
    newReplicas[replicaIndex] = newReplica;
    replicas = newReplicas;
    onReplicaChange(replicaIndex, oldReplica, newReplica);
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 62 with PartitionReplica

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

the class InternalPartitionImpl method onReplicasChange.

/**
 * Calls the partition replica change interceptor for all changed replicas.
 */
private void onReplicasChange(PartitionReplica[] newReplicas, PartitionReplica[] oldReplicas) {
    for (int replicaIndex = 0; replicaIndex < MAX_REPLICA_COUNT; replicaIndex++) {
        PartitionReplica oldReplicasId = oldReplicas[replicaIndex];
        PartitionReplica newReplicasId = newReplicas[replicaIndex];
        onReplicaChange(replicaIndex, oldReplicasId, newReplicasId);
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 63 with PartitionReplica

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

the class InternalPartitionImpl method swapReplicas.

/**
 * Swaps the replicas for {@code index1} and {@code index2} and call the partition listeners
 */
void swapReplicas(int index1, int index2) {
    PartitionReplica[] newReplicas = copyOf(replicas, MAX_REPLICA_COUNT);
    PartitionReplica a1 = newReplicas[index1];
    PartitionReplica a2 = newReplicas[index2];
    newReplicas[index1] = a2;
    newReplicas[index2] = a1;
    replicas = newReplicas;
    onReplicaChange(index1, a1, a2);
    onReplicaChange(index2, a2, a1);
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 64 with PartitionReplica

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

the class MigrationPlanner method fixCycle.

// Fix cyclic partition replica movements.
// When there are cycles among replica migrations, it's impossible to define a migration order.
// For example followings are cycles:
// - [A,B] -> [B,A]
// - [A,B,C] -> [B,C,A]
boolean fixCycle(PartitionReplica[] oldReplicas, PartitionReplica[] newReplicas) {
    boolean cyclic = false;
    for (int i = 0; i < oldReplicas.length; i++) {
        final PartitionReplica oldAddress = oldReplicas[i];
        final PartitionReplica newAddress = newReplicas[i];
        if (oldAddress == null || newAddress == null || oldAddress.equals(newAddress)) {
            continue;
        }
        if (isCyclic(oldReplicas, newReplicas, i)) {
            fixCycle(oldReplicas, newReplicas, i);
            cyclic = true;
        }
    }
    return cyclic;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 65 with PartitionReplica

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

the class MigrationPlanner method isCyclic.

// Finds whether there's a migration cycle.
// For example followings are cycles:
// - [A,B] -> [B,A]
// - [A,B,C] -> [B,C,A]
boolean isCyclic(PartitionReplica[] oldReplicas, PartitionReplica[] newReplicas) {
    for (int i = 0; i < oldReplicas.length; i++) {
        final PartitionReplica oldAddress = oldReplicas[i];
        final PartitionReplica newAddress = newReplicas[i];
        if (oldAddress == null || newAddress == null || oldAddress.equals(newAddress)) {
            continue;
        }
        if (isCyclic(oldReplicas, newReplicas, i)) {
            return true;
        }
    }
    return false;
}
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