mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Return new block ULID in compactor
This commit is contained in:
parent
b945098e3a
commit
7087f68647
14
compact.go
14
compact.go
|
@ -58,7 +58,7 @@ type Compactor interface {
|
||||||
|
|
||||||
// Compact runs compaction against the provided directories. Must
|
// Compact runs compaction against the provided directories. Must
|
||||||
// only be called concurrently with results of Plan().
|
// only be called concurrently with results of Plan().
|
||||||
Compact(dest string, dirs ...string) error
|
Compact(dest string, dirs ...string) (ulid.ULID, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LeveledCompactor implements the Compactor interface.
|
// LeveledCompactor implements the Compactor interface.
|
||||||
|
@ -305,7 +305,7 @@ func compactBlockMetas(uid ulid.ULID, blocks ...*BlockMeta) *BlockMeta {
|
||||||
|
|
||||||
// Compact creates a new block in the compactor's directory from the blocks in the
|
// Compact creates a new block in the compactor's directory from the blocks in the
|
||||||
// provided directories.
|
// provided directories.
|
||||||
func (c *LeveledCompactor) Compact(dest string, dirs ...string) (err error) {
|
func (c *LeveledCompactor) Compact(dest string, dirs ...string) (uid ulid.ULID, err error) {
|
||||||
var blocks []BlockReader
|
var blocks []BlockReader
|
||||||
var bs []*Block
|
var bs []*Block
|
||||||
var metas []*BlockMeta
|
var metas []*BlockMeta
|
||||||
|
@ -313,13 +313,13 @@ func (c *LeveledCompactor) Compact(dest string, dirs ...string) (err error) {
|
||||||
for _, d := range dirs {
|
for _, d := range dirs {
|
||||||
b, err := OpenBlock(d, c.chunkPool)
|
b, err := OpenBlock(d, c.chunkPool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return uid, err
|
||||||
}
|
}
|
||||||
defer b.Close()
|
defer b.Close()
|
||||||
|
|
||||||
meta, err := readMetaFile(d)
|
meta, err := readMetaFile(d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return uid, err
|
||||||
}
|
}
|
||||||
|
|
||||||
metas = append(metas, meta)
|
metas = append(metas, meta)
|
||||||
|
@ -328,11 +328,11 @@ func (c *LeveledCompactor) Compact(dest string, dirs ...string) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
entropy := rand.New(rand.NewSource(time.Now().UnixNano()))
|
entropy := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||||
uid := ulid.MustNew(ulid.Now(), entropy)
|
uid = ulid.MustNew(ulid.Now(), entropy)
|
||||||
|
|
||||||
err = c.write(dest, compactBlockMetas(uid, metas...), blocks...)
|
err = c.write(dest, compactBlockMetas(uid, metas...), blocks...)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return nil
|
return uid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var merr MultiError
|
var merr MultiError
|
||||||
|
@ -344,7 +344,7 @@ func (c *LeveledCompactor) Compact(dest string, dirs ...string) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return merr
|
return uid, merr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LeveledCompactor) Write(dest string, b BlockReader, mint, maxt int64) (ulid.ULID, error) {
|
func (c *LeveledCompactor) Write(dest string, b BlockReader, mint, maxt int64) (ulid.ULID, error) {
|
||||||
|
|
2
db.go
2
db.go
|
@ -386,7 +386,7 @@ func (db *DB) compact() (changes bool, err error) {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := db.compactor.Compact(db.dir, plan...); err != nil {
|
if _, err := db.compactor.Compact(db.dir, plan...); err != nil {
|
||||||
return changes, errors.Wrapf(err, "compact %s", plan)
|
return changes, errors.Wrapf(err, "compact %s", plan)
|
||||||
}
|
}
|
||||||
changes = true
|
changes = true
|
||||||
|
|
Loading…
Reference in a new issue