use of com.hazelcast.internal.partition.PartitionMigrationEvent in project hazelcast by hazelcast.
the class BaseMigrationOperation method executeBeforeMigrations.
/**
* Notifies all {@link MigrationAwareService}s that the migration is starting.
*/
void executeBeforeMigrations() throws Exception {
PartitionMigrationEvent event = getMigrationEvent();
Throwable t = null;
for (MigrationAwareService service : getMigrationAwareServices()) {
// 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.internal.partition.PartitionMigrationEvent in project hazelcast by hazelcast.
the class QueryRunnerTest method verifyIndexedQueryFailureWhileMigratingInFlight.
@Test
public void verifyIndexedQueryFailureWhileMigratingInFlight() {
map.addIndex(IndexType.HASH, "this");
Predicate predicate = new EqualPredicate("this", value) {
@Override
public Set<QueryableEntry> filter(QueryContext queryContext) {
// start a new migration while executing an indexed query
mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
return super.filter(queryContext);
}
};
Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
assertNull(result.getPartitionIds());
}
use of com.hazelcast.internal.partition.PartitionMigrationEvent in project hazelcast by hazelcast.
the class QueryRunnerTest method verifyFullScanFailureWhileMigratingInFlight.
@Test
public void verifyFullScanFailureWhileMigratingInFlight() {
Predicate predicate = new EqualPredicate("this", value) {
@Override
protected boolean applyForSingleAttributeValue(Comparable attributeValue) {
// start a new migration while executing a full scan
mapService.beforeMigration(new PartitionMigrationEvent(MigrationEndpoint.SOURCE, partitionId, 0, 1, UUID.randomUUID()));
return super.applyForSingleAttributeValue(attributeValue);
}
};
Query query = Query.of().mapName(map.getName()).predicate(predicate).iterationType(IterationType.ENTRY).partitionIdSet(SetUtil.allPartitionIds(instance.getPartitionService().getPartitions().size())).build();
QueryResult result = (QueryResult) queryRunner.runIndexOrPartitionScanQueryOnOwnedPartitions(query);
assertNull(result.getPartitionIds());
}
use of com.hazelcast.internal.partition.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 } });
}
Aggregations