Search in sources :

Example 46 with PartitionReplica

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

the class MigrationPlannerTest method test_SHIFT_UP_toReplicaIndexWithExistingOwner.

@Test
public void test_SHIFT_UP_toReplicaIndexWithExistingOwner() throws UnknownHostException {
    final PartitionReplica[] oldReplicas = { new PartitionReplica(new Address("localhost", 5701), uuids[0]), new PartitionReplica(new Address("localhost", 5702), uuids[1]), new PartitionReplica(new Address("localhost", 5703), uuids[2]), new PartitionReplica(new Address("localhost", 5704), uuids[3]), null, null, null };
    final PartitionReplica[] newReplicas = { new PartitionReplica(new Address("localhost", 5701), uuids[0]), new PartitionReplica(new Address("localhost", 5704), uuids[3]), new PartitionReplica(new Address("localhost", 5703), uuids[2]), null, null, null, null };
    migrationPlanner.planMigrations(0, oldReplicas, newReplicas, callback);
    verify(callback).migrate(new PartitionReplica(new Address("localhost", 5702), uuids[1]), 1, -1, new PartitionReplica(new Address("localhost", 5704), uuids[3]), 3, 1);
}
Also used : Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 47 with PartitionReplica

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

the class MigrationPlannerTest method test_SHIFT_UPS_performedBy_MOVE.

@Test
public void test_SHIFT_UPS_performedBy_MOVE() throws UnknownHostException {
    final PartitionReplica[] oldReplicas = { new PartitionReplica(new Address("localhost", 5701), uuids[0]), new PartitionReplica(new Address("localhost", 5702), uuids[1]), new PartitionReplica(new Address("localhost", 5703), uuids[2]), new PartitionReplica(new Address("localhost", 5704), uuids[3]), null, null, null };
    final PartitionReplica[] newReplicas = { new PartitionReplica(new Address("localhost", 5701), uuids[0]), new PartitionReplica(new Address("localhost", 5703), uuids[2]), new PartitionReplica(new Address("localhost", 5704), uuids[3]), new PartitionReplica(new Address("localhost", 5705), uuids[4]), null, null, null };
    migrationPlanner.planMigrations(0, oldReplicas, newReplicas, callback);
    verify(callback).migrate(new PartitionReplica(new Address("localhost", 5704), uuids[3]), 3, -1, new PartitionReplica(new Address("localhost", 5705), uuids[4]), -1, 3);
    verify(callback).migrate(new PartitionReplica(new Address("localhost", 5703), uuids[2]), 2, -1, new PartitionReplica(new Address("localhost", 5704), uuids[3]), -1, 2);
    verify(callback).migrate(new PartitionReplica(new Address("localhost", 5702), uuids[1]), 1, -1, new PartitionReplica(new Address("localhost", 5703), uuids[2]), -1, 1);
}
Also used : Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 48 with PartitionReplica

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

the class PartitionReplicaStateChecker_triggerAndWaitForReplicaSyncTest method whenHasMissingReplicaOwners_withAddress_thenWaitForMissingReplicaOwners.

@Test
public void whenHasMissingReplicaOwners_withAddress_thenWaitForMissingReplicaOwners() throws Exception {
    configureNeedsReplicaStateCheckResponse();
    Address address = new Address("127.0.0.1", 5701);
    PartitionReplica replica = new PartitionReplica(address, UuidUtil.newUnsecureUUID());
    InternalPartition partition = new ReadonlyInternalPartition(new PartitionReplica[] { replica }, 1, 0);
    partitions.add(partition);
    assertEquals(REPLICA_NOT_OWNED, replicaStateChecker.getPartitionServiceState());
    assertFalse(replicaStateChecker.triggerAndWaitForReplicaSync(10, TimeUnit.MILLISECONDS, 5));
}
Also used : Address(com.hazelcast.cluster.Address) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with PartitionReplica

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

the class Backup method beforeRun.

