Unverified Commit 64859ccb by Ganesh Vernekar Committed by GitHub

Merge pull request #7656 from codesome/release-2.19

Cherry pick commits for 2.19.3
parents c448ada6 30b2592f
...@@ -220,19 +220,20 @@ func (w *Writer) cut() error { ...@@ -220,19 +220,20 @@ func (w *Writer) cut() error {
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, err error) {
p, seq, err := nextSequenceFile(dirFile.Name()) p, seq, err := nextSequenceFile(dirFile.Name())
if err != nil { if err != nil {
return 0, nil, 0, err return 0, nil, 0, errors.Wrap(err, "next sequence file")
} }
f, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE, 0666) ptmp := p + ".tmp"
f, err := os.OpenFile(ptmp, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil { if err != nil {
return 0, nil, 0, err return 0, nil, 0, errors.Wrap(err, "open temp file")
} }
if allocSize > 0 { if allocSize > 0 {
if err = fileutil.Preallocate(f, allocSize, true); err != nil { if err = fileutil.Preallocate(f, allocSize, true); err != nil {
return 0, nil, 0, err return 0, nil, 0, errors.Wrap(err, "preallocate")
} }
} }
if err = dirFile.Sync(); err != nil { if err = dirFile.Sync(); err != nil {
return 0, nil, 0, err return 0, nil, 0, errors.Wrap(err, "sync directory")
} }
// Write header metadata for new file. // Write header metadata for new file.
...@@ -242,7 +243,23 @@ func cutSegmentFile(dirFile *os.File, magicNumber uint32, chunksFormat byte, all ...@@ -242,7 +243,23 @@ func cutSegmentFile(dirFile *os.File, magicNumber uint32, chunksFormat byte, all
n, err := f.Write(metab) n, err := f.Write(metab)
if err != nil { if err != nil {
return 0, nil, 0, err return 0, nil, 0, errors.Wrap(err, "write header")
}
if err := f.Close(); err != nil {
return 0, nil, 0, errors.Wrap(err, "close temp file")
}
if err := fileutil.Rename(ptmp, p); err != nil {
return 0, nil, 0, errors.Wrap(err, "replace file")
}
f, err = os.OpenFile(p, os.O_WRONLY, 0666)
if err != nil {
return 0, nil, 0, errors.Wrap(err, "open final file")
}
// Skip the header for the further writes.
if _, err := f.Seek(int64(n), 0); err != nil {
return 0, nil, 0, errors.Wrap(err, "seek in final file")
} }
return n, f, seq, nil return n, f, seq, nil
} }
......
...@@ -125,19 +125,5 @@ func Replace(from, to string) error { ...@@ -125,19 +125,5 @@ func Replace(from, to string) error {
} }
} }
if err := os.Rename(from, to); err != nil { return Rename(from, to)
return err
}
// Directory was renamed; sync parent dir to persist rename.
pdir, err := OpenDir(filepath.Dir(to))
if err != nil {
return err
}
if err = pdir.Sync(); err != nil {
pdir.Close()
return err
}
return pdir.Close()
} }
...@@ -2186,10 +2186,8 @@ func (s *memSeries) iterator(id int, isoState *isolationState, chunkDiskMapper * ...@@ -2186,10 +2186,8 @@ func (s *memSeries) iterator(id int, isoState *isolationState, chunkDiskMapper *
previousSamples += int(d.numSamples) previousSamples += int(d.numSamples)
} }
} }
// mmappedChunks does not contain the last chunk. Hence check it separately.
if len(s.mmappedChunks) < ix { if s.headChunk != nil {
previousSamples += s.headChunk.chunk.NumSamples()
} else {
totalSamples += s.headChunk.chunk.NumSamples() totalSamples += s.headChunk.chunk.NumSamples()
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment