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);
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations