Search in sources :

Example 66 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.

the class LRUListTest method testAddElevenRemoveLRU.

@Test
public void testAddElevenRemoveLRU() {
    final OByteBufferPool bufferPool = new OByteBufferPool(1);
    OCachePointer[] cachePointers = new OCachePointer[11];
    for (int i = 0; i < 11; i++) {
        ByteBuffer buffer = bufferPool.acquireDirect(true);
        cachePointers[i] = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
        lruList.putToMRU(new OCacheEntry(1, i * 10, cachePointers[i], false));
    }
    lruList.removeLRU();
    Assert.assertEquals(lruList.size(), 10);
    Iterator<OCacheEntry> entryIterator = lruList.iterator();
    for (int i = 10; i > 0; i--) {
        Assert.assertTrue(entryIterator.hasNext());
        Assert.assertEquals(entryIterator.next(), new OCacheEntry(1, i * 10, cachePointers[i], false));
    }
}
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) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) ByteBuffer(java.nio.ByteBuffer) Test(org.testng.annotations.Test)

Example 67 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.

the class ONullBucketTest method testAddGetValue.

public void testAddGetValue() throws IOException {
    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);
    bucket.setValue(new OSBTreeValue<String>(false, -1, "test"));
    OSBTreeValue<String> treeValue = bucket.getValue();
    Assert.assertEquals(treeValue.getValue(), "test");
    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 68 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber 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 69 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber 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 70 with OLogSequenceNumber

use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber 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

OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)97 ByteBuffer (java.nio.ByteBuffer)78 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)74 OByteBufferPool (com.orientechnologies.common.directmemory.OByteBufferPool)69 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)68 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)16 ORecordId (com.orientechnologies.orient.core.id.ORecordId)10 Random (java.util.Random)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 TreeSet (java.util.TreeSet)8 OFileClassic (com.orientechnologies.orient.core.storage.fs.OFileClassic)6 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)3 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)3 HazelcastException (com.hazelcast.core.HazelcastException)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)2