Search in sources :

Example 26 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testDeleteRecordAndAddNewOnItsPlace.

public void testDeleteRecordAndAddNewOnItsPlace() throws IOException {
    byte[] smallRecord = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    int recordVersion = 0;
    recordVersion++;
    recordVersion++;
    OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 1, null);
    Assert.assertEquals(physicalPosition.clusterPosition, 0);
    paginatedCluster.deleteRecord(physicalPosition.clusterPosition);
    recordVersion = 0;
    Assert.assertEquals(recordVersion, 0);
    physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 1, null);
    Assert.assertEquals(physicalPosition.clusterPosition, 1);
    Assert.assertEquals(physicalPosition.recordVersion, recordVersion);
}
Also used : OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition)

Example 27 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testUpdateOneSmallRecord.

public void testUpdateOneSmallRecord() throws IOException {
    byte[] smallRecord = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    int recordVersion = 0;
    recordVersion++;
    recordVersion++;
    OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 1, null);
    Assert.assertEquals(physicalPosition.clusterPosition, 0);
    recordVersion++;
    smallRecord = new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3 };
    paginatedCluster.updateRecord(physicalPosition.clusterPosition, smallRecord, recordVersion, (byte) 2);
    ORawBuffer rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
    Assert.assertNotNull(rawBuffer);
    Assert.assertEquals(rawBuffer.version, recordVersion);
    Assert.assertEquals(rawBuffer.buffer, smallRecord);
    Assert.assertEquals(rawBuffer.recordType, 2);
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition)

Example 28 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testResurrectRecord.

public void testResurrectRecord() throws IOException {
    byte[] smallRecord = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
    int recordVersion = 0;
    OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 1, null);
    Assert.assertEquals(physicalPosition.clusterPosition, 0);
    Assert.assertEquals(paginatedCluster.getRecordStatus(physicalPosition.clusterPosition), OPaginatedCluster.RECORD_STATUS.PRESENT);
    for (int i = 0; i < 1000; ++i) {
        smallRecord = new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3 };
        try {
            paginatedCluster.recycleRecord(physicalPosition.clusterPosition);
            Assert.fail("it must be not possible to resurrect a non deleted record");
        } catch (OPaginatedClusterException e) {
        // OK
        }
        Assert.assertEquals(paginatedCluster.getRecordStatus(physicalPosition.clusterPosition), OPaginatedCluster.RECORD_STATUS.PRESENT);
        paginatedCluster.deleteRecord(physicalPosition.clusterPosition);
        Assert.assertEquals(paginatedCluster.getRecordStatus(physicalPosition.clusterPosition), OPaginatedCluster.RECORD_STATUS.REMOVED);
        ORawBuffer rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
        Assert.assertNull(rawBuffer);
        paginatedCluster.recycleRecord(physicalPosition.clusterPosition);
        Assert.assertEquals(paginatedCluster.getRecordStatus(physicalPosition.clusterPosition), OPaginatedCluster.RECORD_STATUS.ALLOCATED);
        final OPhysicalPosition pos = paginatedCluster.createRecord(smallRecord, 1, ODocument.RECORD_TYPE, new OPhysicalPosition(physicalPosition.clusterPosition));
        Assert.assertEquals(pos.clusterPosition, physicalPosition.clusterPosition);
        rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
        Assert.assertNotNull(rawBuffer);
        Assert.assertEquals(rawBuffer.version, recordVersion + 1);
        Assert.assertEquals(rawBuffer.buffer, smallRecord);
        Assert.assertEquals(rawBuffer.recordType, ODocument.RECORD_TYPE);
        // UPDATE 10 TIMES WITH A GROWING CONTENT TO STIMULATE DEFRAG AND CHANGE OF PAGES
        for (int k = 0; k < 10; ++k) {
            final byte[] updatedRecord = new byte[10 * k];
            for (int j = 0; j < updatedRecord.length; ++j) {
                updatedRecord[j] = (byte) j;
            }
            paginatedCluster.updateRecord(physicalPosition.clusterPosition, updatedRecord, recordVersion, (byte) 4);
        }
    }
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) OPaginatedClusterException(com.orientechnologies.orient.core.exception.OPaginatedClusterException)

Example 29 with OPhysicalPosition

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

the class LocalPaginatedStorageIncrementalSync method assertDatabasesAreInSynch.

private void assertDatabasesAreInSynch() throws Exception {
    originalDB.activateOnCurrentThread();
    final long originalRecords = originalDB.countClass("Sample");
    syncDB.activateOnCurrentThread();
    final long syncRecords = syncDB.countClass("Sample");
    Assert.assertEquals(originalRecords, syncRecords);
    originalDB.activateOnCurrentThread();
    OSchema schema = originalDB.getMetadata().getSchema();
    OClass clazz = schema.getClass("Sample");
    int[] clusterIds = clazz.getClusterIds();
    for (int clusterId : clusterIds) {
        final OStorage originalStorage = originalDB.getStorage();
        final OStorage syncedStorage = syncDB.getStorage();
        final long[] db1Range = originalStorage.getClusterDataRange(clusterId);
        final long[] db2Range = syncedStorage.getClusterDataRange(clusterId);
        Assert.assertEquals(db1Range, db2Range);
        final ORecordId rid = new ORecordId(clusterId);
        OPhysicalPosition[] physicalPositions = originalStorage.ceilingPhysicalPositions(clusterId, new OPhysicalPosition(0));
        while (physicalPositions.length > 0) {
            for (OPhysicalPosition physicalPosition : physicalPositions) {
                rid.setClusterPosition(physicalPosition.clusterPosition);
                final ORawBuffer originalBuffer = originalStorage.readRecord(rid, null, true, false, null).getResult();
                final ORawBuffer syncBuffer = syncedStorage.readRecord(rid, null, true, false, null).getResult();
                Assert.assertEquals(originalBuffer.recordType, syncBuffer.recordType);
                Assert.assertEquals(originalBuffer.version, syncBuffer.version);
                Assert.assertEquals(originalBuffer.buffer, syncBuffer.buffer);
            }
            physicalPositions = originalStorage.higherPhysicalPositions(clusterId, physicalPositions[physicalPositions.length - 1]);
        }
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) 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)

Example 30 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testForwardIteration.

public void testForwardIteration() throws IOException {
    final int records = 10000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testForwardIteration 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 = 0;
    OPhysicalPosition[] positions = paginatedCluster.ceilingPositions(physicalPosition);
    Assert.assertTrue(positions.length > 0);
    int counter = 0;
    for (long testedPosition : positionRecordMap.keySet()) {
        Assert.assertTrue(positions.length > 0);
        Assert.assertEquals(positions[0].clusterPosition, testedPosition);
        OPhysicalPosition positionToFind = positions[0];
        positions = paginatedCluster.higherPositions(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)

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