Search in sources :

Example 11 with OPhysicalPosition

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

the class ClusterDebugInfoTest method testTwoPagesRecordDebugInfo.

@Test
public void testTwoPagesRecordDebugInfo() 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[(size + 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.pages.size(), 2);
        Assert.assertEquals(debug.clusterPosition, result.getResult().clusterPosition);
        Assert.assertNotEquals(debug.contentSize, 0);
        Assert.assertFalse(debug.empty);
        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);
    } 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 12 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testRemoveHalfSmallRecords.

public void testRemoveHalfSmallRecords() throws IOException {
    final int records = 10000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testRemoveHalfSmallRecords 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 deletedRecords = 0;
    Assert.assertEquals(records, paginatedCluster.getEntries());
    Set<Long> deletedPositions = new HashSet<Long>();
    Iterator<Long> positionIterator = positionRecordMap.keySet().iterator();
    while (positionIterator.hasNext()) {
        long clusterPosition = positionIterator.next();
        if (mersenneTwisterFast.nextBoolean()) {
            deletedPositions.add(clusterPosition);
            Assert.assertTrue(paginatedCluster.deleteRecord(clusterPosition));
            deletedRecords++;
            Assert.assertEquals(records - deletedRecords, paginatedCluster.getEntries());
            positionIterator.remove();
        }
    }
    Assert.assertEquals(paginatedCluster.getEntries(), records - deletedRecords);
    for (long deletedPosition : deletedPositions) {
        Assert.assertNull(paginatedCluster.readRecord(deletedPosition, false));
        Assert.assertFalse(paginatedCluster.deleteRecord(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)

Example 13 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testAddManyRecords.

public void testAddManyRecords() throws IOException {
    final int records = 10000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testAddManyRecords 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(2 * OClusterPage.MAX_RECORD_SIZE) + 1;
        byte[] smallRecord = new byte[recordSize];
        mersenneTwisterFast.nextBytes(smallRecord);
        final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 2, null);
        positionRecordMap.put(physicalPosition.clusterPosition, smallRecord);
    }
    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 : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition)

Example 14 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testAddOneSmallRecord.

public void testAddOneSmallRecord() 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);
    ORawBuffer rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
    Assert.assertNotNull(rawBuffer);
    Assert.assertEquals(rawBuffer.version, recordVersion);
    Assert.assertEquals(rawBuffer.buffer, smallRecord);
    Assert.assertEquals(rawBuffer.recordType, 1);
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition)

Example 15 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testAddManyBigRecords.

public void testAddManyBigRecords() throws IOException {
    final int records = 5000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testAddManyBigRecords 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(2 * OClusterPage.MAX_RECORD_SIZE) + 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);
    }
    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 : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) 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