code: synchronized void endCurrentLogSegment(boolean writeEndTxn)
        throws IOException {
      LOG.info("Ending log segment " + curSegmentTxId);
      if (state != State.IN_SEGMENT) {
        throw new IllegalStateException("Bad state: " + state);
      }
      waitForSyncToFinish();
      if (writeEndTxn) {
        logEdit(LogSegmentOp.getInstance(FSEditLogOpCodes.OP_END_LOG_SEGMENT));
      }
      logSyncAll();
      printStatistics(true);
      final long lastTxId = getLastWrittenTxId();
  
      try {
        journalSet.finalizeLogSegment(curSegmentTxId, lastTxId);
        editLogStream = null;
      } catch (IOException e) {
        // All journals have failed, it will be handled in logSync.
        FSNamesystem.LOG.info("Cannot finalize log segment: " + e.toString());
      }
      state = State.BETWEEN_LOG_SEGMENTS;
    }
docs: Finalize the current log segment. Transitions from IN_SEGMENT state to
  BETWEEN_LOG_SEGMENTS state.