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.
This commit is contained in:
naivewong 2019-03-18 22:14:10 +08:00 committed by Krasi Georgiev
parent 99703b3269
commit dd0d3c6f02
2 changed files with 4 additions and 4 deletions

View file

@ -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])

4
db.go
View file

@ -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
}