Search in sources :

Example 16 with OLogSequenceNumber

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

the class OSBTreeBonsaiLeafBucketTest method testSearch.

public void testSearch() throws Exception {
    long seed = System.currentTimeMillis();
    System.out.println("testSearch seed : " + seed);
    TreeSet<Long> keys = new TreeSet<Long>();
    Random random = new Random(seed);
    while (keys.size() < 2 * OSBTreeBonsaiBucket.MAX_BUCKET_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();
    OSBTreeBonsaiBucket<Long, OIdentifiable> treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, true, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
    int index = 0;
    Map<Long, Integer> keyIndexMap = new HashMap<Long, Integer>();
    for (Long key : keys) {
        if (!treeBucket.addEntry(index, new OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true))
            break;
        keyIndexMap.put(key, index);
        index++;
    }
    Assert.assertEquals(treeBucket.size(), keyIndexMap.size());
    for (Map.Entry<Long, Integer> keyIndexEntry : keyIndexMap.entrySet()) {
        int bucketIndex = treeBucket.find(keyIndexEntry.getKey());
        Assert.assertEquals(bucketIndex, (int) 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 17 with OLogSequenceNumber

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

the class OSBTreeBonsaiLeafBucketTest 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 * OSBTreeBonsaiBucket.MAX_BUCKET_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();
    OSBTreeBonsaiBucket<Long, OIdentifiable> treeBucket = new OSBTreeBonsaiBucket<Long, OIdentifiable>(cacheEntry, 0, true, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null, null);
    int index = 0;
    for (Long key : keys) {
        if (!treeBucket.addEntry(index, new OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, 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 OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true))
            break;
        keyIndexMap.put(key, index);
        index++;
        addedKeys++;
    }
    for (Map.Entry<Long, Integer> keyIndexEntry : keyIndexMap.entrySet()) {
        OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable> entry = treeBucket.getEntry(keyIndexEntry.getValue());
        Assert.assertEquals(entry, new OSBTreeBonsaiBucket.SBTreeEntry<Long, OIdentifiable>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, keyIndexEntry.getKey(), 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) 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 18 with OLogSequenceNumber

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

the class WOWCacheTest method testDataUpdate.

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())[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())[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())[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())[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)

Example 19 with OLogSequenceNumber

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

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

the class SBTreeValuePageTest method testFreeListPointer.

public void testFreeListPointer() 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();
    OSBTreeValuePage valuePage = new OSBTreeValuePage(cacheEntry, null, true);
    valuePage.setNextFreeListPage(124);
    Assert.assertEquals(valuePage.getNextFreeListPage(), 124);
    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)

Aggregations

OLogSequenceNumber (com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber)95 ByteBuffer (java.nio.ByteBuffer)76 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)74 OByteBufferPool (com.orientechnologies.common.directmemory.OByteBufferPool)69 OCachePointer (com.orientechnologies.orient.core.storage.cache.OCachePointer)66 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)15 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)4 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)3 HazelcastException (com.hazelcast.core.HazelcastException)2 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)2 OOfflineNodeException (com.orientechnologies.common.concur.OOfflineNodeException)2 OException (com.orientechnologies.common.exception.OException)2 OIOException (com.orientechnologies.common.io.OIOException)2