Search in sources :

Example 16 with OCachePointer

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

the class ClusterPageTest method testAddThreeRecords.

public void testAddThreeRecords() 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);
        addThreeRecords(localPage);
        addThreeRecords(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)

Example 17 with OCachePointer

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

the class ClusterPageTest method testReplaceOneRecordNoVersionUpdate.

public void testReplaceOneRecordNoVersionUpdate() 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);
        replaceOneRecordNoVersionUpdate(localPage);
        replaceOneRecordNoVersionUpdate(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)

Example 18 with OCachePointer

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

the class ClusterPageTest method testFindLastRecord.

public void testFindLastRecord() 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();
    final long seed = System.currentTimeMillis();
    try {
        OClusterPage localPage = new OClusterPage(cacheEntry, true, new OWALChangesTree());
        OClusterPage directLocalPage = new OClusterPage(directCacheEntry, true, null);
        findLastRecord(seed, localPage);
        findLastRecord(seed, 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)

Example 19 with OCachePointer

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

the class ReadWriteDiskCacheTest method testFlushTillLSN.

public void testFlushTillLSN() throws Exception {
    closeBufferAndDeleteFile();
    File file = new File(storageLocal.getConfiguration().getDirectory());
    if (!file.exists())
        file.mkdir();
    writeAheadLog = new ODiskWriteAheadLog(1024, -1, 10 * 1024, null, true, storageLocal, 10);
    final OStorageSegmentConfiguration segmentConfiguration = new OStorageSegmentConfiguration(storageLocal.getConfiguration(), "readWriteDiskCacheTest.tst", 0);
    segmentConfiguration.fileType = OFileClassic.NAME;
    writeBuffer = new OWOWCache(false, 8 + systemOffset, new OByteBufferPool(8 + systemOffset), 10000, writeAheadLog, 100, 2 * (8 + systemOffset), 2 * (8 + systemOffset) + 4 * (8 + systemOffset), storageLocal, false, files, 10);
    writeBuffer.loadRegisteredFiles();
    readBuffer = new O2QCache(4 * (8 + systemOffset), 8 + systemOffset, false, 20);
    long fileId = readBuffer.addFile(fileName, writeBuffer);
    OLogSequenceNumber lsnToFlush = null;
    for (int i = 0; i < 8; i++) {
        OCacheEntry cacheEntry = readBuffer.load(fileId, i, false, writeBuffer, 1, true);
        if (cacheEntry == null) {
            cacheEntry = readBuffer.allocateNewPage(fileId, writeBuffer, true);
            Assert.assertEquals(cacheEntry.getPageIndex(), i);
        }
        OCachePointer dataPointer = cacheEntry.getCachePointer();
        dataPointer.acquireExclusiveLock();
        OLogSequenceNumber pageLSN = writeAheadLog.log(new WriteAheadLogTest.TestRecord(30, false));
        setLsn(dataPointer.getSharedBuffer(), pageLSN);
        lsnToFlush = pageLSN;
        cacheEntry.markDirty();
        dataPointer.releaseExclusiveLock();
        readBuffer.release(cacheEntry, writeBuffer);
    }
    Thread.sleep(1000);
    Assert.assertEquals(writeAheadLog.getFlushedLsn(), lsnToFlush);
}
Also used : WriteAheadLogTest(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.WriteAheadLogTest) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ODiskWriteAheadLog(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.ODiskWriteAheadLog) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OWOWCache(com.orientechnologies.orient.core.storage.cache.local.OWOWCache) OStorageSegmentConfiguration(com.orientechnologies.orient.core.config.OStorageSegmentConfiguration) File(java.io.File) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer)

Example 20 with OCachePointer

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

the class WOWCacheTest method testDataUpdate.

