Search in sources :

Example 6 with RandomAccessLoggable

use of jetbrains.exodus.log.RandomAccessLoggable in project xodus by JetBrains.

the class BTreeReclaimTest method testPageNoDup.

@Test
public void testPageNoDup() {
    int p;
    long rootAddress = init(p = 1000);
    tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, false, 1))).getMutableCopy();
    final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(0);
    RandomAccessLoggable leaf = iter.next();
    RandomAccessLoggable next;
    while (true) {
        next = iter.next();
        if (next.getType() == BTreeBase.INTERNAL) {
            break;
        }
    }
    final BasePage page = getTree().loadPage(next.getAddress());
    Assert.assertTrue(tm.reclaim(leaf, iter));
    final AddressIterator addressIterator = getTreeAddresses(getTree());
    while (addressIterator.hasNext()) {
        final long address = addressIterator.next();
        assertAffected(log.read(address), page, (BTreeTraverser) addressIterator.getTraverser());
    }
    rootAddress = saveTree();
    checkTree(tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, false, 1))).getMutableCopy(), p).run();
}
Also used : RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Test(org.junit.Test)

Example 7 with RandomAccessLoggable

use of jetbrains.exodus.log.RandomAccessLoggable in project xodus by JetBrains.

the class BTreeReclaimSpecialTest method testStartAddress.

@Test
public void testStartAddress() {
    final long fileSize = log.getFileLengthBound();
    log.beginWrite();
    for (long l = 1; l < fileSize; ++l) {
        // fill all file except for one byte with nulls
        log.write(NullLoggable.create());
    }
    log.flush();
    log.endWrite();
    Assert.assertEquals(1, log.getNumberOfFiles());
    Assert.assertTrue(log.getHighAddress() < fileSize);
    tm = new BTreeEmpty(log, true, 1).getMutableCopy();
    final ArrayByteIterable key = key("K");
    for (int i = 0; i <= COUNT; i++) {
        tm.put(key, v(i));
    }
    long saved = saveTree();
    reloadMutableTree(saved);
    Assert.assertEquals(4, log.getNumberOfFiles());
    final long address = 0L;
    log.forgetFile(address);
    // emulate gc of first file
    log.removeFile(address);
    Iterator<RandomAccessLoggable> loggables = log.getLoggableIterator(log.getFileAddress(fileSize * 2));
    // reclaim third file
    tm.reclaim(loggables.next(), loggables);
    saved = saveTree();
    reloadMutableTree(saved);
    log.forgetFile(fileSize * 2);
    // remove reclaimed file
    log.removeFile(fileSize * 2);
    loggables = log.getLoggableIterator(log.getFileAddress(fileSize));
    // reclaim second file
    tm.reclaim(loggables.next(), loggables);
    saved = saveTree();
    reloadMutableTree(saved);
    // make sure that some files were added
    Assert.assertTrue(log.getNumberOfFiles() > 2);
    log.forgetFile(fileSize);
    // remove reclaimed file
    log.removeFile(fileSize);
    try (ITreeCursor cursor = tm.openCursor()) {
        // access minimum key
        Assert.assertTrue(cursor.getNext());
    }
}
Also used : ArrayByteIterable(jetbrains.exodus.ArrayByteIterable) RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) ITreeCursor(jetbrains.exodus.tree.ITreeCursor) Test(org.junit.Test)

Example 8 with RandomAccessLoggable

use of jetbrains.exodus.log.RandomAccessLoggable in project xodus by JetBrains.

the class BTreeReclaimTest method testLeafNoDup.

@Test
public void testLeafNoDup() {
    int p;
    long rootAddress = init(p = 1000);
    tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, false, 1))).getMutableCopy();
    final ByteIterable key = key(0);
    final ILeafNode savedLeaf = getTree().getRoot().get(key);
    Assert.assertNotNull(savedLeaf);
    final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(savedLeaf.getAddress());
    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());
    }
    rootAddress = saveTree();
    checkTree(tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, false, 1))).getMutableCopy(), p).run();
}
Also used : ByteIterable(jetbrains.exodus.ByteIterable) RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Test(org.junit.Test)

Example 9 with RandomAccessLoggable

use of jetbrains.exodus.log.RandomAccessLoggable 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 10 with RandomAccessLoggable

use of jetbrains.exodus.log.RandomAccessLoggable 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)

Aggregations

RandomAccessLoggable (jetbrains.exodus.log.RandomAccessLoggable)10 Test (org.junit.Test)10 ByteIterable (jetbrains.exodus.ByteIterable)7 Loggable (jetbrains.exodus.log.Loggable)2 ArrayByteIterable (jetbrains.exodus.ArrayByteIterable)1 Log (jetbrains.exodus.log.Log)1 ITreeCursor (jetbrains.exodus.tree.ITreeCursor)1