private CompletableFuture < Void > tryDeleteSealedCollection ( String scope , String stream , Integer collectionNum ) { // purge garbage znodes // attempt to delete entities node // delete collection return getLatestCollection ( scope , stream ) . thenCompose ( latestcollectionNum -> // 1. purge storeHelper . getChildren ( getEntitiesPath ( scope , stream , collectionNum ) ) . thenCompose ( entitiesPos -> { String entitiesPath = getEntitiesPath ( scope , stream , collectionNum ) ; // delete entities greater than max pos return Futures . allOf ( entitiesPos . stream ( ) . filter ( pos -> getPositionFromPath ( pos ) > rollOverAfter ) . map ( pos -> storeHelper . deletePath ( ZKPaths . makePath ( entitiesPath , pos ) , false ) ) . collect ( Collectors . toList ( ) ) ) ; } ) ) . thenCompose ( x -> { // 2. Try deleting entities root path. // if we are able to delete entities node then we can delete the whole thing return Futures . exceptionallyExpecting ( storeHelper . deletePath ( getEntitiesPath ( scope , stream , collectionNum ) , false ) . thenCompose ( v -> storeHelper . deleteTree ( getCollectionPath ( scope , stream , collectionNum ) ) ) , e -> Exceptions . unwrap ( e ) instanceof StoreException . DataNotEmptyException , null ) ; } ) ; }
Collection should be sealed while calling this method