Search in sources :

Example 1 with BroadcastTxRollbackOperation

use of com.hazelcast.transaction.impl.operations.BroadcastTxRollbackOperation in project hazelcast by hazelcast.

the class TransactionManagerServiceImpl method finalize.

private boolean finalize(String uuid, String txnId, TxBackupLog log) {
    OperationService operationService = nodeEngine.getOperationService();
    if (!uuid.equals(log.callerUuid)) {
        return false;
    }
    if (log.state == ACTIVE) {
        if (logger.isFinestEnabled()) {
            logger.finest("Rolling-back transaction[id:" + txnId + ", state:ACTIVE] of endpoint " + uuid);
        }
        Collection<Member> memberList = nodeEngine.getClusterService().getMembers();
        Collection<Future> futures = new ArrayList<Future>(memberList.size());
        for (Member member : memberList) {
            Operation op = new BroadcastTxRollbackOperation(txnId);
            Future f = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
            futures.add(f);
        }
        long timeoutMillis = TransactionOptions.getDefault().getTimeoutMillis();
        waitWithDeadline(futures, timeoutMillis, TimeUnit.MILLISECONDS, finalizeExceptionHandler);
    } else {
        TransactionImpl tx;
        if (log.allowedDuringPassiveState) {
            tx = new AllowedDuringPassiveStateTransactionImpl(this, nodeEngine, txnId, log.records, log.timeoutMillis, log.startTime, log.callerUuid);
        } else {
            tx = new TransactionImpl(this, nodeEngine, txnId, log.records, log.timeoutMillis, log.startTime, log.callerUuid);
        }
        if (log.state == COMMITTING) {
            if (logger.isFinestEnabled()) {
                logger.finest("Committing transaction[id:" + txnId + ", state:COMMITTING] of endpoint " + uuid);
            }
            try {
                tx.commit();
            } catch (Throwable e) {
                logger.warning("Error during committing from tx backup!", e);
            }
        } else {
            if (logger.isFinestEnabled()) {
                logger.finest("Rolling-back transaction[id:" + txnId + ", state:" + log.state + "] of endpoint " + uuid);
            }
            try {
                tx.rollback();
            } catch (Throwable e) {
                logger.warning("Error during rolling-back from tx backup!", e);
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.OperationService) BroadcastTxRollbackOperation(com.hazelcast.transaction.impl.operations.BroadcastTxRollbackOperation) Operation(com.hazelcast.spi.Operation) Member(com.hazelcast.core.Member) BroadcastTxRollbackOperation(com.hazelcast.transaction.impl.operations.BroadcastTxRollbackOperation)

Example 2 with BroadcastTxRollbackOperation

use of com.hazelcast.transaction.impl.operations.BroadcastTxRollbackOperation in project hazelcast by hazelcast.

the class TransactionManagerServiceImpl method finalizeTransaction.

private boolean finalizeTransaction(UUID uuid, UUID txnId, TxBackupLog log) {
    OperationService operationService = nodeEngine.getOperationService();
    if (!uuid.equals(log.callerUuid)) {
        return false;
    }
    if (log.state == ACTIVE) {
        if (logger.isFinestEnabled()) {
            logger.finest("Rolling-back transaction[id:" + txnId + ", state:ACTIVE] of endpoint " + uuid);
        }
        Collection<Member> memberList = nodeEngine.getClusterService().getMembers();
        Collection<Future> futures = new ArrayList<>(memberList.size());
        for (Member member : memberList) {
            Operation op = new BroadcastTxRollbackOperation(txnId);
            Future f = operationService.invokeOnTarget(SERVICE_NAME, op, member.getAddress());
            futures.add(f);
        }
        long timeoutMillis = TransactionOptions.getDefault().getTimeoutMillis();
        waitWithDeadline(futures, timeoutMillis, TimeUnit.MILLISECONDS, finalizeExceptionHandler);
    } else {
        TransactionImpl tx;
        if (log.allowedDuringPassiveState) {
            tx = new AllowedDuringPassiveStateTransactionImpl(this, nodeEngine, txnId, log.records, log.timeoutMillis, log.startTime, log.callerUuid);
        } else {
            tx = new TransactionImpl(this, nodeEngine, txnId, log.records, log.timeoutMillis, log.startTime, log.callerUuid);
        }
        if (log.state == COMMITTING) {
            if (logger.isFinestEnabled()) {
                logger.finest("Committing transaction[id:" + txnId + ", state:COMMITTING] of endpoint " + uuid);
            }
            try {
                tx.commit();
            } catch (Throwable e) {
                logger.warning("Error during committing from tx backup!", e);
            }
        } else {
            if (logger.isFinestEnabled()) {
                logger.finest("Rolling-back transaction[id:" + txnId + ", state:" + log.state + "] of endpoint " + uuid);
            }
            try {
                tx.rollback();
            } catch (Throwable e) {
                logger.warning("Error during rolling-back from tx backup!", e);
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) BroadcastTxRollbackOperation(com.hazelcast.transaction.impl.operations.BroadcastTxRollbackOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) Member(com.hazelcast.cluster.Member) BroadcastTxRollbackOperation(com.hazelcast.transaction.impl.operations.BroadcastTxRollbackOperation)

Aggregations

BroadcastTxRollbackOperation (com.hazelcast.transaction.impl.operations.BroadcastTxRollbackOperation)2 ArrayList (java.util.ArrayList)2 Future (java.util.concurrent.Future)2 Member (com.hazelcast.cluster.Member)1 Member (com.hazelcast.core.Member)1 Operation (com.hazelcast.spi.Operation)1 OperationService (com.hazelcast.spi.OperationService)1 Operation (com.hazelcast.spi.impl.operationservice.Operation)1 OperationService (com.hazelcast.spi.impl.operationservice.OperationService)1