Search in sources :

Example 6 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testHideHalfRecordsAndAddAnotherHalfAgain.

public void testHideHalfRecordsAndAddAnotherHalfAgain() throws IOException {
    final int records = 10000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testHideHalfRecordsAndAddAnotherHalfAgain 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(3 * OClusterPage.MAX_RECORD_SIZE) + 1;
        byte[] bigRecord = new byte[recordSize];
        mersenneTwisterFast.nextBytes(bigRecord);
        final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(bigRecord, recordVersion, (byte) 2, null);
        positionRecordMap.put(physicalPosition.clusterPosition, bigRecord);
    }
    int hiddenRecords = 0;
    Assert.assertEquals(records, paginatedCluster.getEntries());
    Iterator<Long> positionIterator = positionRecordMap.keySet().iterator();
    while (positionIterator.hasNext()) {
        long clusterPosition = positionIterator.next();
        if (mersenneTwisterFast.nextBoolean()) {
            Assert.assertTrue(paginatedCluster.hideRecord(clusterPosition));
            hiddenRecords++;
            Assert.assertEquals(paginatedCluster.getEntries(), records - hiddenRecords);
            positionIterator.remove();
        }
    }
    Assert.assertEquals(paginatedCluster.getEntries(), records - hiddenRecords);
    for (int i = 0; i < records / 2; i++) {
        int recordSize = mersenneTwisterFast.nextInt(3 * OClusterPage.MAX_RECORD_SIZE) + 1;
        byte[] bigRecord = new byte[recordSize];
        mersenneTwisterFast.nextBytes(bigRecord);
        final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(bigRecord, recordVersion, (byte) 2, null);
        positionRecordMap.put(physicalPosition.clusterPosition, bigRecord);
    }
    Assert.assertEquals(paginatedCluster.getEntries(), (long) (1.5 * records - hiddenRecords));
}
Also used : OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition)

Example 7 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testGetPhysicalPosition.

public void testGetPhysicalPosition() throws IOException {
    final int records = 10000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testGetPhysicalPosition seed : " + seed);
    Set<OPhysicalPosition> positions = new HashSet<OPhysicalPosition>();
    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);
        recordVersion++;
        final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(record, recordVersion, (byte) i, null);
        positions.add(physicalPosition);
    }
    Set<OPhysicalPosition> removedPositions = new HashSet<OPhysicalPosition>();
    for (OPhysicalPosition position : positions) {
        OPhysicalPosition physicalPosition = new OPhysicalPosition();
        physicalPosition.clusterPosition = position.clusterPosition;
        physicalPosition = paginatedCluster.getPhysicalPosition(physicalPosition);
        Assert.assertEquals(physicalPosition.clusterPosition, position.clusterPosition);
        Assert.assertEquals(physicalPosition.recordType, position.recordType);
        Assert.assertEquals(physicalPosition.recordSize, position.recordSize);
        if (mersenneTwisterFast.nextBoolean()) {
            paginatedCluster.deleteRecord(position.clusterPosition);
            removedPositions.add(position);
        }
    }
    for (OPhysicalPosition position : positions) {
        OPhysicalPosition physicalPosition = new OPhysicalPosition();
        physicalPosition.clusterPosition = position.clusterPosition;
        physicalPosition = paginatedCluster.getPhysicalPosition(physicalPosition);
        if (removedPositions.contains(position))
            Assert.assertNull(physicalPosition);
        else {
            Assert.assertEquals(physicalPosition.clusterPosition, position.clusterPosition);
            Assert.assertEquals(physicalPosition.recordType, position.recordType);
            Assert.assertEquals(physicalPosition.recordSize, position.recordSize);
        }
    }
}
Also used : OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition)

Example 8 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testUpdateManySmallRecords.

public void testUpdateManySmallRecords() throws IOException {
    final int records = 10000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testUpdateManySmallRecords seed : " + seed);
    Map<Long, byte[]> positionRecordMap = new HashMap<Long, byte[]>();
    Set<Long> updatedPositions = new HashSet<Long>();
    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 newRecordVersion = 0;
    newRecordVersion = recordVersion;
    newRecordVersion++;
    for (long clusterPosition : positionRecordMap.keySet()) {
        if (mersenneTwisterFast.nextBoolean()) {
            int recordSize = mersenneTwisterFast.nextInt(OClusterPage.MAX_RECORD_SIZE - 1) + 1;
            byte[] smallRecord = new byte[recordSize];
            mersenneTwisterFast.nextBytes(smallRecord);
            paginatedCluster.updateRecord(clusterPosition, smallRecord, newRecordVersion, (byte) 3);
            positionRecordMap.put(clusterPosition, smallRecord);
            updatedPositions.add(clusterPosition);
        }
    }
    for (Map.Entry<Long, byte[]> entry : positionRecordMap.entrySet()) {
        ORawBuffer rawBuffer = paginatedCluster.readRecord(entry.getKey(), false);
        Assert.assertNotNull(rawBuffer);
        Assert.assertEquals(rawBuffer.buffer, entry.getValue());
        if (updatedPositions.contains(entry.getKey())) {
            Assert.assertEquals(rawBuffer.version, newRecordVersion);
            Assert.assertEquals(rawBuffer.recordType, 3);
        } else {
            Assert.assertEquals(rawBuffer.version, recordVersion);
            Assert.assertEquals(rawBuffer.recordType, 2);
        }
    }
}
Also used : OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer)

