Skip to content

Commit

Permalink
Copy stable node on write
Browse files Browse the repository at this point in the history
When writing key content to a node, a new version of that node is created with generation equal to unstableGeneration, if node does not already have generation = unstableGeneration. If that is the case, changes are done directly in that node.
When only updating sibling, newGen or child pointers, a new version is not created as generation of those pointers are already handled by GSPP.

SplitResult -> StructurePropagation is now passed in from SingleIndexWriter instead of returned in method calls.
It is updated with information about new generation of nodes being created.

Various javadoc cleanup.
  • Loading branch information
burqen authored and tinwelint committed Dec 4, 2016
1 parent 8e2aa00 commit b141504
Show file tree
Hide file tree
Showing 5 changed files with 352 additions and 174 deletions.
26 changes: 20 additions & 6 deletions community/index/src/main/java/org/neo4j/index/gbptree/GBPTree.java
Expand Up @@ -417,12 +417,14 @@ private void checkOutOfBounds( PageCursor cursor )
private class SingleIndexWriter implements IndexWriter<KEY,VALUE>
{
private final InternalTreeLogic<KEY,VALUE> treeLogic;
private final StructurePropagation<KEY> structurePropagation;
private PageCursor cursor;
private IndexWriter.Options options;
private final byte[] tmp = new byte[0];

SingleIndexWriter( InternalTreeLogic<KEY,VALUE> treeLogic )
{
this.structurePropagation = new StructurePropagation<>( layout.newKey() );
this.treeLogic = treeLogic;
}

Expand All @@ -444,11 +446,12 @@ public void merge( KEY key, VALUE value, ValueMerger<VALUE> valueMerger ) throws
{
goToRoot( cursor );

SplitResult<KEY> split = treeLogic.insert( cursor, key, value, valueMerger, options,
treeLogic.insert( cursor, structurePropagation, key, value, valueMerger, options,
stableGeneration, unstableGeneration );

if ( split != null )
if ( structurePropagation.hasSplit )
{
structurePropagation.hasSplit = false;
// New root
long newRootId = acquireNewId();
if ( !cursor.next( newRootId ) )
Expand All @@ -457,12 +460,17 @@ public void merge( KEY key, VALUE value, ValueMerger<VALUE> valueMerger ) throws
}

bTreeNode.initializeInternal( cursor, stableGeneration, unstableGeneration );
bTreeNode.insertKeyAt( cursor, split.primKey, 0, 0, tmp );
bTreeNode.insertKeyAt( cursor, structurePropagation.primKey, 0, 0, tmp );
bTreeNode.setKeyCount( cursor, 1 );
bTreeNode.setChildAt( cursor, split.left, 0, stableGeneration, unstableGeneration );
bTreeNode.setChildAt( cursor, split.right, 1, stableGeneration, unstableGeneration );
bTreeNode.setChildAt( cursor, structurePropagation.left, 0, stableGeneration, unstableGeneration );
bTreeNode.setChildAt( cursor, structurePropagation.right, 1, stableGeneration, unstableGeneration );
rootId = newRootId;
}
else if ( structurePropagation.hasNewGen )
{
rootId = structurePropagation.left;
}
structurePropagation.hasNewGen = false;

checkOutOfBounds( cursor );
}
Expand All @@ -472,7 +480,13 @@ public VALUE remove( KEY key ) throws IOException
{
goToRoot( cursor );

VALUE result = treeLogic.remove( cursor, key, layout.newValue(), stableGeneration, unstableGeneration );
VALUE result = treeLogic.remove( cursor, structurePropagation, key, layout.newValue(),
stableGeneration, unstableGeneration );
if ( structurePropagation.hasNewGen )
{
structurePropagation.hasNewGen = false;
rootId = structurePropagation.left;
}

checkOutOfBounds( cursor );
return result;
Expand Down

0 comments on commit b141504

Please sign in to comment.