Search in sources :

Example 36 with OCachePointer

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

the class SBTreeLeafBucketTest method testUpdateValue.

public void testUpdateValue() throws Exception {
    long seed = System.currentTimeMillis();
    System.out.println("testUpdateValue 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);
    OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
    cacheEntry.acquireExclusiveLock();
    cachePointer.incrementReferrer();
    OSBTreeBucket<Long, OIdentifiable> treeBucket = new OSBTreeBucket<Long, OIdentifiable>(cacheEntry, true, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null);
    Map<Long, Integer> keyIndexMap = new HashMap<Long, Integer>();
    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;
        keyIndexMap.put(key, index);
        index++;
    }
    Assert.assertEquals(keyIndexMap.size(), treeBucket.size());
    for (int i = 0; i < treeBucket.size(); i++) treeBucket.updateValue(i, new OSBTreeValue<OIdentifiable>(false, -1, new ORecordId(i + 5, i + 5)));
    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() + 5, keyIndexEntry.getValue() + 5))));
        Assert.assertEquals(keyIndexEntry.getKey(), treeBucket.getKey(keyIndexEntry.getValue()));
    }
    cacheEntry.releaseExclusiveLock();
    cachePointer.decrementReferrer();
}
Also used : HashMap(java.util.HashMap) OByteBufferPool(com.orientechnologies.common.directmemory.OByteBufferPool) ByteBuffer(java.nio.ByteBuffer) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLogSequenceNumber(com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber) Random(java.util.Random) TreeSet(java.util.TreeSet) OCachePointer(com.orientechnologies.orient.core.storage.cache.OCachePointer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 37 with OCachePointer

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

the class SBTreeLeafBucketTest method testShrink.

public void testShrink() throws Exception {
    long seed = System.currentTimeMillis();
    System.out.println("testShrink 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();
    treeBucket.shrink(treeBucket.size() / 2);
    Assert.assertEquals(treeBucket.size(), index / 2);
    index = 0;
    final Map<Long, Integer> keyIndexMap = new HashMap<Long, Integer>();
    Iterator<Long> keysIterator = keys.iterator();
    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)

Example 38 with OCachePointer

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

the class SBTreeLeafBucketTest method testSetLeftSibling.

public void testSetLeftSibling() 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();
    OSBTreeBucket<Long, OIdentifiable> treeBucket = new OSBTreeBucket<Long, OIdentifiable>(cacheEntry, true, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null);
    treeBucket.setLeftSibling(123);
    Assert.assertEquals(treeBucket.getLeftSibling(), 123);
    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) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 39 with OCachePointer

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

the class LRUListTest method testAdd9128Get.

@Test
public void testAdd9128Get() {
    final OByteBufferPool bufferPool = new OByteBufferPool(1);
    OCachePointer[] cachePointers = new OCachePointer[9128];
    for (int i = 0; i < 9128; 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));
    }
    Assert.assertEquals(lruList.size(), 9128);
    for (int i = 0; i < 9128; i++) Assert.assertEquals(lruList.get(1, i * 10), new OCacheEntry(1, i * 10, cachePointers[i], false));
    Iterator<OCacheEntry> entryIterator = lruList.iterator();
    for (int i = 9127; 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 40 with OCachePointer

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

the class LRUListTest method testAddElevenRemoveMiddle.

@Test
public void testAddElevenRemoveMiddle() {
    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));
    }
    Assert.assertEquals(lruList.remove(1, 50), new OCacheEntry(1, 50, cachePointers[5], false));
    Assert.assertNull(lruList.remove(1, 500));
    Assert.assertEquals(lruList.size(), 10);
    Iterator<OCacheEntry> entryIterator = lruList.iterator();
    for (int i = 10; i >= 0; i--) {
        if (i == 5)
            continue;
        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)

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