1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-05-04 10:31:06 +02:00
seaweedfs/weed/shell/command_lock_unlock.go
Ryan Russell 824f7ad9e1
refactor(shell): readability improvements (#3704)
Signed-off-by: Ryan Russell <git@ryanrussell.org>

Signed-off-by: Ryan Russell <git@ryanrussell.org>
2022-09-16 02:43:49 -07:00

56 lines
1,003 B
Go

package shell
import (
"github.com/seaweedfs/seaweedfs/weed/util"
"io"
)
func init() {
Commands = append(Commands, &commandUnlock{})
Commands = append(Commands, &commandLock{})
}
// =========== Lock ==============
type commandLock struct {
}
func (c *commandLock) Name() string {
return "lock"
}
func (c *commandLock) Help() string {
return `lock in order to exclusively manage the cluster
This is a blocking operation if there is already another lock.
`
}
func (c *commandLock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
commandEnv.locker.RequestLock(util.DetectedHostAddress())
return nil
}
// =========== Unlock ==============
type commandUnlock struct {
}
func (c *commandUnlock) Name() string {
return "unlock"
}
func (c *commandUnlock) Help() string {
return `unlock the cluster-wide lock
`
}
func (c *commandUnlock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
commandEnv.locker.ReleaseLock()
return nil
}