From dd0d3c6f02f6b00e49ef4a9ebd08adb53cc17895 Mon Sep 17 00:00:00 2001 From: naivewong <867245430@qq.com> Date: Mon, 18 Mar 2019 22:14:10 +0800 Subject: [PATCH] Several small fixes (#550) `if ds[i].meta.MinTime < t0 || ds[i].meta.MaxTime > t0+tr `, ds[i].meta.MinTime is always larger or equal to t0, so no need for this check. `ulid.Parse` only checks if the length is 26. So changed to using `ulid.ParseStrict` to also check the validity of ulid. --- compact.go | 4 ++-- db.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compact.go b/compact.go index a1a7aa76f6..bf07d25e89 100644 --- a/compact.go +++ b/compact.go @@ -309,7 +309,7 @@ func splitByRange(ds []dirMeta, tr int64) [][]dirMeta { } // Skip blocks that don't fall into the range. This can happen via mis-alignment or // by being the multiple of the intended range. - if ds[i].meta.MinTime < t0 || ds[i].meta.MaxTime > t0+tr { + if m.MaxTime > t0+tr { i++ continue } @@ -317,7 +317,7 @@ func splitByRange(ds []dirMeta, tr int64) [][]dirMeta { // Add all dirs to the current group that are within [t0, t0+tr]. for ; i < len(ds); i++ { // Either the block falls into the next range or doesn't fit at all (checked above). - if ds[i].meta.MinTime < t0 || ds[i].meta.MaxTime > t0+tr { + if ds[i].meta.MaxTime > t0+tr { break } group = append(group, ds[i]) diff --git a/db.go b/db.go index 0022df12dd..275d96eb7c 100644 --- a/db.go +++ b/db.go @@ -896,7 +896,7 @@ func (db *DB) Snapshot(dir string, withHead bool) error { if dir == db.dir { return errors.Errorf("cannot snapshot into base directory") } - if _, err := ulid.Parse(dir); err == nil { + if _, err := ulid.ParseStrict(dir); err == nil { return errors.Errorf("dir must not be a valid ULID") } @@ -1037,7 +1037,7 @@ func isBlockDir(fi os.FileInfo) bool { if !fi.IsDir() { return false } - _, err := ulid.Parse(fi.Name()) + _, err := ulid.ParseStrict(fi.Name()) return err == nil }