Skip to content

Commit

Permalink
Performs assertNoSuccessor as an assertion in GBPTree
Browse files Browse the repository at this point in the history
because it's somewhat costly when moving around a lot in the tree for
doing updates and have never been a real problem, it's just been added
there as additional confidence from the beginning.
  • Loading branch information
tinwelint committed Aug 21, 2017
1 parent 230966b commit 8ad2aa7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Expand Up @@ -43,13 +43,15 @@
import org.neo4j.io.pagecache.PagedFile; import org.neo4j.io.pagecache.PagedFile;


import static java.lang.String.format; import static java.lang.String.format;

import static org.neo4j.index.internal.gbptree.Generation.generation; import static org.neo4j.index.internal.gbptree.Generation.generation;
import static org.neo4j.index.internal.gbptree.Generation.stableGeneration; import static org.neo4j.index.internal.gbptree.Generation.stableGeneration;
import static org.neo4j.index.internal.gbptree.Generation.unstableGeneration; import static org.neo4j.index.internal.gbptree.Generation.unstableGeneration;
import static org.neo4j.index.internal.gbptree.GenerationSafePointer.MIN_GENERATION; import static org.neo4j.index.internal.gbptree.GenerationSafePointer.MIN_GENERATION;
import static org.neo4j.index.internal.gbptree.Header.CARRY_OVER_PREVIOUS_HEADER; import static org.neo4j.index.internal.gbptree.Header.CARRY_OVER_PREVIOUS_HEADER;
import static org.neo4j.index.internal.gbptree.Header.replace; import static org.neo4j.index.internal.gbptree.Header.replace;
import static org.neo4j.index.internal.gbptree.PageCursorUtil.checkOutOfBounds; import static org.neo4j.index.internal.gbptree.PageCursorUtil.checkOutOfBounds;
import static org.neo4j.index.internal.gbptree.PointerChecking.assertNoSuccessor;


/** /**
* A generation-aware B+tree (GB+Tree) implementation directly atop a {@link PageCache} with no caching in between. * A generation-aware B+tree (GB+Tree) implementation directly atop a {@link PageCache} with no caching in between.
Expand Down Expand Up @@ -1118,7 +1120,7 @@ void initialize() throws IOException
cursor = openRootCursor( PagedFile.PF_SHARED_WRITE_LOCK ); cursor = openRootCursor( PagedFile.PF_SHARED_WRITE_LOCK );
stableGeneration = stableGeneration( generation ); stableGeneration = stableGeneration( generation );
unstableGeneration = unstableGeneration( generation ); unstableGeneration = unstableGeneration( generation );
PointerChecking.assertNoSuccessor( cursor, stableGeneration, unstableGeneration ); assert assertNoSuccessor( cursor, stableGeneration, unstableGeneration );
treeLogic.initialize( cursor ); treeLogic.initialize( cursor );
success = true; success = true;
} }
Expand Down
Expand Up @@ -28,10 +28,10 @@
import static org.neo4j.index.internal.gbptree.KeySearch.isHit; 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.KeySearch.positionOf;
import static org.neo4j.index.internal.gbptree.PointerChecking.assertNoSuccessor; import static org.neo4j.index.internal.gbptree.PointerChecking.assertNoSuccessor;
import static org.neo4j.index.internal.gbptree.StructurePropagation.KeyReplaceStrategy.BUBBLE;
import static org.neo4j.index.internal.gbptree.StructurePropagation.KeyReplaceStrategy.REPLACE;
import static org.neo4j.index.internal.gbptree.StructurePropagation.UPDATE_MID_CHILD; import static org.neo4j.index.internal.gbptree.StructurePropagation.UPDATE_MID_CHILD;
import static org.neo4j.index.internal.gbptree.StructurePropagation.UPDATE_RIGHT_CHILD; import static org.neo4j.index.internal.gbptree.StructurePropagation.UPDATE_RIGHT_CHILD;
import static org.neo4j.index.internal.gbptree.StructurePropagation.KeyReplaceStrategy.BUBBLE;
import static org.neo4j.index.internal.gbptree.StructurePropagation.KeyReplaceStrategy.REPLACE;


/** /**
* Implementation of GB+ tree insert/remove algorithms. * Implementation of GB+ tree insert/remove algorithms.
Expand Down Expand Up @@ -303,7 +303,7 @@ private void moveToCorrectLeaf( PageCursor cursor, KEY key, long stableGeneratio
TreeNode.goTo( cursor, "child", childId ); TreeNode.goTo( cursor, "child", childId );
level.treeNodeId = cursor.getCurrentPageId(); level.treeNodeId = cursor.getCurrentPageId();


assertNoSuccessor( cursor, stableGeneration, unstableGeneration ); assert assertNoSuccessor( cursor, stableGeneration, unstableGeneration );
} }


assert TreeNode.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 " +
Expand Down
Expand Up @@ -64,12 +64,13 @@ static void checkPointer( long result, boolean allowNoNode )
* @param stableGeneration Current stable generation of tree. * @param stableGeneration Current stable generation of tree.
* @param unstableGeneration Current unstable generation of tree. * @param unstableGeneration Current unstable generation of tree.
*/ */
static void assertNoSuccessor( PageCursor cursor, long stableGeneration, long unstableGeneration ) static boolean assertNoSuccessor( PageCursor cursor, long stableGeneration, long unstableGeneration )
{ {
long successor = TreeNode.successor( cursor, stableGeneration, unstableGeneration ); long successor = TreeNode.successor( cursor, stableGeneration, unstableGeneration );
if ( TreeNode.isNode( successor ) ) if ( TreeNode.isNode( successor ) )
{ {
throw new TreeInconsistencyException( WRITER_TRAVERSE_OLD_STATE_MESSAGE ); throw new TreeInconsistencyException( WRITER_TRAVERSE_OLD_STATE_MESSAGE );
} }
return true;
} }
} }

0 comments on commit 8ad2aa7

Please sign in to comment.