Search in sources :

Example 6 with InternalPartition

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

the class OperationBackupHandler method makeBackups.

private int makeBackups(BackupAwareOperation backupAwareOp, int partitionId, long[] replicaVersions, int syncBackups, int asyncBackups) {
    int sendSyncBackups;
    int totalBackups = syncBackups + asyncBackups;
    InternalPartitionService partitionService = node.getPartitionService();
    InternalPartition partition = partitionService.getPartition(partitionId);
    if (totalBackups == 1) {
        sendSyncBackups = sendSingleBackup(backupAwareOp, partition, replicaVersions, syncBackups);
    } else {
        sendSyncBackups = sendMultipleBackups(backupAwareOp, partition, replicaVersions, syncBackups, totalBackups);
    }
    return sendSyncBackups;
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) InternalPartition(com.hazelcast.internal.partition.InternalPartition)

Example 7 with InternalPartition

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

the class MigrationCommitTest method shouldCommitMigrationWhenSourceFailsDuringCommit.

@Test
public void shouldCommitMigrationWhenSourceFailsDuringCommit() {
    CountDownLatch migrationStartLatch = new CountDownLatch(1);
    Config config1 = createConfig();
    config1.setLiteMember(true);
    TerminateOtherMemberOnMigrationComplete masterListener = new TerminateOtherMemberOnMigrationComplete(migrationStartLatch);
    config1.addListenerConfig(new ListenerConfig(masterListener));
    HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
    HazelcastInstance hz2 = factory.newHazelcastInstance(createConfig());
    warmUpPartitions(hz1, hz2);
    waitAllForSafeState(hz1, hz2);
    Config config3 = createConfig();
    InternalMigrationListenerImpl targetListener = new InternalMigrationListenerImpl();
    config3.addListenerConfig(new ListenerConfig(targetListener));
    HazelcastInstance hz3 = factory.newHazelcastInstance(config3);
    masterListener.other = hz2;
    migrationStartLatch.countDown();
    waitAllForSafeState(hz1, hz3);
    InternalPartition partition0 = getPartitionService(hz3).getPartition(0);
    InternalPartition partition1 = getPartitionService(hz3).getPartition(1);
    assertEquals(getAddress(hz3), partition0.getOwnerOrNull());
    assertEquals(getAddress(hz3), partition1.getOwnerOrNull());
    assertFalse(partition0.isMigrating());
    assertFalse(partition1.isMigrating());
    assertFalse(masterListener.rollback);
    List<MigrationProgressNotification> notifications = targetListener.getNotifications();
    assertFalse(notifications.isEmpty());
    assertEquals(COMMIT, notifications.get(notifications.size() - 1).event);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) MigrationProgressNotification(com.hazelcast.internal.partition.impl.InternalMigrationListenerTest.MigrationProgressNotification) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) InternalMigrationListenerImpl(com.hazelcast.internal.partition.impl.InternalMigrationListenerTest.InternalMigrationListenerImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 8 with InternalPartition

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

the class MigrationCommitTest method shouldCommitMigrationWhenMasterCrashesAfterDestinationCommit.

@Test
public void shouldCommitMigrationWhenMasterCrashesAfterDestinationCommit() {
    CountDownLatch migrationStartLatch = new CountDownLatch(1);
    Config config1 = createConfig();
    config1.setLiteMember(true);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
    Config config2 = createConfig();
    final CollectMigrationTaskOnCommit sourceListener = new CollectMigrationTaskOnCommit();
    config2.addListenerConfig(new ListenerConfig(sourceListener));
    HazelcastInstance hz2 = factory.newHazelcastInstance(config2);
    warmUpPartitions(hz1, hz2);
    waitAllForSafeState(hz1, hz2);
    Config config3 = createConfig();
    TerminateOtherMemberOnMigrationCommit destinationListener = new TerminateOtherMemberOnMigrationCommit(migrationStartLatch);
    destinationListener.other = hz1;
    config3.addListenerConfig(new ListenerConfig(destinationListener));
    HazelcastInstance hz3 = factory.newHazelcastInstance(config3);
    migrationStartLatch.countDown();
    waitAllForSafeState(hz2, hz3);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(sourceListener.commit);
        }
    });
    InternalPartition hz2Partition = getOwnedPartition(hz2);
    InternalPartition hz3Partition = getOwnedPartition(hz3);
    assertNotNull(hz2Partition);
    assertNotNull(hz3Partition);
    assertNotEquals(hz2Partition, hz3Partition);
    assertFalse(hz2Partition.isMigrating());
    assertFalse(hz3Partition.isMigrating());
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 9 with InternalPartition

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

