diff --git a/community/index/src/main/java/org/neo4j/index/gbptree/ConsistencyChecker.java b/community/index/src/main/java/org/neo4j/index/gbptree/ConsistencyChecker.java index 01ba185e198f0..f2c304746177a 100644 --- a/community/index/src/main/java/org/neo4j/index/gbptree/ConsistencyChecker.java +++ b/community/index/src/main/java/org/neo4j/index/gbptree/ConsistencyChecker.java @@ -100,7 +100,7 @@ private long assertSiblings( PageCursor cursor, int level ) return rightmost.assertNext( cursor ); } - private void assertKeyOrderAndSubtrees( PageCursor cursor, final long pageId, KeyRange range, int level ) + private void assertKeyOrderAndSubtrees( PageCursor cursor, long pageId, KeyRange range, int level ) throws IOException { int keyCount = node.keyCount( cursor ); @@ -111,7 +111,8 @@ private void assertKeyOrderAndSubtrees( PageCursor cursor, final long pageId, Ke while ( pos < keyCount ) { node.keyAt( cursor, readKey, pos ); - assert range.inRange( readKey ); + assert range.inRange( readKey ) : + readKey + " (pos " + pos + "/" + (keyCount-1) + ")" + " isn't in range " + range; if ( pos > 0 ) { assert comparator.compare( prev, readKey ) < 0; // Assume unique keys diff --git a/community/index/src/main/java/org/neo4j/index/gbptree/GBPTree.java b/community/index/src/main/java/org/neo4j/index/gbptree/GBPTree.java index 8f7d0a53260a5..6160b58ce530b 100644 --- a/community/index/src/main/java/org/neo4j/index/gbptree/GBPTree.java +++ b/community/index/src/main/java/org/neo4j/index/gbptree/GBPTree.java @@ -257,7 +257,7 @@ private void writeState( PagedFile pagedFile ) throws IOException } } - private PageCursor openMetaPageCursor( PagedFile pagedFile ) throws IOException + private static PageCursor openMetaPageCursor( PagedFile pagedFile ) throws IOException { PageCursor metaCursor = pagedFile.io( IdSpace.META_PAGE_ID, PagedFile.PF_SHARED_WRITE_LOCK ); if ( !metaCursor.next() ) @@ -314,7 +314,8 @@ private void writeMeta( Layout layout, PagedFile pagedFile ) throws I } } - private PagedFile mapWithCorrectPageSize( PageCache pageCache, File indexFile, PagedFile pagedFile ) throws IOException + private PagedFile mapWithCorrectPageSize( PageCache pageCache, File indexFile, PagedFile pagedFile ) + throws IOException { // This index was created with another page size, re-open with that actual page size if ( pageSize != pageCache.pageSize() ) @@ -425,7 +426,7 @@ private void goToRoot( PageCursor cursor ) throws IOException bTreeNode.goTo( cursor, rootId, stableGeneration, unstableGeneration ); } - private void checkOutOfBounds( PageCursor cursor ) + private static void checkOutOfBounds( PageCursor cursor ) { if ( cursor.checkAndClearBoundsFlag() ) { diff --git a/community/index/src/main/java/org/neo4j/index/gbptree/TreeState.java b/community/index/src/main/java/org/neo4j/index/gbptree/TreeState.java index 6980f3417cb4b..f3529514b5144 100644 --- a/community/index/src/main/java/org/neo4j/index/gbptree/TreeState.java +++ b/community/index/src/main/java/org/neo4j/index/gbptree/TreeState.java @@ -19,8 +19,6 @@ */ package org.neo4j.index.gbptree; -import java.io.IOException; - import org.neo4j.io.pagecache.PageCursor; class TreeState @@ -73,12 +71,11 @@ boolean isValid() } static void write( PageCursor cursor, long stableGeneration, long unstableGeneration, long rootId, - long lastId ) throws IOException + long lastId ) { GenSafePointer.assertGeneration( stableGeneration ); GenSafePointer.assertGeneration( unstableGeneration ); - writeStateOnce( cursor, stableGeneration, unstableGeneration, rootId, lastId ); // Write state writeStateOnce( cursor, stableGeneration, unstableGeneration, rootId, lastId ); // Write checksum } diff --git a/community/index/src/test/java/org/neo4j/index/gbptree/SeekCursorTest.java b/community/index/src/test/java/org/neo4j/index/gbptree/SeekCursorTest.java index 870ebc2fa148d..bfee7424974c7 100644 --- a/community/index/src/test/java/org/neo4j/index/gbptree/SeekCursorTest.java +++ b/community/index/src/test/java/org/neo4j/index/gbptree/SeekCursorTest.java @@ -43,7 +43,7 @@ public class SeekCursorTest private final Layout layout = new SimpleLongLayout(); private final TreeNode treeNode = new TreeNode<>( PAGE_SIZE, layout ); private final PageAwareByteArrayCursor delegate = new PageAwareByteArrayCursor( PAGE_SIZE ); - private final TestPageCursor pageCursor = new TestPageCursor( delegate ); + private final TestPageCursor cursor = new TestPageCursor( delegate ); private final int maxKeyCount = treeNode.leafMaxKeyCount(); private final byte[] tmp = new byte[PAGE_SIZE]; @@ -55,8 +55,8 @@ public class SeekCursorTest @Before public void setUp() throws IOException { - pageCursor.next( 0L ); - treeNode.initializeLeaf( pageCursor, STABLE_GENERATION, UNSTABLE_GENERATION ); + cursor.next( 0L ); + treeNode.initializeLeaf( cursor, STABLE_GENERATION, UNSTABLE_GENERATION ); } /* NO CONCURRENT INSERT */ @@ -132,13 +132,13 @@ public void mustFindEntriesSpanningTwoLeaves() throws Exception append( i ); i++; } - long left = createRightSibling( pageCursor ); + long left = createRightSibling( cursor ); while ( i < maxKeyCount * 2 ) { append( i ); i++; } - pageCursor.next( left ); + cursor.next( left ); int fromInclusive = 0; int toExclusive = maxKeyCount * 2; @@ -157,17 +157,17 @@ public void mustFindEntriesOnSecondLeafWhenStartingFromFirstLeaf() throws Except { // GIVEN int i = 0; - long left = pageCursor.getCurrentPageId(); + long left = cursor.getCurrentPageId(); while ( i < maxKeyCount * 2 ) { if ( i == maxKeyCount ) { - createRightSibling( pageCursor ); + createRightSibling( cursor ); } append( i ); i++; } - pageCursor.next( left ); + cursor.next( left ); int fromInclusive = maxKeyCount; int toExclusive = maxKeyCount * 2; @@ -184,7 +184,7 @@ public void mustFindEntriesOnSecondLeafWhenStartingFromFirstLeaf() throws Except public void mustNotContinueToSecondLeafAfterFindingEndOfRangeInFirst() throws Exception { AtomicBoolean nextCalled = new AtomicBoolean(); - PageCursor pageCursorSpy = new DelegatingPageCursor( pageCursor ) + PageCursor pageCursorSpy = new DelegatingPageCursor( cursor ) { @Override public boolean next( long pageId ) throws IOException @@ -196,7 +196,7 @@ public boolean next( long pageId ) throws IOException // GIVEN int i = 0; - long left = pageCursor.getCurrentPageId(); + long left = cursor.getCurrentPageId(); while ( i < maxKeyCount * 2 ) { if ( i == maxKeyCount ) @@ -252,7 +252,7 @@ public void mustFindNewKeyInsertedRightOfSeekPoint() throws Exception // Seeker pauses and writer insert new key at the end of leaf append( middle ); - pageCursor.changed(); + this.cursor.changed(); // Seeker continue while ( cursor.next() ) @@ -296,7 +296,7 @@ public void mustFindKeyInsertedOnSeekPosition() throws Exception long midInsert = (stopPoint * 2) - 1; insertIn( stopPoint, midInsert ); expected.add( readKeys, midInsert ); - pageCursor.changed(); + this.cursor.changed(); while ( cursor.next() ) { @@ -339,7 +339,7 @@ public void mustNotFindKeyInsertedLeftOfSeekPoint() throws Exception // Seeker pauses and writer insert new key to the left of seekers next position long midInsert = ((stopPoint - 1) * 2) - 1; insertIn( stopPoint - 1, midInsert ); - pageCursor.changed(); + this.cursor.changed(); while ( cursor.next() ) { @@ -385,16 +385,16 @@ public void mustContinueToNextLeafWhenRangeIsSplitIntoRightLeafAndPosToLeft() th expected.add( (long) maxKeyCount ); // Add rightmost keys to right sibling - long left = createRightSibling( pageCursor ); + long left = createRightSibling( this.cursor ); for ( int i = middle; i <= maxKeyCount; i++ ) { Long key = expected.get( i ); append( key ); } // Update keycount in left sibling - pageCursor.next( left ); - treeNode.setKeyCount( pageCursor, middle ); - pageCursor.changed(); + this.cursor.next( left ); + treeNode.setKeyCount( this.cursor, middle ); + this.cursor.changed(); while ( cursor.next() ) { @@ -438,16 +438,16 @@ public void mustContinueToNextLeafWhenRangeIsSplitIntoRightLeafAndPosToRight() t expected.add( (long) maxKeyCount ); // Add rightmost keys to right sibling - long left = createRightSibling( pageCursor ); + long left = createRightSibling( this.cursor ); for ( int i = middle; i <= maxKeyCount; i++ ) { Long key = expected.get( i ); append( key ); } // Update keycount in left sibling - pageCursor.next( left ); - treeNode.setKeyCount( pageCursor, middle ); - pageCursor.changed(); + this.cursor.next( left ); + treeNode.setKeyCount( this.cursor, middle ); + this.cursor.changed(); while ( cursor.next() ) { @@ -490,7 +490,7 @@ public void mustNotFindKeyRemovedRightOfSeekPoint() throws Exception // Seeker pauses and writer remove rightmost key // [0 1 ... maxKeyCount-2] remove( maxKeyCount - 1 ); - pageCursor.changed(); + this.cursor.changed(); while ( cursor.next() ) { @@ -531,7 +531,7 @@ public void mustFindKeyMovedToLeftOfSeekPointBecauseOfRemove() throws Exception // Seeker pauses and writer remove rightmost key // [1 ... maxKeyCount-1] remove( 0 ); - pageCursor.changed(); + this.cursor.changed(); while ( cursor.next() ) { @@ -570,7 +570,7 @@ public void mustFindKeyMovedToLeftOfSeekPointBecauseOfRemoveOfPreviouslyReturned // Seeker pauses and writer remove rightmost key remove( middle - 1 ); - pageCursor.changed(); + this.cursor.changed(); while ( cursor.next() ) { @@ -607,7 +607,7 @@ public void mustRereadHeadersOnRetry() throws Exception to.setValue( keyCount + 1 ); // +1 because we're adding one more down below // WHEN - try ( SeekCursor cursor = new SeekCursor<>( pageCursor, key, value, + try ( SeekCursor cursor = new SeekCursor<>( this.cursor, key, value, treeNode, from, to, layout, STABLE_GENERATION, UNSTABLE_GENERATION, 2, keyCount ) ) { // reading a couple of keys @@ -618,7 +618,7 @@ public void mustRereadHeadersOnRetry() throws Exception // and WHEN a change happens append( keyCount ); - pageCursor.changed(); + this.cursor.changed(); // THEN at least keyCount should be re-read on next() assertTrue( cursor.next() ); @@ -638,7 +638,7 @@ public void mustRereadHeadersOnRetry() throws Exception private SeekCursor seekCursor( long fromInclusive, long toExclusive, int pos, int keyCount ) { - return seekCursor( fromInclusive, toExclusive, pos, pageCursor, keyCount ); + return seekCursor( fromInclusive, toExclusive, pos, cursor, keyCount ); } private SeekCursor seekCursor( long fromInclusive, long toExclusive, int pos, @@ -651,7 +651,7 @@ private SeekCursor seekCursor( long fromInclusive, long } /** - * Create a right sibling to node pointed to by pageCursor. Leave cursor on new right sibling when done, + * Create a right sibling to node pointed to by cursor. Leave cursor on new right sibling when done, * and return id of left sibling. */ private long createRightSibling( PageCursor pageCursor ) throws IOException @@ -709,33 +709,33 @@ private void insertKeysAndValues( int keyCount ) private void append( long k ) { - int keyCount = treeNode.keyCount( pageCursor ); + int keyCount = treeNode.keyCount( cursor ); key.setValue( k ); value.setValue( valueForKey( k ) ); - treeNode.insertKeyAt( pageCursor, key, keyCount, keyCount, tmp ); - treeNode.insertValueAt( pageCursor, value, keyCount, keyCount, tmp ); - treeNode.setKeyCount( pageCursor, keyCount + 1 ); + treeNode.insertKeyAt( cursor, key, keyCount, keyCount, tmp ); + treeNode.insertValueAt( cursor, value, keyCount, keyCount, tmp ); + treeNode.setKeyCount( cursor, keyCount + 1 ); } private void insertIn( int pos, long k ) { - int keyCount = treeNode.keyCount( pageCursor ); + int keyCount = treeNode.keyCount( cursor ); if ( keyCount + 1 > maxKeyCount ) { throw new IllegalStateException( "Can not insert another key in current node" ); } key.setValue( k ); value.setValue( valueForKey( k ) ); - treeNode.insertKeyAt( pageCursor, key, pos, keyCount, tmp ); - treeNode.insertValueAt( pageCursor, value, pos, keyCount, tmp ); - treeNode.setKeyCount( pageCursor, keyCount + 1 ); + treeNode.insertKeyAt( cursor, key, pos, keyCount, tmp ); + treeNode.insertValueAt( cursor, value, pos, keyCount, tmp ); + treeNode.setKeyCount( cursor, keyCount + 1 ); } private void remove( int pos ) { - int keyCount = treeNode.keyCount( pageCursor ); - treeNode.removeKeyAt( pageCursor, pos, keyCount, tmp ); - treeNode.removeValueAt( pageCursor, pos, keyCount, tmp ); - treeNode.setKeyCount( pageCursor, keyCount - 1 ); + int keyCount = treeNode.keyCount( cursor ); + treeNode.removeKeyAt( cursor, pos, keyCount, tmp ); + treeNode.removeValueAt( cursor, pos, keyCount, tmp ); + treeNode.setKeyCount( cursor, keyCount - 1 ); } } diff --git a/community/index/src/test/java/org/neo4j/index/gbptree/TreeStatePairTest.java b/community/index/src/test/java/org/neo4j/index/gbptree/TreeStatePairTest.java index c59fcd82fc6c7..15108850ac39b 100644 --- a/community/index/src/test/java/org/neo4j/index/gbptree/TreeStatePairTest.java +++ b/community/index/src/test/java/org/neo4j/index/gbptree/TreeStatePairTest.java @@ -190,4 +190,4 @@ void verify( Pair states, SelectionUseCase selection ) abstract void verify( Pair states, SelectionUseCase selection ); } -} \ No newline at end of file +} diff --git a/community/index/src/test/java/org/neo4j/index/gbptree/TreeStateTest.java b/community/index/src/test/java/org/neo4j/index/gbptree/TreeStateTest.java index 1d9f23b0556f3..4bfa014b09153 100644 --- a/community/index/src/test/java/org/neo4j/index/gbptree/TreeStateTest.java +++ b/community/index/src/test/java/org/neo4j/index/gbptree/TreeStateTest.java @@ -127,4 +127,4 @@ private void breakChecksum( PageCursor cursor ) long existing = cursor.getLong( cursor.getOffset() ); cursor.putLong( cursor.getOffset(), ~existing ); } -} \ No newline at end of file +}