code: public synchronized Segment nextSegment() {
      assertOpen();
      Segment lastSegment = lastSegment();
      SegmentDescriptor descriptor = SegmentDescriptor.builder()
        .withId(lastSegment != null ? lastSegment.descriptor().id() + 1 : 1)
        .withVersion(1)
        .withIndex(currentSegment.lastIndex() + 1)
        .withMaxSegmentSize(storage.maxSegmentSize())
        .withMaxEntries(storage.maxEntriesPerSegment())
        .build();
      descriptor.lock();
  
      currentSegment = createSegment(descriptor);
  
      segments.put(descriptor.index(), currentSegment);
      return currentSegment;
    }
docs: Creates and returns the next segment.
  
  @return The next segment.
  @throws IllegalStateException if the segment manager is not open