code: func (w *WAL) nextSegment() error {
  	// Only flush the current page if it actually holds data.
  	if w.page.alloc > 0 {
  		if err := w.flushPage(true); err != nil {
  			return err
  		}
  	}
  	next, err := CreateSegment(w.dir, w.segment.Index()+1)
  	if err != nil {
  		return errors.Wrap(err, "create new segment file")
  	}
  	prev := w.segment
  	if err := w.setSegment(next); err != nil {
  		return err
  	}
  
  	// Don't block further writes by fsyncing the last segment.
  	w.actorc <- func() {
  		if err := w.fsync(prev); err != nil {
  			level.Error(w.logger).Log("msg", "sync previous segment", "err", err)
  		}
  		if err := prev.Close(); err != nil {
  			level.Error(w.logger).Log("msg", "close previous segment", "err", err)
  		}
  	}
  	return nil
  }
docs: // nextSegment creates the next segment and closes the previous one.