command_lock_unlock.go 1002 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package shell
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/util"
  4. "io"
  5. )
  6. func init() {
  7. Commands = append(Commands, &commandUnlock{})
  8. Commands = append(Commands, &commandLock{})
  9. }
  10. // =========== Lock ==============
  11. type commandLock struct {
  12. }
  13. func (c *commandLock) Name() string {
  14. return "lock"
  15. }
  16. func (c *commandLock) Help() string {
  17. return `lock in order to exclusively manage the cluster
  18. This is a blocking operation if there is alread another lock.
  19. `
  20. }
  21. func (c *commandLock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  22. commandEnv.locker.RequestLock(util.DetectedHostAddress())
  23. return nil
  24. }
  25. // =========== Unlock ==============
  26. type commandUnlock struct {
  27. }
  28. func (c *commandUnlock) Name() string {
  29. return "unlock"
  30. }
  31. func (c *commandUnlock) Help() string {
  32. return `unlock the cluster-wide lock
  33. `
  34. }
  35. func (c *commandUnlock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  36. commandEnv.locker.ReleaseLock()
  37. return nil
  38. }