Search in sources :

Example 66 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class BTreeReclaimTest method testSkipDupTree.

@Test
public void testSkipDupTree() {
    /* int p;
        int u; */
    long rootAddress = initDup(/* p = */
    10, /* u = */
    100);
    tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy();
    final ByteIterable key = key(5);
    final ILeafNode savedLeaf = getTree().getRoot().get(key);
    Assert.assertNotNull(savedLeaf);
    final long oldAddress = savedLeaf.getAddress();
    tm.delete(key);
    tm.delete(key(6));
    getTreeMutable().put(key(6), value("v6#0"));
    rootAddress = saveTree();
    tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy();
    final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(oldAddress);
    /* Loggable loggable = iter.next();
        while (loggable.getType() != BTree.DUP_INTERNAL) {
            loggable = iter.next();
        }
        Assert.assertTrue(loggable.getAddress() < savedLeaf.getAddress()); // some dup tree stored before our leaf */
    Assert.assertTrue(tm.reclaim(iter.next(), iter));
    final AddressIterator addressIterator = getTreeAddresses(getTree());
    while (addressIterator.hasNext()) {
        final long address = addressIterator.next();
        isAffected(log.read(address), key, (BTreeTraverser) addressIterator.getTraverser());
        RandomAccessLoggable loggable = log.read(address);
        if (BTreeTraverser.isInDupMode(addressIterator) && isAffected(loggable, key, BTreeTraverser.getTraverserNoDup(addressIterator))) {
            assertAffected(getTreeMutable(), getTree(), loggable, key);
        }
    }
/* rootAddress = saveTree();
        checkTree(tm = (t = new BTree(log, rootAddress, getTreeMutable().getBalancePolicy(), true, 1)).getMutableCopy(), p, u).run(); */
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Test(org.junit.Test)

Example 67 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class BTreeReclaimTest method testLeafSimpleRemove.

@Test
public void testLeafSimpleRemove() {
    tm = new BTreeEmpty(log, createTestSplittingPolicy(), false, 1).getMutableCopy();
    getTreeMutable().put(kv(0, "thing"));
    getTreeMutable().put(kv(1, "nothing"));
    getTreeMutable().put(kv(2, "something"));
    getTreeMutable().put(kv(3, "jumping"));
    getTreeMutable().put(kv(4, "dumping"));
    getTreeMutable().put(kv(5, "rambling"));
    getTreeMutable().put(kv(6, "plumbing"));
    long rootAddress = saveTree();
    t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, false, 1);
    final ByteIterable key = key(0);
    final ILeafNode savedLeaf = getTree().getRoot().get(key);
    Assert.assertNotNull(savedLeaf);
    final long savedLeafAddress = savedLeaf.getAddress();
    tm = getTree().getMutableCopy();
    tm.delete(key(1));
    rootAddress = saveTree();
    tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, false, 1))).getMutableCopy();
    final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(savedLeafAddress);
    Assert.assertTrue(tm.reclaim(iter.next(), iter));
    System.out.println(tm.getExpiredLoggables().getSize());
    final AddressIterator addressIterator = getTreeAddresses(getTree());
    while (addressIterator.hasNext()) {
        final long address = addressIterator.next();
        isAffected(log.read(address), key, (BTreeTraverser) addressIterator.getTraverser());
    }
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Test(org.junit.Test)

Example 68 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class TreeCursorNoDuplicatesTest method testOrderedInserts.

@Test
public void testOrderedInserts() {
    final ByteIterable value = value("value");
    final TreeSet<String> keys = new TreeSet<>();
    for (int i = 0; i < 10000; ++i) {
        keys.add(rndString());
    }
    tm = createMutableTree(false, 1);
    for (final String key : keys) {
        Assert.assertTrue(tm.add(key(key), value));
    }
    testCursorOrder(keys);
    tm = createMutableTree(false, 1);
    for (final String key : keys.descendingSet()) {
        Assert.assertTrue(tm.add(key(key), value));
    }
    testCursorOrder(keys);
}
Also used : TreeSet(java.util.TreeSet) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Test(org.junit.Test)

Example 69 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class TreeCursorNoDuplicatesTest method testInsertDeletes.

@Test
public void testInsertDeletes() {
    final ByteIterable value = value("value");
    final TreeSet<String> keys = new TreeSet<>();
    tm = createMutableTree(false, 1);
    for (int i = 0; i < 10000; ++i) {
        final String key = rndString();
        if (keys.add(key)) {
            Assert.assertTrue(tm.add(key(key), value));
        }
        if (keys.size() > 1000) {
            final String obsoleteKey = keys.first();
            keys.remove(obsoleteKey);
            Assert.assertTrue(tm.delete(key(obsoleteKey)));
        }
    }
    testCursorOrder(keys);
}
Also used : TreeSet(java.util.TreeSet) ByteIterable(jetbrains.exodus.ByteIterable) ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) Test(org.junit.Test)

Example 70 with ByteIterable

use of jetbrains.exodus.ByteIterable in project xodus by JetBrains.

the class EnvironmentTestsBase method assertNotNullStringValues.

protected void assertNotNullStringValues(final Store store, final String... values) {
    env.executeInTransaction(txn -> {
        try (Cursor cursor = store.openCursor(txn)) {
            int i = 0;
            while (cursor.getNext()) {
                final ByteIterable valueEntry = cursor.getValue();
                Assert.assertNotNull(valueEntry);
                final String value = values[i++];
                Assert.assertEquals(value, StringBinding.entryToString(valueEntry));
            }
        }
    });
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable)

Aggregations

ByteIterable (jetbrains.exodus.ByteIterable)93 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)47 Test (org.junit.Test)26 CompressedUnsignedLongByteIterable (jetbrains.exodus.log.CompressedUnsignedLongByteIterable)16 Nullable (org.jetbrains.annotations.Nullable)11 Cursor (jetbrains.exodus.env.Cursor)8 ITreeCursor (jetbrains.exodus.tree.ITreeCursor)8 RandomAccessLoggable (jetbrains.exodus.log.RandomAccessLoggable)7 CompoundByteIterable (jetbrains.exodus.CompoundByteIterable)6 Store (jetbrains.exodus.env.Store)4 TreeSet (java.util.TreeSet)3 TokyoCabinetBenchmark (jetbrains.exodus.benchmark.TokyoCabinetBenchmark)3 PersistentStoreTransaction (jetbrains.exodus.entitystore.PersistentStoreTransaction)3 Exchange (com.persistit.Exchange)2 ExodusException (jetbrains.exodus.ExodusException)2 Pair (jetbrains.exodus.core.dataStructures.Pair)2 HashSet (jetbrains.exodus.core.dataStructures.hash.HashSet)2 PersistentLongSet (jetbrains.exodus.core.dataStructures.persistent.PersistentLongSet)2 Transaction (jetbrains.exodus.env.Transaction)2 Loggable (jetbrains.exodus.log.Loggable)2