Search in sources :

Example 31 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testManyAllocatePositionMap.

public void testManyAllocatePositionMap() throws IOException {
    final int records = 10000;
    List<OPhysicalPosition> positions = new ArrayList<OPhysicalPosition>();
    for (int i = 0; i < records; i++) {
        OPhysicalPosition position = paginatedCluster.allocatePosition((byte) 'd');
        Assert.assertTrue(position.clusterPosition >= 0);
        ORawBuffer rec = paginatedCluster.readRecord(position.clusterPosition, false);
        Assert.assertNull(rec);
        positions.add(position);
    }
    for (int i = 0; i < records; i++) {
        OPhysicalPosition position = positions.get(i);
        paginatedCluster.createRecord(new byte[20], 1, (byte) 'd', position);
        ORawBuffer rec = paginatedCluster.readRecord(position.clusterPosition, false);
        Assert.assertNotNull(rec);
    }
}
Also used : ORawBuffer(com.orientechnologies.orient.core.storage.ORawBuffer) OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition)

Example 32 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testHideHalfBigRecords.

public void testHideHalfBigRecords() throws IOException {
    final int records = 5000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testHideHalfBigRecords 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);
    }
    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 hiddenPosition : hiddenPositions) {
        Assert.assertNull(paginatedCluster.readRecord(hiddenPosition, false));
        Assert.assertFalse(paginatedCluster.hideRecord(hiddenPosition));
    }
    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 33 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testRemoveHalfBigRecords.

public void testRemoveHalfBigRecords() throws IOException {
    final int records = 5000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testRemoveHalfBigRecords 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);
    }
    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 34 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testRemoveHalfRecordsAndAddAnotherHalfAgain.

public void testRemoveHalfRecordsAndAddAnotherHalfAgain() throws IOException {
    final int records = 10000;
    long seed = System.currentTimeMillis();
    Random mersenneTwisterFast = new Random(seed);
    System.out.println("testRemoveHalfRecordsAndAddAnotherHalfAgain 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 deletedRecords = 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.deleteRecord(clusterPosition));
            deletedRecords++;
            Assert.assertEquals(paginatedCluster.getEntries(), records - deletedRecords);
            positionIterator.remove();
        }
    }
    Assert.assertEquals(paginatedCluster.getEntries(), records - deletedRecords);
    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 - deletedRecords));
}
Also used : OPhysicalPosition(com.orientechnologies.orient.core.storage.OPhysicalPosition)

Example 35 with OPhysicalPosition

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

the class LocalPaginatedClusterTest method testAddOneBigRecord.

public void testAddOneBigRecord() throws IOException {
    byte[] bigRecord = new byte[2 * 65536 + 100];
    Random mersenneTwisterFast = new Random();
    mersenneTwisterFast.nextBytes(bigRecord);
    int recordVersion = 0;
    recordVersion++;
    recordVersion++;
    OPhysicalPosition physicalPosition = paginatedCluster.createRecord(bigRecord, 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, bigRecord);
    Assert.assertEquals(rawBuffer.recordType, 1);
}
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