Search in sources :

Example 91 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.

the class GBPTreeTest method mustThrowIfStuckInInfiniteRootCatchup.

/* Inconsistency tests */
@Test
void mustThrowIfStuckInInfiniteRootCatchup() throws IOException {
    // Create a tree with root and two children.
    // Corrupt one of the children and make it look like a freelist node.
    // This will cause seekCursor to start from root in an attempt, believing it went wrong because of concurrent updates.
    // When seekCursor comes back to the same corrupt child again and again it should eventually escape from that loop
    // with an exception.
    List<Long> trace = new ArrayList<>();
    MutableBoolean onOffSwitch = new MutableBoolean(true);
    CursorContext cursorContext = new CursorContext(trackingPageCursorTracer(trace, onOffSwitch));
    // Build a tree with root and two children.
    try (PageCache pageCache = createPageCache(defaultPageSize);
        GBPTree<MutableLong, MutableLong> tree = index(pageCache).build()) {
        // Insert data until we have a split in root
        treeWithRootSplit(trace, tree, cursorContext);
        long corruptChild = trace.get(1);
        // We are not interested in further trace tracking
        onOffSwitch.setFalse();
        // Corrupt the child
        corruptTheChild(pageCache, corruptChild);
        assertThatThrownBy(() -> {
            // when seek end up in this corrupt child we should eventually fail with a tree inconsistency exception
            try (Seeker<MutableLong, MutableLong> seek = tree.seek(new MutableLong(0), new MutableLong(0), cursorContext)) {
                seek.next();
            }
        }).isInstanceOf(TreeInconsistencyException.class).hasMessageContaining("Index traversal aborted due to being stuck in infinite loop. This is most likely caused by an inconsistency " + "in the index. Loop occurred when restarting search from root from page " + corruptChild + ".");
    }
}
Also used : MutableLong(org.apache.commons.lang3.mutable.MutableLong) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) MutableLong(org.apache.commons.lang3.mutable.MutableLong) ArrayList(java.util.ArrayList) CursorContext(org.neo4j.io.pagecache.context.CursorContext) PageCache(org.neo4j.io.pagecache.PageCache) DelegatingPageCache(org.neo4j.io.pagecache.DelegatingPageCache) Test(org.junit.jupiter.api.Test)

Example 92 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.

the class GBPTreeConsistencyCheckerTestBase method assertReportAllocSpaceOverlapOffsetArray.

private static <KEY, VALUE> void assertReportAllocSpaceOverlapOffsetArray(GBPTree<KEY, VALUE> index, long targetNode) throws IOException {
    MutableBoolean called = new MutableBoolean();
    index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {

        @Override
        public void nodeMetaInconsistency(long pageId, String message, Path file) {
            called.setTrue();
            assertEquals(targetNode, pageId);
            assertThat(message).contains("Overlap between offsetArray and allocSpace");
        }
    }, NULL);
    assertCalled(called);
}
Also used : Path(java.nio.file.Path) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Example 93 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.

the class GBPTreeConsistencyCheckerTestBase method assertReportCircularChildPointer.

private static <KEY, VALUE> void assertReportCircularChildPointer(GBPTree<KEY, VALUE> index, long targetNode) throws IOException {
    MutableBoolean called = new MutableBoolean();
    index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {

        @Override
        public void childNodeFoundAmongParentNodes(KeyRange<KEY> superRange, int level, long pageId, Path file) {
            called.setTrue();
            assertEquals(targetNode, pageId);
        }
    }, NULL);
    assertCalled(called);
}
Also used : Path(java.nio.file.Path) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Example 94 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.

the class GBPTreeConsistencyCheckerTestBase method assertReportUnreasonableKeyCount.

private static <KEY, VALUE> void assertReportUnreasonableKeyCount(GBPTree<KEY, VALUE> index, long targetNode, int targetKeyCount) throws IOException {
    MutableBoolean called = new MutableBoolean();
    index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {

        @Override
        public void unreasonableKeyCount(long pageId, int keyCount, Path file) {
            called.setTrue();
            assertEquals(targetNode, pageId);
            assertEquals(targetKeyCount, keyCount);
        }
    }, NULL);
    assertCalled(called);
}
Also used : Path(java.nio.file.Path) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Example 95 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project neo4j by neo4j.

the class GBPTreeConsistencyCheckerTestBase method assertReportPointerGenerationLowerThanNodeGeneration.

private static <KEY, VALUE> void assertReportPointerGenerationLowerThanNodeGeneration(GBPTree<KEY, VALUE> index, long targetNode, GBPTreePointerType expectedPointerType) throws IOException {
    MutableBoolean called = new MutableBoolean();
    index.consistencyCheck(new GBPTreeConsistencyCheckVisitor.Adaptor<>() {

        @Override
        public void pointerHasLowerGenerationThanNode(GBPTreePointerType pointerType, long sourceNode, long pointerGeneration, long pointer, long targetNodeGeneration, Path file) {
            called.setTrue();
            assertEquals(targetNode, sourceNode);
            assertEquals(expectedPointerType, pointerType);
        }
    }, NULL);
    assertCalled(called);
}
Also used : Path(java.nio.file.Path) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Aggregations

MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)107 Test (org.junit.Test)28 Path (java.nio.file.Path)26 Test (org.junit.jupiter.api.Test)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)12 Query (org.apache.apex.malhar.lib.appdata.schemas.Query)11 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)11 List (java.util.List)9 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)8 MutableInt (org.apache.commons.lang3.mutable.MutableInt)7 MutableLong (org.apache.commons.lang3.mutable.MutableLong)7 Collections (java.util.Collections)6 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)6 Set (java.util.Set)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 PageCache (org.neo4j.io.pagecache.PageCache)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ClassAd (org.apache.asterix.external.classad.ClassAd)4