public int numberOfSegments() {
        return segments.size();
    }
Take care! this is an O(n) operation, where n is the number of segments.

This method is thread-safe.

@return The number of segments.
storage/src/main/java/org/apache/kafka/storage/internals/log/LogSegments.java