use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class OClassIndexManager method onRecordBeforeDelete.
@Override
public RESULT onRecordBeforeDelete(final ODocument iDocument) {
// Cache the transaction-provided value
final int version = iDocument.getVersion();
if (iDocument.fields() == 0 && iDocument.getIdentity().isPersistent()) {
// FORCE LOADING OF CLASS+FIELDS TO USE IT AFTER ON onRecordAfterDelete METHOD
iDocument.reload();
if (// check for record version errors
version > -1 && iDocument.getVersion() != version)
if (OFastConcurrentModificationException.enabled())
throw OFastConcurrentModificationException.instance();
else
throw new OConcurrentModificationException(iDocument.getIdentity(), iDocument.getVersion(), version, ORecordOperation.DELETED);
}
final OClass class_ = ODocumentInternal.getImmutableSchemaClass(iDocument);
if (class_ != null) {
final Collection<OIndex<?>> indexes = class_.getIndexes();
final TreeMap<OIndex<?>, List<Object>> indexKeysMap = new TreeMap<OIndex<?>, List<Object>>();
for (final OIndex<?> index : indexes) {
if (index.getInternal() instanceof OIndexUnique) {
OIndexRecorder indexRecorder = new OIndexRecorder((OIndexUnique) index.getInternal());
addIndexEntry(iDocument, iDocument.getIdentity(), indexRecorder);
indexKeysMap.put(index, indexRecorder.getAffectedKeys());
}
}
if (noTx(iDocument)) {
final List<Lock[]> locks = new ArrayList<Lock[]>(indexKeysMap.size());
for (Map.Entry<OIndex<?>, List<Object>> entry : indexKeysMap.entrySet()) {
final OIndexInternal<?> index = entry.getKey().getInternal();
locks.add(index.lockKeysForUpdate(entry.getValue()));
}
lockedKeys.push(locks);
}
}
return RESULT.RECORD_NOT_CHANGED;
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class TestAsyncReplMode method dbClient2.
protected void dbClient2() {
synchronized (LOCK) {
OrientBaseGraph graph = new OrientGraph(getRemoteURL());
OrientVertex parentV1 = null;
OrientVertex parentV2 = null;
int countPropValue = 0;
try {
for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
pause();
if (exceptionInThread != null)
break;
// Let's give it some time for asynchronous replication.
// sleep(500);
countPropValue++;
if (parentV1 == null) {
parentV1 = graph.getVertex(parentV1Id);
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV1.setProperty("cnt", countPropValue);
graph.commit();
} catch (OConcurrentModificationException c) {
graph.rollback();
parentV1.reload();
}
}
if (parentV2 == null) {
parentV2 = graph.getVertex(parentV2Id);
}
for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
try {
parentV2.setProperty("cnt", countPropValue);
graph.commit();
} 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 SimulateOperationsAgainstServer method updateDocument.
protected void updateDocument(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, " update no item " + iSkip + " because out of range");
else {
doc = (ODocument) result.get(0);
doc.field("updated", "" + (doc.getVersion() + 1));
doc.save();
log(threadId, iCycle, dbUrl, " updated item " + iSkip + " RID=" + result.get(0));
}
// OK
break;
} catch (OConcurrentModificationException e) {
log(threadId, iCycle, dbUrl, " concurrent update against record " + doc + ", reload it and retry " + retry + "/" + MAX_RETRY + "...");
if (doc != null)
doc.reload(null, true);
} catch (ORecordNotFoundException e) {
log(threadId, iCycle, dbUrl, " update no item " + iSkip + " because not found");
break;
} finally {
db.close();
}
}
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class OConflictManagementTest method testVersionStrategy.
public void testVersionStrategy() {
database.setConflictStrategy("version");
ODocument rootDoc = new ODocument().field("name", "Jay").save();
ODocument copy = rootDoc.copy();
rootDoc.field("name", "Jay1");
rootDoc.save();
copy.field("name", "Jay2");
try {
copy.save();
Assert.assertTrue(false);
} catch (OConcurrentModificationException e) {
}
}
use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.
the class ORidBagAtomicUpdateTest method testAddOneSavedDocumentsAndDeleteOneWithoutTx.
/**
* This test is no longer useful
*/
@Test(enabled = false)
public void testAddOneSavedDocumentsAndDeleteOneWithoutTx() {
ODocument docOne = new ODocument();
docOne.save();
ODocument docTwo = new ODocument();
docTwo.save();
ODocument docThree = new ODocument();
docThree.save();
ODocument rootDoc = new ODocument();
ORidBag ridBag = new ORidBag();
rootDoc.field("ridBag", ridBag);
ridBag.add(docOne);
ridBag.add(docTwo);
rootDoc.save();
ODocument staleRooDoc = database.load(rootDoc.getIdentity());
ORidBag staleRidBag = staleRooDoc.field("ridBag");
Iterator<OIdentifiable> iterator = staleRidBag.iterator();
iterator.next();
iterator.remove();
staleRidBag.add(docThree);
rootDoc.setDirty();
rootDoc.save();
try {
staleRooDoc.save();
Assert.fail();
} catch (OConcurrentModificationException e) {
}
rootDoc = database.load(rootDoc.getIdentity());
ridBag = rootDoc.field("ridBag");
Assert.assertEquals(ridBag.size(), 2);
iterator = ridBag.iterator();
Assert.assertEquals(iterator.next(), docOne);
Assert.assertEquals(iterator.next(), docTwo);
Assert.assertTrue(!iterator.hasNext());
}
Aggregations