@Test
public void testDataUpdate() throws Exception {
    final NavigableMap<Long, byte[]> pageIndexDataMap = new TreeMap<Long, byte[]>();
    long fileId = wowCache.addFile(fileName);
    Random random = new Random();
    for (int i = 0; i < 600; i++) {
        long pageIndex = random.nextInt(2048);
        byte[] data = new byte[8];
        random.nextBytes(data);
        pageIndexDataMap.put(pageIndex, data);
        final OCachePointer cachePointer = wowCache.load(fileId, pageIndex, 1, true, new OModifiableBoolean(), true)[0];
        cachePointer.acquireExclusiveLock();
        ByteBuffer buffer = cachePointer.getSharedBuffer();
        buffer.position(systemOffset);
        buffer.put(data);
        cachePointer.releaseExclusiveLock();
        wowCache.store(fileId, pageIndex, cachePointer);
        cachePointer.decrementReadersReferrer();
    }
    for (Map.Entry<Long, byte[]> entry : pageIndexDataMap.entrySet()) {
        long pageIndex = entry.getKey();
        byte[] dataOne = entry.getValue();
        OCachePointer cachePointer = wowCache.load(fileId, pageIndex, 1, false, new OModifiableBoolean(), true)[0];
        byte[] dataTwo = new byte[8];
        ByteBuffer buffer = cachePointer.getSharedBuffer();
        buffer.position(systemOffset);
        buffer.get(dataTwo);
        cachePointer.decrementReadersReferrer();
        Assert.assertEquals(dataTwo, dataOne);
    }
    for (int i = 0; i < 300; i++) {
        long desiredIndex = random.nextInt(2048);
        Long pageIndex = pageIndexDataMap.ceilingKey(desiredIndex);
        if (pageIndex == null)
            pageIndex = pageIndexDataMap.floorKey(desiredIndex);
        byte[] data = new byte[8];
        random.nextBytes(data);
        pageIndexDataMap.put(pageIndex, data);
        final OCachePointer cachePointer = wowCache.load(fileId, pageIndex, 1, true, new OModifiableBoolean(), true)[0];
        cachePointer.acquireExclusiveLock();
        ByteBuffer buffer = cachePointer.getSharedBuffer();
        buffer.position(systemOffset);
        buffer.put(data);
        cachePointer.releaseExclusiveLock();
        wowCache.store(fileId, pageIndex, cachePointer);
        cachePointer.decrementReadersReferrer();
    }
    for (Map.Entry<Long, byte[]> entry : pageIndexDataMap.entrySet()) {
        long pageIndex = entry.getKey();
        byte[] dataOne = entry.getValue();
        OCachePointer cachePointer = wowCache.load(fileId, pageIndex, 1, false, new OModifiableBoolean(), true)[0];
        byte[] dataTwo = new byte[8];
        ByteBuffer buffer = cachePointer.getSharedBuffer();
        buffer.position(systemOffset);
        buffer.get(dataTwo);
        cachePointer.decrementReadersReferrer();
        Assert.assertEquals(dataTwo, dataOne);
    }
    wowCache.flush();
    for (Map.Entry<Long, byte[]> entry : pageIndexDataMap.entrySet()) {
        assertFile(entry.getKey(), entry.getValue(), new OLogSequenceNumber(0, 0));
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean) Test(org.testng.annotations.Test) WriteAheadLogTest(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.WriteAheadLogTest)

Aggregations

OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)77 ByteBuffer (java.nio.ByteBuffer)73 OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)68 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)65 OByteBufferPool (com.orientechnologies.common.directmemory.OByteBufferPool)61 Test (org.testng.annotations.Test)22 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 OWALChangesTree (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree)19 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)9 OFileClassic (com.orientechnologies.orient.core.storage.fs.OFileClassic)9 Random (java.util.Random)9 ORecordId (com.orientechnologies.orient.core.id.ORecordId)8 WriteAheadLogTest (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.WriteAheadLogTest)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 TreeSet (java.util.TreeSet)8 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)2 Assert (org.testng.Assert)2