Search in sources :

Example 31 with OCachePointer

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

the class LRUListTest method testAddOneRemoveLRU.

@Test
public void testAddOneRemoveLRU() {
    final OByteBufferPool bufferPool = new OByteBufferPool(1);
    ByteBuffer buffer = bufferPool.acquireDirect(true);
    OCachePointer cachePointerOne = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
    lruList.putToMRU(new OCacheEntry(1, 10, cachePointerOne, false));
    lruList.removeLRU();
    Assert.assertEquals(lruList.size(), 0);
    Iterator<OCacheEntry> entryIterator = lruList.iterator();
    Assert.assertFalse(entryIterator.hasNext());
}
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) Test(org.testng.annotations.Test)

Example 32 with OCachePointer

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

the class ONullBucketTest method testAddRemoveValue.

public void testAddRemoveValue() 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"));
    bucket.removeValue();
    OSBTreeValue<String> treeValue = bucket.getValue();
    Assert.assertNull(treeValue);
    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 33 with OCachePointer

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

the class ONullBucketTest method testAddRemoveAddValue.

public void testAddRemoveAddValue() 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"));
    bucket.removeValue();
    OSBTreeValue<String> treeValue = bucket.getValue();
    Assert.assertNull(treeValue);
    bucket.setValue(new OSBTreeValue<String>(false, -1, "testOne"));
    treeValue = bucket.getValue();
    Assert.assertEquals(treeValue.getValue(), "testOne");
    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 34 with OCachePointer

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

the class OWOWCache method cacheFileContent.

private OCachePointer[] cacheFileContent(final int intId, final long startPageIndex, final int pageCount, final boolean addNewPages, OModifiableBoolean cacheHit) throws IOException, InterruptedException {
    final long fileId = composeFileId(id, intId);
    final OClosableEntry<Long, OFileClassic> entry = files.acquire(fileId);
    try {
        final OFileClassic fileClassic = entry.get();
        if (fileClassic == null)
            throw new IllegalArgumentException("File with id " + intId + " not found in WOW Cache");
        final OLogSequenceNumber lastLsn;
        if (writeAheadLog != null)
            lastLsn = writeAheadLog.getFlushedLsn();
        else
            lastLsn = new OLogSequenceNumber(-1, -1);
        final long firstPageStartPosition = startPageIndex * pageSize;
        final long firstPageEndPosition = firstPageStartPosition + pageSize;
        if (fileClassic.getFileSize() >= firstPageEndPosition) {
            final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = performanceStatisticManager.getSessionPerformanceStatistic();
            if (sessionStoragePerformanceStatistic != null) {
                sessionStoragePerformanceStatistic.startPageReadFromFileTimer();
            }
            int pagesRead = 0;
            try {
                if (pageCount == 1) {
                    final ByteBuffer buffer = bufferPool.acquireDirect(false);
                    fileClassic.read(firstPageStartPosition, buffer);
                    buffer.position(0);
                    final OCachePointer dataPointer = new OCachePointer(buffer, bufferPool, lastLsn, fileId, startPageIndex);
                    pagesRead = 1;
                    return new OCachePointer[] { dataPointer };
                }
                final long maxPageCount = (fileClassic.getFileSize() - firstPageStartPosition) / pageSize;
                final int realPageCount = Math.min((int) maxPageCount, pageCount);
                final ByteBuffer[] buffers = new ByteBuffer[realPageCount];
                for (int i = 0; i < buffers.length; i++) {
                    buffers[i] = bufferPool.acquireDirect(false);
                    assert buffers[i].position() == 0;
                }
                fileClassic.read(firstPageStartPosition, buffers);
                final OCachePointer[] dataPointers = new OCachePointer[buffers.length];
                for (int n = 0; n < buffers.length; n++) {
                    buffers[n].position(0);
                    dataPointers[n] = new OCachePointer(buffers[n], bufferPool, lastLsn, fileId, startPageIndex + n);
                }
                pagesRead = dataPointers.length;
                return dataPointers;
            } finally {
                if (sessionStoragePerformanceStatistic != null) {
                    sessionStoragePerformanceStatistic.stopPageReadFromFileTimer(pagesRead);
                }
            }
        } else if (addNewPages) {
            final int space = (int) (firstPageEndPosition - fileClassic.getFileSize());
            if (space > 0)
                fileClassic.allocateSpace(space);
            freeSpaceCheckAfterNewPageAdd();
            final ByteBuffer buffer = bufferPool.acquireDirect(true);
            final OCachePointer dataPointer = new OCachePointer(buffer, bufferPool, lastLsn, fileId, startPageIndex);
            cacheHit.setValue(true);
            return new OCachePointer[] { dataPointer };
        } else
            return new OCachePointer[0];
    } finally {
        files.release(entry);
    }
}
Also used : OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) AtomicLong(java.util.concurrent.atomic.AtomicLong) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic) ByteBuffer(java.nio.ByteBuffer) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) OFileClassic(com.orientechnologies.orient.core.storage.fs.OFileClassic)

