Browse Source

Expose DB.Compact()

Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
pull/6667/head
Ganesh Vernekar 5 years ago
parent
commit
e0733a99e3
No known key found for this signature in database
GPG Key ID: 241A11211763456
  1. 2
      tsdb/compact_test.go
  2. 4
      tsdb/db.go
  3. 20
      tsdb/db_test.go

2
tsdb/compact_test.go

@ -1079,7 +1079,7 @@ func TestDeleteCompactionBlockAfterFailedReload(t *testing.T) {
// Do the compaction and check the metrics.
// Compaction should succeed, but the reload should fail and
// the new block created from the compaction should be deleted.
testutil.NotOk(t, db.compact())
testutil.NotOk(t, db.Compact())
testutil.Equals(t, 1.0, prom_testutil.ToFloat64(db.metrics.reloadsFailed), "'failed db reload' count metrics mismatch")
testutil.Equals(t, 1.0, prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran), "`compaction` count metric mismatch")
testutil.Equals(t, 1.0, prom_testutil.ToFloat64(db.metrics.compactionsFailed), "`compactions failed` count metric mismatch")

4
tsdb/db.go

@ -606,7 +606,7 @@ func (db *DB) run() {
db.autoCompactMtx.Lock()
if db.autoCompact {
if err := db.compact(); err != nil {
if err := db.Compact(); err != nil {
level.Error(db.logger).Log("msg", "compaction failed", "err", err)
backoff = exponential(backoff, 1*time.Second, 1*time.Minute)
} else {
@ -655,7 +655,7 @@ func (a dbAppender) Commit() error {
// this is sufficient to reliably delete old data.
// Old blocks are only deleted on reload based on the new block's parent information.
// See DB.reload documentation for further information.
func (db *DB) compact() (err error) {
func (db *DB) Compact() (err error) {
db.cmtx.Lock()
defer db.cmtx.Unlock()
defer func() {

20
tsdb/db_test.go

@ -1412,7 +1412,7 @@ func TestChunkAtBlockBoundary(t *testing.T) {
err := app.Commit()
testutil.Ok(t, err)
err = db.compact()
err = db.Compact()
testutil.Ok(t, err)
for _, block := range db.Blocks() {
@ -1467,7 +1467,7 @@ func TestQuerierWithBoundaryChunks(t *testing.T) {
err := app.Commit()
testutil.Ok(t, err)
err = db.compact()
err = db.Compact()
testutil.Ok(t, err)
testutil.Assert(t, len(db.blocks) >= 3, "invalid test, less than three blocks in DB")
@ -1613,7 +1613,7 @@ func TestNoEmptyBlocks(t *testing.T) {
defaultMatcher := labels.MustNewMatcher(labels.MatchRegexp, "", ".*")
t.Run("Test no blocks after compact with empty head.", func(t *testing.T) {
testutil.Ok(t, db.compact())
testutil.Ok(t, db.Compact())
actBlocks, err := blockDirs(db.Dir())
testutil.Ok(t, err)
testutil.Equals(t, len(db.Blocks()), len(actBlocks))
@ -1631,7 +1631,7 @@ func TestNoEmptyBlocks(t *testing.T) {
testutil.Ok(t, err)
testutil.Ok(t, app.Commit())
testutil.Ok(t, db.Delete(math.MinInt64, math.MaxInt64, defaultMatcher))
testutil.Ok(t, db.compact())
testutil.Ok(t, db.Compact())
testutil.Equals(t, 1, int(prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran)), "compaction should have been triggered here")
actBlocks, err := blockDirs(db.Dir())
@ -1653,7 +1653,7 @@ func TestNoEmptyBlocks(t *testing.T) {
testutil.Ok(t, err)
testutil.Ok(t, app.Commit())
testutil.Ok(t, db.compact())
testutil.Ok(t, db.Compact())
testutil.Equals(t, 2, int(prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran)), "compaction should have been triggered here")
actBlocks, err = blockDirs(db.Dir())
testutil.Ok(t, err)
@ -1674,7 +1674,7 @@ func TestNoEmptyBlocks(t *testing.T) {
testutil.Ok(t, err)
testutil.Ok(t, app.Commit())
testutil.Ok(t, db.head.Delete(math.MinInt64, math.MaxInt64, defaultMatcher))
testutil.Ok(t, db.compact())
testutil.Ok(t, db.Compact())
testutil.Equals(t, 3, int(prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran)), "compaction should have been triggered here")
testutil.Equals(t, oldBlocks, db.Blocks())
})
@ -1693,7 +1693,7 @@ func TestNoEmptyBlocks(t *testing.T) {
testutil.Ok(t, db.reload()) // Reload the db to register the new blocks.
testutil.Equals(t, len(blocks)+len(oldBlocks), len(db.Blocks())) // Ensure all blocks are registered.
testutil.Ok(t, db.Delete(math.MinInt64, math.MaxInt64, defaultMatcher))
testutil.Ok(t, db.compact())
testutil.Ok(t, db.Compact())
testutil.Equals(t, 5, int(prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran)), "compaction should have been triggered here once for each block that have tombstones")
actBlocks, err := blockDirs(db.Dir())
@ -1776,7 +1776,7 @@ func TestDB_LabelNames(t *testing.T) {
testutil.Ok(t, headIndexr.Close())
// Testing disk.
err = db.compact()
err = db.Compact()
testutil.Ok(t, err)
// All blocks have same label names, hence check them individually.
// No need to aggregate and check.
@ -1823,7 +1823,7 @@ func TestCorrectNumTombstones(t *testing.T) {
}
testutil.Ok(t, app.Commit())
err := db.compact()
err := db.Compact()
testutil.Ok(t, err)
testutil.Equals(t, 1, len(db.blocks))
@ -2189,7 +2189,7 @@ func TestVerticalCompaction(t *testing.T) {
// Vertical compaction.
lc := db.compactor.(*LeveledCompactor)
testutil.Equals(t, 0, int(prom_testutil.ToFloat64(lc.metrics.overlappingBlocks)), "overlapping blocks count should be still 0 here")
err = db.compact()
err = db.Compact()
testutil.Ok(t, err)
testutil.Equals(t, c.expBlockNum, len(db.Blocks()), "Wrong number of blocks [after compact]")

Loading…
Cancel
Save