2020-04-23 18:11:07 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/util"
|
2020-04-23 18:11:07 +08: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
|
|
|
|
|
2022-09-16 17:43:49 +08:00
|
|
|
This is a blocking operation if there is already another lock.
|
2020-04-23 18:11:07 +08:00
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2024-09-30 01:38:22 +08:00
|
|
|
func (c *commandLock) HasTag(CommandTag) bool {
|
2024-09-29 11:22:57 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-04-23 18:11:07 +08:00
|
|
|
func (c *commandLock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
|
2021-04-23 14:56:35 +08:00
|
|
|
commandEnv.locker.RequestLock(util.DetectedHostAddress())
|
2020-04-23 18:11:07 +08: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
|
|
|
|
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2024-09-30 01:38:22 +08:00
|
|
|
func (c *commandUnlock) HasTag(CommandTag) bool {
|
2024-09-29 11:22:57 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-04-23 18:11:07 +08:00
|
|
|
func (c *commandUnlock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
|
|
|
|
|
|
|
commandEnv.locker.ReleaseLock()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|