Search in sources :

Example 66 with OByteBufferPool

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

the class ReadWriteDiskCacheTest method testIfNotEnoughSpaceOldPagesShouldBeMovedToA1Out.

public void testIfNotEnoughSpaceOldPagesShouldBeMovedToA1Out() throws Exception {
    long fileId = readBuffer.addFile(fileName, writeBuffer);
    OCacheEntry[] entries = new OCacheEntry[6];
    for (int i = 0; i < 6; 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, 7 });
        entries[i].getCachePointer().releaseExclusiveLock();
        readBuffer.release(entries[i], writeBuffer);
    }
    LRUList am = readBuffer.getAm();
    LRUList a1in = readBuffer.getA1in();
    LRUList a1out = readBuffer.getA1out();
    Assert.assertEquals(am.size(), 0);
    for (int i = 0; i < 2; i++) {
        OCacheEntry entry = generateRemovedEntry(fileId, i);
        Assert.assertEquals(a1out.get(entry.getFileId(), entry.getPageIndex()), entry);
    }
    final OByteBufferPool bufferPool = OByteBufferPool.instance();
    for (int i = 2; i < 6; i++) {
        OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
        Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry);
    }
    Assert.assertEquals(writeBuffer.getFilledUpTo(fileId), 6);
    writeBuffer.flush();
    for (int i = 0; i < 6; i++) {
        assertFile(i, new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, 7 }, new OLogSequenceNumber(0, 0));
    }
}
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 67 with OByteBufferPool

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

the class ReadWriteDiskCacheTest method testCloseFileShouldFlushData.

public void testCloseFileShouldFlushData() throws Exception {
    long fileId = readBuffer.addFile(fileName, writeBuffer);
    OCacheEntry[] entries = new OCacheEntry[4];
    for (int i = 0; i < 4; 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();
        ByteBuffer buffer = entries[i].getCachePointer().getSharedBuffer();
        buffer.position(systemOffset);
        buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i });
        entries[i].getCachePointer().releaseExclusiveLock();
        readBuffer.release(entries[i], writeBuffer);
    }
    LRUList am = readBuffer.getAm();
    LRUList a1in = readBuffer.getA1in();
    LRUList a1out = readBuffer.getA1out();
    Assert.assertEquals(am.size(), 0);
    Assert.assertEquals(a1out.size(), 0);
    final OByteBufferPool bufferPool = OByteBufferPool.instance();
    for (int i = 0; i < 4; i++) {
        OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
        Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry);
    }
    Assert.assertEquals(writeBuffer.getFilledUpTo(fileId), 4);
    readBuffer.closeFile(fileId, true, writeBuffer);
    for (int i = 0; i < 4; i++) {
        assertFile(i, new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }, new OLogSequenceNumber(0, 0));
    }
}
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 68 with OByteBufferPool

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

the class ReadWriteDiskCacheTest method initBuffer.

private void initBuffer() throws IOException {
    writeBuffer = new OWOWCache(false, PAGE_SIZE, new OByteBufferPool(PAGE_SIZE), -1, writeAheadLog, -1, WRITE_CACHE_MAX_SIZE, WRITE_CACHE_MAX_SIZE + READ_CACHE_MAX_MEMORY, storageLocal, false, files, 1);
    writeBuffer.loadRegisteredFiles();
    readBuffer = new O2QCache(READ_CACHE_MAX_MEMORY, PAGE_SIZE, false, 50);
}
Also used : OWOWCache(com.orientechnologies.orient.core.storage.cache.local.OWOWCache) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool)

Example 69 with OByteBufferPool

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

the class ReadWriteDiskCacheTest method testFrequentlyReadItemsAreMovedInAm.

public void testFrequentlyReadItemsAreMovedInAm() 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);
    }
    writeBuffer.flush();
    readBuffer.clear();
    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));
    for (int i = 0; i < 8; i++) {
        entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
        readBuffer.release(entries[i], writeBuffer);
    }
    for (int i = 2; i < 4; i++) {
        entries[i] = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
        readBuffer.release(entries[i], writeBuffer);
    }
    LRUList am = readBuffer.getAm();
    LRUList a1in = readBuffer.getA1in();
    LRUList a1out = readBuffer.getA1out();
    Assert.assertEquals(am.size(), 2);
    Assert.assertEquals(a1in.size(), 2);
    Assert.assertEquals(a1out.size(), 2);
    final OByteBufferPool bufferPool = OByteBufferPool.instance();
    for (int i = 2; i < 4; 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 = 4; i < 6; i++) {
        OCacheEntry lruEntry = generateRemovedEntry(fileId, i);
        Assert.assertEquals(a1out.get(fileId, i), lruEntry);
    }
    for (int i = 6; i < 8; i++) {
        OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(1, i));
        Assert.assertEquals(a1in.get(fileId, i), lruEntry);
    }
}
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 70 with OByteBufferPool

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

the class ReadWriteDiskCacheTest method testLoadAndLockForReadShouldHitCache.

public void testLoadAndLockForReadShouldHitCache() throws Exception {
    long fileId = readBuffer.addFile(fileName, writeBuffer);
    OCacheEntry cacheEntry = readBuffer.load(fileId, 0, false, writeBuffer, 1, true);
    if (cacheEntry == null) {
        cacheEntry = readBuffer.allocateNewPage(fileId, writeBuffer, true);
        Assert.assertEquals(cacheEntry.getPageIndex(), 0);
    }
    readBuffer.release(cacheEntry, writeBuffer);
    LRUList am = readBuffer.getAm();
    LRUList a1in = readBuffer.getA1in();
    LRUList a1out = readBuffer.getA1out();
    Assert.assertEquals(am.size(), 0);
    Assert.assertEquals(a1out.size(), 0);
    final OByteBufferPool bufferPool = OByteBufferPool.instance();
    final OCacheEntry entry = generateEntry(fileId, 0, cacheEntry.getCachePointer().getSharedBuffer(), bufferPool, false, new OLogSequenceNumber(0, 0));
    Assert.assertEquals(a1in.size(), 1);
    Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry);
}
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)

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