Search in sources :

Example 1 with IndeterminateOperationStateException

use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.

the class IndeterminateOperationStateExceptionTest method partitionInvocation_shouldFail_whenPartitionPrimaryLeaves.

@Test
public void partitionInvocation_shouldFail_whenPartitionPrimaryLeaves() throws InterruptedException, TimeoutException {
    setup(true);
    int partitionId = getPartitionId(instance2);
    OperationServiceImpl operationService = getNodeEngineImpl(instance1).getOperationService();
    InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new SilentOperation(), partitionId).invoke();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertTrue(instance2.getUserContext().containsKey(SilentOperation.EXECUTION_STARTED));
        }
    });
    spawn(new Runnable() {

        @Override
        public void run() {
            instance2.getLifecycleService().terminate();
        }
    });
    try {
        future.get(2, TimeUnit.MINUTES);
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof IndeterminateOperationStateException);
    }
}
Also used : AssertTask(com.hazelcast.test.AssertTask) IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException) ExecutionException(java.util.concurrent.ExecutionException) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with IndeterminateOperationStateException

use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.

the class BaseInvocation method detectAndHandleBackupTimeout.

/**
 * @param timeoutMillis timeout value to wait for backups after  the response received
 * @return true if invocation is completed
 */
public boolean detectAndHandleBackupTimeout(long timeoutMillis) {
    // since the backupsAcksExpected will always be equal to the backupsAcksReceived
    if (backupsAcksExpected == backupsAcksReceived) {
        return false;
    }
    // if the response of the primary has been received, but the backups have not replied
    if (pendingResponse == VOID) {
        return false;
    }
    // if this has not yet expired (so has not been in the system for a too long period) we ignore it
    long expirationTime = pendingResponseReceivedMillis + timeoutMillis;
    boolean timeoutReached = expirationTime > 0 && expirationTime < Clock.currentTimeMillis();
    if (!timeoutReached) {
        return false;
    }
    if (shouldFailOnIndeterminateOperationState()) {
        completeExceptionally(new IndeterminateOperationStateException(this + " failed because backup acks missed."));
        return true;
    }
    if (shouldCompleteWithoutBackups()) {
        // the backups have not yet completed, but we are going to release the future anyway if a pendingResponse has been set
        completeWithPendingResponse();
        return true;
    }
    return false;
}
Also used : IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException)

Example 3 with IndeterminateOperationStateException

use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.

the class InvocationFuture method resolve.

@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" })
@Override
protected Object resolve(Object unresolved) {
    if (unresolved == null) {
        return null;
    } else if (unresolved == INTERRUPTED) {
        return new ExceptionalResult(new InterruptedException(invocation.op.getClass().getSimpleName() + " was interrupted. " + invocation));
    } else if (unresolved == CALL_TIMEOUT) {
        return new ExceptionalResult(newOperationTimeoutException(false));
    } else if (unresolved == HEARTBEAT_TIMEOUT) {
        return new ExceptionalResult(newOperationTimeoutException(true));
    } else if (unresolved.getClass() == Packet.class) {
        NormalResponse response = invocation.context.serializationService.toObject(unresolved);
        unresolved = response.getValue();
    }
    Object value = unresolved;
    if (deserialize && value instanceof Data) {
        value = invocation.context.serializationService.toObject(value);
        if (value == null) {
            return null;
        }
    }
    Throwable cause = (value instanceof ExceptionalResult) ? ((ExceptionalResult) value).getCause() : null;
    if (invocation.shouldFailOnIndeterminateOperationState() && (value instanceof IndeterminateOperationState || cause instanceof IndeterminateOperationState)) {
        value = wrapThrowable(new IndeterminateOperationStateException("indeterminate operation state", cause == null ? (Throwable) value : cause));
    }
    return value;
}
Also used : Data(com.hazelcast.internal.serialization.Data) IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) IndeterminateOperationState(com.hazelcast.core.IndeterminateOperationState)

Example 4 with IndeterminateOperationStateException

use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.

the class IndeterminateOperationStateExceptionTest method transaction_shouldFail_whenBackupTimeoutOccurs.

@Test
public void transaction_shouldFail_whenBackupTimeoutOccurs() {
    setup(true);
    dropOperationsBetween(instance1, instance2, F_ID, singletonList(SpiDataSerializerHook.BACKUP));
    dropOperationsBetween(instance2, instance1, F_ID, singletonList(SpiDataSerializerHook.BACKUP));
    String name = randomMapName();
    String key1 = generateKeyOwnedBy(instance1);
    String key2 = generateKeyOwnedBy(instance2);
    TransactionContext context = instance1.newTransactionContext();
    context.beginTransaction();
    try {
        TransactionalMap<Object, Object> map = context.getMap(name);
        map.put(key1, "value");
        map.put(key2, "value");
        context.commitTransaction();
        fail("Should fail with IndeterminateOperationStateException");
    } catch (IndeterminateOperationStateException e) {
        context.rollbackTransaction();
    }
    IMap<Object, Object> map = instance1.getMap(name);
    assertNull(map.get(key1));
    assertNull(map.get(key2));
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with IndeterminateOperationStateException

use of com.hazelcast.core.IndeterminateOperationStateException in project hazelcast by hazelcast.

the class IndeterminateOperationStateExceptionTest method partitionInvocation_shouldFailOnBackupTimeout_whenConfigurationEnabledForInvocation.

@Test
public void partitionInvocation_shouldFailOnBackupTimeout_whenConfigurationEnabledForInvocation() throws InterruptedException, TimeoutException {
    setup(false);
    dropOperationsBetween(instance1, instance2, F_ID, singletonList(SpiDataSerializerHook.BACKUP));
    int partitionId = getPartitionId(instance1);
    OperationServiceImpl operationService = getNodeEngineImpl(instance1).getOperationService();
    InternalCompletableFuture<Object> future = operationService.createInvocationBuilder(InternalPartitionService.SERVICE_NAME, new PrimaryOperation(), partitionId).setFailOnIndeterminateOperationState(true).invoke();
    try {
        future.get(2, TimeUnit.MINUTES);
        fail();
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof IndeterminateOperationStateException);
    }
}
Also used : IndeterminateOperationStateException(com.hazelcast.core.IndeterminateOperationStateException) ExecutionException(java.util.concurrent.ExecutionException) OperationServiceImpl(com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

IndeterminateOperationStateException (com.hazelcast.core.IndeterminateOperationStateException)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 OperationServiceImpl (com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl)3 ExecutionException (java.util.concurrent.ExecutionException)3 IndeterminateOperationState (com.hazelcast.core.IndeterminateOperationState)1 Data (com.hazelcast.internal.serialization.Data)1 NormalResponse (com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse)1 AssertTask (com.hazelcast.test.AssertTask)1 TransactionContext (com.hazelcast.transaction.TransactionContext)1