From eab78875fe791e908bbac6c1dfa20bf88a28b480 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Wed, 25 Apr 2018 10:37:25 +0200 Subject: [PATCH 1/2] repair: improve error message This change adds the directory path to the error message in case the repair process fails. Signed-off-by: Simon Pasquier --- repair.go | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/repair.go b/repair.go index 2722609a7..c7291bb5d 100644 --- a/repair.go +++ b/repair.go @@ -5,12 +5,10 @@ import ( "io" "io/ioutil" "os" - "path" "path/filepath" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" - "github.com/oklog/ulid" "github.com/pkg/errors" "github.com/prometheus/tsdb/fileutil" ) @@ -20,20 +18,18 @@ import ( func repairBadIndexVersion(logger log.Logger, dir string) error { // All blocks written by Prometheus 2.1 with a meta.json version of 2 are affected. // We must actually set the index file version to 2 and revert the meta.json version back to 1. - subdirs, err := fileutil.ReadDir(dir) + dirs, err := blockDirs(dir) if err != nil { - return err + return errors.Wrapf(err, "list block dirs %s", dir) } - for _, d := range subdirs { - // Skip non-block dirs. - if _, err := ulid.Parse(d); err != nil { - continue - } - d = path.Join(dir, d) + wrapErr := func(err error, d string) error { + return errors.Wrapf(err, "block dir: %s", d) + } + for _, d := range dirs { meta, err := readBogusMetaFile(d) if err != nil { - return err + return wrapErr(err, d) } if meta.Version == 1 { level.Info(logger).Log( @@ -53,35 +49,35 @@ func repairBadIndexVersion(logger log.Logger, dir string) error { repl, err := os.Create(filepath.Join(d, "index.repaired")) if err != nil { - return err + return wrapErr(err, d) } broken, err := os.Open(filepath.Join(d, "index")) if err != nil { - return err + return wrapErr(err, d) } if _, err := io.Copy(repl, broken); err != nil { - return err + return wrapErr(err, d) } // Set the 5th byte to 2 to indiciate the correct file format version. if _, err := repl.WriteAt([]byte{2}, 4); err != nil { - return err + return wrapErr(err, d) } if err := fileutil.Fsync(repl); err != nil { - return err + return wrapErr(err, d) } if err := repl.Close(); err != nil { - return err + return wrapErr(err, d) } if err := broken.Close(); err != nil { - return err + return wrapErr(err, d) } if err := renameFile(repl.Name(), broken.Name()); err != nil { - return err + return wrapErr(err, d) } // Reset version of meta.json to 1. meta.Version = 1 if err := writeMetaFile(d, meta); err != nil { - return err + return wrapErr(err, d) } } return nil From 22061306aa2549919d34337bfa93708f3a390ba9 Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Wed, 20 Jun 2018 09:19:49 +0200 Subject: [PATCH 2/2] Address Julius's comment Signed-off-by: Simon Pasquier --- repair.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/repair.go b/repair.go index c7291bb5d..be8c1f3ed 100644 --- a/repair.go +++ b/repair.go @@ -20,11 +20,11 @@ func repairBadIndexVersion(logger log.Logger, dir string) error { // We must actually set the index file version to 2 and revert the meta.json version back to 1. dirs, err := blockDirs(dir) if err != nil { - return errors.Wrapf(err, "list block dirs %s", dir) + return errors.Wrapf(err, "list block dirs in %q", dir) } wrapErr := func(err error, d string) error { - return errors.Wrapf(err, "block dir: %s", d) + return errors.Wrapf(err, "block dir: %q", d) } for _, d := range dirs { meta, err := readBogusMetaFile(d)