Search in sources :

Example 1 with OPhysicalPosition

use of com.orientechnologies.orient.core.storage.OPhysicalPosition 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 2 with OPhysicalPosition

use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.

the class LocalPaginatedStorageUpdateCrashRestoreIT method compareDocuments.

private void compareDocuments(long lastTs) {
    long minTs = Long.MAX_VALUE;
    baseDocumentTx.activateOnCurrentThread();
    int clusterId = baseDocumentTx.getClusterIdByName("TestClass");
    OStorage baseStorage = baseDocumentTx.getStorage();
    OPhysicalPosition[] physicalPositions = baseStorage.ceilingPhysicalPositions(clusterId, new OPhysicalPosition(0));
    int recordsRestored = 0;
    int recordsTested = 0;
    while (physicalPositions.length > 0) {
        final ORecordId rid = new ORecordId(clusterId);
        for (OPhysicalPosition physicalPosition : physicalPositions) {
            rid.setClusterPosition(physicalPosition.clusterPosition);
            baseDocumentTx.activateOnCurrentThread();
            ODocument baseDocument = baseDocumentTx.load(rid);
            testDocumentTx.activateOnCurrentThread();
            List<ODocument> testDocuments = testDocumentTx.query(new OSQLSynchQuery<ODocument>("select from TestClass where id  = " + baseDocument.field("id")));
            Assert.assertTrue(!testDocuments.isEmpty());
            ODocument testDocument = testDocuments.get(0);
            if (testDocument.field("timestamp").equals(baseDocument.field("timestamp")) && testDocument.field("stringValue").equals(baseDocument.field("stringValue"))) {
                recordsRestored++;
            } else {
                if (((Long) baseDocument.field("timestamp")) < minTs)
                    minTs = baseDocument.field("timestamp");
            }
            recordsTested++;
            if (recordsTested % 10000 == 0)
                System.out.println(recordsTested + " were tested, " + recordsRestored + " were restored ...");
        }
        physicalPositions = baseStorage.higherPhysicalPositions(clusterId, 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(recordsTested - recordsRestored).isLessThan(120);
    assertThat(maxInterval).isLessThan(2000);
}
Also used : OStorage(com.orientechnologies.orient.core.storage.OStorage) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORecordId(com.orientechnologies.orient.core.id.ORecordId) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OPhysicalPosition

use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.

the class RemoteProtocolCommandsTest method testRawCreateWithoutIDTest.

@Test
public void testRawCreateWithoutIDTest() {
    OClass clazz = this.database.getMetadata().getSchema().createClass("RidCreationTestClass");
    OStorage storage = this.database.getStorage();
    ODocument doc = new ODocument("RidCreationTestClass");
    doc.field("test", "test");
    ORecordId bad = new ORecordId(-1, -1);
    OStorageOperationResult<OPhysicalPosition> res = storage.createRecord(bad, doc.toStream(), doc.getVersion(), ODocument.RECORD_TYPE, OPERATION_MODE.SYNCHRONOUS.ordinal(), null);
    // assertTrue(" the cluster is not valid", bad.clusterId >= 0);
    String ids = "";
    for (int aId : clazz.getClusterIds()) ids += aId;
    assertTrue(" returned id:" + bad.getClusterId() + " shoud be one of:" + ids, Arrays.binarySearch(clazz.getClusterIds(), bad.getClusterId()) >= 0);
}
Also used : OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OStorage(com.orientechnologies.orient.core.storage.OStorage) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 4 with OPhysicalPosition

use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.

the class LocalPaginatedClusterTest method testBackwardIteration.

public void testBackwardIteration() throws IOException {
    final int records = 10000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testBackwardIteration seed : " + seed);
    NavigableMap<Long, byte[]> positionRecordMap = new TreeMap<Long, byte[]>();
    int recordVersion = 0;
    recordVersion++;
    recordVersion++;
    for (int i = 0; i < records; i++) {
        int recordSize = mersenneTwisterFast.nextInt(2 * OClusterPage.MAX_RECORD_SIZE) + 1;
        byte[] record = new byte[recordSize];
        mersenneTwisterFast.nextBytes(record);
        final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(record, recordVersion, (byte) 2, null);
        positionRecordMap.put(physicalPosition.clusterPosition, record);
    }
    Iterator<Long> positionIterator = positionRecordMap.keySet().iterator();
    while (positionIterator.hasNext()) {
        long clusterPosition = positionIterator.next();
        if (mersenneTwisterFast.nextBoolean()) {
            Assert.assertTrue(paginatedCluster.deleteRecord(clusterPosition));
            positionIterator.remove();
        }
    }
    OPhysicalPosition physicalPosition = new OPhysicalPosition();
    physicalPosition.clusterPosition = Long.MAX_VALUE;
    OPhysicalPosition[] positions = paginatedCluster.floorPositions(physicalPosition);
    Assert.assertTrue(positions.length > 0);
    positionIterator = positionRecordMap.descendingKeySet().iterator();
    int counter = 0;
    while (positionIterator.hasNext()) {
        Assert.assertTrue(positions.length > 0);
        long testedPosition = positionIterator.next();
        Assert.assertEquals(positions[positions.length - 1].clusterPosition, testedPosition);
        OPhysicalPosition positionToFind = positions[positions.length - 1];
        positions = paginatedCluster.lowerPositions(positionToFind);
        counter++;
    }
    Assert.assertEquals(paginatedCluster.getEntries(), counter);
    Assert.assertEquals(paginatedCluster.getFirstPosition(), (long) positionRecordMap.firstKey());
    Assert.assertEquals(paginatedCluster.getLastPosition(), (long) positionRecordMap.lastKey());
}
Also used : OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition)

Example 5 with OPhysicalPosition

use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.

the class LocalPaginatedClusterTest method testHideHalfSmallRecords.

public void testHideHalfSmallRecords() throws IOException {
    final int records = 10000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testHideHalfSmallRecords seed : " + seed);
    Map<Long, byte[]> positionRecordMap = new HashMap<Long, byte[]>();
    int recordVersion = 0;
    recordVersion++;
    recordVersion++;
    for (int i = 0; i < records; i++) {
        int recordSize = mersenneTwisterFast.nextInt(OClusterPage.MAX_RECORD_SIZE - 1) + 1;
        byte[] smallRecord = new byte[recordSize];
        mersenneTwisterFast.nextBytes(smallRecord);
        final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 2, null);
        positionRecordMap.put(physicalPosition.clusterPosition, smallRecord);
    }
    int hiddenRecords = 0;
    Assert.assertEquals(records, paginatedCluster.getEntries());
    Set<Long> hiddenPositions = new HashSet<Long>();
    Iterator<Long> positionIterator = positionRecordMap.keySet().iterator();
    while (positionIterator.hasNext()) {
        long clusterPosition = positionIterator.next();
        if (mersenneTwisterFast.nextBoolean()) {
            hiddenPositions.add(clusterPosition);
            Assert.assertTrue(paginatedCluster.hideRecord(clusterPosition));
            hiddenRecords++;
            Assert.assertEquals(records - hiddenRecords, paginatedCluster.getEntries());
            positionIterator.remove();
        }
    }
    Assert.assertEquals(paginatedCluster.getEntries(), records - hiddenRecords);
    for (long deletedPosition : hiddenPositions) {
        Assert.assertNull(paginatedCluster.readRecord(deletedPosition, false));
        Assert.assertFalse(paginatedCluster.hideRecord(deletedPosition));
    }
    for (Map.Entry<Long, byte[]> entry : positionRecordMap.entrySet()) {
        ORawBuffer rawBuffer = paginatedCluster.readRecord(entry.getKey(), false);
        Assert.assertNotNull(rawBuffer);
        Assert.assertEquals(rawBuffer.version, recordVersion);
        Assert.assertEquals(rawBuffer.buffer, entry.getValue());
        Assert.assertEquals(rawBuffer.recordType, 2);
    }
}
Also used : OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer)

Aggregations

OPhysicalPosition (com.orientechnologies.orient.core.storage.OPhysicalPosition)40 ORawBuffer (com.orientechnologies.orient.core.storage.ORawBuffer)23 ORecordId (com.orientechnologies.orient.core.id.ORecordId)13 OStorage (com.orientechnologies.orient.core.storage.OStorage)13 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)9 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 Test (org.testng.annotations.Test)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 ORID (com.orientechnologies.orient.core.id.ORID)2 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)2 ORecord (com.orientechnologies.orient.core.record.ORecord)2 OStorageConfiguration (com.orientechnologies.orient.core.config.OStorageConfiguration)1 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)1 OPaginatedClusterException (com.orientechnologies.orient.core.exception.OPaginatedClusterException)1 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)1 ODocumentHelper (com.orientechnologies.orient.core.record.impl.ODocumentHelper)1 ODbRelatedCall (com.orientechnologies.orient.core.record.impl.ODocumentHelper.ODbRelatedCall)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1