@ Override public void clear ( ) throws IOException { boolean rollback = false ; final OAtomicOperation atomicOperation = startAtomicOperation ( true ) ; try { final Lock lock = FILE_LOCK_MANAGER . acquireExclusiveLock ( fileId ) ; try { final Queue < OBonsaiBucketPointer > subTreesToDelete = new LinkedList <> ( ) ; final OCacheEntry cacheEntry = loadPageForWrite ( atomicOperation , fileId , rootBucketPointer . getPageIndex ( ) , false , true ) ; try { OSBTreeBonsaiBucket < K , V > rootBucket = new OSBTreeBonsaiBucket <> ( cacheEntry , rootBucketPointer . getPageOffset ( ) , keySerializer , valueSerializer , this ) ; addChildrenToQueue ( subTreesToDelete , rootBucket ) ; rootBucket . shrink ( 0 ) ; rootBucket = new OSBTreeBonsaiBucket <> ( cacheEntry , rootBucketPointer . getPageOffset ( ) , true , keySerializer , valueSerializer , this ) ; rootBucket . setTreeSize ( 0 ) ; } finally { releasePageFromWrite ( atomicOperation , cacheEntry ) ; } recycleSubTrees ( subTreesToDelete , atomicOperation ) ; } finally { lock . unlock ( ) ; } } catch ( final Exception e ) { rollback = true ; throw e ; } finally { endAtomicOperation ( rollback ) ; } }
Removes all entries from bonsai tree . Put all but the root page to free list for further reuse .