tsdb: fix sequence check for WAL segments (#7032)

Signed-off-by: zhulongcheng <zhulongcheng.dev@gmail.com>
This commit is contained in:
zhulongcheng 2020-03-23 15:46:28 +08:00 committed by GitHub
parent 24ecae9956
commit e813f60fd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -763,21 +763,21 @@ func listSegments(dir string) (refs []segmentRef, err error) {
if err != nil {
return nil, err
}
var last int
for _, fn := range files {
k, err := strconv.Atoi(fn)
if err != nil {
continue
}
if len(refs) > 0 && k > last+1 {
return nil, errors.New("segments are not sequential")
}
refs = append(refs, segmentRef{name: fn, index: k})
last = k
}
sort.Slice(refs, func(i, j int) bool {
return refs[i].index < refs[j].index
})
for i := 0; i < len(refs)-1; i++ {
if refs[i].index+1 != refs[i+1].index {
return nil, errors.New("segments are not sequential")
}
}
return refs, nil
}