private void initialize(List<LogSegment> segmentsToLoad, long segmentCapacityInBytes, boolean mayNeedSwapSegment)
      throws StoreException {
    if (segmentsToLoad.size() == 0) {
      // bootstrapping log.
      segmentsToLoad =
          Collections.singletonList(createFirstSegment(segmentCapacityInBytes, mayNeedSwapSegment));
    }

    LogSegment anySegment = segmentsToLoad.get(0);
    long totalSegments = anySegment.getName().isSingleSegment() ? 1 : capacityInBytes / anySegment.getCapacityInBytes();
    for (LogSegment segment : segmentsToLoad) {
      // putting the segments in the map orders them
      segmentsByName.put(segment.getName(), segment);
    }
    remainingUnallocatedSegments.set(totalSegments - segmentsByName.size());
    activeSegment = segmentsByName.lastEntry().getValue();
    activeSegment.initBufferForAppend();
  }
Initializes the log.
@param segmentsToLoad the {@link LogSegment} instances to include as a part of the log. These are not in any order
@param segmentCapacityInBytes the capacity of a single {@link LogSegment}.
@param mayNeedSwapSegment whether compactor may need swap segment.
@throws StoreException if there is any store exception during initialization.
ambry-store/src/main/java/com/github/ambry/store/Log.java