Search in sources :

Example 6 with PartitionMigrationEvent

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);
    }
}
Also used : PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) MigrationAwareService(com.hazelcast.internal.partition.MigrationAwareService)

Example 7 with PartitionMigrationEvent

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());
}
Also used : EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) QueryContext(com.hazelcast.query.impl.QueryContext) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with PartitionMigrationEvent

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());
}
Also used : EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent) EqualPredicate(com.hazelcast.query.impl.predicates.EqualPredicate) Predicate(com.hazelcast.query.Predicate) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 9 with PartitionMigrationEvent

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 } });
}
Also used : PartitionMigrationEvent(com.hazelcast.internal.partition.PartitionMigrationEvent)

Aggregations

PartitionMigrationEvent (com.hazelcast.internal.partition.PartitionMigrationEvent)9 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 Predicate (com.hazelcast.query.Predicate)4 EqualPredicate (com.hazelcast.query.impl.predicates.EqualPredicate)4 MigrationAwareService (com.hazelcast.internal.partition.MigrationAwareService)3 ILogger (com.hazelcast.logging.ILogger)1 QueryContext (com.hazelcast.query.impl.QueryContext)1 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)1 Ringbuffer (com.hazelcast.ringbuffer.Ringbuffer)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1