Search in sources :

Example 1 with RandomAccessLoggable

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

the class GarbageCollectorTest method reclaimTreeWithRootInLastFile.

@Test
public void reclaimTreeWithRootInLastFile() {
    set1KbFileWithoutGC();
    final Log log = env.getLog();
    final long startAddress = createStore("store", 100);
    Assert.assertEquals(2, log.getNumberOfFiles());
    createStore("corrupted", 160);
    Assert.assertEquals(4, log.getNumberOfFiles());
    final long fileAddress = 2 * log.getFileSize() * LogUtil.LOG_BLOCK_ALIGNMENT;
    log.forgetFile(fileAddress);
    log.removeFile(fileAddress);
    final StoreImpl store = openStoreAutoCommit("store");
    final Iterator<RandomAccessLoggable> itr = log.getLoggableIterator(startAddress);
    final TransactionBase txn = env.beginTransaction();
    Assert.assertTrue(txn.getTree(store).getMutableCopy().reclaim(itr.next(), itr));
    txn.abort();
}
Also used : Log(jetbrains.exodus.log.Log) RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Test(org.junit.Test)

Example 2 with RandomAccessLoggable

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

the class BTreeReclaimTest method testLeafDup.

@Test
public void testLeafDup() {
    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(0);
    final ByteIterable value = value("v0#10");
    final LeafNodeDup dupLeaf = (LeafNodeDup) getTree().getRoot().get(key);
    Assert.assertNotNull(dupLeaf);
    final BTreeDup dt = dupLeaf.tree;
    final ILeafNode savedLeaf = dt.getRoot().get(value);
    Assert.assertNotNull(savedLeaf);
    final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(savedLeaf.getAddress());
    Assert.assertTrue(tm.reclaim(iter.next(), iter));
    final AddressIterator addressIterator = getTreeAddresses(getTree());
    final LeafNodeDupMutable dupLeafMutable = (LeafNodeDupMutable) getTreeMutable().getRoot().get(key);
    Assert.assertNotNull(dupLeafMutable);
    final BTreeDupMutable dtm = dupLeafMutable.tree;
    while (addressIterator.hasNext()) {
        final long address = addressIterator.next();
        final Loggable loggable = log.read(address);
        if (BTreeTraverser.isInDupMode(addressIterator) && isAffected(loggable, key, BTreeTraverser.getTraverserNoDup(addressIterator))) {
            assertAffected(dtm, dt, loggable, value, (BTreeTraverser) addressIterator.getTraverser());
        }
    }
    checkTree(tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy(), p, u).run();
}
Also used : RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Loggable(jetbrains.exodus.log.Loggable) ByteIterable(jetbrains.exodus.ByteIterable) Test(org.junit.Test)

Example 3 with RandomAccessLoggable

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

the class BTreeReclaimTest method testPageDup.

@Test
public void testPageDup() {
    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(0);
    final ByteIterable value = value("v0#10");
    final LeafNodeDup dupLeaf = (LeafNodeDup) getTree().getRoot().get(key);
    Assert.assertNotNull(dupLeaf);
    final BTreeBase dt = dupLeaf.tree;
    final ILeafNode savedLeaf = dt.getRoot().get(value);
    Assert.assertNotNull(savedLeaf);
    final Iterator<RandomAccessLoggable> iter = log.getLoggableIterator(savedLeaf.getAddress());
    RandomAccessLoggable loggable = iter.next();
    while (loggable.getType() != BTreeBase.DUP_INTERNAL) {
        loggable = iter.next();
    }
    final BasePage page = dt.loadPage(loggable.getAddress());
    Assert.assertTrue(tm.reclaim(loggable, iter));
    final AddressIterator addressIterator = getTreeAddresses(getTree());
    final LeafNodeDupMutable dupLeafMutable = (LeafNodeDupMutable) getTreeMutable().getRoot().get(key);
    Assert.assertNotNull(dupLeafMutable);
    final BTreeMutable dtm = dupLeafMutable.tree;
    while (addressIterator.hasNext()) {
        final long address = addressIterator.next();
        loggable = log.read(address);
        if (BTreeTraverser.isInDupMode(addressIterator) && isAffected(loggable, value, BTreeTraverser.getTraverserNoDup(addressIterator))) {
            assertAffected(dtm, dt, loggable, page, (BTreeTraverser) addressIterator.getTraverser());
        }
    }
    checkTree(tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy(), p, u).run();
}
Also used : RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) ByteIterable(jetbrains.exodus.ByteIterable) Test(org.junit.Test)

Example 4 with RandomAccessLoggable

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

the class BTreeReclaimTest method testDupLeaf.

@Test
public void testDupLeaf() {
    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(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());
        final Loggable loggable = log.read(address);
        if (BTreeTraverser.isInDupMode(addressIterator) && isAffected(loggable, key, BTreeTraverser.getTraverserNoDup(addressIterator))) {
            assertAffected(getTreeMutable(), getTree(), loggable, key);
        }
    }
    rootAddress = saveTree();
    checkTree(tm = ((BTree) (t = new BTree(log, getTreeMutable().getBalancePolicy(), rootAddress, true, 1))).getMutableCopy(), p, u).run();
}
Also used : RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Loggable(jetbrains.exodus.log.Loggable) ByteIterable(jetbrains.exodus.ByteIterable) RandomAccessLoggable(jetbrains.exodus.log.RandomAccessLoggable) Test(org.junit.Test)

Example 5 with RandomAccessLoggable

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

the class BTreeReclaimTest method testLeafSimple.

@Test
public void testLeafSimple() {
    tm = new BTreeEmpty(log, createTestSplittingPolicy(), false, 1).getMutableCopy();
    getTreeMutable().put(kv(0, "nothing"));
    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();
    getTreeMutable().put(kv(0, "anything"));
    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));
    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