Search in sources :

Example 51 with OByteBufferPool

use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.

the class ONullBucketTest method testEmptyBucket.

public void testEmptyBucket() {
    OByteBufferPool bufferPool = new OByteBufferPool(1024);
    ByteBuffer buffer = bufferPool.acquireDirect(true);
    OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    cachePointer.incrementReferrer();
    OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
    cacheEntry.acquireExclusiveLock();
    ONullBucket<String> bucket = new ONullBucket<String>(cacheEntry, null, OStringSerializer.INSTANCE, true);
    Assert.assertNull(bucket.getValue());
    cacheEntry.releaseExclusiveLock();
    cachePointer.decrementReferrer();
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer)

Example 52 with OByteBufferPool

use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.

the class WALChangesTreeTest method testAddOverlappedVersionsDM.

public void testAddOverlappedVersionsDM() {
    final OWALChangesTree tree = new OWALChangesTree();
    tree.setDebug(true);
    tree.add(new byte[] { 35, 30 }, 11);
    tree.add(new byte[] { 10, 20 }, 10);
    OByteBufferPool bufferPool = new OByteBufferPool(20);
    ByteBuffer buffer = bufferPool.acquireDirect(true);
    tree.applyChanges(buffer);
    Assert.assertEquals(getByteArray(buffer, 10, 3), new byte[] { 10, 20, 30 });
}
Also used : OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer)

Example 53 with OByteBufferPool

use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.

the class WALChangesTreeTest method testInsertCase4and5DM.

public void testInsertCase4and5DM() {
    final OWALChangesTree tree = new OWALChangesTree();
    tree.setDebug(true);
    tree.add(new byte[] { 50 }, 50);
    tree.add(new byte[] { 60 }, 60);
    tree.add(new byte[] { 40 }, 40);
    tree.add(new byte[] { 30 }, 30);
    tree.add(new byte[] { 35 }, 35);
    OByteBufferPool bufferPool = new OByteBufferPool(80);
    ByteBuffer buffer = bufferPool.acquireDirect(true);
    tree.applyChanges(buffer);
    Assert.assertEquals(getByteArray(buffer, 50, 1), new byte[] { 50 });
    Assert.assertEquals(getByteArray(buffer, 60, 1), new byte[] { 60 });
    Assert.assertEquals(getByteArray(buffer, 40, 1), new byte[] { 40 });
    Assert.assertEquals(getByteArray(buffer, 30, 1), new byte[] { 30 });
    Assert.assertEquals(getByteArray(buffer, 35, 1), new byte[] { 35 });
}
Also used : OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer)

Example 54 with OByteBufferPool

use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.

the class ReadWriteDiskCacheTest method testFrequentlyAddItemsAreMovedInAm.

public void testFrequentlyAddItemsAreMovedInAm() throws Exception {
    long fileId = readBuffer.addFile(fileName, writeBuffer);
    OCacheEntry[] entries = new OCacheEntry[10];
    for (int i = 0; i < 10; i++) {
        entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
        if (entries[i] == null) {
            entries[i] = readBuffer.allocateNewPage(fileId, writeBuffer, true);
            Assert.assertEquals(entries[i].getPageIndex(), i);
        }
        entries[i].getCachePointer().acquireExclusiveLock();
        entries[i].markDirty();
        final ByteBuffer buffer = entries[i].getCachePointer().getSharedBuffer();
        buffer.position(systemOffset);
        buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i });
        setLsn(buffer, new OLogSequenceNumber(1, i));
        entries[i].getCachePointer().releaseExclusiveLock();
        readBuffer.release(entries[i], writeBuffer);
    }
    LRUList am = readBuffer.getAm();
    LRUList a1in = readBuffer.getA1in();
    LRUList a1out = readBuffer.getA1out();
    Assert.assertEquals(a1in.size(), 4);
    Assert.assertEquals(a1out.size(), 2);
    Assert.assertEquals(am.size(), 0);
    OByteBufferPool bufferPool = OByteBufferPool.instance();
    for (int i = 6; i < 10; i++) {
        OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
        Assert.assertEquals(a1in.get(fileId, i), lruEntry);
    }
    for (int i = 4; i < 6; i++) {
        OCacheEntry lruEntry = generateRemovedEntry(fileId, i);
        Assert.assertEquals(a1out.get(fileId, i), lruEntry);
    }
    for (int i = 4; i < 6; i++) {
        entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
        readBuffer.release(entries[i], writeBuffer);
    }
    Assert.assertEquals(am.size(), 2);
    Assert.assertEquals(a1in.size(), 2);
    Assert.assertEquals(a1out.size(), 2);
    for (int i = 4; i < 6; i++) {
        OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(1, i));
        Assert.assertEquals(am.get(fileId, i), lruEntry);
    }
    for (int i = 6; i < 8; i++) {
        OCacheEntry lruEntry = generateRemovedEntry(fileId, i);
        Assert.assertEquals(a1out.get(fileId, i), lruEntry);
    }
    for (int i = 8; i < 10; i++) {
        OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
        Assert.assertEquals(a1in.get(fileId, i), lruEntry);
    }
    writeBuffer.flush();
    for (int i = 0; i < 10; i++) assertFile(i, new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }, new OLogSequenceNumber(1, i));
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer)

Example 55 with OByteBufferPool

use of com.orientechnologies.common.directmemory.OByteBufferPool in project orientdb by orientechnologies.

the class ClusterPageTest method testDeleteAddBiggerVersion.

public void testDeleteAddBiggerVersion() throws Exception {
    OByteBufferPool bufferPool = OByteBufferPool.instance();
    ByteBuffer buffer = bufferPool.acquireDirect(true);
    OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    cachePointer.incrementReferrer();
    OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
    cacheEntry.acquireExclusiveLock();
    ByteBuffer directBuffer = bufferPool.acquireDirect(true);
    OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    directCachePointer.incrementReferrer();
    OCacheEntry directCacheEntry = new OCacheEntry(0, 0, directCachePointer, false);
    directCacheEntry.acquireExclusiveLock();
    try {
        OClusterPage localPage = new OClusterPage(cacheEntry, true, new OWALChangesTree());
        OClusterPage directLocalPage = new OClusterPage(directCacheEntry, true, null);
        deleteAddBiggerVersion(localPage);
        deleteAddBiggerVersion(directLocalPage);
        assertChangesTracking(localPage, directBuffer, bufferPool);
    } finally {
        cacheEntry.releaseExclusiveLock();
        directCacheEntry.releaseExclusiveLock();
        cachePointer.decrementReferrer();
        directCachePointer.decrementReferrer();
    }
}
Also used : OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OWALChangesTree(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer)

Aggregations

OByteBufferPool (com.orientechnologies.common.directmemory.OByteBufferPool)78 ByteBuffer (java.nio.ByteBuffer)73 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)69 OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)69 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)61 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)19 Test (org.testng.annotations.Test)15 Random (java.util.Random)10 ORecordId (com.orientechnologies.orient.core.id.ORecordId)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 TreeSet (java.util.TreeSet)8 OWOWCache (com.orientechnologies.orient.core.storage.cache.local.OWOWCache)4 OStorageSegmentConfiguration (com.orientechnologies.orient.core.config.OStorageSegmentConfiguration)1 O2QCache (com.orientechnologies.orient.core.storage.cache.local.twoq.O2QCache)1 ODiskWriteAheadLog (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog)1 WriteAheadLogTest (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.WriteAheadLogTest)1 File (java.io.File)1