Example 9 with OPhysicalPosition

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

the class ClusterDebugInfoTest method testThreePagesRecordDebugInfo.

@Test
public void testThreePagesRecordDebugInfo() throws IOException {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:ClusterDebugInfoTest");
    db.create();
    try {
        OStorage storage = db.getStorage();
        int defaultId = storage.getDefaultClusterId();
        OPaginatedCluster cluster = (OPaginatedCluster) storage.getClusterById(defaultId);
        int size = OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger();
        byte[] content = new byte[(size + size) * 1024];
        OStorageOperationResult<OPhysicalPosition> result = storage.createRecord(new ORecordId(defaultId), content, 0, (byte) 'b', OPERATION_MODE.SYNCHRONOUS.ordinal(), null);
        OPaginatedClusterDebug debug = cluster.readDebug(result.getResult().clusterPosition);
        Assert.assertEquals(debug.clusterPosition, result.getResult().clusterPosition);
        Assert.assertNotEquals(debug.contentSize, 0);
        Assert.assertFalse(debug.empty);
        Assert.assertEquals(debug.pages.size(), 3);
        Assert.assertNotEquals(debug.pages.get(0).pageIndex, -1);
        Assert.assertNotEquals(debug.pages.get(0).inPagePosition, -1);
        Assert.assertNotEquals(debug.pages.get(0).inPageSize, -1);
        Assert.assertNotNull(debug.pages.get(0).content);
        Assert.assertNotEquals(debug.pages.get(1).pageIndex, -1);
        Assert.assertNotEquals(debug.pages.get(1).inPagePosition, -1);
        Assert.assertNotEquals(debug.pages.get(1).inPageSize, -1);
        Assert.assertNotNull(debug.pages.get(1).content);
        Assert.assertNotEquals(debug.pages.get(2).pageIndex, -1);
        Assert.assertNotEquals(debug.pages.get(2).inPagePosition, -1);
        Assert.assertNotEquals(debug.pages.get(2).inPageSize, -1);
        Assert.assertNotNull(debug.pages.get(2).content);
    } finally {
        db.drop();
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

Example 10 with OPhysicalPosition

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

the class ClusterDebugInfoTest method testOnePageRecordDebugInfo.

@Test
public void testOnePageRecordDebugInfo() throws IOException {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:ClusterDebugInfoTest");
    db.create();
    try {
        OStorage storage = db.getStorage();
        int defaultId = storage.getDefaultClusterId();
        OPaginatedCluster cluster = (OPaginatedCluster) storage.getClusterById(defaultId);
        int size = OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger();
        int half = size / 2;
        byte[] content = new byte[half * 1024];
        OStorageOperationResult<OPhysicalPosition> result = storage.createRecord(new ORecordId(defaultId), content, 0, (byte) 'b', OPERATION_MODE.SYNCHRONOUS.ordinal(), null);
        OPaginatedClusterDebug debug = cluster.readDebug(result.getResult().clusterPosition);
        Assert.assertEquals(debug.clusterPosition, result.getResult().clusterPosition);
        Assert.assertNotEquals(debug.contentSize, 0);
        Assert.assertFalse(debug.empty);
        Assert.assertEquals(debug.pages.size(), 1);
        Assert.assertNotEquals(debug.pages.get(0).pageIndex, -1);
        Assert.assertNotEquals(debug.pages.get(0).inPagePosition, -1);
        Assert.assertNotEquals(debug.pages.get(0).inPageSize, -1);
        Assert.assertNotNull(debug.pages.get(0).content);
    } finally {
        db.drop();
    }
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OStorage(com.orientechnologies.orient.core.storage.OStorage) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition) ORecordId(com.orientechnologies.orient.core.id.ORecordId) Test(org.testng.annotations.Test)

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