use of com.orientechnologies.orient.core.replication.OAsyncReplicationError in project orientdb by orientechnologies.
the class ServerClusterAsyncGraphTest method executeTest.
@Override
protected void executeTest() throws Exception {
{
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
g.createVertexType("Post");
g.createVertexType("User");
g.createEdgeType("Own");
g.addVertex("class:User");
g.command(new OCommandSQL("insert into Post (content, timestamp) values('test', 1)")).execute();
} finally {
g.shutdown();
}
}
// CHECK VERTEX CREATION ON ALL THE SERVERS
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g2 = factory2.getNoTx();
try {
Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Post")).execute();
Assert.assertTrue(result.iterator().hasNext());
Assert.assertNotNull(result.iterator().next());
} finally {
g2.shutdown();
}
}
{
OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
OrientGraphNoTx g = factory.getNoTx();
try {
g.command(new OCommandSQL("create edge Own from (select from User) to (select from Post)").onAsyncReplicationError(new OAsyncReplicationError() {
@Override
public ACTION onAsyncReplicationError(Throwable iException, int iRetry) {
return iException instanceof ONeedRetryException && iRetry <= 3 ? ACTION.RETRY : ACTION.IGNORE;
}
})).execute();
} finally {
g.shutdown();
}
}
Thread.sleep(1000);
// CHECK VERTEX CREATION ON ALL THE SERVERS
for (int s = 0; s < SERVERS; ++s) {
OrientGraphFactory factory2 = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
OrientGraphNoTx g2 = factory2.getNoTx();
try {
Iterable<OrientVertex> result = g2.command(new OCommandSQL("select from Own")).execute();
Assert.assertTrue(result.iterator().hasNext());
Assert.assertNotNull(result.iterator().next());
result = g2.command(new OCommandSQL("select from Post")).execute();
Assert.assertTrue(result.iterator().hasNext());
final OrientVertex v = result.iterator().next();
Assert.assertNotNull(v);
final Iterable<Edge> inEdges = v.getEdges(Direction.IN);
Assert.assertTrue(inEdges.iterator().hasNext());
Assert.assertNotNull(inEdges.iterator().next());
result = g2.command(new OCommandSQL("select from User")).execute();
Assert.assertTrue(result.iterator().hasNext());
final OrientVertex v2 = result.iterator().next();
Assert.assertNotNull(v2);
final Iterable<Edge> outEdges = v2.getEdges(Direction.OUT);
Assert.assertTrue(outEdges.iterator().hasNext());
Assert.assertNotNull(outEdges.iterator().next());
} finally {
g2.shutdown();
}
}
}
use of com.orientechnologies.orient.core.replication.OAsyncReplicationError in project orientdb by orientechnologies.
the class ODistributedStorage method getAsyncReplicationError.
protected OAsyncReplicationError getAsyncReplicationError() {
if (OExecutionThreadLocal.INSTANCE.get().onAsyncReplicationError != null) {
final OAsyncReplicationError subCallback = OExecutionThreadLocal.INSTANCE.get().onAsyncReplicationError;
final ODatabaseDocumentTx currentDatabase = (ODatabaseDocumentTx) ODatabaseRecordThreadLocal.INSTANCE.get();
final ODatabaseDocumentTx copyDatabase = currentDatabase.copy();
currentDatabase.activateOnCurrentThread();
return new OAsyncReplicationError() {
@Override
public ACTION onAsyncReplicationError(final Throwable iException, final int iRetry) {
copyDatabase.activateOnCurrentThread();
switch(subCallback.onAsyncReplicationError(iException, iRetry)) {
case RETRY:
break;
case IGNORE:
}
return OAsyncReplicationError.ACTION.IGNORE;
}
};
} else
return null;
}
use of com.orientechnologies.orient.core.replication.OAsyncReplicationError 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