diff --git a/cmd/tsdb/main.go b/cmd/tsdb/main.go index cafc7c9a0..2cece4d78 100644 --- a/cmd/tsdb/main.go +++ b/cmd/tsdb/main.go @@ -50,7 +50,7 @@ type writeBenchmark struct { cleanup bool numMetrics int - storage *tsdb.PartitionedDB + storage *tsdb.DB cpuprof *os.File memprof *os.File @@ -90,7 +90,7 @@ func (b *writeBenchmark) run(cmd *cobra.Command, args []string) { dir := filepath.Join(b.outPath, "storage") - st, err := tsdb.OpenPartitioned(dir, 1, nil, &tsdb.Options{ + st, err := tsdb.Open(dir, nil, &tsdb.Options{ WALFlushInterval: 200 * time.Millisecond, RetentionDuration: 1 * 24 * 60 * 60 * 1000, // 1 days in milliseconds MinBlockDuration: 3 * 60 * 60 * 1000, // 2 hours in milliseconds diff --git a/compact.go b/compact.go index 768bc460d..6a0d67499 100644 --- a/compact.go +++ b/compact.go @@ -158,12 +158,11 @@ func (c *compactor) compact(dir string, blocks ...Block) (err error) { c.metrics.duration.Observe(time.Since(start).Seconds()) }() - if fileutil.Exist(dir) { - if err = os.RemoveAll(dir); err != nil { - return err - } + if err = os.RemoveAll(dir); err != nil { + return err } - if err = os.MkdirAll(dir, 0755); err != nil { + + if err = os.MkdirAll(dir, 0777); err != nil { return err } diff --git a/db.go b/db.go index 27c19b65a..76794a98c 100644 --- a/db.go +++ b/db.go @@ -131,7 +131,7 @@ func newDBMetrics(r prometheus.Registerer) *dbMetrics { } // Open returns a new DB in the given directory. -func Open(dir string, logger log.Logger, opts *Options) (db *DB, err error) { +func Open(dir string, l log.Logger, opts *Options) (db *DB, err error) { if err := os.MkdirAll(dir, 0777); err != nil { return nil, err } @@ -148,8 +148,13 @@ func Open(dir string, logger log.Logger, opts *Options) (db *DB, err error) { return nil, errors.Wrapf(err, "open DB in %s", dir) } - // var r prometheus.Registerer - r := prometheus.DefaultRegisterer + if l == nil { + l = log.NewLogfmtLogger(os.Stdout) + l = log.NewContext(l).With("ts", log.DefaultTimestampUTC, "caller", log.DefaultCaller) + } + + var r prometheus.Registerer + // r := prometheus.DefaultRegisterer if opts == nil { opts = DefaultOptions @@ -161,7 +166,7 @@ func Open(dir string, logger log.Logger, opts *Options) (db *DB, err error) { db = &DB{ dir: dir, lockf: lockf, - logger: logger, + logger: l, metrics: newDBMetrics(r), opts: opts, compactc: make(chan struct{}, 1),