the class MigrationCommitTest method shouldRollbackMigrationWhenDestinationCrashesDuringCommit.

@Test
public void shouldRollbackMigrationWhenDestinationCrashesDuringCommit() {
    CountDownLatch migrationStartLatch = new CountDownLatch(1);
    Config config1 = createConfig();
    config1.setLiteMember(true);
    DelayMigrationStartOnMaster masterListener = new DelayMigrationStartOnMaster(migrationStartLatch);
    config1.addListenerConfig(new ListenerConfig(masterListener));
    HazelcastInstance hz1 = factory.newHazelcastInstance(config1);
    HazelcastInstance hz2 = factory.newHazelcastInstance(createConfig());
    warmUpPartitions(hz1, hz2);
    waitAllForSafeState(hz1, hz2);
    CountDownLatch terminationLatch = new CountDownLatch(1);
    TerminateOnMigrationCommit memberListener = new TerminateOnMigrationCommit(terminationLatch);
    Config config3 = createConfig();
    config3.addListenerConfig(new ListenerConfig(memberListener));
    HazelcastInstance hz3 = factory.newHazelcastInstance(config3);
    warmUpPartitions(hz1, hz2, hz3);
    migrationStartLatch.countDown();
    waitAllForSafeState(hz1, hz2);
    InternalPartition partition0 = getPartitionService(hz1).getPartition(0);
    InternalPartition partition1 = getPartitionService(hz1).getPartition(1);
    assertEquals(getAddress(hz2), partition0.getOwnerOrNull());
    assertEquals(getAddress(hz2), partition1.getOwnerOrNull());
    assertFalse(partition0.isMigrating());
    assertFalse(partition1.isMigrating());
    assertTrue(masterListener.rollback.get());
    terminationLatch.countDown();
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) InternalPartition(com.hazelcast.internal.partition.InternalPartition) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with InternalPartition

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

the class MigrationCommitTest method shouldCommitMigrationWhenMasterIsMigrationSource.

@Test
public void shouldCommitMigrationWhenMasterIsMigrationSource() {
    HazelcastInstance hz1 = factory.newHazelcastInstance(createConfig());
    Config config2 = createConfig();
    config2.setLiteMember(true);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config2);
    warmUpPartitions(hz1, hz2);
    waitAllForSafeState(hz1, hz2);
    HazelcastInstance hz3 = factory.newHazelcastInstance(createConfig());
    warmUpPartitions(hz3);
    waitAllForSafeState(hz1, hz2, hz3);
    InternalPartition hz1Partition = getOwnedPartition(hz1);
    InternalPartition hz3Partition = getOwnedPartition(hz3);
    assertNotNull(hz1Partition);
    assertNotNull(hz3Partition);
    assertNotEquals(hz1Partition, hz3Partition);
    assertFalse(hz1Partition.isMigrating());
    assertFalse(hz3Partition.isMigrating());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) InternalPartition(com.hazelcast.internal.partition.InternalPartition) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

InternalPartition (com.hazelcast.internal.partition.InternalPartition)26 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 QuickTest (com.hazelcast.test.annotation.QuickTest)13 Test (org.junit.Test)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)12 Address (com.hazelcast.nio.Address)12 Config (com.hazelcast.config.Config)8 ListenerConfig (com.hazelcast.config.ListenerConfig)6 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 AssertTask (com.hazelcast.test.AssertTask)4 ClusterState (com.hazelcast.cluster.ClusterState)3 MigrationInfo (com.hazelcast.internal.partition.MigrationInfo)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 Node (com.hazelcast.instance.Node)2 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)2 PartitionRuntimeState (com.hazelcast.internal.partition.PartitionRuntimeState)2 TargetNotMemberException (com.hazelcast.spi.exception.TargetNotMemberException)2 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)2 TransactionException (com.hazelcast.transaction.TransactionException)2