adjust APIs

This commit is contained in:
chrislu 2023-09-15 22:20:05 -07:00
parent 436d99443b
commit 7f685ce7ba
2 changed files with 14 additions and 6 deletions

View file

@ -73,6 +73,7 @@ service SeaweedFiler {
}
rpc Unlock(UnlockRequest) returns (UnlockResponse) {
}
// distributed lock management internal use only
rpc TransferLocks(TransferLocksRequest) returns (TransferLocksResponse) {
}
}

View file

@ -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) {
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()
if servers == nil {
err = NoLockServerError
return
}
server := hashKeyToServer(key, servers)
if server != dlm.Host {
movedTo = server
return
}
renewToken, err = dlm.lockManager.Lock(key, expiredAtNs, token)
movedTo = hashKeyToServer(key, servers)
return
}