diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2020-11-05 12:02:47 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-11-05 12:02:47 +0800 |
| commit | 546f1bcb903dd26ba447cdbedb972736fdb31b42 (patch) | |
| tree | 09b8119faa7162acaa7240de5af6fd0bebe96c2f /weed/shell | |
| parent | 843865f2ca534bb6286b7a3d79c436384d875608 (diff) | |
| parent | 75887ba2a20b9f3f7ff9c4b8998cf3af0c0f48c2 (diff) | |
| download | seaweedfs-546f1bcb903dd26ba447cdbedb972736fdb31b42.tar.xz seaweedfs-546f1bcb903dd26ba447cdbedb972736fdb31b42.zip | |
Merge pull request #34 from chrislusf/master
sync
Diffstat (limited to 'weed/shell')
| -rw-r--r-- | weed/shell/command_volume_mark.go | 55 | ||||
| -rw-r--r-- | weed/shell/command_volume_move.go | 15 |
2 files changed, 70 insertions, 0 deletions
diff --git a/weed/shell/command_volume_mark.go b/weed/shell/command_volume_mark.go new file mode 100644 index 000000000..19b614310 --- /dev/null +++ b/weed/shell/command_volume_mark.go @@ -0,0 +1,55 @@ +package shell + +import ( + "flag" + "fmt" + "io" + + "github.com/chrislusf/seaweedfs/weed/storage/needle" +) + +func init() { + Commands = append(Commands, &commandVolumeMark{}) +} + +type commandVolumeMark struct { +} + +func (c *commandVolumeMark) Name() string { + return "volume.mark" +} + +func (c *commandVolumeMark) Help() string { + return `Mark volume writable or readonly from one volume server + + volume.mark -node <volume server host:port> -volumeId <volume id> -writable or -readonly +` +} + +func (c *commandVolumeMark) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) { + + if err = commandEnv.confirmIsLocked(); err != nil { + return + } + + volMarkCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) + volumeIdInt := volMarkCommand.Int("volumeId", 0, "the volume id") + nodeStr := volMarkCommand.String("node", "", "the volume server <host>:<port>") + writable := volMarkCommand.Bool("writable", false, "volume mark writable") + readonly := volMarkCommand.Bool("readonly", false, "volume mark readonly") + if err = volMarkCommand.Parse(args); err != nil { + return nil + } + markWritable := false + if (*writable && *readonly) || (!*writable && !*readonly) { + return fmt.Errorf("use -readonly or -writable") + } else if *writable { + markWritable = true + } + + sourceVolumeServer := *nodeStr + + volumeId := needle.VolumeId(*volumeIdInt) + + return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, markWritable) +} diff --git a/weed/shell/command_volume_move.go b/weed/shell/command_volume_move.go index b136604e5..2bc8dfad8 100644 --- a/weed/shell/command_volume_move.go +++ b/weed/shell/command_volume_move.go @@ -166,3 +166,18 @@ func deleteVolume(grpcDialOption grpc.DialOption, volumeId needle.VolumeId, sour return deleteErr }) } + +func markVolumeWritable(grpcDialOption grpc.DialOption, volumeId needle.VolumeId, sourceVolumeServer string, writable bool) (err error) { + return operation.WithVolumeServerClient(sourceVolumeServer, grpcDialOption, func(volumeServerClient volume_server_pb.VolumeServerClient) error { + if writable { + _, err = volumeServerClient.VolumeMarkWritable(context.Background(), &volume_server_pb.VolumeMarkWritableRequest{ + VolumeId: uint32(volumeId), + }) + } else { + _, err = volumeServerClient.VolumeMarkReadonly(context.Background(), &volume_server_pb.VolumeMarkReadonlyRequest{ + VolumeId: uint32(volumeId), + }) + } + return err + }) +} |
