code: func (w *WAL) Close() (err error) {
  	w.mtx.Lock()
  	defer w.mtx.Unlock()
  
  	if w.closed {
  		return errors.New("wal already closed")
  	}
  
  	// Flush the last page and zero out all its remaining size.
  	// We must not flush an empty page as it would falsely signal
  	// the segment is done if we start writing to it again after opening.
  	if w.page.alloc > 0 {
  		if err := w.flushPage(true); err != nil {
  			return err
  		}
  	}
  
  	donec := make(chan struct{})
  	w.stopc <- donec
  	<-donec
  
  	if err = w.fsync(w.segment); err != nil {
  		level.Error(w.logger).Log("msg", "sync previous segment", "err", err)
  	}
  	if err := w.segment.Close(); err != nil {
  		level.Error(w.logger).Log("msg", "close previous segment", "err", err)
  	}
  	w.closed = true
  	return nil
  }
docs: // Close flushes all writes and closes active segment.