use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class SimulateOperationsAgainstServer method deleteDocument.
protected void deleteDocument(final int threadId, final int iCycle, final String dbUrl, final String className, final int iSkip) {
final ODatabaseDocumentTx db = getDatabase(dbUrl);
for (int retry = 0; retry < MAX_RETRY; ++retry) {
ODocument doc = null;
try {
List<OIdentifiable> result = db.query(new OSQLSynchQuery<Object>("select from " + className + " skip " + iSkip + " limit 1"));
if (result == null || result.isEmpty())
log(threadId, iCycle, dbUrl, " delete no item " + iSkip + " because out of range");
else {
doc = result.get(0).getRecord();
doc.delete();
log(threadId, iCycle, dbUrl, " deleted item " + iSkip + " RID=" + result.get(0));
}
break;
} catch (OConcurrentModificationException e) {
log(threadId, iCycle, dbUrl, " concurrent delete against record " + doc + ", reload it and retry " + retry + "/" + MAX_RETRY + "...");
if (doc != null)
doc.reload(null, true);
} catch (ORecordNotFoundException e) {
log(threadId, iCycle, dbUrl, " delete no item " + iSkip + " because not found");
} finally {
db.close();
}
}
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class StandAloneDatabaseJavaThreadPoolTest method startThread.
private Runnable startThread(final int id, final OrientGraphFactory graphFactory) {
Runnable th = new Runnable() {
@Override
public void run() {
// OrientBaseGraph graph = new OrientGraph(getDBURL());
// OrientGraph graph = graphFactory.getTx();
boolean useSQL = false;
StringBuilder sb = new StringBuilder(".");
for (int m = 0; m < id; m++) {
sb.append(".");
}
long st = System.currentTimeMillis();
try {
String query = "select from Test where prop2='v2-1'";
boolean isRunning = true;
for (int i = 1; i < 10000000 && isRunning; i++) {
if ((i % 2500) == 0) {
long et = System.currentTimeMillis();
log(sb.toString() + " [" + id + "] Total Records Processed: [" + i + "] Current: [2500] Time taken: [" + (et - st) / 1000 + "] seconds");
st = System.currentTimeMillis();
}
OrientGraph graph = graphFactory.getTx();
try {
if (useSQL) {
boolean update = true;
boolean isException = false;
String sql = "Update Test set prop5='" + String.valueOf(System.currentTimeMillis()) + "', updateTime='" + new Date().toString() + "' where prop2='v2-1'";
for (int k = 0; k < 10 && update; k++) {
try {
graph.command(new OCommandSQL(sql)).execute();
if (isException) {
log("********** [" + id + "][" + k + "] Update success after distributed lock Exception");
}
update = false;
break;
} catch (ONeedRetryException ex) {
if (ex instanceof OConcurrentModificationException || ex.getCause() instanceof OConcurrentModificationException) {
} else {
isException = true;
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] ");
}
} catch (ODistributedException ex) {
if (ex.getCause() instanceof OConcurrentModificationException) {
} else {
isException = true;
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] ");
}
} catch (Exception ex) {
log("[" + id + "][" + k + "] Exception " + ex);
}
}
} else {
boolean retry = true;
Iterable<Vertex> vtxs = null;
for (int k = 0; k < 100 && retry; k++) try {
vtxs = graph.command(new OCommandSQL(query)).execute();
break;
} catch (ONeedRetryException e) {
// RETRY
}
for (Vertex vtx : vtxs) {
if (retry) {
retry = true;
boolean isException = false;
for (int k = 0; k < 100 && retry; k++) {
OrientVertex vtx1 = (OrientVertex) vtx;
try {
vtx1.setProperty("prop5", "prop55");
vtx1.setProperty("updateTime", new Date().toString());
graph.commit();
if (isException) {
// log("********** [" + id + "][" + k + "] Update success after distributed lock Exception for vertex " +
// vtx1);
}
retry = false;
break;
} catch (OConcurrentModificationException ex) {
vtx1.reload();
} catch (ONeedRetryException ex) {
if (ex instanceof ONeedRetryException || ex.getCause() instanceof ONeedRetryException) {
vtx1.reload();
} else {
if (ex.getCause() instanceof ConcurrentModificationException) {
ex.printStackTrace();
}
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] for vertex " + vtx1);
}
// log("*** [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ?
// ex.getCause() : "--") + "] for vertex " + vtx1);
isException = true;
} catch (ODistributedException ex) {
if (ex.getCause() instanceof ONeedRetryException) {
vtx1.reload();
} else {
if (ex.getCause() instanceof ConcurrentModificationException) {
ex.printStackTrace();
}
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] for vertex " + vtx1);
}
// log("*** [" + id + "][" + k + "] Distributed Exception: [" + ex + "] Cause: [" + (ex.getCause() != null ?
// ex.getCause() : "--") + "] for vertex " + vtx1);
isException = true;
} catch (Exception ex) {
log("[" + id + "][" + k + "] Exception " + ex + " for vertex " + vtx1);
}
}
if (retry) {
log("*******#################******* [" + id + "] Failed to update after Exception for vertex " + vtx);
}
}
}
}
} finally {
graph.shutdown();
}
}
} catch (Exception ex) {
System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
ex.printStackTrace();
} finally {
log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
}
}
};
return th;
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class TestAsyncReplMode method dbClient1.
protected void dbClient1() {
sleep(1000);
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getLocalURL());
try {
// Create 2 parent vertices.
OrientVertex parentV1 = graph.addVertex("vertextype1", (String) null);
graph.commit();
assertEquals(1, parentV1.getRecord().getVersion());
parentV1Id = parentV1.getId();
OrientVertex parentV2 = graph.addVertex("vertextype2", (String) null);
graph.commit();
assertEquals(1, parentV2.getRecord().getVersion());
parentV2Id = parentV2.getId();
// Create vertices.
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
// sleep(500);
OrientVertex vertex = graph.addVertex("vertextype3", (String) null);
graph.commit();
assertEquals(1, vertex.getRecord().getVersion());
vertex.setProperty("num", i);
graph.commit();
assertEquals(2, vertex.getRecord().getVersion());
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV1.addEdge("edgetype1", vertex);
graph.commit();
assertNotNull(parentV1.getProperty("cnt"));
boolean edge1Exists = false;
for (Edge e : parentV1.getEdges(Direction.OUT, "edgetype1")) {
if (e.getVertex(Direction.IN).equals(vertex)) {
edge1Exists = true;
break;
}
}
assertTrue(edge1Exists);
boolean edge2Exists = false;
for (Edge e : vertex.getEdges(Direction.IN, "edgetype1")) {
if (e.getVertex(Direction.OUT).equals(parentV1)) {
edge2Exists = true;
break;
}
}
assertTrue(edge2Exists);
assertNotNull(vertex.getProperty("num"));
break;
} catch (OConcurrentModificationException c) {
System.out.println("***********ROLLBACK***************");
graph.rollback();
parentV1.reload();
vertex.reload();
}
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV2.addEdge("edgetype2", vertex);
graph.commit();
assertNotNull(parentV2.getProperty("cnt"));
boolean edge1Exists = false;
for (Edge e : parentV2.getEdges(Direction.OUT, "edgetype2")) {
if (e.getVertex(Direction.IN).equals(vertex)) {
edge1Exists = true;
break;
}
}
assertTrue(edge1Exists);
boolean edge2Exists = false;
for (Edge e : vertex.getEdges(Direction.IN, "edgetype2")) {
if (e.getVertex(Direction.OUT).equals(parentV2)) {
edge2Exists = true;
break;
}
}
assertTrue(edge2Exists);
assertNotNull(vertex.getProperty("num"));
break;
} catch (OConcurrentModificationException c) {
System.out.println("***********ROLLBACK***************");
graph.rollback();
parentV2.reload();
vertex.reload();
}
}
}
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
System.out.println("Shutting down");
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class TestAsyncReplMode2Servers method dbClient1.
protected void dbClient1() {
OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getRemoteURL());
try {
OrientVertex parentV1 = graph.addVertex("vertextype", (String) null);
graph.commit();
assertEquals(1, parentV1.getRecord().getVersion());
parentV1Id = parentV1.getId();
OrientVertex parentV2 = graph.addVertex("vertextype", (String) null);
graph.commit();
assertEquals(1, parentV2.getRecord().getVersion());
parentV2Id = parentV2.getId();
int countPropValue = 0;
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV1.setProperty(CNT_PROP_NAME, ++countPropValue);
graph.commit();
System.out.println("Committing parentV1" + parentV1.getRecord() + "...");
break;
} catch (OConcurrentModificationException c) {
graph.rollback();
parentV1.reload();
}
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV2.setProperty(CNT_PROP_NAME, countPropValue);
graph.commit();
System.out.println("Committing parentV2" + parentV2.getRecord() + "...");
break;
} catch (OConcurrentModificationException c) {
graph.rollback();
parentV2.reload();
}
}
}
} catch (Throwable e) {
if (exceptionInThread == null) {
exceptionInThread = e;
}
} finally {
System.out.println("Shutting down");
graph.shutdown();
LOCK.notifyAll();
}
}
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class ORidBagTest method testContentChange.
public void testContentChange() {
ODocument document = new ODocument();
final ORidBag ridBag = new ORidBag();
document.field("ridBag", ridBag);
document.save();
ridBag.add(new ORecordId("#77:10"));
Assert.assertTrue(document.isDirty());
boolean expectCME = false;
if (ORecordInternal.isContentChanged(document)) {
assertEmbedded(true);
expectCME = true;
} else {
assertEmbedded(false);
}
document.save();
ODocument copy = new ODocument();
copy.fromStream(document.toStream());
ORecordInternal.setIdentity(copy, new ORecordId(document.getIdentity()));
ORecordInternal.setVersion(copy, document.getVersion());
ORidBag copyRidBag = copy.field("ridBag");
Assert.assertNotSame(copyRidBag, ridBag);
copyRidBag.add(new ORecordId("#77:11"));
Assert.assertTrue(copy.isDirty());
Assert.assertTrue(!document.isDirty());
ridBag.add(new ORecordId("#77:12"));
Assert.assertTrue(document.isDirty());
document.save();
try {
copy.save();
Assert.assertTrue(!expectCME);
} catch (OConcurrentModificationException cme) {
Assert.assertTrue(expectCME);
}
}
Aggregations