Search in sources :

Example 76 with OCachePointer

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

the class WOWCacheTest method testFlushAllContentEventually.

public void testFlushAllContentEventually() throws Exception {
    Random random = new Random();
    byte[][] pageData = new byte[200][];
    long fileId = wowCache.addFile(fileName);
    for (int i = 0; i < pageData.length; i++) {
        byte[] data = new byte[8];
        random.nextBytes(data);
        pageData[i] = data;
        final OCachePointer cachePointer = wowCache.load(fileId, i, 1, true, new OModifiableBoolean(), true)[0];
        cachePointer.acquireExclusiveLock();
        ByteBuffer buffer = cachePointer.getSharedBuffer();
        buffer.position(systemOffset);
        buffer.put(data);
        cachePointer.releaseExclusiveLock();
        wowCache.store(fileId, i, cachePointer);
        cachePointer.decrementReadersReferrer();
    }
    for (int i = 0; i < pageData.length; i++) {
        byte[] dataOne = pageData[i];
        OCachePointer cachePointer = wowCache.load(fileId, i, 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);
    }
    final long start = System.currentTimeMillis();
    while (wowCache.getWriteCacheSize() != 0) {
        Thread.sleep(1000);
        // wait no more than 10 min
        if (((System.currentTimeMillis() - start) / 1000) > 10 * 60) {
            Assert.assertEquals(wowCache.getWriteCacheSize(), 0);
        }
    }
    for (int i = 0; i < pageData.length; i++) {
        byte[] dataContent = pageData[i];
        assertFile(i, dataContent, new OLogSequenceNumber(0, 0));
    }
}
Also used : 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) ByteBuffer(java.nio.ByteBuffer)

Example 77 with OCachePointer

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

the class WOWCacheTest method testMagicFailure.

@Test
public void testMagicFailure() throws IOException {
    wowCache.setChecksumMode(OChecksumMode.StoreAndThrow);
    final long fileId = wowCache.addFile(fileName);
    final OCachePointer cachePointer = wowCache.load(fileId, 0, 1, true, new OModifiableBoolean(), true)[0];
    cachePointer.acquireExclusiveLock();
    final ByteBuffer buffer = cachePointer.getSharedBuffer();
    buffer.position(systemOffset);
    buffer.put(new byte[buffer.remaining()]);
    cachePointer.releaseExclusiveLock();
    wowCache.store(fileId, 0, cachePointer);
    cachePointer.decrementReadersReferrer();
    wowCache.flush();
    final String path = storageLocal.getConfiguration().getDirectory() + File.separator + fileName;
    final OFileClassic file = new OFileClassic(path, "rw");
    file.open();
    file.writeByte(0, (byte) 1);
    file.close();
    Assert.assertThrows(OStorageException.class, new Assert.ThrowingRunnable() {

        @Override
        public void run() throws Throwable {
            wowCache.load(fileId, 0, 1, true, new OModifiableBoolean(), true);
        }
    });
}
Also used : Assert(org.testng.Assert) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean) ByteBuffer(java.nio.ByteBuffer) OFileClassic(com.orientechnologies.orient.core.storage.fs.OFileClassic) 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