Skip to content

Commit

Permalink
Testing for create new version of node on write if stable and Pointer…
Browse files Browse the repository at this point in the history
…Checking update

Add checkSiblingPointer to PointerChecking
Use checkSiblingPointer and checkChildPointer whenever a child or sibling pointer is read.
Testing for PointerChecking

PageAwareByteArrayCursor now support openLinkedCursor.
  • Loading branch information
burqen authored and tinwelint committed Dec 4, 2016
1 parent 4805cbf commit 123d46e
Show file tree
Hide file tree
Showing 8 changed files with 511 additions and 46 deletions.
Expand Up @@ -210,7 +210,7 @@ public long getCurrentPageId()
@Override @Override
public int getCurrentPageSize() public int getCurrentPageSize()
{ {
throw new UnsupportedOperationException(); return buffer.capacity();
} }


@Override @Override
Expand Down
Expand Up @@ -27,8 +27,20 @@ public class IdSpace
*/ */
static final long META_PAGE_ID = 0L; static final long META_PAGE_ID = 0L;


/**
* State page with IDs such as free-list, highId, rootId and more. There are two such pages alternating
* between checkpoints, this is the first.
*/
static final long STATE_PAGE_A = 1L;

/**
* State page with IDs such as free-list, highId, rootId and more. There are two such pages alternating
* between checkpoints, this is the second.
*/
static final long STATE_PAGE_B = 2L;

/** /**
* Min value allowed as tree node id. * Min value allowed as tree node id.
*/ */
static final long MIN_TREE_NODE_ID = 1L; static final long MIN_TREE_NODE_ID = 3L;
} }
Expand Up @@ -231,6 +231,7 @@ private void splitInternal( PageCursor cursor, StructurePropagation<KEY> structu
{ {
long current = cursor.getCurrentPageId(); long current = cursor.getCurrentPageId();
long oldRight = bTreeNode.rightSibling( cursor, stableGeneration, unstableGeneration ); long oldRight = bTreeNode.rightSibling( cursor, stableGeneration, unstableGeneration );
PointerChecking.checkSiblingPointer( oldRight );
long newRight = idProvider.acquireNewId(); long newRight = idProvider.acquireNewId();


// Find position to insert new key // Find position to insert new key
Expand Down Expand Up @@ -386,6 +387,7 @@ private void splitLeaf( PageCursor cursor, StructurePropagation<KEY> structurePr


long current = cursor.getCurrentPageId(); long current = cursor.getCurrentPageId();
long oldRight = bTreeNode.rightSibling( cursor, stableGeneration, unstableGeneration ); long oldRight = bTreeNode.rightSibling( cursor, stableGeneration, unstableGeneration );
PointerChecking.checkSiblingPointer( oldRight );
long newRight = idProvider.acquireNewId(); long newRight = idProvider.acquireNewId();


// BALANCE KEYS AND VALUES // BALANCE KEYS AND VALUES
Expand Down Expand Up @@ -529,6 +531,7 @@ VALUE remove( PageCursor cursor, StructurePropagation<KEY> structurePropagation,


long currentId = cursor.getCurrentPageId(); long currentId = cursor.getCurrentPageId();
long childId = bTreeNode.childAt( cursor, pos, stableGeneration, unstableGeneration ); long childId = bTreeNode.childAt( cursor, pos, stableGeneration, unstableGeneration );
PointerChecking.checkChildPointer( childId );
bTreeNode.goTo( cursor, childId, stableGeneration, unstableGeneration ); bTreeNode.goTo( cursor, childId, stableGeneration, unstableGeneration );


VALUE result = remove( cursor, structurePropagation, key, into, stableGeneration, unstableGeneration ); VALUE result = remove( cursor, structurePropagation, key, into, stableGeneration, unstableGeneration );
Expand Down Expand Up @@ -619,6 +622,10 @@ private void createUnstableVersionIfNeeded( PageCursor cursor, StructurePropagat
long newGenId = idProvider.acquireNewId(); long newGenId = idProvider.acquireNewId();
try ( PageCursor newGenCursor = cursor.openLinkedCursor( newGenId ) ) try ( PageCursor newGenCursor = cursor.openLinkedCursor( newGenId ) )
{ {
if ( !newGenCursor.next() )
{
throw new IllegalStateException( "Could not go to new node " + newGenId );
}
cursor.copyTo( 0, newGenCursor, 0, cursor.getCurrentPageSize() ); cursor.copyTo( 0, newGenCursor, 0, cursor.getCurrentPageSize() );
bTreeNode.setGen( newGenCursor, unstableGeneration ); bTreeNode.setGen( newGenCursor, unstableGeneration );
} }
Expand All @@ -640,7 +647,9 @@ private void createUnstableVersionIfNeeded( PageCursor cursor, StructurePropagat
// v v v // v v v
// (leftSiblingOfStableNode) -[rightSibling]-> (newUnstableNode) <-[leftSibling]- (rightSiblingOfStableNode) // (leftSiblingOfStableNode) -[rightSibling]-> (newUnstableNode) <-[leftSibling]- (rightSiblingOfStableNode)
long leftSibling = bTreeNode.leftSibling( cursor, stableGeneration, unstableGeneration ); long leftSibling = bTreeNode.leftSibling( cursor, stableGeneration, unstableGeneration );
PointerChecking.checkSiblingPointer( leftSibling );
long rightSibling = bTreeNode.rightSibling( cursor, stableGeneration, unstableGeneration ); long rightSibling = bTreeNode.rightSibling( cursor, stableGeneration, unstableGeneration );
PointerChecking.checkSiblingPointer( rightSibling );
if ( leftSibling != TreeNode.NO_NODE_FLAG ) if ( leftSibling != TreeNode.NO_NODE_FLAG )
{ {
bTreeNode.goTo( cursor, leftSibling, stableGeneration, unstableGeneration ); bTreeNode.goTo( cursor, leftSibling, stableGeneration, unstableGeneration );
Expand Down
Expand Up @@ -42,4 +42,17 @@ static void checkChildPointer( long result )
IdSpace.MIN_TREE_NODE_ID ); IdSpace.MIN_TREE_NODE_ID );
} }
} }

static void checkSiblingPointer( long result )
{
if ( !GenSafePointerPair.isSuccess( result ) )
{
throw new IllegalStateException( GenSafePointerPair.failureDescription( result ) );
}
if ( result < IdSpace.MIN_TREE_NODE_ID && result != TreeNode.NO_NODE_FLAG )
{
throw new IllegalStateException( "Pointer to id " + result + " not allowed. Minimum node id allowed is " +
IdSpace.MIN_TREE_NODE_ID );
}
}
} }

0 comments on commit 123d46e

Please sign in to comment.