Search in sources :

Example 1 with PartitionMigratingException

use of com.hazelcast.spi.exception.PartitionMigratingException in project hazelcast by hazelcast.

the class OperationRunnerImpl method ensureNoPartitionProblems.

private void ensureNoPartitionProblems(Operation op) {
    int partitionId = op.getPartitionId();
    if (partitionId < 0) {
        return;
    }
    if (partitionId != getPartitionId()) {
        throw new IllegalStateException("wrong partition, expected: " + getPartitionId() + " but found:" + partitionId);
    }
    if (internalPartition == null) {
        internalPartition = nodeEngine.getPartitionService().getPartition(partitionId);
    }
    if (retryDuringMigration(op) && internalPartition.isMigrating()) {
        throw new PartitionMigratingException(thisAddress, partitionId, op.getClass().getName(), op.getServiceName());
    }
    Address owner = internalPartition.getReplicaAddress(op.getReplicaIndex());
    if (op.validatesTarget() && !thisAddress.equals(owner)) {
        throw new WrongTargetException(thisAddress, owner, partitionId, op.getReplicaIndex(), op.getClass().getName(), op.getServiceName());
    }
}
Also used : Address(com.hazelcast.nio.Address) OperationAccessor.setCallerAddress(com.hazelcast.spi.OperationAccessor.setCallerAddress) WrongTargetException(com.hazelcast.spi.exception.WrongTargetException) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException)

Example 2 with PartitionMigratingException

use of com.hazelcast.spi.exception.PartitionMigratingException in project hazelcast by hazelcast.

the class OperationParkerImpl method onPartitionMigrate.

// This is executed under partition migration lock!
public void onPartitionMigrate(Address thisAddress, MigrationInfo migrationInfo) {
    if (!thisAddress.equals(migrationInfo.getSource())) {
        return;
    }
    int partitionId = migrationInfo.getPartitionId();
    for (Queue<ParkedOperation> parkQueue : parkQueueMap.values()) {
        Iterator<ParkedOperation> it = parkQueue.iterator();
        while (it.hasNext()) {
            if (Thread.interrupted()) {
                return;
            }
            ParkedOperation parkedOperation = it.next();
            if (!parkedOperation.isValid()) {
                continue;
            }
            Operation op = parkedOperation.getOperation();
            if (partitionId == op.getPartitionId()) {
                parkedOperation.setValid(false);
                PartitionMigratingException pme = new PartitionMigratingException(thisAddress, partitionId, op.getClass().getName(), op.getServiceName());
                OperationResponseHandler responseHandler = op.getOperationResponseHandler();
                responseHandler.sendResponse(op, pme);
                it.remove();
            }
        }
    }
}
Also used : BlockingOperation(com.hazelcast.spi.BlockingOperation) Operation(com.hazelcast.spi.Operation) OperationResponseHandler(com.hazelcast.spi.OperationResponseHandler) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException)

Example 3 with PartitionMigratingException

use of com.hazelcast.spi.exception.PartitionMigratingException in project hazelcast by hazelcast.

the class StaleReadDuringMigrationTest method testReadOperationFailsWhenStaleReadDisabledDuringMigration.

@Test
public void testReadOperationFailsWhenStaleReadDisabledDuringMigration() throws ExecutionException, InterruptedException {
    final Config config = new Config();
    config.setProperty(GroupProperty.DISABLE_STALE_READ_ON_PARTITION_MIGRATION.getName(), "true");
    final InternalCompletableFuture<Boolean> future = invokeOperation(config);
    try {
        future.get();
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof PartitionMigratingException);
    }
}
Also used : Config(com.hazelcast.config.Config) ExecutionException(java.util.concurrent.ExecutionException) PartitionMigratingException(com.hazelcast.spi.exception.PartitionMigratingException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

PartitionMigratingException (com.hazelcast.spi.exception.PartitionMigratingException)3 Config (com.hazelcast.config.Config)1 Address (com.hazelcast.nio.Address)1 BlockingOperation (com.hazelcast.spi.BlockingOperation)1 Operation (com.hazelcast.spi.Operation)1 OperationAccessor.setCallerAddress (com.hazelcast.spi.OperationAccessor.setCallerAddress)1 OperationResponseHandler (com.hazelcast.spi.OperationResponseHandler)1 WrongTargetException (com.hazelcast.spi.exception.WrongTargetException)1 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.junit.Test)1