boolean autoCloseLastLogSegmentIfQualified() throws StoreException {
    if (compactionPolicySwitchInfoCounterValueReached() && !activeSegment.isEmpty()) {
      //ensure the capacity to open the new log segment and allocate new log segment.
      //if not able to close the last log segment, continue running the compaction.
      try {
        ensureCapacity(0);
        setActiveSegment(0, true);
        return true;
      } catch (IllegalStateException e) {
        //no-op
        logger.info("There's no more capacity left in: {} to create new log segment, bypass clean up journal logic",
            dataDir);
        return false;
      }
    }
    logger.trace("Current compaction policy is not qualified for auto close last logsegment");
    return false;
  }
Closes the last log segment periodically if replica is in sealed status.
@return {@code True} if last log segment has been closed and new log segment has been successfully
generated. {@code False} otherwise.
@throws StoreException if any store exception occurred as part of ensuring capacity.
ambry-store/src/main/java/com/github/ambry/store/Log.java