Search in sources :

Example 1 with PartitionMigrationEvent

use of com.hazelcast.spi.PartitionMigrationEvent in project hazelcast by hazelcast.

the class RingbufferServiceTest method rollbackMigration.

@Test
public void rollbackMigration() {
    Ringbuffer ringbuffer = hz.getRingbuffer("foo");
    int partitionId = getPartitionId(hz, ringbuffer.getName());
    PartitionMigrationEvent partitionEvent = new PartitionMigrationEvent(DESTINATION, partitionId, -1, 0);
    service.rollbackMigration(partitionEvent);
    assertEquals(0, service.getContainers().size());
}
Also used : Ringbuffer(com.hazelcast.ringbuffer.Ringbuffer) PartitionMigrationEvent(com.hazelcast.spi.PartitionMigrationEvent) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with PartitionMigrationEvent

use of com.hazelcast.spi.PartitionMigrationEvent in project hazelcast by hazelcast.

the class CountingMigrationAwareServiceTest method parameters.

@Parameterized.Parameters(name = "{0}, replica: {1}")
public static Collection<Object> parameters() {
    PartitionMigrationEvent promotionEvent = mock(PartitionMigrationEvent.class);
    when(promotionEvent.getNewReplicaIndex()).thenReturn(PRIMARY_REPLICA_INDEX);
    when(promotionEvent.getCurrentReplicaIndex()).thenReturn(1);
    when(promotionEvent.toString()).thenReturn("1 > 0");
    PartitionMigrationEvent demotionEvent = mock(PartitionMigrationEvent.class);
    when(demotionEvent.getNewReplicaIndex()).thenReturn(1);
    when(demotionEvent.getCurrentReplicaIndex()).thenReturn(PRIMARY_REPLICA_INDEX);
    when(demotionEvent.toString()).thenReturn("0 > 1");
    PartitionMigrationEvent backupsEvent = mock(PartitionMigrationEvent.class);
    when(backupsEvent.getNewReplicaIndex()).thenReturn(1);
    when(backupsEvent.getCurrentReplicaIndex()).thenReturn(2);
    when(backupsEvent.toString()).thenReturn("2 > 1");
    return Arrays.asList(new Object[] { new Object[] { new NoOpMigrationAwareService(), promotionEvent }, new Object[] { new NoOpMigrationAwareService(), demotionEvent }, new Object[] { new NoOpMigrationAwareService(), backupsEvent }, new Object[] { new ExceptionThrowingMigrationAwareService(), promotionEvent }, new Object[] { new ExceptionThrowingMigrationAwareService(), demotionEvent }, new Object[] { new ExceptionThrowingMigrationAwareService(), backupsEvent } });
}
Also used : PartitionMigrationEvent(com.hazelcast.spi.PartitionMigrationEvent)

Example 3 with PartitionMigrationEvent

use of com.hazelcast.spi.PartitionMigrationEvent in project hazelcast by hazelcast.

the class BaseMigrationOperation method executeBeforeMigrations.

void executeBeforeMigrations() throws Exception {
    NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
    PartitionMigrationEvent event = getMigrationEvent();
    Throwable t = null;
    for (MigrationAwareService service : nodeEngine.getServices(MigrationAwareService.class)) {
        // we need to make sure all beforeMigration() methods are executed
        try {
            service.beforeMigration(event);
        } catch (Throwable e) {
            getLogger().warning("Error while executing beforeMigration()", e);
            t = e;
        }
    }
    if (t != null) {
        throw ExceptionUtil.rethrow(t);
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) PartitionMigrationEvent(com.hazelcast.spi.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.spi.MigrationAwareService)

Example 4 with PartitionMigrationEvent

use of com.hazelcast.spi.PartitionMigrationEvent in project hazelcast by hazelcast.

the class BeforePromotionOperation method run.

@Override
public void run() throws Exception {
    ILogger logger = getLogger();
    if (logger.isFinestEnabled()) {
        logger.finest("Running before promotion for " + getPartitionMigrationEvent());
    }
    PartitionMigrationEvent event = getPartitionMigrationEvent();
    for (MigrationAwareService service : getMigrationAwareServices()) {
        try {
            service.beforeMigration(event);
        } catch (Throwable e) {
            logger.warning("While promoting " + getPartitionMigrationEvent(), e);
        }
    }
}
Also used : PartitionMigrationEvent(com.hazelcast.spi.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.spi.MigrationAwareService) ILogger(com.hazelcast.logging.ILogger)

Example 5 with PartitionMigrationEvent

use of com.hazelcast.spi.PartitionMigrationEvent in project hazelcast by hazelcast.

the class FinalizeMigrationOperation method notifyServices.

private void notifyServices(NodeEngineImpl nodeEngine) {
    PartitionMigrationEvent event = getPartitionMigrationEvent();
    Collection<MigrationAwareService> migrationAwareServices = nodeEngine.getServices(MigrationAwareService.class);
    // knows replica is moved away from itself.
    if (nodeEngine.getThisAddress().equals(migrationInfo.getSource()) && migrationInfo.getSourceCurrentReplicaIndex() > 0) {
        // execute beforeMigration on old backup before commit/rollback
        for (MigrationAwareService service : migrationAwareServices) {
            beforeMigration(event, service);
        }
    }
    for (MigrationAwareService service : migrationAwareServices) {
        finishMigration(event, service);
    }
}
Also used : PartitionMigrationEvent(com.hazelcast.spi.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.spi.MigrationAwareService)

Aggregations

PartitionMigrationEvent (com.hazelcast.spi.PartitionMigrationEvent)5 MigrationAwareService (com.hazelcast.spi.MigrationAwareService)3 ILogger (com.hazelcast.logging.ILogger)1 Ringbuffer (com.hazelcast.ringbuffer.Ringbuffer)1 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 Test (org.junit.Test)1