Skip to content

Commit

Permalink
General cleanup in SeekCursor
Browse files Browse the repository at this point in the history
  • Loading branch information
burqen committed Jan 5, 2017
1 parent e06f1c4 commit f4e7781
Showing 1 changed file with 15 additions and 18 deletions.
Expand Up @@ -414,9 +414,10 @@ private void traverseDownToFirstLeaf() throws IOException
checkOutOfBounds( cursor ); checkOutOfBounds( cursor );


// Act // Act
if ( saneRead() ) if ( notSaneRead() )
{ {
restartSeekFromRoot(); prepareToStartFromRoot();
isInternal = true;
continue; continue;
} }


Expand Down Expand Up @@ -494,10 +495,11 @@ public boolean next() throws IOException
checkOutOfBounds( cursor ); checkOutOfBounds( cursor );


// Act // Act
if ( saneRead() ) if ( notSaneRead() )
{ {
// This node has been reused for something else than a tree node. Restart seek from root. // This node has been reused for something else than a tree node. Restart seek from root.
restartSeekFromRoot(); prepareToStartFromRoot();
traverseDownToFirstLeaf();
continue; continue;
} }


Expand Down Expand Up @@ -634,14 +636,14 @@ private long readPointerGenOnSuccess( long pointerId )
*/ */
private boolean verifyFirstKeyInNodeIsExpectedAfterGoTo() private boolean verifyFirstKeyInNodeIsExpectedAfterGoTo()
{ {
boolean result = true;
if ( verifyExpectedFirstAfterGoToNext && layout.compare( firstKeyInNode, expectedFirstAfterGoToNext ) != 0 ) if ( verifyExpectedFirstAfterGoToNext && layout.compare( firstKeyInNode, expectedFirstAfterGoToNext ) != 0 )
{ {
concurrentWriteHappened = true; concurrentWriteHappened = true;
verifyExpectedFirstAfterGoToNext = false; result = false;
return false;
} }
verifyExpectedFirstAfterGoToNext = false; verifyExpectedFirstAfterGoToNext = false;
return true; return result;
} }


/** /**
Expand Down Expand Up @@ -706,12 +708,8 @@ private boolean readHeader()
isInternal = bTreeNode.isInternal( cursor ); isInternal = bTreeNode.isInternal( cursor );
// Find the left-most key within from-range // Find the left-most key within from-range
keyCount = bTreeNode.keyCount( cursor ); keyCount = bTreeNode.keyCount( cursor );
if ( !keyCountIsSane( keyCount ) )
{
return false;
}


return true; return keyCountIsSane( keyCount );
} }


/** /**
Expand Down Expand Up @@ -901,23 +899,22 @@ private boolean keyCountIsSane( int keyCount )
} }


/** /**
* Restarts seek from root, i.e. updates current root (and its generation) and traverses down to * Perform a generation catchup, updates current root and update range to start from
* leaf containing the key containing the last returned, or first, key. * previously returned key. Should be followed by a call to {@link #traverseDownToFirstLeaf()}
* or if already in that method just loop again.
* <p> * <p>
* Caller should retry most recent read after calling this method. * Caller should retry most recent read after calling this method.
* *
* @throws IOException on {@link PageCursor}. * @throws IOException on {@link PageCursor}.
*/ */
private void restartSeekFromRoot() throws IOException private void prepareToStartFromRoot() throws IOException
{ {
generationCatchup(); generationCatchup();
lastFollowedPointerGen = rootCatchup.get().goTo( cursor ); lastFollowedPointerGen = rootCatchup.get().goTo( cursor );
if ( !first ) if ( !first )
{ {
layout.copyKey( prevKey, fromInclusive ); layout.copyKey( prevKey, fromInclusive );
} }
isInternal = true;
traverseDownToFirstLeaf();
} }


/** /**
Expand Down Expand Up @@ -1002,7 +999,7 @@ private boolean generationCatchup()
* @return {@code true} if read is sane and can be trusted, otherwise {@code false} meaning that * @return {@code true} if read is sane and can be trusted, otherwise {@code false} meaning that
* seek should be restarted from root. * seek should be restarted from root.
*/ */
private boolean saneRead() private boolean notSaneRead()
{ {
return nodeType != NODE_TYPE_TREE_NODE || !saneKeyCountRead( keyCount ) || !verifyNodeGenInvariants(); return nodeType != NODE_TYPE_TREE_NODE || !saneKeyCountRead( keyCount ) || !verifyNodeGenInvariants();
} }
Expand Down

0 comments on commit f4e7781

Please sign in to comment.