Search in sources :

Example 1 with OConcurrentModificationException

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;
}
Also used : OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) Lock(java.util.concurrent.locks.Lock) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 2 with OConcurrentModificationException

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();
        }
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException)

Example 3 with OConcurrentModificationException

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();
        }
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ORecordNotFoundException(com.orientechnologies.orient.core.exception.ORecordNotFoundException) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 4 with OConcurrentModificationException

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) {
    }
}
Also used : OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OConcurrentModificationException

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());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Aggregations

OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)40 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)25 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)11 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)11 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)11 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)8 ArrayList (java.util.ArrayList)8 Test (org.testng.annotations.Test)8 Vertex (com.tinkerpop.blueprints.Vertex)7 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)6 Test (org.junit.Test)5 ORID (com.orientechnologies.orient.core.id.ORID)4 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)4 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)4 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)4 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)3 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)2 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2