Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

shell: add lock/unlock command

Chris Lu69f336e59f6e
diff --git a/weed/shell/command_fs_lock_unlock.go b/weed/shell/command_fs_lock_unlock.go
new file mode 100644
index 0000000000..a173d6c851
--- /dev/null
+++ b/weed/shell/command_fs_lock_unlock.go
@@ -0,0 +1,55 @@
+package shell
+
+import (
+ "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) {
+
+ commandEnv.locker.RequestLock()
+
+ 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
+}
+
diff --git a/weed/shell/exclusive_locker.go b/weed/shell/exclusive_locker.go
index 9485b255c2..38f5caace2 100644
--- a/weed/shell/exclusive_locker.go
+++ b/weed/shell/exclusive_locker.go
@@ -36,7 +36,7 @@ func (l *ExclusiveLocker) GetToken() (token int64, lockTsNs int64) {
return atomic.LoadInt64(&l.token), atomic.LoadInt64(&l.lockTsNs)
}
-func (l *ExclusiveLocker) Lock() {
+func (l *ExclusiveLocker) RequestLock() {
// retry to get the lease
for {
if err := l.masterClient.WithClient(func(client master_pb.SeaweedClient) error {
@@ -69,6 +69,7 @@ func (l *ExclusiveLocker) Lock() {
if err == nil {
atomic.StoreInt64(&l.token, resp.Token)
atomic.StoreInt64(&l.lockTsNs, resp.LockTsNs)
+ // println("ts", l.lockTsNs, "token", l.token)
}
return err
}); err != nil {
@@ -83,7 +84,7 @@ func (l *ExclusiveLocker) Lock() {
}
-func (l *ExclusiveLocker) Unlock() {
+func (l *ExclusiveLocker) ReleaseLock() {
l.isLocking = false
l.masterClient.WithClient(func(client master_pb.SeaweedClient) error {
client.ReleaseAdminToken(context.Background(), &master_pb.ReleaseAdminTokenRequest{