mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
adjust APIs
This commit is contained in:
parent
436d99443b
commit
7f685ce7ba
|
@ -73,6 +73,7 @@ service SeaweedFiler {
|
||||||
}
|
}
|
||||||
rpc Unlock(UnlockRequest) returns (UnlockResponse) {
|
rpc Unlock(UnlockRequest) returns (UnlockResponse) {
|
||||||
}
|
}
|
||||||
|
// distributed lock management internal use only
|
||||||
rpc TransferLocks(TransferLocksRequest) returns (TransferLocksResponse) {
|
rpc TransferLocks(TransferLocksRequest) returns (TransferLocksResponse) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,18 +29,25 @@ func (dlm *DistributedLockManager) Lock(key string, token string) (renewToken st
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dlm *DistributedLockManager) LockWithTimeout(key string, expiredAtNs int64, token string) (renewToken string, movedTo pb.ServerAddress, err error) {
|
func (dlm *DistributedLockManager) LockWithTimeout(key string, expiredAtNs int64, token string) (renewToken string, movedTo pb.ServerAddress, err error) {
|
||||||
|
movedTo, err = dlm.FindLockOwner(key)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if movedTo != dlm.Host {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
renewToken, err = dlm.lockManager.Lock(key, expiredAtNs, token)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (dlm *DistributedLockManager) FindLockOwner(key string) (movedTo pb.ServerAddress, err error) {
|
||||||
servers := dlm.LockRing.GetSnapshot()
|
servers := dlm.LockRing.GetSnapshot()
|
||||||
if servers == nil {
|
if servers == nil {
|
||||||
err = NoLockServerError
|
err = NoLockServerError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
server := hashKeyToServer(key, servers)
|
movedTo = hashKeyToServer(key, servers)
|
||||||
if server != dlm.Host {
|
|
||||||
movedTo = server
|
|
||||||
return
|
|
||||||
}
|
|
||||||
renewToken, err = dlm.lockManager.Lock(key, expiredAtNs, token)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue