From e006bc6dc62997648202ff09083b76f1a9bf5fde Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Thu, 19 Jan 2017 08:40:15 +0100 Subject: [PATCH] Improve error messages, create regular dir for block --- block.go | 10 ++++++---- compact.go | 2 +- db.go | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/block.go b/block.go index 7d7cbe86d..410f490c1 100644 --- a/block.go +++ b/block.go @@ -114,18 +114,20 @@ type mmapFile struct { } func openMmapFile(path string) (*mmapFile, error) { - f, err := fileutil.TryLockFile(path, os.O_RDONLY, 0666) + // We have to open the file in RDWR for the lock to work with fileutil. + // TODO(fabxc): use own flock call that supports multi-reader. + f, err := fileutil.TryLockFile(path, os.O_RDWR, 0666) if err != nil { - return nil, err + return nil, errors.Wrap(err, "try lock file") } info, err := f.Stat() if err != nil { - return nil, err + return nil, errors.Wrap(err, "stat") } b, err := mmap(f.File, int(info.Size())) if err != nil { - return nil, err + return nil, errors.Wrap(err, "mmap") } return &mmapFile{f: f, b: b}, nil diff --git a/compact.go b/compact.go index a40762245..ca63ceeea 100644 --- a/compact.go +++ b/compact.go @@ -134,7 +134,7 @@ func (c *compactor) compact(dir string, blocks ...Block) (err error) { return err } } - if err = fileutil.CreateDirAll(dir); err != nil { + if err = os.MkdirAll(dir, 0755); err != nil { return err } diff --git a/db.go b/db.go index 977dc5906..84883237c 100644 --- a/db.go +++ b/db.go @@ -113,8 +113,8 @@ func Open(dir string, logger log.Logger, opts *Options) (db *DB, err error) { return nil, err } } - var r prometheus.Registerer - // r := prometheus.DefaultRegisterer + // var r prometheus.Registerer + r := prometheus.DefaultRegisterer if opts == nil { opts = DefaultOptions @@ -393,6 +393,8 @@ func (a *dbAppender) Add(ref uint64, t int64, v float64) error { if gen != a.gen { return ErrNotFound } + a.db.metrics.samplesAppended.Inc() + return a.head.Add(ref, t, v) }