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();
}
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());
}
}
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();
}
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(); */
}
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());
}
}
Aggregations