Search in sources :

Example 66 with PartitionReplica

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;
    }
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 67 with PartitionReplica

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);
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ReplicaMigrationEventImpl(com.hazelcast.internal.partition.ReplicaMigrationEventImpl) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) ReplicaMigrationEvent(com.hazelcast.partition.ReplicaMigrationEvent) Member(com.hazelcast.cluster.Member)

Example 68 with PartitionReplica

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();
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica)

Example 69 with PartitionReplica

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;
}
Also used : NodeEngine(com.hazelcast.spi.impl.NodeEngine) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) InternalPartitionServiceImpl(com.hazelcast.internal.partition.impl.InternalPartitionServiceImpl) InternalPartitionImpl(com.hazelcast.internal.partition.impl.InternalPartitionImpl) ILogger(com.hazelcast.logging.ILogger) PartitionStateManager(com.hazelcast.internal.partition.impl.PartitionStateManager)

Example 70 with PartitionReplica

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;
    }
}
Also used : Random(java.util.Random) 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