Files
seaweedfs/weed/storage/idx/check.go
T
Chris LuandGitHub acbb6f7550 fix(scrub): don't flag offset-0 logical tombstones in volume scrub (#10148)
* fix(scrub): don't flag offset-0 logical tombstones in volume scrub

A remote-tier delete records a tombstone at .idx offset 0 with no physical .dat
bytes. Full scrub double-flagged a healthy remote-tiered volume with deletes:
scrubVolumeData counted the tombstone's GetActualSize(-1)=32 toward totalRead
(want > physical .dat), and CheckIndexFile treated it as occupying [0,31] and
flagged the first live needle as overlapping. Skip offset-0 logical tombstones
from both the size reconcile and the overlap check; they are still counted for
the index-size check. Local deletes (offset != 0) are unaffected.

Claude-Session: https://claude.ai/code/session_015EE9Sc9EvNp8BCVva4RKdo

* fix(scrub): mirror offset-0 logical tombstone handling into Rust

Same fix as the Go volume_checking.go + idx/check.go change: Volume::scrub skips
offset-0 logical tombstones from total_read, and check_index_file excludes them
from the overlap check (still counted for the index-size check).

Claude-Session: https://claude.ai/code/session_015EE9Sc9EvNp8BCVva4RKdo
2026-06-30 02:01:14 -07:00

115 lines
2.9 KiB
Go

package idx
import (
"fmt"
"io"
"sort"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
"github.com/seaweedfs/seaweedfs/weed/storage/types"
)
type indexEntry struct {
index int
id types.NeedleId
offset int64
size types.Size
}
func (ie *indexEntry) Compare(other *indexEntry) int {
if ie.offset < other.offset {
return -1
}
if ie.offset > other.offset {
return 1
}
if ie.size < other.size {
return -1
}
if ie.size > other.size {
return 1
}
return 0
}
// CheckIndexFile verifies the integrity of a IDX/ECX index file. Returns a count of processed file entries, and slice of found errors.
func CheckIndexFile(r io.ReaderAt, indexFileSize int64, version needle.Version) (int64, []error) {
errs := []error{}
entries := []*indexEntry{}
var i int
err := WalkIndexFile(r, 0, func(id types.NeedleId, offset types.Offset, size types.Size) error {
entries = append(entries, &indexEntry{
index: i,
id: id,
offset: offset.ToActualOffset(),
size: size,
})
i++
return nil
})
if err != nil {
errs = append(errs, err)
}
sort.Slice(entries, func(i, j int) bool {
return entries[i].Compare(entries[j]) < 0
})
// Offset-0 logical tombstones (remote-tier deletes) occupy no physical .dat
// extent, so they cannot overlap anything — exclude them from the overlap
// check. They are still counted below for the index-size check.
physical := make([]*indexEntry, 0, len(entries))
for _, e := range entries {
if e.offset == 0 && e.size.IsDeleted() {
continue
}
physical = append(physical, e)
}
for i, e := range physical {
if i == 0 {
// nothing to check for the first entry
continue
}
start, end := e.offset, e.offset
if size := needle.GetActualSize(e.size, version); size != 0 {
end += size - 1
}
last := physical[i-1]
lastStart, lastEnd := last.offset, last.offset
if lastSize := needle.GetActualSize(last.size, version); lastSize != 0 {
lastEnd += lastSize - 1
}
// check if needles overlap
if start <= lastEnd {
errs = append(errs, fmt.Errorf(
"needle %d (#%d) at [%d-%d] overlaps needle %d at [%d-%d]",
e.id, e.index+1,
start, end,
last.id,
lastStart, lastEnd))
}
// The check below is intended to ensure all index entries are contiguous; unfortunately, Seaweed
// can delete index entries for files while keeping their data, so volumes with deleted files
// will fail this test :(
// See https://github.com/seaweedfs/seaweedfs/issues/8204 for details.
/*
if e.offset != lastEnd + 1 {
errs = append(errs, fmt.Errorf("offset %d for needle %d (#%d) doesn't match end of needle %d at %d", e.offset, e.id, e.index+1, last.id, lastEnd))
}
*/
}
count := int64(len(entries))
if got, want := count*types.NeedleMapEntrySize, indexFileSize; got != want {
errs = append(errs, fmt.Errorf("expected an index file of size %d, got %d", want, got))
}
return count, errs
}