func (w *Writer) Sync() error {
	c := make(chan error)
	w.action <- func() {
		c <- w.curr.Sync()
		w.syncs.Inc()
	}
	return <-c
}
Sync the current segment to disk.
package ingest
import (
	"time"
	"github.com/prometheus/client_golang/prometheus"
)
func NewWriter(
	log Log,
	d time.Duration,
	sz int,
	bytes, records, syncs prometheus.Counter,
	age, size prometheus.Histogram,
) (*Writer, error) {
	curr, err := log.Create()
	if err != nil {
		return nil, err
	}
	w := &Writer{
		log:     log,
		curr:    curr,
		cursz:   0,
		maxsz:   sz,
		action:  make(chan func()),
		bytes:   bytes,
		records: records,
		syncs:   syncs,
		age:     age,
		size:    size,
		stop:    make(chan chan struct{}),
	}
	go w.loop(d)
	return w, nil
}
type Writer struct {
	log     Log
	curr    WriteSegment
	curts   time.Time  
	cursz   int
	maxsz   int
	action  chan func()
	bytes   prometheus.Counter
	records prometheus.Counter
	syncs   prometheus.Counter
	age     prometheus.Histogram
	size    prometheus.Histogram
	stop    chan chan struct{}
}
func (w *Writer) Write(p []byte) (int, error) {
	type res struct {
		n   int
		err error
	}
	c := make(chan res)
	w.action <- func() {
		n, err := w.curr.Write(p)
		if err != nil {
			c <- res{n, err}
			return
		}
		if w.curts.IsZero() {
			w.curts = time.Now()
		}
		w.bytes.Add(float64(n))
		w.records.Inc()
		w.cursz += n
		if w.cursz >= w.maxsz {
			w.closeRotate()
		}
		c <- res{n, err}
	}
	r := <-c
	return r.n, r.err
}