2020-04-23 10:11:07 +00:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2020-04-23 10:11:07 +00:00
|
|
|
"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 alread another lock.
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandLock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
|
2021-04-23 06:56:35 +00:00
|
|
|
commandEnv.locker.RequestLock(util.DetectedHostAddress())
|
2020-04-23 10:11:07 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|