mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Fix close handling
Signed-off-by: Fabian Reinartz <freinartz@google.com>
This commit is contained in:
parent
1a5573b4ce
commit
92e1b20957
17
wal.go
17
wal.go
|
@ -1213,7 +1213,7 @@ func (r *walReader) decodeDeletes(flag byte, b []byte, res *[]Stone) error {
|
|||
}
|
||||
|
||||
// MigrateWAL rewrites the deprecated write ahead log into the new format.
|
||||
func MigrateWAL(logger log.Logger, dir string) error {
|
||||
func MigrateWAL(logger log.Logger, dir string) (err error) {
|
||||
// Detect whether we still have the old WAL.
|
||||
fns, err := sequenceFiles(dir)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
|
@ -1227,6 +1227,8 @@ func MigrateWAL(logger log.Logger, dir string) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "check first existing segment")
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
var hdr [4]byte
|
||||
if n, err := f.Read(hdr[:]); err != nil {
|
||||
return errors.Wrap(err, "read header from first segment")
|
||||
|
@ -1247,10 +1249,20 @@ func MigrateWAL(logger log.Logger, dir string) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "open new WAL")
|
||||
}
|
||||
// We close it once already before as part of finalization.
|
||||
// Do it once again in case of prior errors.
|
||||
defer func() {
|
||||
if err != nil {
|
||||
repl.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
w, err := OpenSegmentWAL(dir, logger, time.Minute, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "open old WAL")
|
||||
}
|
||||
defer w.Close()
|
||||
|
||||
rdr := w.Reader()
|
||||
|
||||
var (
|
||||
|
@ -1283,9 +1295,6 @@ func MigrateWAL(logger log.Logger, dir string) error {
|
|||
if err != nil {
|
||||
return errors.Wrap(err, "write new entries")
|
||||
}
|
||||
if err := w.Close(); err != nil {
|
||||
return errors.Wrap(err, "close old WAL")
|
||||
}
|
||||
if err := repl.Close(); err != nil {
|
||||
return errors.Wrap(err, "close new WAL")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue