From bd15d37c70a25173cc2fa0fcfb5cafa6204258ad Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Fri, 20 Oct 2017 14:25:01 -0600 Subject: [PATCH] Extract commit func --- tsdb/engine/tsm1/tombstone.go | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/tsdb/engine/tsm1/tombstone.go b/tsdb/engine/tsm1/tombstone.go index f200da8e53..242d835b9f 100644 --- a/tsdb/engine/tsm1/tombstone.go +++ b/tsdb/engine/tsm1/tombstone.go @@ -230,27 +230,7 @@ func (t *Tombstoner) writeTombstoneV3(tombstones []Tombstone) error { } } - if err := gz.Close(); err != nil { - return err - } - - if err := bw.Flush(); err != nil { - return err - } - - // fsync the file to flush the write - if err := tmp.Sync(); err != nil { - return err - } - - tmpFilename := tmp.Name() - tmp.Close() - - if err := renameFile(tmpFilename, t.tombstonePath()); err != nil { - return err - } - - return syncDir(filepath.Dir(t.tombstonePath())) + return t.commit(gz, bw, tmp) } // writeTombstoneV4 writes v3 files that are concatenated together. A v4 header is @@ -309,6 +289,10 @@ func (t *Tombstoner) writeTombstoneV4(tombstones []Tombstone) error { } } + return t.commit(gz, bw, tmp) +} + +func (t *Tombstoner) commit(gz *gzip.Writer, bw *bufio.Writer, tmp *os.File) error { if err := gz.Close(); err != nil { return err }