1
0
mirror of https://github.com/seaweedfs/seaweedfs.git synced 2024-12-24 17:47:57 +08:00
seaweedfs/weed/shell/command_volume_mark.go

62 lines
1.6 KiB
Go
Raw Normal View History

2020-10-29 01:47:09 +08:00
package shell
import (
"flag"
2020-10-29 02:17:03 +08:00
"fmt"
2020-10-29 01:47:09 +08:00
"io"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
2020-10-29 01:47:09 +08:00
)
func init() {
Commands = append(Commands, &commandVolumeMark{})
}
type commandVolumeMark struct {
}
func (c *commandVolumeMark) Name() string {
return "volume.mark"
}
func (c *commandVolumeMark) Help() string {
2020-10-29 02:17:03 +08:00
return `Mark volume writable or readonly from one volume server
2020-10-29 01:47:09 +08:00
2020-10-29 02:17:03 +08:00
volume.mark -node <volume server host:port> -volumeId <volume id> -writable or -readonly
2020-10-29 01:47:09 +08:00
`
}
2024-09-30 01:38:22 +08:00
func (c *commandVolumeMark) HasTag(CommandTag) bool {
return false
}
2020-10-29 01:47:09 +08:00
func (c *commandVolumeMark) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
volMarkCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
volumeIdInt := volMarkCommand.Int("volumeId", 0, "the volume id")
nodeStr := volMarkCommand.String("node", "", "the volume server <host>:<port>")
2020-10-29 02:17:03 +08:00
writable := volMarkCommand.Bool("writable", false, "volume mark writable")
readonly := volMarkCommand.Bool("readonly", false, "volume mark readonly")
2020-10-29 01:47:09 +08:00
if err = volMarkCommand.Parse(args); err != nil {
return nil
}
2020-10-29 02:17:03 +08:00
markWritable := false
if (*writable && *readonly) || (!*writable && !*readonly) {
return fmt.Errorf("use -readonly or -writable")
} else if *writable {
markWritable = true
}
2020-10-29 01:47:09 +08:00
2021-12-11 05:24:38 +08:00
if err = commandEnv.confirmIsLocked(args); err != nil {
return
}
sourceVolumeServer := pb.ServerAddress(*nodeStr)
2020-10-29 01:47:09 +08:00
volumeId := needle.VolumeId(*volumeIdInt)
return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, markWritable, true)
2020-10-29 01:47:09 +08:00
}