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

Signed-off-by: zhulongcheng <zhulongcheng.dev@gmail.com>
pull/7037/head
zhulongcheng 5 years ago committed by GitHub
parent 24ecae9956
commit e813f60fd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save