mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Fix review comments
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
This commit is contained in:
parent
7a763ff61e
commit
b8a7e80f9b
|
@ -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…
Reference in a new issue