code: func (w *SegmentWAL) Sync() error {
  	var head *segmentFile
  	var err error
  
  	// Flush the writer and retrieve the reference to the head segment under mutex lock.
  	func() {
  		w.mtx.Lock()
  		defer w.mtx.Unlock()
  		if err = w.flush(); err != nil {
  			return
  		}
  		head = w.head()
  	}()
  	if err != nil {
  		return errors.Wrap(err, "flush buffer")
  	}
  	if head != nil {
  		// But only fsync the head segment after releasing the mutex as it will block on disk I/O.
  		start := time.Now()
  		err := fileutil.Fdatasync(head.File)
  		w.metrics.fsyncDuration.Observe(time.Since(start).Seconds())
  		return err
  	}
  	return nil
  }
docs: // Sync flushes the changes to disk.