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());
}
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 } });
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations