private LogSegment createFirstSegment(long segmentCapacity, boolean needSwapSegment) throws StoreException {
    segmentCapacity = Math.min(capacityInBytes, config.storeSegmentSizeInBytes);
    long numSegments = capacityInBytes / segmentCapacity;
    Pair<LogSegmentName, String> segmentNameAndFilename = getNextSegmentNameAndFilename();
    logger.info("Allocating first segment with name [{}], back by file {} and capacity {} bytes. Total number of "
            + "segments is {}", segmentNameAndFilename.getFirst(), segmentNameAndFilename.getSecond(), segmentCapacity,
        numSegments);
    File segmentFile = allocate(segmentNameAndFilename.getSecond(), segmentCapacity, needSwapSegment);
    // to be backwards compatible, headers are not written for a log segment if it is the only log segment.
    return new LogSegment(segmentNameAndFilename.getFirst(), segmentFile, segmentCapacity, config, metrics,
        isLogSegmented);
  }
Checks the provided arguments for consistency and allocates the first segment file and creates the
{@link LogSegment} instance for it.
@param segmentCapacity the intended capacity of each segment of the log.
@param needSwapSegment whether a swap segment is needed by {@link BlobStoreCompactor}
@return the {@link LogSegment} instance that is created.
@throws StoreException if there is store exception when creating the segment files or creating {@link LogSegment} instances.
ambry-store/src/main/java/com/github/ambry/store/Log.java