Browse Source

adjust APIs

pull/4855/head
chrislu 1 year ago
parent
commit
7f685ce7ba
  1. 1
      other/java/client/src/main/proto/filer.proto
  2. 19
      weed/cluster/lock_manager/distributed_lock_manager.go

1
other/java/client/src/main/proto/filer.proto

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

19
weed/cluster/lock_manager/distributed_lock_manager.go

@ -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
}

Loading…
Cancel
Save