private LogMetadata updateMetadata ( LogMetadata currentMetadata , LedgerHandle newLedger , boolean clearEmptyLedgers ) throws DurableDataLogException { boolean create = currentMetadata == null ; if ( create ) { // This is the first ledger ever in the metadata. currentMetadata = new LogMetadata ( newLedger . getId ( ) ) ; } else { currentMetadata = currentMetadata . addLedger ( newLedger . getId ( ) ) ; if ( clearEmptyLedgers ) { // Remove those ledgers from the metadata that are empty. currentMetadata = currentMetadata . removeEmptyLedgers ( Ledgers . MIN_FENCE_LEDGER_COUNT ) ; } } try { persistMetadata ( currentMetadata , create ) ; } catch ( DurableDataLogException ex ) { try { Ledgers . delete ( newLedger . getId ( ) , this . bookKeeper ) ; } catch ( Exception deleteEx ) { log . warn ( "{}: Unable to delete newly created ledger {}." , this . traceObjectId , newLedger . getId ( ) , deleteEx ) ; ex . addSuppressed ( deleteEx ) ; } throw ex ; } log . info ( "{} Metadata updated ({})." , this . traceObjectId , currentMetadata ) ; return currentMetadata ; }
Updates the metadata and persists it as a result of adding a new Ledger .