mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
tsdb: add block meta version constant (#5994)
Signed-off-by: zhulongcheng <zhulongcheng.dev@gmail.com>
This commit is contained in:
parent
5774d790a5
commit
937cc1a52a
|
@ -201,6 +201,7 @@ type BlockMetaCompaction struct {
|
||||||
|
|
||||||
const indexFilename = "index"
|
const indexFilename = "index"
|
||||||
const metaFilename = "meta.json"
|
const metaFilename = "meta.json"
|
||||||
|
const metaVersion1 = 1
|
||||||
|
|
||||||
func chunkDir(dir string) string { return filepath.Join(dir, "chunks") }
|
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 {
|
if err := json.Unmarshal(b, &m); err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
if m.Version != 1 {
|
if m.Version != metaVersion1 {
|
||||||
return nil, 0, errors.Errorf("unexpected meta file version %d", m.Version)
|
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) {
|
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.
|
// Make any changes to the file appear atomic.
|
||||||
path := filepath.Join(dir, metaFilename)
|
path := filepath.Join(dir, metaFilename)
|
||||||
|
|
|
@ -55,7 +55,7 @@ func repairBadIndexVersion(logger log.Logger, dir string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return wrapErr(err, d)
|
return wrapErr(err, d)
|
||||||
}
|
}
|
||||||
if meta.Version == 1 {
|
if meta.Version == metaVersion1 {
|
||||||
level.Info(logger).Log(
|
level.Info(logger).Log(
|
||||||
"msg", "found healthy block",
|
"msg", "found healthy block",
|
||||||
"mint", meta.MinTime,
|
"mint", meta.MinTime,
|
||||||
|
@ -108,7 +108,7 @@ func repairBadIndexVersion(logger log.Logger, dir string) error {
|
||||||
return wrapErr(err, d)
|
return wrapErr(err, d)
|
||||||
}
|
}
|
||||||
// Reset version of meta.json to 1.
|
// Reset version of meta.json to 1.
|
||||||
meta.Version = 1
|
meta.Version = metaVersion1
|
||||||
if _, err := writeMetaFile(logger, d, meta); err != nil {
|
if _, err := writeMetaFile(logger, d, meta); err != nil {
|
||||||
return wrapErr(err, d)
|
return wrapErr(err, d)
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ func readBogusMetaFile(dir string) (*BlockMeta, error) {
|
||||||
if err := json.Unmarshal(b, &m); err != nil {
|
if err := json.Unmarshal(b, &m); err != nil {
|
||||||
return nil, err
|
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 nil, errors.Errorf("unexpected meta file version %d", m.Version)
|
||||||
}
|
}
|
||||||
return &m, nil
|
return &m, nil
|
||||||
|
|
|
@ -123,5 +123,5 @@ func TestRepairBadIndexVersion(t *testing.T) {
|
||||||
|
|
||||||
meta, _, err := readMetaFile(tmpDbDir)
|
meta, _, err := readMetaFile(tmpDbDir)
|
||||||
testutil.Ok(t, err)
|
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)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue