seaweedfs/weed/shell/command_volume_mark.go

56 lines
1.4 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/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 {
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
`
}
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>")
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
sourceVolumeServer := *nodeStr
volumeId := needle.VolumeId(*volumeIdInt)
2020-10-29 02:17:03 +08:00
return markVolumeWritable(commandEnv.option.GrpcDialOption, volumeId, sourceVolumeServer, markWritable)
2020-10-29 01:47:09 +08:00
}