Skip to content

Commit

Permalink
GBPTree - Rebalance support: Small cleanup in InternalTreeLogic
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Feb 14, 2017
1 parent a8eb7bc commit 41a30a8
Showing 1 changed file with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import static org.neo4j.index.internal.gbptree.KeySearch.isHit;
import static org.neo4j.index.internal.gbptree.KeySearch.positionOf;
import static org.neo4j.index.internal.gbptree.PageCursorUtil.goTo;

/**
* Implementation of GB+ tree insert/remove algorithms.
Expand Down Expand Up @@ -136,15 +135,9 @@ private static class Level<KEY>
*/
boolean covers( KEY key )
{
if ( !lowerIsOpenEnded && layout.compare( key, lower ) < 0 )
{
return false;
}
if ( !upperIsOpenEnded && layout.compare( key, upper ) >= 0 )
{
return false;
}
return true;
boolean insideLower = lowerIsOpenEnded || layout.compare( key, lower ) >= 0;
boolean insideHigher = upperIsOpenEnded || layout.compare( key, upper ) < 0;
return insideLower && insideHigher;
}
}

Expand Down Expand Up @@ -249,10 +242,10 @@ private void moveToCorrectLeaf( PageCursor cursor, KEY key, long stableGeneratio
}
if ( currentLevel != previousLevel )
{
goTo( cursor, "parent", levels[currentLevel].treeNodeId );
bTreeNode.goTo( cursor, "parent", levels[currentLevel].treeNodeId );
}

while ( bTreeNode.isInternal( cursor ) )
while ( TreeNode.isInternal( cursor ) )
{
// We still need to go down further, but we're on the right path
int keyCount = bTreeNode.keyCount( cursor );
Expand Down Expand Up @@ -306,7 +299,7 @@ private void moveToCorrectLeaf( PageCursor cursor, KEY key, long stableGeneratio
level.treeNodeId = cursor.getCurrentPageId();
}

assert bTreeNode.isLeaf( cursor ) : "Ended up on a tree node which isn't a leaf after moving cursor towards " +
assert TreeNode.isLeaf( cursor ) : "Ended up on a tree node which isn't a leaf after moving cursor towards " +
key + ", cursor is at " + cursor.getCurrentPageId();
}

Expand Down Expand Up @@ -478,7 +471,7 @@ private void splitInternal( PageCursor cursor, StructurePropagation<KEY> structu
// Update new right
try ( PageCursor rightCursor = cursor.openLinkedCursor( newRight ) )
{
goTo( rightCursor, "new right sibling in split", newRight );
bTreeNode.goTo( rightCursor, "new right sibling in split", newRight );
bTreeNode.initializeInternal( rightCursor, stableGeneration, unstableGeneration );
bTreeNode.setRightSibling( rightCursor, oldRight, stableGeneration, unstableGeneration );
bTreeNode.setLeftSibling( rightCursor, current, stableGeneration, unstableGeneration );
Expand Down Expand Up @@ -738,7 +731,7 @@ private void splitLeaf( PageCursor cursor, StructurePropagation<KEY> structurePr
// Update new right
try ( PageCursor rightCursor = cursor.openLinkedCursor( newRight ) )
{
goTo( rightCursor, "new right sibling in split", newRight );
bTreeNode.goTo( rightCursor, "new right sibling in split", newRight );
bTreeNode.initializeLeaf( rightCursor, stableGeneration, unstableGeneration );
bTreeNode.setRightSibling( rightCursor, oldRight, stableGeneration, unstableGeneration );
bTreeNode.setLeftSibling( rightCursor, current, stableGeneration, unstableGeneration );
Expand Down Expand Up @@ -936,7 +929,7 @@ private void createUnstableVersionIfNeeded( PageCursor cursor, StructurePropagat
long newGenId = idProvider.acquireNewId( stableGeneration, unstableGeneration );
try ( PageCursor newGenCursor = cursor.openLinkedCursor( newGenId ) )
{
goTo( newGenCursor, "new gen", newGenId );
bTreeNode.goTo( newGenCursor, "new gen", newGenId );
cursor.copyTo( 0, newGenCursor, 0, cursor.getCurrentPageSize() );
bTreeNode.setGen( newGenCursor, unstableGeneration );
bTreeNode.setNewGen( newGenCursor, TreeNode.NO_NODE_FLAG, stableGeneration, unstableGeneration );
Expand Down

0 comments on commit 41a30a8

Please sign in to comment.