From 937cc1a52af503d6be93119c6579228e43a60ec0 Mon Sep 17 00:00:00 2001 From: zhulongcheng Date: Mon, 9 Sep 2019 17:28:01 +0800 Subject: [PATCH] tsdb: add block meta version constant (#5994) Signed-off-by: zhulongcheng --- tsdb/block.go | 5 +++-- tsdb/repair.go | 6 +++--- tsdb/repair_test.go | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tsdb/block.go b/tsdb/block.go index b7771d6bbc..0030fbd685 100644 --- a/tsdb/block.go +++ b/tsdb/block.go @@ -201,6 +201,7 @@ type BlockMetaCompaction struct { const indexFilename = "index" const metaFilename = "meta.json" +const metaVersion1 = 1 func chunkDir(dir string) string { return filepath.Join(dir, "chunks") } @@ -214,7 +215,7 @@ func readMetaFile(dir string) (*BlockMeta, int64, error) { if err := json.Unmarshal(b, &m); err != nil { return nil, 0, err } - if m.Version != 1 { + if m.Version != metaVersion1 { return nil, 0, errors.Errorf("unexpected meta file version %d", m.Version) } @@ -222,7 +223,7 @@ func readMetaFile(dir string) (*BlockMeta, int64, error) { } func writeMetaFile(logger log.Logger, dir string, meta *BlockMeta) (int64, error) { - meta.Version = 1 + meta.Version = metaVersion1 // Make any changes to the file appear atomic. path := filepath.Join(dir, metaFilename) diff --git a/tsdb/repair.go b/tsdb/repair.go index 494f005e42..0df612d3d4 100644 --- a/tsdb/repair.go +++ b/tsdb/repair.go @@ -55,7 +55,7 @@ func repairBadIndexVersion(logger log.Logger, dir string) error { if err != nil { return wrapErr(err, d) } - if meta.Version == 1 { + if meta.Version == metaVersion1 { level.Info(logger).Log( "msg", "found healthy block", "mint", meta.MinTime, @@ -108,7 +108,7 @@ func repairBadIndexVersion(logger log.Logger, dir string) error { return wrapErr(err, d) } // Reset version of meta.json to 1. - meta.Version = 1 + meta.Version = metaVersion1 if _, err := writeMetaFile(logger, d, meta); err != nil { return wrapErr(err, d) } @@ -126,7 +126,7 @@ func readBogusMetaFile(dir string) (*BlockMeta, error) { if err := json.Unmarshal(b, &m); err != nil { return nil, err } - if m.Version != 1 && m.Version != 2 { + if m.Version != metaVersion1 && m.Version != 2 { return nil, errors.Errorf("unexpected meta file version %d", m.Version) } return &m, nil diff --git a/tsdb/repair_test.go b/tsdb/repair_test.go index c3a1d22b2e..a40baf3005 100644 --- a/tsdb/repair_test.go +++ b/tsdb/repair_test.go @@ -123,5 +123,5 @@ func TestRepairBadIndexVersion(t *testing.T) { meta, _, err := readMetaFile(tmpDbDir) testutil.Ok(t, err) - testutil.Assert(t, meta.Version == 1, "unexpected meta version %d", meta.Version) + testutil.Assert(t, meta.Version == metaVersion1, "unexpected meta version %d", meta.Version) }