Improve error messages, create regular dir for block

This commit is contained in:
Fabian Reinartz 2017-01-19 08:40:15 +01:00
parent d2322f6095
commit e006bc6dc6
3 changed files with 11 additions and 7 deletions

View File

@ -114,18 +114,20 @@ type mmapFile struct {
} }
func openMmapFile(path string) (*mmapFile, error) { 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 { if err != nil {
return nil, err return nil, errors.Wrap(err, "try lock file")
} }
info, err := f.Stat() info, err := f.Stat()
if err != nil { if err != nil {
return nil, err return nil, errors.Wrap(err, "stat")
} }
b, err := mmap(f.File, int(info.Size())) b, err := mmap(f.File, int(info.Size()))
if err != nil { if err != nil {
return nil, err return nil, errors.Wrap(err, "mmap")
} }
return &mmapFile{f: f, b: b}, nil return &mmapFile{f: f, b: b}, nil

View File

@ -134,7 +134,7 @@ func (c *compactor) compact(dir string, blocks ...Block) (err error) {
return err return err
} }
} }
if err = fileutil.CreateDirAll(dir); err != nil { if err = os.MkdirAll(dir, 0755); err != nil {
return err return err
} }

6
db.go
View File

@ -113,8 +113,8 @@ func Open(dir string, logger log.Logger, opts *Options) (db *DB, err error) {
return nil, err return nil, err
} }
} }
var r prometheus.Registerer // var r prometheus.Registerer
// r := prometheus.DefaultRegisterer r := prometheus.DefaultRegisterer
if opts == nil { if opts == nil {
opts = DefaultOptions opts = DefaultOptions
@ -393,6 +393,8 @@ func (a *dbAppender) Add(ref uint64, t int64, v float64) error {
if gen != a.gen { if gen != a.gen {
return ErrNotFound return ErrNotFound
} }
a.db.metrics.samplesAppended.Inc()
return a.head.Add(ref, t, v) return a.head.Add(ref, t, v)
} }