Search in sources :

Example 1 with OAsyncReplicationOk

use of com.orientechnologies.orient.core.replication.OAsyncReplicationOk in project orientdb by orientechnologies.

the class ODistributedTransactionManager method executeAsyncTx.

protected void executeAsyncTx(final Set<String> nodes, final OTxTaskResult localResult, final Set<String> involvedClusters, final OAbstractReplicatedTask txTask, final long messageId, final String localNodeName, final OCallable<Void, ODistributedRequestId> afterSendCallback) {
    final OAsyncReplicationOk onAsyncReplicationOk = OExecutionThreadLocal.INSTANCE.get().onAsyncReplicationOk;
    final OAsyncReplicationError onAsyncReplicationError = storage.getAsyncReplicationError();
    // ASYNCHRONOUSLY REPLICATE IT TO ALL THE OTHER NODES
    storage.asynchronousExecution(new OAsynchDistributedOperation(storage.getName(), involvedClusters, nodes, txTask, messageId, localResult, afterSendCallback, new OCallable<Object, OPair<ODistributedRequestId, Object>>() {

        @Override
        public Object call(final OPair<ODistributedRequestId, Object> iArgument) {
            try {
                final Object value = iArgument.getValue();
                final ODistributedRequestId reqId = iArgument.getKey();
                if (value instanceof OTxTaskResult) {
                    // SEND 2-PHASE DISTRIBUTED COMMIT TX
                    sendTxCompleted(localNodeName, involvedClusters, nodes, reqId, true, txTask.getPartitionKey());
                    if (onAsyncReplicationOk != null)
                        onAsyncReplicationOk.onAsyncReplicationOk();
                    return null;
                } else if (value instanceof Exception) {
                    try {
                        storage.executeUndoOnLocalServer(reqId, txTask);
                        if (ODistributedServerLog.isDebugEnabled())
                            ODistributedServerLog.debug(this, localNodeName, null, ODistributedServerLog.DIRECTION.NONE, "Async distributed transaction failed: %s", value);
                        // SEND 2-PHASE DISTRIBUTED ROLLBACK TX
                        sendTxCompleted(localNodeName, involvedClusters, nodes, reqId, false, txTask.getPartitionKey());
                        if (value instanceof RuntimeException)
                            throw (RuntimeException) value;
                        else
                            throw OException.wrapException(new OTransactionException("Error on execution async distributed transaction"), (Exception) value);
                    } finally {
                        if (onAsyncReplicationError != null)
                            onAsyncReplicationError.onAsyncReplicationError((Throwable) value, 0);
                    }
                }
                // UNKNOWN RESPONSE TYPE
                if (ODistributedServerLog.isDebugEnabled())
                    ODistributedServerLog.debug(this, localNodeName, null, ODistributedServerLog.DIRECTION.NONE, "Async distributed transaction error, received unknown response type: %s", iArgument);
                throw new OTransactionException("Error on committing async distributed transaction, received unknown response type " + iArgument);
            } finally {
                try {
                    afterSendCallback.call(iArgument.getKey());
                } catch (Exception e) {
                    ODistributedServerLog.debug(this, localNodeName, null, ODistributedServerLog.DIRECTION.NONE, "Error on unlocking Async distributed transaction", e);
                }
            }
        }
    }));
}
Also used : OAsyncReplicationError(com.orientechnologies.orient.core.replication.OAsyncReplicationError) OCallable(com.orientechnologies.common.util.OCallable) OPair(com.orientechnologies.common.util.OPair) OException(com.orientechnologies.common.exception.OException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) IOException(java.io.IOException) OAsyncReplicationOk(com.orientechnologies.orient.core.replication.OAsyncReplicationOk)

Aggregations

ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 OException (com.orientechnologies.common.exception.OException)1 OCallable (com.orientechnologies.common.util.OCallable)1 OPair (com.orientechnologies.common.util.OPair)1 OAsyncReplicationError (com.orientechnologies.orient.core.replication.OAsyncReplicationError)1 OAsyncReplicationOk (com.orientechnologies.orient.core.replication.OAsyncReplicationOk)1 IOException (java.io.IOException)1