mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
refactor
This commit is contained in:
parent
5abdc0be77
commit
ad5099e570
|
@ -49,7 +49,7 @@ func NewCommandEnv(options ShellOptions) *CommandEnv {
|
||||||
MasterClient: wdclient.NewMasterClient(options.GrpcDialOption, pb.AdminShellClient, "", "", pb.ServerAddresses(*options.Masters).ToAddresses()),
|
MasterClient: wdclient.NewMasterClient(options.GrpcDialOption, pb.AdminShellClient, "", "", pb.ServerAddresses(*options.Masters).ToAddresses()),
|
||||||
option: options,
|
option: options,
|
||||||
}
|
}
|
||||||
ce.locker = exclusive_locks.NewExclusiveLocker(ce.MasterClient)
|
ce.locker = exclusive_locks.NewExclusiveLocker(ce.MasterClient, "admin")
|
||||||
return ce
|
return ce
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@ const (
|
||||||
RenewInteval = 4 * time.Second
|
RenewInteval = 4 * time.Second
|
||||||
SafeRenewInteval = 3 * time.Second
|
SafeRenewInteval = 3 * time.Second
|
||||||
InitLockInteval = 1 * time.Second
|
InitLockInteval = 1 * time.Second
|
||||||
AdminLockName = "admin"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ExclusiveLocker struct {
|
type ExclusiveLocker struct {
|
||||||
|
@ -22,13 +21,16 @@ type ExclusiveLocker struct {
|
||||||
lockTsNs int64
|
lockTsNs int64
|
||||||
isLocking bool
|
isLocking bool
|
||||||
masterClient *wdclient.MasterClient
|
masterClient *wdclient.MasterClient
|
||||||
|
lockName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewExclusiveLocker(masterClient *wdclient.MasterClient) *ExclusiveLocker {
|
func NewExclusiveLocker(masterClient *wdclient.MasterClient, lockName string) *ExclusiveLocker {
|
||||||
return &ExclusiveLocker{
|
return &ExclusiveLocker{
|
||||||
masterClient: masterClient,
|
masterClient: masterClient,
|
||||||
|
lockName: lockName,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ExclusiveLocker) IsLocking() bool {
|
func (l *ExclusiveLocker) IsLocking() bool {
|
||||||
return l.isLocking
|
return l.isLocking
|
||||||
}
|
}
|
||||||
|
@ -55,7 +57,7 @@ func (l *ExclusiveLocker) RequestLock(clientName string) {
|
||||||
resp, err := client.LeaseAdminToken(ctx, &master_pb.LeaseAdminTokenRequest{
|
resp, err := client.LeaseAdminToken(ctx, &master_pb.LeaseAdminTokenRequest{
|
||||||
PreviousToken: atomic.LoadInt64(&l.token),
|
PreviousToken: atomic.LoadInt64(&l.token),
|
||||||
PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
|
PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
|
||||||
LockName: AdminLockName,
|
LockName: l.lockName,
|
||||||
ClientName: clientName,
|
ClientName: clientName,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -83,7 +85,7 @@ func (l *ExclusiveLocker) RequestLock(clientName string) {
|
||||||
resp, err := client.LeaseAdminToken(ctx2, &master_pb.LeaseAdminTokenRequest{
|
resp, err := client.LeaseAdminToken(ctx2, &master_pb.LeaseAdminTokenRequest{
|
||||||
PreviousToken: atomic.LoadInt64(&l.token),
|
PreviousToken: atomic.LoadInt64(&l.token),
|
||||||
PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
|
PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
|
||||||
LockName: AdminLockName,
|
LockName: l.lockName,
|
||||||
ClientName: clientName,
|
ClientName: clientName,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -114,7 +116,7 @@ func (l *ExclusiveLocker) ReleaseLock() {
|
||||||
client.ReleaseAdminToken(ctx, &master_pb.ReleaseAdminTokenRequest{
|
client.ReleaseAdminToken(ctx, &master_pb.ReleaseAdminTokenRequest{
|
||||||
PreviousToken: atomic.LoadInt64(&l.token),
|
PreviousToken: atomic.LoadInt64(&l.token),
|
||||||
PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
|
PreviousLockTime: atomic.LoadInt64(&l.lockTsNs),
|
||||||
LockName: AdminLockName,
|
LockName: l.lockName,
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue