aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-09-19 12:02:23 -0700
committerChris Lu <chris.lu@gmail.com>2021-09-19 12:02:23 -0700
commitad5099e57011e3a7cac8e34436ecf718acf3e5b3 (patch)
tree72ab8f57a5f02b00e6d976561087285a177afd2c
parent5abdc0be7750f51f7eb171ff80e6ec20674f3617 (diff)
downloadseaweedfs-ad5099e57011e3a7cac8e34436ecf718acf3e5b3.tar.xz
seaweedfs-ad5099e57011e3a7cac8e34436ecf718acf3e5b3.zip
refactor
-rw-r--r--weed/shell/commands.go2
-rw-r--r--weed/wdclient/exclusive_locks/exclusive_locker.go12
2 files changed, 8 insertions, 6 deletions
diff --git a/weed/shell/commands.go b/weed/shell/commands.go
index 18f357ac7..6b614c159 100644
--- a/weed/shell/commands.go
+++ b/weed/shell/commands.go
@@ -49,7 +49,7 @@ func NewCommandEnv(options ShellOptions) *CommandEnv {
MasterClient: wdclient.NewMasterClient(options.GrpcDialOption, pb.AdminShellClient, "", "", pb.ServerAddresses(*options.Masters).ToAddresses()),
option: options,
}
- ce.locker = exclusive_locks.NewExclusiveLocker(ce.MasterClient)
+ ce.locker = exclusive_locks.NewExclusiveLocker(ce.MasterClient, "admin")
return ce
}
diff --git a/weed/wdclient/exclusive_locks/exclusive_locker.go b/weed/wdclient/exclusive_locks/exclusive_locker.go
index 0fa138496..2f033f36b 100644
--- a/weed/wdclient/exclusive_locks/exclusive_locker.go
+++ b/weed/wdclient/exclusive_locks/exclusive_locker.go
@@ -14,7 +14,6 @@ const (
RenewInteval = 4 * time.Second
SafeRenewInteval = 3 * time.Second
InitLockInteval = 1 * time.Second
- AdminLockName = "admin"
)
type ExclusiveLocker struct {
@@ -22,13 +21,16 @@ type ExclusiveLocker struct {
lockTsNs int64
isLocking bool
masterClient *wdclient.MasterClient
+ lockName string
}
-func NewExclusiveLocker(masterClient *wdclient.MasterClient) *ExclusiveLocker {
+func NewExclusiveLocker(masterClient *wdclient.MasterClient, lockName string) *ExclusiveLocker {
return &ExclusiveLocker{
masterClient: masterClient,
+ lockName: lockName,
}
}
+
func (l *ExclusiveLocker) IsLocking() bool {
return l.isLocking
}
@@ -55,7 +57,7 @@ func (l *ExclusiveLocker) RequestLock(clientName string) {
resp, err := client.LeaseAdminToken(ctx, &master_pb.LeaseAdminTokenRequest{
PreviousToken: atomic.LoadInt64(&l.token),
PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
- LockName: AdminLockName,
+ LockName: l.lockName,
ClientName: clientName,
})
if err == nil {
@@ -83,7 +85,7 @@ func (l *ExclusiveLocker) RequestLock(clientName string) {
resp, err := client.LeaseAdminToken(ctx2, &master_pb.LeaseAdminTokenRequest{
PreviousToken: atomic.LoadInt64(&l.token),
PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
- LockName: AdminLockName,
+ LockName: l.lockName,
ClientName: clientName,
})
if err == nil {
@@ -114,7 +116,7 @@ func (l *ExclusiveLocker) ReleaseLock() {
client.ReleaseAdminToken(ctx, &master_pb.ReleaseAdminTokenRequest{
PreviousToken: atomic.LoadInt64(&l.token),
PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
- LockName: AdminLockName,
+ LockName: l.lockName,
})
return nil
})