Example 35 with OCachePointer

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

the class SBTreeLeafBucketTest method testRemove.

public void testRemove() throws Exception {
    long seed = System.currentTimeMillis();
    System.out.println("testRemove seed : " + seed);
    TreeSet<Long> keys = new TreeSet<Long>();
    Random random = new Random(seed);
    while (keys.size() < 2 * OSBTreeBucket.MAX_PAGE_SIZE_BYTES / OLongSerializer.LONG_SIZE) {
        keys.add(random.nextLong());
    }
    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();
    OSBTreeBucket<Long, OIdentifiable> treeBucket = new OSBTreeBucket<Long, OIdentifiable>(cacheEntry, true, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null);
    int index = 0;
    for (Long key : keys) {
        if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry<Long, OIdentifiable>(-1, -1, key, new OSBTreeValue<OIdentifiable>(false, -1, new ORecordId(index, index))), true))
            break;
        index++;
    }
    int originalSize = treeBucket.size();
    int itemsToDelete = originalSize / 2;
    for (int i = 0; i < itemsToDelete; i++) {
        treeBucket.remove(treeBucket.size() - 1);
    }
    Assert.assertEquals(treeBucket.size(), originalSize - itemsToDelete);
    final Map<Long, Integer> keyIndexMap = new HashMap<Long, Integer>();
    Iterator<Long> keysIterator = keys.iterator();
    index = 0;
    while (keysIterator.hasNext() && index < treeBucket.size()) {
        Long key = keysIterator.next();
        keyIndexMap.put(key, index);
        index++;
    }
    for (Map.Entry<Long, Integer> keyIndexEntry : keyIndexMap.entrySet()) {
        int bucketIndex = treeBucket.find(keyIndexEntry.getKey());
        Assert.assertEquals(bucketIndex, (int) keyIndexEntry.getValue());
    }
    int keysToAdd = originalSize - treeBucket.size();
    int addedKeys = 0;
    while (keysIterator.hasNext() && index < originalSize) {
        Long key = keysIterator.next();
        if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry<Long, OIdentifiable>(-1, -1, key, new OSBTreeValue<OIdentifiable>(false, -1, new ORecordId(index, index))), true))
            break;
        keyIndexMap.put(key, index);
        index++;
        addedKeys++;
    }
    for (Map.Entry<Long, Integer> keyIndexEntry : keyIndexMap.entrySet()) {
        OSBTreeBucket.SBTreeEntry<Long, OIdentifiable> entry = treeBucket.getEntry(keyIndexEntry.getValue());
        Assert.assertEquals(entry, new OSBTreeBucket.SBTreeEntry<Long, OIdentifiable>(-1, -1, keyIndexEntry.getKey(), new OSBTreeValue<OIdentifiable>(false, -1, new ORecordId(keyIndexEntry.getValue(), keyIndexEntry.getValue()))));
    }
    Assert.assertEquals(treeBucket.size(), originalSize);
    Assert.assertEquals(addedKeys, keysToAdd);
    cacheEntry.releaseExclusiveLock();
    cachePointer.decrementReferrer();
}
Also used : HashMap(java.util.HashMap) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) Random(java.util.Random) TreeSet(java.util.TreeSet) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) HashMap(java.util.HashMap) Map(java.util.Map)

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