shell: volume.delete and volume.move accept a -timeout (#10701)

* shell: volume.delete accepts a -timeout

* shell: volume.move accepts a -timeout
This commit is contained in:
Chris Lu
2026-08-10 11:10:29 -07:00
committed by GitHub
parent 6d25ccc357
commit 89e6f9a16e
2 changed files with 21 additions and 2 deletions
+11 -1
View File
@@ -24,8 +24,10 @@ func (c *commandVolumeDelete) Help() string {
return `delete a live volume from one volume server
volume.delete -node <volume server host:port> -volumeId <volume id>
volume.delete -node <volume server host:port> -volumeId <volume id> -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 <host>:<port>")
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)
}
+10 -1
View File
@@ -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|<tag>]" 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 <host>:<port>")
diskTypeStr := volMoveCommand.String("disk", "", "[hdd|ssd|<tag>] 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.