mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-19 10:54:08 +01:00
* Introduce a new `READS` scrub mode. `READS` performs a full volume scrub but, unlike `FULL`, it will attempt to reconstruct data for missing/damaged shard intervals from other shards in the cluster when necessary. The goal of this check is to ensure that EC volume contents _are readable by Seaweed_ even on a degraded storage state, by exercising parity data which is not read in `FULL` mode. This is useful not only to validate data is user-readable, but also to detect potential parity shard issues which may be difficult to pinpoint otherwise - particularly for older volumes lacking sidecar data, and hence unaffected by `CHECKSUM` scrubs. For regular volumes, this operation is equivalent to `FULL`. Example: ``` > ec.shard.unmount --volumeId=1 --shardId=0,3,11 --delete --apply Live shard topology for volume ID 1 (14 shards): 0@10.200.18.89:9001 1@10.200.18.89:9002 2@10.200.18.89:9003 3@10.200.18.89:9004 4@10.200.18.89:9005 5@10.200.18.89:9006 6@10.200.18.89:9007 7@10.200.18.89:9008 8@10.200.18.89:9009 9@10.200.18.89:9013 10@10.200.18.89:9010 11@10.200.18.89:9011 12@10.200.18.89:9012 13@10.200.18.89:9020 Will unmount + delete 3 shard(s): 0@10.200.18.89:9001 3@10.200.18.89:9004 11@10.200.18.89:9011 Unmounting shard 0@10.200.18.89:9001 for volume ID 1... Deleting shard 0@10.200.18.89:9001 for volume ID 1... Unmounting shard 3@10.200.18.89:9004 for volume ID 1... Deleting shard 3@10.200.18.89:9004 for volume ID 1... Unmounting shard 11@10.200.18.89:9011 for volume ID 1... Deleting shard 11@10.200.18.89:9011 for volume ID 1... All done! > ec.scrub --volumeId=1 --node=10.200.18.89:9002 --mode=full using FULL mode Scrubbing 10.200.18.89:9002 (1/1)... Scrubbed 6 EC files and 1 volumes on 1 nodes Got scrub failures on 1 EC volumes and 1 EC shards :( Affected volumes: 10.200.18.89:9002:1 Affected shards: 10.200.18.89:9002:1:0 > ec.scrub --volumeId=1 --node=10.200.18.89:9002 --mode=reads using READS mode Scrubbing 10.200.18.89:9002 (1/1)... Scrubbed 6 EC files and 1 volumes on 1 nodes ``` * ec: report the shards a READS scrub had to rebuild A READS scrub that recovers an interval was recording nothing, so a volume missing three shards came back clean and nobody repaired it. The unreadable shard is now recorded before the rebuild is attempted: READS reports the same broken shards as FULL and differs only in whether the needles themselves failed, which is the signal worth having - shards are gone, data is still there. forceDeletedNeedlesCheck now applies to READS as well, in the shell and in the RPC guard: it runs the same needle walk as FULL. Regenerated the proto instead of hand-editing it, so the pancis typo (which protoc-gen-go-grpc emits into eight other files here) and the header whitespace stay as generated. Mirrors into the Rust volume server, which also now honors force_deleted_needles_check rather than hardcoding it off. Claude-Session: https://claude.ai/code/session_014yMNebkUjSbx9sfUCWJJtq * ec: answer a deleted needle from a READS rebuild as deleted #11020 gave the Rust recovery a deleted flag alongside its bytes, and it answers a deleted needle with no bytes at all. The READS scrub appended that empty answer, which does not compile against the new signature and, once it did, would leave the needle short and report the size mismatch as damage. Zero-fill the interval instead, the way the direct read beside it already does: the assembled needle then reaches read_bytes as the delete-state mismatch the walk already tolerates. Go takes the same branch off the flag its recovery returns, rather than discarding it. Claude-Session: https://claude.ai/code/session_014yMNebkUjSbx9sfUCWJJtq --------- Co-authored-by: Lisandro Pin <lisandro.pin@proton.ch>
129 lines
5.0 KiB
Go
129 lines
5.0 KiB
Go
package storage
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"slices"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/types"
|
|
)
|
|
|
|
// ScrubEcVolume checks the full integrity of a EC volume, across both local and remote shards.
|
|
// Returns a count of processed file entries, slice of found broken shards, and slice of found errors.
|
|
//
|
|
// FULL reports an unreadable shard and gives up on the needle. READS additionally rebuilds the
|
|
// interval from the surviving shards, so it reports the same broken shards but only errors on
|
|
// needles that parity can no longer recover - which is what exercises the parity data.
|
|
func (s *Store) ScrubEcVolume(vid needle.VolumeId, mode volume_server_pb.VolumeScrubMode, forceDeletedNeedlesCheck bool) (int64, []*volume_server_pb.EcShardInfo, []error) {
|
|
ecv, found := s.FindEcVolume(vid)
|
|
if !found {
|
|
return 0, nil, []error{fmt.Errorf("EC volume id %d not found", vid)}
|
|
}
|
|
if err := s.cachedLookupEcShardLocations(ecv); err != nil {
|
|
return 0, nil, []error{fmt.Errorf("failed to locate shard via master grpc %s: %v", s.MasterAddress, err)}
|
|
}
|
|
|
|
// full scan means verifying indexes as well
|
|
_, errs := ecv.ScrubIndex()
|
|
|
|
recoverUnreadable := mode == volume_server_pb.VolumeScrubMode_READS
|
|
|
|
var count int64
|
|
// reads for EC chunks can hit the same shard multiple times, so dedupe upon read errors
|
|
brokenShardsMap := map[erasure_coding.ShardId]*volume_server_pb.EcShardInfo{}
|
|
|
|
err := ecv.WalkIndex(func(id types.NeedleId, offset types.Offset, size types.Size) error {
|
|
count++
|
|
if size.IsTombstone() {
|
|
// nothing to do for tombstones...
|
|
return nil
|
|
}
|
|
|
|
data := make([]byte, 0, needle.GetActualSize(size, ecv.Version))
|
|
intervals := ecv.LocateEcShardNeedleInterval(ecv.Version, offset.ToActualOffset(), size)
|
|
|
|
shardIds := make([]erasure_coding.ShardId, len(intervals))
|
|
for i, iv := range intervals {
|
|
sid, _ := s.IntervalToShardIdAndOffset(iv)
|
|
shardIds[i] = sid
|
|
}
|
|
slices.Sort(shardIds)
|
|
|
|
for i, iv := range intervals {
|
|
chunk := make([]byte, iv.Size)
|
|
shardId, offset := s.IntervalToShardIdAndOffset(iv)
|
|
|
|
// try a local shard read first...
|
|
if err := s.readLocalEcShardInterval(ecv, shardId, chunk, offset); err == nil {
|
|
data = append(data, chunk...)
|
|
continue
|
|
}
|
|
|
|
// ...then remote. neither read decodes: the point is to find shards that are
|
|
// themselves broken, not to heal around them
|
|
ecv.ShardLocationsLock.RLock()
|
|
sourceDataNodes, ok := ecv.ShardLocations[shardId]
|
|
ecv.ShardLocationsLock.RUnlock()
|
|
readErr := errors.New("no known shard locations")
|
|
if ok {
|
|
if _, _, readErr = s.readRemoteEcShardInterval(sourceDataNodes, id, ecv.VolumeId, shardId, chunk, offset, ecv.EncodeTsNs); readErr == nil {
|
|
data = append(data, chunk...)
|
|
continue
|
|
}
|
|
}
|
|
|
|
// the shard is broken whether or not the needle survives it, so report it either way
|
|
brokenShardsMap[shardId] = &volume_server_pb.EcShardInfo{
|
|
ShardId: uint32(shardId),
|
|
Size: int64(iv.Size),
|
|
Collection: ecv.Collection,
|
|
VolumeId: uint32(ecv.VolumeId),
|
|
}
|
|
|
|
if !recoverUnreadable {
|
|
errs = append(errs, fmt.Errorf("failed to read EC shard %d for needle %d on volume %d (interval %d/%d): %v", shardId, id, ecv.VolumeId, i+1, len(intervals), readErr))
|
|
break
|
|
}
|
|
// A holder reporting the needle deleted is authoritative, and it answers
|
|
// with no bytes: the chunk stays zeroed and reaches ReadBytes as the
|
|
// delete-state mismatch the walk below already tolerates.
|
|
if _, isDeleted, err := s.recoverOneRemoteEcShardInterval(id, ecv, shardId, chunk, offset); err != nil && !isDeleted {
|
|
errs = append(errs, fmt.Errorf("failed to recover EC shard %d for needle %d on volume %d (interval %d/%d): %v", shardId, id, ecv.VolumeId, i+1, len(intervals), err))
|
|
break
|
|
}
|
|
data = append(data, chunk...)
|
|
}
|
|
|
|
if got, want := int64(len(data)), needle.GetActualSize(size, ecv.Version); got != want {
|
|
errs = append(errs, fmt.Errorf("EC volume %d, needle %d on shards %v: expected %d bytes, got %d", ecv.VolumeId, id, shardIds, want, got))
|
|
return nil
|
|
}
|
|
|
|
n := needle.Needle{}
|
|
if err := n.ReadBytes(data, 0, size, ecv.Version); err != nil {
|
|
// needles flagged as deleted in the index but not in the volume (or vice-versa) cannot
|
|
// be properly hydrated, as the header read by needle.ReadBytes() will mismatch.
|
|
deleteSizeMismatch := size.IsDeleted() != (n.Size == 0)
|
|
if !errors.Is(err, needle.ErrorSizeMismatch) || !deleteSizeMismatch || forceDeletedNeedlesCheck {
|
|
errs = append(errs, fmt.Errorf("EC volume %d, needle %d on shards %v: %v", ecv.VolumeId, id, shardIds, err))
|
|
}
|
|
}
|
|
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
errs = append(errs, err)
|
|
}
|
|
|
|
brokenShards := []*volume_server_pb.EcShardInfo{}
|
|
for _, s := range brokenShardsMap {
|
|
brokenShards = append(brokenShards, s)
|
|
}
|
|
slices.SortFunc(brokenShards, erasure_coding.CmpEcShardInfo)
|
|
|
|
return count, brokenShards, errs
|
|
}
|