use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method testRandomChangedInTxWithCME.
public void testRandomChangedInTxWithCME() {
final ODocument cmeDoc = new ODocument();
cmeDoc.save();
Random rnd = new Random();
final int levels = rnd.nextInt(2) + 1;
final List<Integer> amountOfAddedDocsPerLevel = new ArrayList<Integer>();
final List<Integer> amountOfAddedDocsAfterSavePerLevel = new ArrayList<Integer>();
final List<Integer> amountOfDeletedDocsPerLevel = new ArrayList<Integer>();
Map<LevelKey, List<OIdentifiable>> addedDocPerLevel = new HashMap<LevelKey, List<OIdentifiable>>();
for (int i = 0; i < levels; i++) {
amountOfAddedDocsPerLevel.add(rnd.nextInt(5) + 10);
amountOfAddedDocsAfterSavePerLevel.add(rnd.nextInt(5) + 5);
amountOfDeletedDocsPerLevel.add(rnd.nextInt(5) + 5);
}
database.getLocalCache().clear();
ODocument staleCMEDoc = database.load(cmeDoc.getIdentity());
Assert.assertNotSame(staleCMEDoc, cmeDoc);
cmeDoc.field("v", "v");
cmeDoc.save();
database.begin();
ODocument rootDoc = new ODocument();
createDocsForLevel(amountOfAddedDocsPerLevel, 0, levels, addedDocPerLevel, rootDoc);
database.commit();
addedDocPerLevel = new HashMap<LevelKey, List<OIdentifiable>>(addedDocPerLevel);
rootDoc = database.load(rootDoc.getIdentity());
database.begin();
deleteDocsForLevel(amountOfDeletedDocsPerLevel, 0, levels, rootDoc, rnd);
addDocsForLevel(amountOfAddedDocsAfterSavePerLevel, 0, levels, rootDoc);
staleCMEDoc.field("v", "vn");
staleCMEDoc.save();
try {
database.commit();
Assert.fail();
} catch (OConcurrentModificationException e) {
}
rootDoc = database.load(rootDoc.getIdentity());
assertDocsAfterRollback(0, levels, addedDocPerLevel, rootDoc);
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class HALocalGraphTest 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 < TOTAL_CYCLES_PER_THREAD && 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();
}
if (sleep > 0)
Thread.sleep(sleep);
OrientGraph graph = graphFactory.getTx();
if (!graph.getRawGraph().getURL().startsWith("remote:"))
Assert.assertTrue(graph.getVertexType("Test").getClusterSelection() instanceof OLocalClusterWrapperStrategy);
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());
vtx1.setProperty("blob", new byte[1000]);
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 ODistributedRecordLockedException) {
if (k > 20)
log("*$$$$$$$$$$$$$$ [" + id + "][" + k + "] ODistributedRecordLockedException: [" + ex + "] Cause: [" + (ex.getCause() != null ? ex.getCause() : "--") + "] for vertex " + vtx1);
vtx1.reload();
} else 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();
}
operations.incrementAndGet();
}
} 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 AbstractServerClusterMergeUpdateTest method executeTest.
private void executeTest(ODatabaseDocumentTx db0, ODatabaseDocumentTx db1) {
db0.activateOnCurrentThread();
// Event #0: Create new document with value 2L, and version 1
ODocument doc = new ODocument("Paper").field(FIELD_NAME, 2L);
db0.save(doc);
ORID orid = doc.getIdentity().copy();
// Event #1: Node 0 starts a transaction, and loads document with version 1 and value 2
db0.begin();
ODocument doc0 = db0.load(orid);
// Event #2: Node 1 starts a transaction, loads the document with
// version 1 and value 2, updates it to value 4, and commit(v2)
{
db1.activateOnCurrentThread();
db1.begin();
ODocument doc1 = db1.load(orid);
doc1.field(FIELD_NAME, 4L);
db1.save(doc1);
db1.commit();
}
// Event #3: Node 1 starts a transaction, loads the document with
// version 2 and value 4, updates it to value 5, and commit(v3)
{
db1.begin();
ODocument doc1 = db1.load(orid);
doc1.field(FIELD_NAME, 5L);
db1.save(doc1);
db1.commit();
}
// Event #4: Node 0 update his document (v1, 2) to value 5(v2), and commit.
db0.activateOnCurrentThread();
doc0.field(FIELD_NAME, 5L);
db0.save(doc0);
boolean anyConflictException = false;
try {
db0.commit();
// Event #5: An exception SHOULD be raised, even though the value is the same, because the versions aren't.
} catch (RuntimeException ex) {
if (ex instanceof OConcurrentModificationException) {
anyConflictException = true;
} else {
throw ex;
}
}
Assert.assertTrue(anyConflictException);
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class ConcurrentDistributedUpdateTest method createWriter.
protected Callable<Void> createWriter(final int serverId, final int threadId, final String databaseURL) {
return new Callable<Void>() {
@Override
public Void call() throws Exception {
final String id = serverId + "." + threadId;
boolean isRunning = true;
final OrientBaseGraph graph = new OrientGraph(databaseURL);
try {
String query = "select from Test where prop2='v2-1'";
for (int i = 0; i < 100 && isRunning; i++) {
if ((i % 25) == 0) {
log("[" + id + "] Records Processed: [" + i + "]");
}
Iterable<Vertex> vtxs = graph.command(new OCommandSQL(query)).execute();
boolean update = true;
for (Vertex vtx : vtxs) {
if (update) {
update = true;
for (int k = 0; k < 10 && update; k++) {
OrientVertex vtx1 = (OrientVertex) vtx;
try {
vtx1.setProperty("prop5", "prop55");
graph.commit();
// log("[" + id + "/" + i + "/" + k + "] OK!\n");
break;
} catch (OConcurrentModificationException ex) {
vtx1.reload();
} catch (ODistributedRecordLockedException ex) {
log("[" + id + "/" + i + "/" + k + "] Distributed lock Exception " + ex + " for vertex " + vtx1 + " \n");
// ex.printStackTrace();
update = false;
// isRunning = false;
break;
} catch (Exception ex) {
log("[" + id + "/" + i + "/" + k + "] Exception " + ex + " for vertex " + vtx1 + "\n\n");
ex.printStackTrace();
isRunning = false;
break;
}
}
if (!isRunning)
break;
}
}
}
} catch (Exception ex) {
System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
ex.printStackTrace();
} finally {
log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
graph.shutdown();
runningWriters.countDown();
}
Assert.assertTrue(isRunning);
return null;
}
};
}
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();
}
}
}
Aggregations