@Override
public void beforeRun() {
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    int partitionId = getPartitionId();
    InternalPartitionService partitionService = nodeEngine.getPartitionService();
    ILogger logger = getLogger();
    ensureBackupOperationInitialized();
    PartitionReplicaVersionManager versionManager = partitionService.getPartitionReplicaVersionManager();
    namespace = versionManager.getServiceNamespace(backupOp);
    if (!nodeEngine.getNode().getNodeExtension().isStartCompleted()) {
        validationFailure = new IllegalStateException("Ignoring backup! " + "Backup operation is received before startup is completed.");
        if (logger.isFinestEnabled()) {
            logger.finest(validationFailure.getMessage());
        }
        return;
    }
    InternalPartition partition = partitionService.getPartition(partitionId);
    PartitionReplica owner = partition.getReplica(getReplicaIndex());
    if (owner == null || !owner.isIdentical(nodeEngine.getLocalMember())) {
        validationFailure = new IllegalStateException("Wrong target! " + toString() + " cannot be processed! Target should be: " + owner);
        if (logger.isFinestEnabled()) {
            logger.finest(validationFailure.getMessage());
        }
        return;
    }
    if (versionManager.isPartitionReplicaVersionStale(getPartitionId(), namespace, replicaVersions, getReplicaIndex())) {
        validationFailure = new IllegalStateException("Ignoring stale backup with namespace: " + namespace + ", versions: " + Arrays.toString(replicaVersions));
        if (logger.isFineEnabled()) {
            long[] currentVersions = versionManager.getPartitionReplicaVersions(partitionId, namespace);
            logger.fine("Ignoring stale backup! namespace: " + namespace + ", Current-versions: " + Arrays.toString(currentVersions) + ", Backup-versions: " + Arrays.toString(replicaVersions));
        }
        return;
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) ILogger(com.hazelcast.logging.ILogger) InternalPartition(com.hazelcast.internal.partition.InternalPartition) PartitionReplicaVersionManager(com.hazelcast.internal.partition.PartitionReplicaVersionManager)

Example 50 with PartitionReplica

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

the class OperationBackupHandler method sendMultipleBackups.

private int sendMultipleBackups(BackupAwareOperation backupAwareOp, InternalPartition partition, long[] replicaVersions, int syncBackups, int totalBackups) {
    int sendSyncBackups = 0;
    Operation backupOp = getBackupOperation(backupAwareOp);
    if (!(backupOp instanceof TargetAware)) {
        // optimize common case: serialize operation once and send to multiple targets
        Data backupOpData = nodeEngine.getSerializationService().toData(backupOp);
        for (int replicaIndex = 1; replicaIndex <= totalBackups; replicaIndex++) {
            PartitionReplica target = partition.getReplica(replicaIndex);
            if (target == null) {
                continue;
            }
            if (skipSendingBackupToTarget(partition, target)) {
                continue;
            }
            boolean isSyncBackup = replicaIndex <= syncBackups;
            Backup backup = newBackup(backupAwareOp, backupOpData, replicaVersions, replicaIndex, isSyncBackup);
            outboundOperationHandler.send(backup, target.address());
            if (isSyncBackup) {
                sendSyncBackups++;
            }
        }
    } else {
        for (int replicaIndex = 1; replicaIndex <= totalBackups; replicaIndex++) {
            int syncBackupSent = sendSingleBackup(backupAwareOp, partition, replicaVersions, syncBackups, replicaIndex);
            sendSyncBackups += syncBackupSent;
        }
    }
    return sendSyncBackups;
}
Also used : PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) Backup(com.hazelcast.spi.impl.operationservice.impl.operations.Backup) TargetAware(com.hazelcast.spi.impl.operationservice.TargetAware) Data(com.hazelcast.internal.serialization.Data) BackupAwareOperation(com.hazelcast.spi.impl.operationservice.BackupAwareOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation)

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