Browse Source

Fix review comments

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
pull/7573/head
Ganesh Vernekar 4 years ago
parent
commit
b8a7e80f9b
No known key found for this signature in database
GPG Key ID: 241A11211763456
  1. 17
      tsdb/chunks/chunks.go

17
tsdb/chunks/chunks.go

@ -217,7 +217,7 @@ func (w *Writer) cut() error {
return nil
}
func cutSegmentFile(dirFile *os.File, magicNumber uint32, chunksFormat byte, allocSize int64) (headerSize int, newFile *os.File, seq int, err error) {
func cutSegmentFile(dirFile *os.File, magicNumber uint32, chunksFormat byte, allocSize int64) (headerSize int, newFile *os.File, seq int, returnErr error) {
p, seq, err := nextSequenceFile(dirFile.Name())
if err != nil {
return 0, nil, 0, errors.Wrap(err, "next sequence file")
@ -227,6 +227,18 @@ func cutSegmentFile(dirFile *os.File, magicNumber uint32, chunksFormat byte, all
if err != nil {
return 0, nil, 0, errors.Wrap(err, "open temp file")
}
defer func() {
if returnErr != nil {
var merr tsdb_errors.MultiError
merr.Add(returnErr)
if f != nil {
merr.Add(f.Close())
}
// Calling RemoveAll on a non-existent file does not return error.
merr.Add(os.RemoveAll(ptmp))
returnErr = merr.Err()
}
}()
if allocSize > 0 {
if err = fileutil.Preallocate(f, allocSize, true); err != nil {
return 0, nil, 0, errors.Wrap(err, "preallocate")
@ -248,6 +260,7 @@ func cutSegmentFile(dirFile *os.File, magicNumber uint32, chunksFormat byte, all
if err := f.Close(); err != nil {
return 0, nil, 0, errors.Wrap(err, "close temp file")
}
f = nil
if err := fileutil.Rename(ptmp, p); err != nil {
return 0, nil, 0, errors.Wrap(err, "replace file")
@ -257,7 +270,7 @@ func cutSegmentFile(dirFile *os.File, magicNumber uint32, chunksFormat byte, all
if err != nil {
return 0, nil, 0, errors.Wrap(err, "open final file")
}
// Skip the header for the further writes.
// Skip header for further writes.
if _, err := f.Seek(int64(n), 0); err != nil {
return 0, nil, 0, errors.Wrap(err, "seek in final file")
}

Loading…
Cancel
Save