mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-11-02 18:22:40 +01:00
* shell: dial scrubbed volume servers on their registered gRPC port volume.scrub, ec.scrub and volume.server.state built each data node's address from its HTTP address alone, so a volume server whose gRPC port is not the HTTP port + 10000 was dialed on the wrong port. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: resolve -node volume servers to their registered gRPC port An explicit -node/-nodes list was dialed on HTTP port + 10000 too. Match each entry against the topology and take the data node's gRPC port; an address the master does not know is used as given. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: keep a gRPC port given in -node A node given as host:port.grpcPort was rewritten to the registered gRPC port; only a bare host:port takes it from the topology. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: dial -node volume servers when the topology is unavailable An explicit node list did not need the master before; keep using it as given if the volume list cannot be fetched. Selecting every node still requires the topology. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: bound the topology lookup for an explicit -node list With the master down, volumeServer.state -nodes waited on the master forever instead of reaching the given volume servers. Give the lookup a 30s deadline and fall back to the addresses as given. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: resolve volume server addresses from a topology-only listing Only the data nodes are needed to find each server's gRPC port, so ask the master for the topology without its volumes and ec shards. A large cluster no longer risks running past the -node lookup deadline and falling back to the HTTP port + 10000. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * shell: skip the topology lookup when every -node names its gRPC port A host:port.grpcPort entry is dialed as given, so a list made only of those does not need the master and no longer waits on it during an outage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
160 lines
5.0 KiB
Go
160 lines
5.0 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"strconv"
|
|
"strings"
|
|
"sync"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/operation"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/volume_server_pb"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
func init() {
|
|
Commands = append(Commands, &commandVolumeScrub{})
|
|
}
|
|
|
|
type commandVolumeScrub struct {
|
|
env *CommandEnv
|
|
volumeServerAddrs []pb.ServerAddress
|
|
volumeIDs []uint32
|
|
mode volume_server_pb.VolumeScrubMode
|
|
grpcDialOption grpc.DialOption
|
|
}
|
|
|
|
func (c *commandVolumeScrub) Name() string {
|
|
return "volume.scrub"
|
|
}
|
|
|
|
func (c *commandVolumeScrub) Help() string {
|
|
return `scrubs volume contents on volume servers.
|
|
|
|
Supports either scrubbing only needle data, or deep scrubbing file contents as well.
|
|
|
|
Scrubbing can be limited to specific volume IDs for specific volume servers.
|
|
By default, all volume IDs across all servers are processed.
|
|
|
|
`
|
|
}
|
|
|
|
func (c *commandVolumeScrub) HasTag(CommandTag) bool {
|
|
return false
|
|
}
|
|
|
|
func (c *commandVolumeScrub) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
volScrubCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
nodesStr := volScrubCommand.String("node", "", "comma-separated list of volume server <host>:<port> (optional)")
|
|
volumeIDsStr := volScrubCommand.String("volumeId", "", "comma-separated volume IDs to process (optional)")
|
|
mode := volScrubCommand.String("mode", "full", "scrubbing mode (index/local/full/reads)")
|
|
markBrokenReadonly := volScrubCommand.Bool("markBrokenReadonly", false, "whether to flag volumes with scrub failures as read-only")
|
|
maxParallelization := volScrubCommand.Int("maxParallelization", DefaultMaxParallelization, "run up to X tasks in parallel, whenever possible")
|
|
showDetails := volScrubCommand.Bool("details", false, "display scrub result details, if available")
|
|
|
|
if err = volScrubCommand.Parse(args); err != nil {
|
|
return err
|
|
}
|
|
if err = commandEnv.confirmIsLocked(args); err != nil {
|
|
return
|
|
}
|
|
|
|
if c.volumeServerAddrs, err = collectVolumeServerAddresses(commandEnv, *nodesStr); err != nil {
|
|
return err
|
|
}
|
|
|
|
c.volumeIDs = []uint32{}
|
|
if *volumeIDsStr != "" {
|
|
for _, vids := range strings.Split(*volumeIDsStr, ",") {
|
|
vids = strings.TrimSpace(vids)
|
|
if vids == "" {
|
|
continue
|
|
}
|
|
if vid, err := strconv.ParseUint(vids, 10, 32); err == nil {
|
|
c.volumeIDs = append(c.volumeIDs, uint32(vid))
|
|
} else {
|
|
return fmt.Errorf("invalid volume ID %q", vids)
|
|
}
|
|
}
|
|
}
|
|
|
|
switch strings.ToUpper(*mode) {
|
|
case "INDEX":
|
|
c.mode = volume_server_pb.VolumeScrubMode_INDEX
|
|
case "LOCAL":
|
|
c.mode = volume_server_pb.VolumeScrubMode_LOCAL
|
|
case "FULL":
|
|
c.mode = volume_server_pb.VolumeScrubMode_FULL
|
|
case "READS":
|
|
// only meaningful for EC volumes; accepted here so one mode name works on both commands
|
|
c.mode = volume_server_pb.VolumeScrubMode_READS
|
|
default:
|
|
return fmt.Errorf("unsupported scrubbing mode %q", *mode)
|
|
}
|
|
fmt.Fprintf(writer, "using %s mode\n", c.mode.String())
|
|
c.env = commandEnv
|
|
|
|
return c.scrubVolumes(writer, *maxParallelization, *markBrokenReadonly, *showDetails)
|
|
}
|
|
|
|
func (c *commandVolumeScrub) scrubVolumes(writer io.Writer, maxParallelization int, markBrokenReadonly bool, showDetails bool) error {
|
|
var brokenVolumesStr []string
|
|
var details []string
|
|
var totalVolumes, brokenVolumes, totalFiles uint64
|
|
var mu sync.Mutex
|
|
|
|
ewg := NewErrorWaitGroup(maxParallelization)
|
|
count := 0
|
|
for _, addr := range c.volumeServerAddrs {
|
|
ewg.Add(func() error {
|
|
mu.Lock()
|
|
count++
|
|
fmt.Fprintf(writer, "Scrubbing %s (%d/%d)...\n", addr.String(), count, len(c.volumeServerAddrs))
|
|
mu.Unlock()
|
|
|
|
err := operation.WithVolumeServerClient(false, addr, c.env.option.GrpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
|
|
res, err := volumeServerClient.ScrubVolume(context.Background(), &volume_server_pb.ScrubVolumeRequest{
|
|
Mode: c.mode,
|
|
VolumeIds: c.volumeIDs,
|
|
MarkBrokenVolumesReadonly: markBrokenReadonly,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
|
|
totalVolumes += res.GetTotalVolumes()
|
|
totalFiles += res.GetTotalFiles()
|
|
brokenVolumes += uint64(len(res.GetBrokenVolumeIds()))
|
|
for _, d := range res.GetDetails() {
|
|
details = append(details, fmt.Sprintf("[%s] %s", addr, d))
|
|
}
|
|
for _, vid := range res.GetBrokenVolumeIds() {
|
|
brokenVolumesStr = append(brokenVolumesStr, fmt.Sprintf("%s:%v", addr, vid))
|
|
}
|
|
|
|
return nil
|
|
})
|
|
return err
|
|
})
|
|
}
|
|
if err := ewg.Wait(); err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Fprintf(writer, "Scrubbed %d files and %d volumes on %d nodes\n", totalFiles, totalVolumes, len(c.volumeServerAddrs))
|
|
if brokenVolumes != 0 {
|
|
fmt.Fprintf(writer, "\nGot scrub failures on %d volumes :(\n", brokenVolumes)
|
|
fmt.Fprintf(writer, "Affected volumes: %s\n", strings.Join(brokenVolumesStr, ", "))
|
|
if showDetails && len(details) != 0 {
|
|
fmt.Fprintf(writer, "Details:\n\t%s\n", strings.Join(details, "\n\t"))
|
|
}
|
|
}
|
|
return nil
|
|
}
|