Search in sources :

Example 11 with OConcurrentModificationException

use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testFromEmbeddedToSBTreeWithCME.

public void testFromEmbeddedToSBTreeWithCME() {
    OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(5);
    OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.setValue(5);
    List<OIdentifiable> docsToAdd = new ArrayList<OIdentifiable>();
    ODocument document = new ODocument();
    ORidBag ridBag = new ORidBag();
    document.field("ridBag", ridBag);
    document.save();
    for (int i = 0; i < 3; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
        docsToAdd.add(docToAdd);
    }
    document.save();
    Assert.assertEquals(docsToAdd.size(), 3);
    Assert.assertTrue(ridBag.isEmbedded());
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    database.getLocalCache().clear();
    ODocument cmeDocument = database.load(document.getIdentity());
    Assert.assertNotSame(cmeDocument, document);
    cmeDocument.field("v", "v1");
    cmeDocument.save();
    for (int i = 0; i < 3; i++) {
        ODocument docToAdd = new ODocument();
        docToAdd.save();
        ridBag.add(docToAdd);
    }
    Assert.assertTrue(document.isDirty());
    try {
        document.save();
        Assert.fail();
    } catch (OConcurrentModificationException e) {
    }
    document = database.load(document.getIdentity());
    ridBag = document.field("ridBag");
    Assert.assertTrue(ridBag.isEmbedded());
    for (OIdentifiable identifiable : ridBag) Assert.assertTrue(docsToAdd.remove(identifiable));
    Assert.assertTrue(docsToAdd.isEmpty());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 12 with OConcurrentModificationException

use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testAddTwoAdditionalSavedDocumentsWithCME.

public void testAddTwoAdditionalSavedDocumentsWithCME() {
    final ODocument cmeDoc = new ODocument();
    cmeDoc.save();
    database.begin();
    ODocument rootDoc = new ODocument();
    ORidBag ridBag = new ORidBag();
    rootDoc.field("ridBag", ridBag);
    ODocument docOne = new ODocument();
    ODocument docTwo = new ODocument();
    ridBag.add(docOne);
    ridBag.add(docTwo);
    rootDoc.save();
    database.commit();
    long recordsCount = database.countClusterElements(database.getDefaultClusterId());
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    database.getLocalCache().clear();
    ODocument staleCMEDoc = database.load(cmeDoc.getIdentity());
    Assert.assertNotSame(staleCMEDoc, cmeDoc);
    cmeDoc.field("v", "v");
    cmeDoc.save();
    database.begin();
    ODocument docThree = new ODocument();
    docThree.save();
    ODocument docFour = new ODocument();
    docFour.save();
    ridBag.add(docThree);
    ridBag.add(docFour);
    rootDoc.save();
    staleCMEDoc.field("v", "vn");
    staleCMEDoc.save();
    try {
        database.commit();
        Assert.fail();
    } catch (OConcurrentModificationException e) {
    }
    Assert.assertEquals(database.countClusterElements(database.getDefaultClusterId()), recordsCount);
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    Assert.assertEquals(ridBag.size(), 2);
    List<OIdentifiable> addedDocs = new ArrayList<OIdentifiable>(Arrays.asList(docOne, docTwo));
    Iterator<OIdentifiable> iterator = ridBag.iterator();
    Assert.assertTrue(addedDocs.remove(iterator.next()));
    Assert.assertTrue(addedDocs.remove(iterator.next()));
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 13 with OConcurrentModificationException

use of com.orientechnologies.orient.core.exception.OConcurrentModificationException in project orientdb by orientechnologies.

the class OSequenceTest method shouldSequenceMTTx.

@Test
@Ignore
public void shouldSequenceMTTx() throws Exception {
    OSequence.CreateParams params = new OSequence.CreateParams().setStart(0L);
    OSequence mtSeq = sequences.createSequence("mtSeq", OSequence.SEQUENCE_TYPE.ORDERED, params);
    final int count = 1000;
    final int threads = 2;
    final CountDownLatch latch = new CountDownLatch(count);
    final AtomicInteger errors = new AtomicInteger(0);
    final AtomicInteger success = new AtomicInteger(0);
    ExecutorService service = Executors.newFixedThreadPool(threads);
    for (int i = 0; i < threads; i++) {
        service.execute(new Runnable() {

            @Override
            public void run() {
                ODatabaseDocument databaseDocument = new ODatabaseDocumentTx("memory:" + OSequenceTest.class.getName());
                databaseDocument.open("admin", "admin");
                OSequence mtSeq1 = databaseDocument.getMetadata().getSequenceLibrary().getSequence("mtSeq");
                for (int j = 0; j < count / threads; j++) {
                    for (int retry = 0; retry < 10; ++retry) {
                        try {
                            databaseDocument.begin();
                            mtSeq1.next();
                            databaseDocument.commit();
                            success.incrementAndGet();
                            break;
                        } catch (OConcurrentModificationException e) {
                            if (retry >= 10) {
                                e.printStackTrace();
                                errors.incrementAndGet();
                                break;
                            }
                            // RETRY
                            try {
                                Thread.sleep(10 + new Random().nextInt(100));
                            } catch (InterruptedException e1) {
                            }
                            mtSeq1.reloadSequence();
                            continue;
                        } catch (Exception e) {
                            e.printStackTrace();
                            errors.incrementAndGet();
                        }
                    }
                    latch.countDown();
                }
            }
        });
    }
    latch.await();
    assertThat(errors.get()).isEqualTo(0);
    assertThat(success.get()).isEqualTo(1000);
    mtSeq.reloadSequence();
    assertThat(mtSeq.getDocument().getVersion()).isEqualTo(1001);
    assertThat(mtSeq.current()).isEqualTo(1000);
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) CountDownLatch(java.util.concurrent.CountDownLatch) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OSequenceException(com.orientechnologies.orient.core.exception.OSequenceException) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ExecutorService(java.util.concurrent.ExecutorService) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 14 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 15 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)

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