use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class MigrationPlanner method isCyclic.
private boolean isCyclic(PartitionReplica[] oldReplicas, PartitionReplica[] newReplicas, final int index) {
final PartitionReplica newOwner = newReplicas[index];
int firstIndex = index;
while (true) {
int nextIndex = InternalPartitionImpl.getReplicaIndex(newReplicas, oldReplicas[firstIndex]);
if (nextIndex == -1) {
return false;
}
if (firstIndex == nextIndex) {
return false;
}
if (newOwner.equals(oldReplicas[nextIndex])) {
return true;
}
firstIndex = nextIndex;
}
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionEventManager method sendMigrationEvent.
/**
* Sends a {@link ReplicaMigrationEvent} to the registered event listeners.
*/
public void sendMigrationEvent(MigrationState state, MigrationInfo migrationInfo, long elapsed) {
ClusterServiceImpl clusterService = node.getClusterService();
PartitionReplica sourceReplica = migrationInfo.getSource();
PartitionReplica destReplica = migrationInfo.getDestination();
Member source = sourceReplica != null ? clusterService.getMember(sourceReplica.address(), sourceReplica.uuid()) : null;
Member destination = clusterService.getMember(destReplica.address(), destReplica.uuid());
int partitionId = migrationInfo.getPartitionId();
int replicaIndex = migrationInfo.getDestinationNewReplicaIndex();
boolean success = migrationInfo.getStatus() == MigrationStatus.SUCCESS;
ReplicaMigrationEvent event = new ReplicaMigrationEventImpl(state, partitionId, replicaIndex, source, destination, success, elapsed);
sendMigrationEvent(event);
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class MigrationRequestOperation method executeBeforeMigrations.
@Override
void executeBeforeMigrations() throws Exception {
NodeEngine nodeEngine = getNodeEngine();
PartitionReplica source = migrationInfo.getSource();
boolean ownerMigration = source != null && source.isIdentical(nodeEngine.getLocalMember());
if (!ownerMigration) {
return;
}
super.executeBeforeMigrations();
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class PartitionReplicaSyncRequest method checkPartitionOwner.
/**
* Checks if we are the primary owner of the partition.
*/
protected boolean checkPartitionOwner() {
InternalPartitionServiceImpl partitionService = getService();
PartitionStateManager partitionStateManager = partitionService.getPartitionStateManager();
InternalPartitionImpl partition = partitionStateManager.getPartitionImpl(partitionId());
PartitionReplica owner = partition.getOwnerReplicaOrNull();
NodeEngine nodeEngine = getNodeEngine();
if (owner == null || !owner.isIdentical(nodeEngine.getLocalMember())) {
ILogger logger = getLogger();
if (logger.isFinestEnabled()) {
logger.finest("This node is not owner partition. Cannot process request. partitionId=" + partitionId() + ", replicaIndex=" + getReplicaIndex() + ", namespaces=" + namespaces);
}
return false;
}
return true;
}
use of com.hazelcast.internal.partition.PartitionReplica in project hazelcast by hazelcast.
the class MigrationPlannerTest method shuffle.
private void shuffle(PartitionReplica[] array, int len) {
int index;
PartitionReplica temp;
Random random = new Random();
for (int i = len - 1; i > 0; i--) {
index = random.nextInt(i + 1);
temp = array[index];
array[index] = array[i];
array[i] = temp;
}
}
Aggregations