Search in sources :

Example 6 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class OPropertyRidBagIndexDefinition method createValue.

@Override
public Object createValue(final Object... params) {
    if (!(params[0] instanceof ORidBag))
        return null;
    final ORidBag ridBag = (ORidBag) params[0];
    final List<Object> values = new ArrayList<Object>();
    for (final OIdentifiable item : ridBag) {
        values.add(createSingleValue(item));
    }
    return values;
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 7 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class LocalPaginatedStorageLinkBagCrashRestoreIT method compareDocuments.

private void compareDocuments(long lastTs) {
    ODatabaseDocumentTx base_db = new ODatabaseDocumentTx("plocal:" + buildDir + "/baseLocalPaginatedStorageLinkBagCrashRestore");
    base_db.open("admin", "admin");
    ODatabaseDocumentTx test_db = new ODatabaseDocumentTx("plocal:" + buildDir + "/testLocalPaginatedStorageLinkBagCrashRestore");
    test_db.open("admin", "admin");
    long minTs = Long.MAX_VALUE;
    OStorage baseStorage = base_db.getStorage();
    OPhysicalPosition[] physicalPositions = baseStorage.ceilingPhysicalPositions(defaultClusterId, new OPhysicalPosition(0));
    int recordsRestored = 0;
    int recordsTested = 0;
    while (physicalPositions.length > 0) {
        final ORecordId rid = new ORecordId(defaultClusterId);
        for (OPhysicalPosition physicalPosition : physicalPositions) {
            rid.setClusterPosition(physicalPosition.clusterPosition);
            ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
            ODocument baseDocument = base_db.load(rid);
            baseDocument.setLazyLoad(false);
            ODatabaseRecordThreadLocal.INSTANCE.set(test_db);
            ODocument testDocument = test_db.load(rid);
            if (testDocument == null) {
                ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
                if (((Long) baseDocument.field("ts")) < minTs)
                    minTs = baseDocument.field("ts");
            } else {
                testDocument.setLazyLoad(false);
                long baseTs;
                long testTs;
                ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
                baseTs = baseDocument.field("ts");
                ODatabaseRecordThreadLocal.INSTANCE.set(test_db);
                testTs = testDocument.field("ts");
                boolean equals = baseTs == testTs;
                if (equals) {
                    Set<ORID> baseRids = new HashSet<ORID>();
                    ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
                    ORidBag baseRidBag = baseDocument.field("ridBag");
                    for (OIdentifiable baseIdentifiable : baseRidBag) baseRids.add(baseIdentifiable.getIdentity());
                    Set<ORID> testRids = new HashSet<ORID>();
                    ODatabaseRecordThreadLocal.INSTANCE.set(test_db);
                    ORidBag testRidBag = testDocument.field("ridBag");
                    for (OIdentifiable testIdentifiable : testRidBag) testRids.add(testIdentifiable.getIdentity());
                    equals = baseRids.equals(testRids);
                }
                if (!equals) {
                    if (((Long) baseDocument.field("ts")) < minTs)
                        minTs = baseDocument.field("ts");
                } else
                    recordsRestored++;
            }
            recordsTested++;
            if (recordsTested % 10000 == 0)
                System.out.println(recordsTested + " were tested, " + recordsRestored + " were restored ...");
        }
        physicalPositions = baseStorage.higherPhysicalPositions(defaultClusterId, physicalPositions[physicalPositions.length - 1]);
    }
    System.out.println(recordsRestored + " records were restored. Total records " + recordsTested + ". lost records " + (recordsTested - recordsRestored));
    long maxInterval = minTs == Long.MAX_VALUE ? 0 : lastTs - minTs;
    System.out.println("Lost records max interval (ms) : " + maxInterval);
    assertThat(maxInterval).isLessThan(2000);
    base_db.activateOnCurrentThread();
    base_db.close();
    test_db.activateOnCurrentThread();
    test_db.close();
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 8 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class OCommandExecutorSQLUpdate method changeVertexEdgePointer.

/**
 * updates old and new vertices connected to an edge after out/in update on the edge itself
 *
 * @param edge          the edge
 * @param prevVertex    the previously connected vertex
 * @param currentVertex the currently connected vertex
 * @param direction     the direction ("out" or "in")
 */
private void changeVertexEdgePointer(ODocument edge, OIdentifiable prevVertex, OIdentifiable currentVertex, String direction) {
    if (prevVertex != null && !prevVertex.equals(currentVertex)) {
        String edgeClassName = edge.getClassName();
        if (edgeClassName.equalsIgnoreCase("E")) {
            edgeClassName = "";
        }
        String vertexFieldName = direction + "_" + edgeClassName;
        ODocument prevOutDoc = ((OIdentifiable) prevVertex).getRecord();
        ORecordLazyMultiValue prevBag = prevOutDoc.field(vertexFieldName);
        if (prevBag == null && edgeClassName.equalsIgnoreCase("E")) {
            prevBag = prevOutDoc.field(vertexFieldName + "E");
        }
        if (prevBag != null) {
            if (prevBag instanceof ORidBag) {
                ((ORidBag) prevBag).remove(edge);
            } else if (prevBag instanceof List) {
                ((List) prevBag).remove(edge);
            } else if (prevBag instanceof Set) {
                ((Set) prevBag).remove(edge);
            } else {
                throw new UnsupportedOperationException();
            }
            prevOutDoc.save();
        }
        ODocument currentVertexDoc = ((OIdentifiable) currentVertex).getRecord();
        ORecordLazyMultiValue currentBag = currentVertexDoc.field(vertexFieldName);
        if (currentBag == null) {
            currentBag = new ORidBag();
            currentVertexDoc.field(vertexFieldName, currentBag);
        }
        if (currentBag instanceof ORidBag) {
            ((ORidBag) currentBag).add(edge);
        } else if (currentBag instanceof List) {
            ((List) currentBag).add(edge);
        } else if (currentBag instanceof Set) {
            ((Set) currentBag).add(edge);
        } else {
            throw new UnsupportedOperationException();
        }
    }
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 9 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class OSBTreeRidBagConcurrencySingleRidBag method testConcurrency.

public void testConcurrency() throws Exception {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(URL);
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    db.create();
    db.declareIntent(new OIntentMassiveInsert());
    ODocument document = new ODocument();
    ORidBag ridBag = new ORidBag();
    ridBag.setAutoConvertToRecord(false);
    document.field("ridBag", ridBag);
    for (int i = 0; i < 100; i++) {
        final ORID ridToAdd = new ORecordId(0, positionCounter.incrementAndGet());
        ridBag.add(ridToAdd);
        ridTree.add(ridToAdd);
    }
    document.save();
    docContainerRid = document.getIdentity();
    List<Future<Void>> futures = new ArrayList<Future<Void>>();
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidAdder(i)));
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidDeleter(i)));
    latch.countDown();
    Thread.sleep(30 * 60000);
    cont = false;
    for (Future<Void> future : futures) future.get();
    document = db.load(document.getIdentity());
    document.setLazyLoad(false);
    ridBag = document.field("ridBag");
    for (OIdentifiable identifiable : ridBag) Assert.assertTrue(ridTree.remove(identifiable.getIdentity()));
    Assert.assertTrue(ridTree.isEmpty());
    System.out.println("Result size is " + ridBag.size());
    db.close();
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OIntentMassiveInsert(com.orientechnologies.orient.core.intent.OIntentMassiveInsert) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Future(java.util.concurrent.Future) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 10 with ORidBag

