use of org.neo4j.index.internal.gbptree.SeekCursor.LEAF_LEVEL in project neo4j by neo4j.
the class SeekCursorTestBase method shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingDownTree.
@Test
void shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingDownTree() throws Exception {
// given
long generation = TreeNode.generation(cursor);
MutableBoolean triggered = new MutableBoolean(false);
// We don't care
long rightChild = 999;
// a newer leaf
long leftChild = cursor.getCurrentPageId();
// A newer leaf
node.initializeLeaf(cursor, stableGeneration + 1, unstableGeneration + 1);
cursor.next();
// a root
long rootId = cursor.getCurrentPageId();
node.initializeInternal(cursor, stableGeneration, unstableGeneration);
long keyInRoot = 10L;
node.insertKeyAndRightChildAt(cursor, key(keyInRoot), rightChild, 0, 0, stableGeneration, unstableGeneration, NULL);
TreeNode.setKeyCount(cursor, 1);
// with old pointer to child (simulating reuse of child node)
node.setChildAt(cursor, leftChild, 0, stableGeneration, unstableGeneration);
// a root catchup that records usage
RootCatchup rootCatchup = fromId -> {
triggered.setTrue();
// and set child generation to match pointer
cursor.next(leftChild);
cursor.zapPage();
node.initializeLeaf(cursor, stableGeneration, unstableGeneration);
cursor.next(rootId);
return new Root(rootId, generation);
};
// when
KEY from = key(1L);
KEY to = key(2L);
// noinspection EmptyTryBlock
try (SeekCursor<KEY, VALUE> ignored = new SeekCursor<>(cursor, node, from, to, layout, stableGeneration, unstableGeneration, generationSupplier, rootCatchup, unstableGeneration, exceptionDecorator, 1, LEAF_LEVEL, SeekCursor.NO_MONITOR, NULL)) {
// do nothing
}
// then
assertTrue(triggered.getValue());
}
use of org.neo4j.index.internal.gbptree.SeekCursor.LEAF_LEVEL in project neo4j by neo4j.
the class SeekCursorTestBase method shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingLeaves.
@Test
void shouldCatchupRootWhenNodeHasTooNewGenerationWhileTraversingLeaves() throws Exception {
// given
MutableBoolean triggered = new MutableBoolean(false);
// We don't care
long oldRightChild = 666;
// a newer right leaf
long rightChild = cursor.getCurrentPageId();
node.initializeLeaf(cursor, stableGeneration, unstableGeneration);
cursor.next();
RootCatchup rootCatchup = fromId -> {
// Use right child as new start over root to terminate test
cursor.next(rightChild);
triggered.setTrue();
return new Root(cursor.getCurrentPageId(), TreeNode.generation(cursor));
};
// a left leaf
long leftChild = cursor.getCurrentPageId();
node.initializeLeaf(cursor, stableGeneration - 1, unstableGeneration - 1);
// with an old pointer to right sibling
TreeNode.setRightSibling(cursor, rightChild, stableGeneration - 1, unstableGeneration - 1);
cursor.next();
// a root
node.initializeInternal(cursor, stableGeneration - 1, unstableGeneration - 1);
long keyInRoot = 10L;
node.insertKeyAndRightChildAt(cursor, key(keyInRoot), oldRightChild, 0, 0, stableGeneration, unstableGeneration, NULL);
TreeNode.setKeyCount(cursor, 1);
// with old pointer to child (simulating reuse of internal node)
node.setChildAt(cursor, leftChild, 0, stableGeneration, unstableGeneration);
// when
KEY from = key(1L);
KEY to = key(20L);
try (SeekCursor<KEY, VALUE> seek = new SeekCursor<>(cursor, node, from, to, layout, stableGeneration - 1, unstableGeneration - 1, generationSupplier, rootCatchup, unstableGeneration, exceptionDecorator, 1, LEAF_LEVEL, SeekCursor.NO_MONITOR, NULL)) {
while (seek.next()) {
seek.key();
}
}
// then
assertTrue(triggered.getValue());
}
use of org.neo4j.index.internal.gbptree.SeekCursor.LEAF_LEVEL in project neo4j by neo4j.
the class SeekCursorTestBase method shouldCatchupRootWhenRootNodeHasTooNewGeneration.
@Test
void shouldCatchupRootWhenRootNodeHasTooNewGeneration() throws Exception {
// given
long id = cursor.getCurrentPageId();
long generation = TreeNode.generation(cursor);
MutableBoolean triggered = new MutableBoolean(false);
RootCatchup rootCatchup = fromId -> {
triggered.setTrue();
return new Root(id, generation);
};
// noinspection EmptyTryBlock
try (SeekCursor<KEY, VALUE> ignored = new SeekCursor<>(cursor, node, key(0), key(1), layout, stableGeneration, unstableGeneration, generationSupplier, rootCatchup, generation - 1, exceptionDecorator, 1, LEAF_LEVEL, SeekCursor.NO_MONITOR, NULL)) {
// do nothing
}
// then
assertTrue(triggered.getValue());
}
Aggregations