code: private void completeLog(UfsJournalFile currentLog, long nextSequenceNumber) throws IOException {
      String current = currentLog.getLocation().toString();
      if (nextSequenceNumber <= currentLog.getStart()) {
        LOG.info("No journal entry found in current journal file {}. Deleting it", current);
        if (!mUfs.deleteFile(current)) {
          LOG.warn("Failed to delete empty journal file {}", current);
        }
        return;
      }
      LOG.info("Completing log {} with next sequence number {}", current, nextSequenceNumber);
      String completed = UfsJournalFile
          .encodeLogFileLocation(mJournal, currentLog.getStart(), nextSequenceNumber).toString();
  
      if (!mUfs.renameFile(current, completed)) {
        // Completes could happen concurrently, check whether another master already did the rename.
        if (!mUfs.exists(completed)) {
          throw new IOException(
              String.format("Failed to rename journal log from %s to %s", current, completed));
        }
        if (mUfs.exists(current)) {
          // Rename is not atomic, so this could happen if we failed partway through a rename.
          LOG.info("Deleting current log {}", current);
          if (!mUfs.deleteFile(current)) {
            LOG.warn("Failed to delete current log file {}", current);
          }
        }
      }
    }
docs: Completes the given log.
  
  If the log is empty, it will be deleted.
  
  This method must be safe to run by multiple masters at the same time. This could happen if a
  primary master loses leadership and takes a while to close its journal. By the time it
  completes the current log, the new primary might be trying to close it as well.
  
  @param currentLog the log to complete
  @param nextSequenceNumber the next sequence number for the log to complete