From 89e6f9a16e997a0a3e4d4033a27c3acc69632eb7 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 10 Aug 2026 11:10:29 -0700 Subject: [PATCH] shell: volume.delete and volume.move accept a -timeout (#10701) * shell: volume.delete accepts a -timeout * shell: volume.move accepts a -timeout --- weed/shell/command_volume_delete.go | 12 +++++++++++- weed/shell/command_volume_move.go | 11 ++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/weed/shell/command_volume_delete.go b/weed/shell/command_volume_delete.go index f69a2997a..7b45554d0 100644 --- a/weed/shell/command_volume_delete.go +++ b/weed/shell/command_volume_delete.go @@ -24,8 +24,10 @@ func (c *commandVolumeDelete) Help() string { return `delete a live volume from one volume server volume.delete -node -volumeId + volume.delete -node -volumeId -timeout 30s This command deletes a volume from one volume server. + The option "-timeout" fails the command if the volume server does not respond in time. ` } @@ -39,6 +41,7 @@ func (c *commandVolumeDelete) Do(args []string, commandEnv *CommandEnv, writer i volDeleteCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) volumeIdInt := volDeleteCommand.Int("volumeId", 0, "the volume id") nodeStr := volDeleteCommand.String("node", "", "the volume server :") + timeout := volDeleteCommand.Duration("timeout", 0, "wall-clock cap on the deletion; 0 = no timeout") if err = volDeleteCommand.Parse(args); err != nil { return nil } @@ -51,6 +54,13 @@ func (c *commandVolumeDelete) Do(args []string, commandEnv *CommandEnv, writer i volumeId := needle.VolumeId(*volumeIdInt) - return deleteVolume(context.Background(), commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, false, false) + ctx := context.Background() + if *timeout > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + return deleteVolume(ctx, commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, false, false) } diff --git a/weed/shell/command_volume_move.go b/weed/shell/command_volume_move.go index 541aa98b7..1dd788c5e 100644 --- a/weed/shell/command_volume_move.go +++ b/weed/shell/command_volume_move.go @@ -45,6 +45,7 @@ func (c *commandVolumeMove) Help() string { 4. This command asks the source volume server to delete the source volume. The option "-disk [hdd|ssd|]" can be used to change the volume disk type. + The option "-timeout" fails the whole move if it does not finish in time. ` } @@ -61,6 +62,7 @@ func (c *commandVolumeMove) Do(args []string, commandEnv *CommandEnv, writer io. targetNodeStr := volMoveCommand.String("target", "", "the target volume server :") diskTypeStr := volMoveCommand.String("disk", "", "[hdd|ssd|] hard drive or solid state drive or any tag") ioBytePerSecond := volMoveCommand.Int64("ioBytePerSecond", 0, "limit the speed of move") + timeout := volMoveCommand.Duration("timeout", 0, "wall-clock cap on the whole move; 0 = no timeout") noLock := volMoveCommand.Bool("noLock", false, "do not lock the admin shell at one's own risk") if err = volMoveCommand.Parse(args); err != nil { @@ -83,7 +85,14 @@ func (c *commandVolumeMove) Do(args []string, commandEnv *CommandEnv, writer io. return fmt.Errorf("source and target volume servers are the same!") } - return LiveMoveVolume(context.Background(), commandEnv.option.GrpcDialOption, writer, volumeId, sourceVolumeServer, targetVolumeServer, 5*time.Second, *diskTypeStr, *ioBytePerSecond, false) + ctx := context.Background() + if *timeout > 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(ctx, *timeout) + defer cancel() + } + + return LiveMoveVolume(ctx, commandEnv.option.GrpcDialOption, writer, volumeId, sourceVolumeServer, targetVolumeServer, 5*time.Second, *diskTypeStr, *ioBytePerSecond, false) } // LiveMoveVolume moves one volume from one source volume server to one target volume server, with idleTimeout to drain the incoming requests.