Search in sources :

Example 61 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 62 with ORidBag

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

the class OConsoleDatabaseApp method displayRawRecord.

@ConsoleCommand(description = "Display a record as raw bytes", onlineHelp = "Console-Command-Display-Raw-Record")
public void displayRawRecord(@ConsoleParameter(name = "rid", description = "The record id to display") final String iRecordId) throws IOException {
    checkForDatabase();
    ORecordId rid;
    if (iRecordId.indexOf(':') > -1)
        rid = new ORecordId(iRecordId);
    else {
        OIdentifiable rec = setCurrentRecord(Integer.parseInt(iRecordId));
        if (rec != null)
            rid = (ORecordId) rec.getIdentity();
        else
            return;
    }
    ORawBuffer record;
    ORecordId id = new ORecordId(rid);
    if (!(currentDatabase.getStorage() instanceof OLocalPaginatedStorage)) {
        record = currentDatabase.getStorage().readRecord(rid, null, false, false, null).getResult();
        if (record != null) {
            String content;
            if (Integer.parseInt(properties.get("maxBinaryDisplay")) < record.buffer.length)
                content = new String(Arrays.copyOf(record.buffer, Integer.parseInt(properties.get("maxBinaryDisplay"))));
            else
                content = new String(record.buffer);
            out.println("\nRaw record content. The size is " + record.buffer.length + " bytes, while settings force to print first " + content.length() + " bytes:\n\n" + content);
        }
    } else {
        final OLocalPaginatedStorage storage = (OLocalPaginatedStorage) currentDatabase.getStorage();
        final OPaginatedCluster cluster = (OPaginatedCluster) storage.getClusterById(id.getClusterId());
        if (cluster == null) {
            message("\n cluster with id %i does not exist", id.getClusterId());
            return;
        }
        message("\n\nLOW LEVEL CLUSTER INFO");
        final OPaginatedCluster.RECORD_STATUS status = cluster.getRecordStatus(id.getClusterPosition());
        message("\n status: %s", status);
        final OPaginatedClusterDebug debugInfo = cluster.readDebug(id.getClusterPosition());
        message("\n cluster fieldId: %d", debugInfo.fileId);
        message("\n cluster name: %s", cluster.getName());
        message("\n in cluster position: %d", debugInfo.clusterPosition);
        message("\n empty: %b", debugInfo.empty);
        message("\n contentSize: %d", debugInfo.contentSize);
        message("\n n-pages: %d", debugInfo.pages.size());
        message("\n\n +----------PAGE_ID---------------+------IN_PAGE_POSITION----------+---------IN_PAGE_SIZE-----------+----PAGE_CONTENT---->> ");
        for (OClusterPageDebug page : debugInfo.pages) {
            message("\n |%30d ", page.pageIndex);
            message(" |%30d ", page.inPagePosition);
            message(" |%30d ", page.inPageSize);
            message(" |%s", OBase64Utils.encodeBytes(page.content));
        }
        record = cluster.readRecord(id.getClusterPosition(), false);
    }
    if (record == null)
        throw new OSystemException("The record has been deleted");
    if ("ORecordSerializerBinary".equals(currentDatabase.getSerializer().toString())) {
        byte[] buff = record.getBuffer();
        ORecordSerializerBinaryDebug debugger = new ORecordSerializerBinaryDebug();
        ORecordSerializationDebug deserializeDebug = debugger.deserializeDebug(buff, currentDatabase);
        message("\n\nRECORD CONTENT INFO");
        message("\n class name: %s", deserializeDebug.className);
        message("\n fail on Reading: %b", deserializeDebug.readingFailure);
        message("\n fail position: %d", deserializeDebug.failPosition);
        if (deserializeDebug.readingException != null) {
            StringWriter writer = new StringWriter();
            deserializeDebug.readingException.printStackTrace(new PrintWriter(writer));
            message("\n Exception On Reading: %s", writer.getBuffer().toString());
        }
        message("\n number of properties : %d", deserializeDebug.properties.size());
        message("\n\n PROPERTIES");
        for (ORecordSerializationDebugProperty prop : deserializeDebug.properties) {
            message("\n  property name: %s", prop.name);
            message("\n  property type: %s", prop.type.name());
            message("\n  property globalId: %d", prop.globalId);
            message("\n  fail on reading: %b", prop.faildToRead);
            if (prop.faildToRead) {
                message("\n  failed on reading position: %b", prop.failPosition);
                StringWriter writer = new StringWriter();
                prop.readingException.printStackTrace(new PrintWriter(writer));
                message("\n  Exception on reading: %s", writer.getBuffer().toString());
            } else {
                if (prop.value instanceof ORidBag) {
                    message("\n  property value: ORidBug ");
                    ((ORidBag) prop.value).debugPrint(System.out);
                } else
                    message("\n  property value: %s", prop.value != null ? prop.value.toString() : "null");
            }
            message("\n");
        }
    }
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OSystemException(com.orientechnologies.common.exception.OSystemException) OLocalPaginatedStorage(com.orientechnologies.orient.core.storage.impl.local.paginated.OLocalPaginatedStorage) ORecordSerializationDebugProperty(com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebugProperty) ORecordSerializerBinaryDebug(com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryDebug) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OClusterPageDebug(com.orientechnologies.orient.core.storage.impl.local.paginated.OClusterPageDebug) OPaginatedCluster(com.orientechnologies.orient.core.storage.impl.local.paginated.OPaginatedCluster) OPaginatedClusterDebug(com.orientechnologies.orient.core.storage.impl.local.paginated.OPaginatedClusterDebug) ORecordSerializationDebug(com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializationDebug) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

Example 63 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 64 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 List<?> params) {
    if (!(params.get(0) instanceof ORidBag))
        return null;
    final ORidBag ridBag = (ORidBag) params.get(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 65 with ORidBag

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

the class OrientVertex method getVertices.

/**
   * Returns a lazy iterable instance against vertices.
   *
   * @param iDirection The direction between OUT, IN or BOTH
   * @param iLabels    Optional varargs of Strings representing edge label to consider
   */
@Override
public Iterable<Vertex> getVertices(final Direction iDirection, final String... iLabels) {
    setCurrentGraphInThreadLocal();
    OrientBaseGraph.getEdgeClassNames(getGraph(), iLabels);
    OrientBaseGraph.encodeClassNames(iLabels);
    final ODocument doc = getRecord();
    final OMultiCollectionIterator<Vertex> iterable = new OMultiCollectionIterator<Vertex>();
    String[] fieldNames = null;
    if (iLabels != null && iLabels.length > 0) {
        // EDGE LABELS: CREATE FIELD NAME TABLE (FASTER THAN EXTRACT FIELD NAMES FROM THE DOCUMENT)
        fieldNames = getFieldNames(iDirection, iLabels);
        if (fieldNames != null)
            // EARLY FETCH ALL THE FIELDS THAT MATTERS
            doc.deserializeFields(fieldNames);
    }
    if (fieldNames == null)
        fieldNames = doc.fieldNames();
    for (String fieldName : fieldNames) {
        final OPair<Direction, String> connection = getConnection(iDirection, fieldName, iLabels);
        if (connection == null)
            // SKIP THIS FIELD
            continue;
        final Object fieldValue = doc.rawField(fieldName);
        if (fieldValue != null)
            if (fieldValue instanceof OIdentifiable) {
                addSingleVertex(doc, iterable, fieldName, connection, fieldValue, iLabels);
            } else if (fieldValue instanceof Collection<?>) {
                Collection<?> coll = (Collection<?>) fieldValue;
                if (coll.size() == 1) {
                    // SINGLE ITEM: AVOID CALLING ITERATOR
                    if (coll instanceof ORecordLazyMultiValue)
                        addSingleVertex(doc, iterable, fieldName, connection, ((ORecordLazyMultiValue) coll).rawIterator().next(), iLabels);
                    else if (coll instanceof List<?>)
                        addSingleVertex(doc, iterable, fieldName, connection, ((List<?>) coll).get(0), iLabels);
                    else
                        addSingleVertex(doc, iterable, fieldName, connection, coll.iterator().next(), iLabels);
                } else {
                    // CREATE LAZY Iterable AGAINST COLLECTION FIELD
                    if (coll instanceof ORecordLazyMultiValue)
                        iterable.add(new OrientVertexIterator(this, coll, ((ORecordLazyMultiValue) coll).rawIterator(), connection, iLabels, coll.size()));
                    else
                        iterable.add(new OrientVertexIterator(this, coll, coll.iterator(), connection, iLabels, -1));
                }
            } else if (fieldValue instanceof ORidBag) {
                iterable.add(new OrientVertexIterator(this, fieldValue, ((ORidBag) fieldValue).rawIterator(), connection, iLabels, -1));
            }
    }
    return iterable;
}
Also used : PartitionVertex(com.tinkerpop.blueprints.util.wrappers.partition.PartitionVertex) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordLazyMultiValue(com.orientechnologies.orient.core.db.record.ORecordLazyMultiValue) OMultiCollectionIterator(com.orientechnologies.common.collection.OMultiCollectionIterator) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

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)70 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