aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLisandro Pin <lisandro.pin@proton.ch>2025-11-14 02:14:36 +0100
committerGitHub <noreply@github.com>2025-11-13 17:14:36 -0800
commit0e69f7c91606b42fe2e1e55d65d24659e546bf33 (patch)
tree6ffa930aac1d3e65c54f4f8561108214563217cf
parent4e73cc778c2624aac4a5a509ca153974a8da3a94 (diff)
downloadseaweedfs-0e69f7c91606b42fe2e1e55d65d24659e546bf33.tar.xz
seaweedfs-0e69f7c91606b42fe2e1e55d65d24659e546bf33.zip
Split logic for `volume.check.disk` into writable and read-only volume replicas. (#7476)
-rw-r--r--weed/shell/command_volume_check_disk.go38
1 files changed, 34 insertions, 4 deletions
diff --git a/weed/shell/command_volume_check_disk.go b/weed/shell/command_volume_check_disk.go
index 740c9679d..ca7efa5d4 100644
--- a/weed/shell/command_volume_check_disk.go
+++ b/weed/shell/command_volume_check_disk.go
@@ -66,10 +66,11 @@ func (c *commandVolumeCheckDisk) Do(args []string, commandEnv *CommandEnv, write
fsckCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
slowMode := fsckCommand.Bool("slow", false, "slow mode checks all replicas even file counts are the same")
verbose := fsckCommand.Bool("v", false, "verbose mode")
- volumeId := fsckCommand.Uint("volumeId", 0, "the volume id")
+ volumeId := fsckCommand.Uint("volumeId", 0, "the volume ID (0 for all)")
applyChanges := fsckCommand.Bool("apply", false, "apply the fix")
// TODO: remove this alias
applyChangesAlias := fsckCommand.Bool("force", false, "apply the fix (alias for -apply)")
+ forceReadonly := fsckCommand.Bool("force-readonly", false, "apply the fix even on readonly volumes")
syncDeletions := fsckCommand.Bool("syncDeleted", false, "sync of deletions the fix")
nonRepairThreshold := fsckCommand.Float64("nonRepairThreshold", 0.3, "repair when missing keys is not more than this limit")
if err = fsckCommand.Parse(args); err != nil {
@@ -100,13 +101,37 @@ func (c *commandVolumeCheckDisk) Do(args []string, commandEnv *CommandEnv, write
if err != nil {
return err
}
+ // collect volume replicas, optionally filtered by volume ID
volumeReplicas, _ := collectVolumeReplicaLocations(topologyInfo)
+ if vid := uint32(*volumeId); vid > 0 {
+ if replicas, ok := volumeReplicas[vid]; ok {
+ volumeReplicas = map[uint32][]*VolumeReplica{
+ vid: replicas,
+ }
+ } else {
+ return fmt.Errorf("volume %d not found", vid)
+ }
+ }
+
+ vcd.write("Pass #1 (writeable volumes)\n")
+ if err := vcd.checkWriteableVolumes(volumeReplicas); err != nil {
+ return err
+ }
+ if *forceReadonly {
+ vcd.write("Pass #2 (read-only volumes)\n")
+ if err := vcd.checkReadOnlyVolumes(volumeReplicas); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+// checkWriteableVolumes fixes volume replicas which are not read-only.
+func (vcd *volumeCheckDisk) checkWriteableVolumes(volumeReplicas map[uint32][]*VolumeReplica) error {
// pick 1 pairs of volume replica
for _, replicas := range volumeReplicas {
- if *volumeId > 0 && replicas[0].info.Id != uint32(*volumeId) {
- continue
- }
// filter readonly replica
var writableReplicas []*VolumeReplica
for _, replica := range replicas {
@@ -148,6 +173,11 @@ func (c *commandVolumeCheckDisk) Do(args []string, commandEnv *CommandEnv, write
return nil
}
+// checkReadOnlyVolumes fixes read-only volume replicas.
+func (vcd *volumeCheckDisk) checkReadOnlyVolumes(volumeReplicas map[uint32][]*VolumeReplica) error {
+ return fmt.Errorf("not yet implemented (https://github.com/seaweedfs/seaweedfs/issues/7442)")
+}
+
func (vcd *volumeCheckDisk) isLocked() bool {
return vcd.commandEnv.isLocked()
}