adjust errors

This commit is contained in:
chrislu
2023-06-25 17:37:54 -07:00
parent 06471dac9d
commit 13a8593ab9
2 changed files with 13 additions and 6 deletions

View File

@@ -6,6 +6,8 @@ import (
"time"
)
var NoLockServerError = fmt.Errorf("no lock server found")
type DistributedLockManager struct {
lockManager *LockManager
LockRing *LockRing
@@ -21,7 +23,7 @@ func NewDistributedLockManager() *DistributedLockManager {
func (dlm *DistributedLockManager) Lock(host pb.ServerAddress, key string, expiredAtNs int64, token string) (renewToken string, movedTo pb.ServerAddress, err error) {
servers := dlm.LockRing.GetSnapshot()
if servers == nil {
err = fmt.Errorf("no lock server found")
err = NoLockServerError
return
}
@@ -37,7 +39,7 @@ func (dlm *DistributedLockManager) Lock(host pb.ServerAddress, key string, expir
func (dlm *DistributedLockManager) Unlock(host pb.ServerAddress, key string, token string) (movedTo pb.ServerAddress, err error) {
servers := dlm.LockRing.GetSnapshot()
if servers == nil {
err = fmt.Errorf("no lock server found")
err = NoLockServerError
return
}