From 19b91f81c402b53ecce1e5f2114f9444ba9605ee Mon Sep 17 00:00:00 2001 From: Anton Persson Date: Fri, 8 Mar 2019 13:44:50 +0100 Subject: [PATCH] Acceptance test for SeekCursor tripCounter --- .../internal/gbptree/SeekCursorTestBase.java | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/community/index/src/test/java/org/neo4j/index/internal/gbptree/SeekCursorTestBase.java b/community/index/src/test/java/org/neo4j/index/internal/gbptree/SeekCursorTestBase.java index b8b4ced9bffb0..1363e2ab67411 100644 --- a/community/index/src/test/java/org/neo4j/index/internal/gbptree/SeekCursorTestBase.java +++ b/community/index/src/test/java/org/neo4j/index/internal/gbptree/SeekCursorTestBase.java @@ -87,7 +87,9 @@ public long getAsLong() private static long unstableGeneration = stableGeneration + 1; private long rootId; + private long rootGeneration; private int numberOfRootSplits; + private Supplier realRootCatchup = () -> new Root( rootId, rootGeneration ); @Before public void setUp() throws IOException @@ -121,6 +123,7 @@ private static void goTo( PageCursor cursor, long pageId ) throws IOException private void updateRoot() { rootId = cursor.getCurrentPageId(); + rootGeneration = unstableGeneration; treeLogic.initialize( cursor ); } @@ -957,6 +960,34 @@ public void mustNotFindKeyRemovedInFrontOfSeeker() throws Exception } } + /* INCONSISTENCY */ + + @Test( timeout = 10_000L ) + public void mustThrowIfStuckInInfiniteBeginFromRootLoop() throws IOException + { + // given + rootWithTwoLeaves(); + + // Find left child and corrupt it by overwriting type to make it look like freelist node instead of tree node. + goTo( utilCursor, rootId ); + long leftChild = node.childAt( utilCursor, 0, stableGeneration, unstableGeneration ); + goTo( utilCursor, leftChild ); + utilCursor.putByte( TreeNode.BYTE_POS_NODE_TYPE, TreeNode.NODE_TYPE_FREE_LIST_NODE ); + + // when + try ( SeekCursor ignore = seekCursor( 0, 0, cursor, stableGeneration, unstableGeneration, realRootCatchup ) ) + { + fail( "Expected to throw." ); + } + catch ( TreeInconsistencyException e ) + { + // then + assertThat( e.getMessage(), containsString( + "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 " + leftChild ) ); + } + } + private long fullLeaf( List expectedSeeds ) { return fullLeaf( 0, expectedSeeds ); @@ -2195,9 +2226,15 @@ private SeekCursor seekCursor( long fromInclusive, long toExclusive, private SeekCursor seekCursor( long fromInclusive, long toExclusive, PageCursor pageCursor, long stableGeneration, long unstableGeneration ) throws IOException + { + return seekCursor( fromInclusive, toExclusive, pageCursor, stableGeneration, unstableGeneration, failingRootCatchup ); + } + + private SeekCursor seekCursor( long fromInclusive, long toExclusive, + PageCursor pageCursor, long stableGeneration, long unstableGeneration, Supplier rootCatchup ) throws IOException { return new SeekCursor<>( pageCursor, node, key( fromInclusive ), key( toExclusive ), layout, stableGeneration, unstableGeneration, - generationSupplier, failingRootCatchup, unstableGeneration , exceptionDecorator, random.nextInt( 1, DEFAULT_MAX_READ_AHEAD ) ); + generationSupplier, rootCatchup, unstableGeneration , exceptionDecorator, random.nextInt( 1, DEFAULT_MAX_READ_AHEAD ) ); } /**