command_lock_unlock.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package shell
  2. import (
  3. "github.com/seaweedfs/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 already another lock.
  19. `
  20. }
  21. func (c *commandLock) HasTag(CommandTag) bool {
  22. return false
  23. }
  24. func (c *commandLock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  25. commandEnv.locker.RequestLock(util.DetectedHostAddress())
  26. return nil
  27. }
  28. // =========== Unlock ==============
  29. type commandUnlock struct {
  30. }
  31. func (c *commandUnlock) Name() string {
  32. return "unlock"
  33. }
  34. func (c *commandUnlock) Help() string {
  35. return `unlock the cluster-wide lock
  36. `
  37. }
  38. func (c *commandUnlock) HasTag(CommandTag) bool {
  39. return false
  40. }
  41. func (c *commandUnlock) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  42. commandEnv.locker.ReleaseLock()
  43. return nil
  44. }