in mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java [325:429]
private DeleteResult<K, V> processDelete( K key, V value, long revision ) throws IOException
{
// Get the current B-tree header, and delete the value from it
BTreeHeader<K, V> btreeHeader = getBTreeHeader( getName() );
// Try to delete the entry starting from the root page. Here, the root
// page may be either a Node or a Leaf
DeleteResult<K, V> result = btreeHeader.getRootPage().delete( key, value, revision );
if ( result instanceof NotPresentResult )
{
// Key not found.
return result;
}
// Create a new BTreeHeader
BTreeHeader<K, V> newBtreeHeader = btreeHeader.copy();
// Inject the old B-tree header into the pages to be freed
// if we are deleting an element from a management BTree
if ( ( btreeType == BTreeTypeEnum.BTREE_OF_BTREES ) || ( btreeType == BTreeTypeEnum.COPIED_PAGES_BTREE ) )
{
PageIO[] pageIos = recordManager.readPageIOs( btreeHeader.getBTreeHeaderOffset(), -1L );
for ( PageIO pageIo : pageIos )
{
recordManager.freedPages.add( pageIo );
}
}
// The element was found, and removed
AbstractDeleteResult<K, V> removeResult = ( AbstractDeleteResult<K, V> ) result;
// This is a new root
Page<K, V> newRootPage = removeResult.getModifiedPage();
// Write the modified page on disk
// Note that we don't use the holder, the new root page will
// remain in memory.
writePage( newRootPage, revision );
// Decrease the number of elements in the current tree
newBtreeHeader.decrementNbElems();
newBtreeHeader.setRootPage( newRootPage );
newBtreeHeader.setRevision( revision );
// Write down the data on disk
long newBtreeHeaderOffset = recordManager.writeBtreeHeader( this, newBtreeHeader );
// Update the B-tree of B-trees with this new offset, if we are not already doing so
switch ( btreeType )
{
case PERSISTED:
// We have a new B-tree header to inject into the B-tree of btrees
recordManager.addInBtreeOfBtrees( getName(), revision, newBtreeHeaderOffset );
recordManager.addInCopiedPagesBtree( getName(), revision, result.getCopiedPages() );
// Store the new revision
storeRevision( newBtreeHeader, recordManager.isKeepRevisions() );
break;
case PERSISTED_SUB:
// Sub-B-trees are only updating the CopiedPage B-tree
recordManager.addInCopiedPagesBtree( getName(), revision, result.getCopiedPages() );
//btreeRevisions.put( revision, newBtreeHeader );
currentRevision.set( revision );
break;
case BTREE_OF_BTREES:
// The B-tree of B-trees or the copiedPages B-tree has been updated, update the RMheader parameters
recordManager.updateRecordManagerHeader( newBtreeHeaderOffset, -1L );
// We can free the copied pages
recordManager.freePages( this, revision, result.getCopiedPages() );
// Store the new revision
storeRevision( newBtreeHeader, recordManager.isKeepRevisions() );
break;
case COPIED_PAGES_BTREE:
// The B-tree of B-trees or the copiedPages B-tree has been updated, update the RMheader parameters
recordManager.updateRecordManagerHeader( -1L, newBtreeHeaderOffset );
// We can free the copied pages
recordManager.freePages( this, revision, result.getCopiedPages() );
// Store the new revision
storeRevision( newBtreeHeader, recordManager.isKeepRevisions() );
break;
default:
// Nothing to do for sub-btrees
break;
}
// Return the value we have found if it was modified
return result;
}