mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 12:31:07 +01:00
lib/persistentqueue: sync data to file inside filestream.Writer.MustFlush
This commit is contained in:
parent
26115891db
commit
f00e0e0103
@ -254,11 +254,17 @@ func (w *Writer) Write(p []byte) (int, error) {
|
||||
}
|
||||
|
||||
// MustFlush flushes all the buffered data to file.
|
||||
func (w *Writer) MustFlush() {
|
||||
//
|
||||
// if isSync is true, then the flushed data is fsynced to the underlying storage.
|
||||
func (w *Writer) MustFlush(isSync bool) {
|
||||
if err := w.bw.Flush(); err != nil {
|
||||
logger.Panicf("FATAL: cannot flush buffered data to file %q: %s", w.f.Name(), err)
|
||||
}
|
||||
// Do not call w.f.Sync() for performance reasons.
|
||||
if isSync {
|
||||
if err := w.f.Sync(); err != nil {
|
||||
logger.Panicf("FATAL: cannot fsync data to the underlying storage for file %q: %s", w.f.Name(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type statWriter struct {
|
||||
|
@ -546,7 +546,7 @@ func (q *Queue) write(buf []byte) error {
|
||||
func (q *Queue) readFull(buf []byte) error {
|
||||
bufLen := uint64(len(buf))
|
||||
if q.readerOffset+bufLen > q.writerFlushedOffset {
|
||||
q.writer.MustFlush()
|
||||
q.writer.MustFlush(false)
|
||||
q.writerFlushedOffset = q.writerOffset
|
||||
}
|
||||
n, err := io.ReadFull(q.reader, buf)
|
||||
@ -567,8 +567,7 @@ func (q *Queue) flushMetainfoIfNeededLocked(flushData bool) error {
|
||||
return nil
|
||||
}
|
||||
if flushData {
|
||||
q.writer.MustFlush()
|
||||
fs.MustSyncPath(q.writerPath)
|
||||
q.writer.MustFlush(true)
|
||||
}
|
||||
if err := q.flushMetainfoLocked(); err != nil {
|
||||
return fmt.Errorf("cannot flush metainfo: %w", err)
|
||||
|
Loading…
Reference in New Issue
Block a user