diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2021-10-27 09:42:23 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-27 09:42:23 +0800 |
| commit | 6999325d3631f0e9f4fe4e081650dcf60a1293c5 (patch) | |
| tree | 99082f145eeee921ae772d0c8601f97f40b7f074 /weed/shell/command_volume_move.go | |
| parent | ee90edd0e3746ae0f6046dd9e7362aeec821456c (diff) | |
| parent | 3eeaffeadd9bcff0148d0b1c860ea4ff03e82904 (diff) | |
| download | seaweedfs-6999325d3631f0e9f4fe4e081650dcf60a1293c5.tar.xz seaweedfs-6999325d3631f0e9f4fe4e081650dcf60a1293c5.zip | |
Merge pull request #84 from chrislusf/master
sync
Diffstat (limited to 'weed/shell/command_volume_move.go')
| -rw-r--r-- | weed/shell/command_volume_move.go | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/weed/shell/command_volume_move.go b/weed/shell/command_volume_move.go index 675f65341..ec71ba2b3 100644 --- a/weed/shell/command_volume_move.go +++ b/weed/shell/command_volume_move.go @@ -78,7 +78,7 @@ func (c *commandVolumeMove) Do(args []string, commandEnv *CommandEnv, writer io. func LiveMoveVolume(grpcDialOption grpc.DialOption, writer io.Writer, volumeId needle.VolumeId, sourceVolumeServer, targetVolumeServer pb.ServerAddress, idleTimeout time.Duration, diskType string, skipTailError bool) (err error) { log.Printf("copying volume %d from %s to %s", volumeId, sourceVolumeServer, targetVolumeServer) - lastAppendAtNs, err := copyVolume(grpcDialOption, volumeId, sourceVolumeServer, targetVolumeServer, diskType) + lastAppendAtNs, err := copyVolume(grpcDialOption, writer, volumeId, sourceVolumeServer, targetVolumeServer, diskType) if err != nil { return fmt.Errorf("copy volume %d from %s to %s: %v", volumeId, sourceVolumeServer, targetVolumeServer, err) } @@ -101,7 +101,7 @@ func LiveMoveVolume(grpcDialOption grpc.DialOption, writer io.Writer, volumeId n return nil } -func copyVolume(grpcDialOption grpc.DialOption, volumeId needle.VolumeId, sourceVolumeServer, targetVolumeServer pb.ServerAddress, diskType string) (lastAppendAtNs uint64, err error) { +func copyVolume(grpcDialOption grpc.DialOption, writer io.Writer, volumeId needle.VolumeId, sourceVolumeServer, targetVolumeServer pb.ServerAddress, diskType string) (lastAppendAtNs uint64, err error) { // check to see if the volume is already read-only and if its not then we need // to mark it as read-only and then before we return we need to undo what we @@ -141,15 +141,31 @@ func copyVolume(grpcDialOption grpc.DialOption, volumeId needle.VolumeId, source } err = operation.WithVolumeServerClient(targetVolumeServer, grpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error { - resp, replicateErr := volumeServerClient.VolumeCopy(context.Background(), &volume_server_pb.VolumeCopyRequest{ + stream, replicateErr := volumeServerClient.VolumeCopy(context.Background(), &volume_server_pb.VolumeCopyRequest{ VolumeId: uint32(volumeId), SourceDataNode: string(sourceVolumeServer), DiskType: diskType, }) - if replicateErr == nil { - lastAppendAtNs = resp.LastAppendAtNs + if replicateErr != nil { + return replicateErr } - return replicateErr + for { + resp, recvErr := stream.Recv() + if recvErr != nil { + if recvErr == io.EOF { + break + } else { + return recvErr + } + } + if resp.LastAppendAtNs != 0 { + lastAppendAtNs = resp.LastAppendAtNs + } else { + fmt.Fprintf(writer, "volume %d processed %d bytes\n", volumeId, resp.ProcessedBytes) + } + } + + return nil }) return |
