Search in sources :

Example 1 with LEAF

use of org.neo4j.index.internal.gbptree.TreeNode.Type.LEAF 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());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) PageCursor(org.neo4j.io.pagecache.PageCursor) LongSupplier(java.util.function.LongSupplier) RandomExtension(org.neo4j.test.extension.RandomExtension) SHARED_RESOURCE(org.neo4j.test.extension.ExecutionSharedContext.SHARED_RESOURCE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GenerationSafePointerPair.pointer(org.neo4j.index.internal.gbptree.GenerationSafePointerPair.pointer) ArrayList(java.util.ArrayList) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Inject(org.neo4j.test.extension.Inject) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RandomRule(org.neo4j.test.rule.RandomRule) LEAF(org.neo4j.index.internal.gbptree.TreeNode.Type.LEAF) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DEFAULT_MAX_READ_AHEAD(org.neo4j.index.internal.gbptree.SeekCursor.DEFAULT_MAX_READ_AHEAD) IOException(java.io.IOException) LEAF_LEVEL(org.neo4j.index.internal.gbptree.SeekCursor.LEAF_LEVEL) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) List(java.util.List) INTERNAL(org.neo4j.index.internal.gbptree.TreeNode.Type.INTERNAL) ValueMergers.overwrite(org.neo4j.index.internal.gbptree.ValueMergers.overwrite) DelegatingPageCursor(org.neo4j.io.pagecache.impl.DelegatingPageCursor) NO_MONITOR(org.neo4j.index.internal.gbptree.GBPTree.NO_MONITOR) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Collections(java.util.Collections) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.jupiter.api.Test)

Example 2 with LEAF

use of org.neo4j.index.internal.gbptree.TreeNode.Type.LEAF 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());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) PageCursor(org.neo4j.io.pagecache.PageCursor) LongSupplier(java.util.function.LongSupplier) RandomExtension(org.neo4j.test.extension.RandomExtension) SHARED_RESOURCE(org.neo4j.test.extension.ExecutionSharedContext.SHARED_RESOURCE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GenerationSafePointerPair.pointer(org.neo4j.index.internal.gbptree.GenerationSafePointerPair.pointer) ArrayList(java.util.ArrayList) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Inject(org.neo4j.test.extension.Inject) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RandomRule(org.neo4j.test.rule.RandomRule) LEAF(org.neo4j.index.internal.gbptree.TreeNode.Type.LEAF) NULL(org.neo4j.io.pagecache.context.CursorContext.NULL) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DEFAULT_MAX_READ_AHEAD(org.neo4j.index.internal.gbptree.SeekCursor.DEFAULT_MAX_READ_AHEAD) IOException(java.io.IOException) LEAF_LEVEL(org.neo4j.index.internal.gbptree.SeekCursor.LEAF_LEVEL) ResourceLock(org.junit.jupiter.api.parallel.ResourceLock) String.format(java.lang.String.format) Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) List(java.util.List) INTERNAL(org.neo4j.index.internal.gbptree.TreeNode.Type.INTERNAL) ValueMergers.overwrite(org.neo4j.index.internal.gbptree.ValueMergers.overwrite) DelegatingPageCursor(org.neo4j.io.pagecache.impl.DelegatingPageCursor) NO_MONITOR(org.neo4j.index.internal.gbptree.GBPTree.NO_MONITOR) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Collections(java.util.Collections) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Test(org.junit.jupiter.api.Test)

Aggregations

IOException (java.io.IOException)2 String.format (java.lang.String.format)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Consumer (java.util.function.Consumer)2 LongSupplier (java.util.function.LongSupplier)2 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)2 ResourceLock (org.junit.jupiter.api.parallel.ResourceLock)2 NO_MONITOR (org.neo4j.index.internal.gbptree.GBPTree.NO_MONITOR)2