public synchronized void finalizeLogSegment ( RequestInfo reqInfo , long startTxId , long endTxId ) throws IOException { checkJournalStorageFormatted ( ) ; checkRequest ( reqInfo ) ; boolean needsValidation = true ; // Finalizing the log that the writer was just writing. if ( startTxId == curSegmentTxId ) { if ( curSegment != null ) { curSegment . close ( ) ; curSegment = null ; curSegmentTxId = HdfsConstants . INVALID_TXID ; currentSegmentWrittenBytes = 0L ; } checkSync ( nextTxId == endTxId + 1 , "Trying to finalize in-progress log segment %s to end at " + "txid %s but only written up to txid %s" , startTxId , endTxId , nextTxId - 1 ) ; // No need to validate the edit log if the client is finalizing // the log segment that it was just writing to. needsValidation = false ; } FileJournalManager . EditLogFile elf = fjm . getLogFile ( startTxId ) ; if ( elf == null ) { throw new JournalOutOfSyncException ( "No log file to finalize at " + "transaction ID " + startTxId ) ; } if ( elf . isInProgress ( ) ) { if ( needsValidation ) { LOG . info ( "Validating log segment " + elf . getFile ( ) + " about to be " + "finalized" ) ; elf . validateLog ( ) ; checkSync ( elf . getLastTxId ( ) == endTxId , "Trying to finalize in-progress log segment %s to end at " + "txid %s but log %s on disk only contains up to txid %s" , startTxId , endTxId , elf . getFile ( ) , elf . getLastTxId ( ) ) ; } fjm . finalizeLogSegment ( startTxId , endTxId ) ; } else { Preconditions . checkArgument ( endTxId == elf . getLastTxId ( ) , "Trying to re-finalize already finalized log " + elf + " with different endTxId " + endTxId ) ; } // Once logs are finalized, a different length will never be decided. // During recovery, we treat a finalized segment the same as an accepted // recovery. Thus, we no longer need to keep track of the previously- // accepted decision. The existence of the finalized log segment is enough. purgePaxosDecision ( elf . getFirstTxId ( ) ) ; }
Finalize the log segment at the given transaction ID .