mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-16 12:16:36 +00:00
LiveMoveVolume and the copy, tail, delete, mark, replicate, and configure helpers around it issued every RPC on context.Background(), so a caller had no way to bound or abort a move once it started. They now take a context, which the exported LiveMoveVolume in particular needs: callers outside the shell drive long moves and want to stop them. The deferred restore in copyVolume runs on a detached, bounded context rather than the caller's. Marking the source writable again is cleanup, and cancelling the copy must not skip it and leave the volume readonly — the same guard balance_task.go already applies for the same reason. Shell commands pass context.Background(): their Do signature carries no context, and changing it would touch every command in the package. Claude-Session: https://claude.ai/code/session_01Ks16jnt4S7gdDk8cheQ3xu
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package shell
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
|
)
|
|
|
|
func init() {
|
|
Commands = append(Commands, &commandVolumeCopy{})
|
|
}
|
|
|
|
type commandVolumeCopy struct {
|
|
}
|
|
|
|
func (c *commandVolumeCopy) Name() string {
|
|
return "volume.copy"
|
|
}
|
|
|
|
func (c *commandVolumeCopy) Help() string {
|
|
return `copy a volume from one volume server to another volume server
|
|
|
|
volume.copy -source <source volume server host:port> -target <target volume server host:port> -volumeId <volume id>
|
|
|
|
This command copies a volume from one volume server to another volume server.
|
|
Usually you will want to unmount the volume first before copying.
|
|
|
|
`
|
|
}
|
|
|
|
func (c *commandVolumeCopy) HasTag(CommandTag) bool {
|
|
return false
|
|
}
|
|
|
|
func (c *commandVolumeCopy) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
volCopyCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
|
|
volumeIdInt := volCopyCommand.Int("volumeId", 0, "the volume id")
|
|
sourceNodeStr := volCopyCommand.String("source", "", "the source volume server <host>:<port>")
|
|
targetNodeStr := volCopyCommand.String("target", "", "the target volume server <host>:<port>")
|
|
noLock := volCopyCommand.Bool("noLock", false, "do not lock the admin shell at one's own risk")
|
|
if err = volCopyCommand.Parse(args); err != nil {
|
|
return nil
|
|
}
|
|
|
|
if *noLock {
|
|
commandEnv.noLock = true
|
|
} else if err = commandEnv.confirmIsLocked(args); err != nil {
|
|
return
|
|
}
|
|
|
|
sourceVolumeServer, targetVolumeServer := pb.ServerAddress(*sourceNodeStr), pb.ServerAddress(*targetNodeStr)
|
|
|
|
volumeId := needle.VolumeId(*volumeIdInt)
|
|
|
|
if sourceVolumeServer == targetVolumeServer {
|
|
return fmt.Errorf("source and target volume servers are the same!")
|
|
}
|
|
|
|
_, err = copyVolume(context.Background(), commandEnv.option.GrpcDialOption, writer, volumeId, sourceVolumeServer, targetVolumeServer, "", 0, true)
|
|
return
|
|
}
|