From 6c34eb8b636b3d08432e96acce0c6d856fd4c94b Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Wed, 30 Jan 2019 11:40:55 +0200 Subject: [PATCH] nits Signed-off-by: Krasi Georgiev --- compact_test.go | 19 +++++++++---------- db.go | 4 ++-- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/compact_test.go b/compact_test.go index 7c5f4f05f..c22babe61 100644 --- a/compact_test.go +++ b/compact_test.go @@ -765,21 +765,21 @@ func TestDeleteCompactionBlockAfterFailedReload(t *testing.T) { testutil.Ok(t, err) testutil.Ok(t, app.Commit()) - return 1 + return 0 }, "Test Block Compaction": func(db *DB) int { - expBlocks := []*BlockMeta{ + blocks := []*BlockMeta{ {MinTime: 0, MaxTime: 100}, {MinTime: 100, MaxTime: 150}, {MinTime: 150, MaxTime: 200}, } - for _, m := range expBlocks { + for _, m := range blocks { createBlock(t, db.Dir(), genSeries(1, 1, m.MinTime, m.MaxTime)) } testutil.Ok(t, db.reload()) - testutil.Equals(t, len(expBlocks), len(db.Blocks()), "unexpected block count after a reload") + testutil.Equals(t, len(blocks), len(db.Blocks()), "unexpected block count after a reload") - return len(expBlocks) + 1 + return len(blocks) }, } @@ -801,15 +801,14 @@ func TestDeleteCompactionBlockAfterFailedReload(t *testing.T) { lastBlockIndex := path.Join(blockPath, indexFilename) actBlocks, err := blockDirs(db.Dir()) testutil.Ok(t, err) - testutil.Equals(t, expBlocks, len(actBlocks)) - testutil.Ok(t, os.RemoveAll(lastBlockIndex)) // Corrupt the block by removing the index file. + testutil.Equals(t, expBlocks, len(actBlocks)-1) // -1 to exclude the corrupted block. + testutil.Ok(t, os.RemoveAll(lastBlockIndex)) // Corrupt the block by removing the index file. testutil.Equals(t, 0.0, prom_testutil.ToFloat64(db.metrics.reloadsFailed), "initial 'failed db reload' count metrics mismatch") testutil.Equals(t, 0.0, prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran), "initial `compactions` count metric mismatch") // Do the compaction and check the metrics. - // Since the most recent block is not included in the compaction, - // the compaction should succeed, but the reload should fail and + // Compaction should succeed, but the reload should fail and // the new block created from the compaction should be deleted. db.EnableCompactions() testutil.NotOk(t, db.compact()) @@ -817,7 +816,7 @@ func TestDeleteCompactionBlockAfterFailedReload(t *testing.T) { testutil.Equals(t, 1.0, prom_testutil.ToFloat64(db.compactor.(*LeveledCompactor).metrics.ran), "`compaction` count metric mismatch") actBlocks, err = blockDirs(db.Dir()) testutil.Ok(t, err) - testutil.Equals(t, expBlocks, len(actBlocks)) + testutil.Equals(t, expBlocks, len(actBlocks)-1, "block count should be the same as before the compaction") // -1 to exclude the corrupted block. }) } } diff --git a/db.go b/db.go index 5063b6837..3bce5b08b 100644 --- a/db.go +++ b/db.go @@ -426,7 +426,7 @@ func (db *DB) compact() (err error) { if err := db.reload(); err != nil { if err := os.RemoveAll(filepath.Join(db.dir, uid.String())); err != nil { - return errors.Wrapf(err, "delete persisted head block after unsuccessful db reload:%s", uid) + return errors.Wrapf(err, "delete persisted head block after failed db reload:%s", uid) } return errors.Wrap(err, "reload blocks") } @@ -465,7 +465,7 @@ func (db *DB) compact() (err error) { if err := db.reload(); err != nil { if err := os.RemoveAll(filepath.Join(db.dir, uid.String())); err != nil { - return errors.Wrapf(err, "delete compacted block after unsuccessful db reload:%s", uid) + return errors.Wrapf(err, "delete compacted block after failed db reload:%s", uid) } return errors.Wrap(err, "reload blocks") }