use of com.orientechnologies.orient.core.db.record.ridbag.ORidBag in project orientdb by orientechnologies.

the class ODirtyManagerTest method testNestedMapDocRidBag.

@Test
public void testNestedMapDocRidBag() {
    ODocument doc = new ODocument();
    Map<String, ODocument> embeddedMap = new HashMap<String, ODocument>();
    ODocument embeddedMapDoc = new ODocument();
    ORidBag embeddedMapDocRidBag = new ORidBag();
    ODocument link = new ODocument();
    embeddedMapDocRidBag.add(link);
    embeddedMapDoc.field("ridBag", embeddedMapDocRidBag);
    embeddedMap.put("k1", embeddedMapDoc);
    doc.field("embeddedMap", embeddedMap, OType.EMBEDDEDMAP);
    ODocumentInternal.convertAllMultiValuesToTrackedVersions(doc);
    ODirtyManager manager = ORecordInternal.getDirtyManager(doc);
    assertEquals(2, manager.getNewRecords().size());
    assertEquals(1, manager.getPointed(doc).size());
    // TODO: double check this, it's an overhead
    assertEquals(1, manager.getPointed(embeddedMapDoc).size());
    assertTrue(manager.getPointed(doc).contains(link));
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ODirtyManager(com.orientechnologies.orient.core.record.impl.ODirtyManager) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)135 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)103 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)68 ORecordId (com.orientechnologies.orient.core.id.ORecordId)37 ArrayList (java.util.ArrayList)27 Test (org.testng.annotations.Test)24 ORID (com.orientechnologies.orient.core.id.ORID)21 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)15 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)13 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)11 OStorage (com.orientechnologies.orient.core.storage.OStorage)7 HashSet (java.util.HashSet)7 ORecordLazyList (com.orientechnologies.orient.core.db.record.ORecordLazyList)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 ORecordLazyMultiValue (com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue)4 ORecordLazySet (com.orientechnologies.orient.core.db.record.ORecordLazySet)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)3