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);
}
}
}
}));
}
Aggregations