static Map < Long , Long > fenceOut ( List < LedgerMetadata > ledgers , BookKeeper bookKeeper , BookKeeperConfig config , String traceObjectId ) throws DurableDataLogException { // Fence out the ledgers, in descending order. During the process, we need to determine whether the ledgers we // fenced out actually have any data in them, and update the LedgerMetadata accordingly. // We need to fence out at least MIN_FENCE_LEDGER_COUNT ledgers that are not empty to properly ensure we fenced // the log correctly and identify any empty ledgers (Since this algorithm is executed upon every recovery, any // empty ledgers should be towards the end of the Log). int nonEmptyCount = 0 ; val result = new HashMap < Long , Long > ( ) ; val iterator = ledgers . listIterator ( ledgers . size ( ) ) ; while ( iterator . hasPrevious ( ) && ( nonEmptyCount < MIN_FENCE_LEDGER_COUNT ) ) { LedgerMetadata ledgerMetadata = iterator . previous ( ) ; LedgerHandle handle = openFence ( ledgerMetadata . getLedgerId ( ) , bookKeeper , config ) ; if ( handle . getLastAddConfirmed ( ) != NO_ENTRY_ID ) { // Non-empty. nonEmptyCount ++ ; } if ( ledgerMetadata . getStatus ( ) == LedgerMetadata . Status . Unknown ) { // We did not know the status of this Ledger before, but now we do. result . put ( ledgerMetadata . getLedgerId ( ) , handle . getLastAddConfirmed ( ) ) ; } close ( handle ) ; log . info ( "{}: Fenced out Ledger {}." , traceObjectId , ledgerMetadata ) ; } return result ; }
Fences out a Log made up of the given ledgers .