Documentation ¶
Index ¶
- Constants
- Variables
- type DistributedLockManager
- func (dlm *DistributedLockManager) CalculateTargetServer(key string, servers []pb.ServerAddress) pb.ServerAddress
- func (dlm *DistributedLockManager) FindLockOwner(key string) (owner string, movedTo pb.ServerAddress, err error)
- func (dlm *DistributedLockManager) InsertLock(key string, expiredAtNs int64, token string, owner string)
- func (dlm *DistributedLockManager) IsLocal(key string) bool
- func (dlm *DistributedLockManager) LockWithTimeout(key string, expiredAtNs int64, token string, owner string) (lockOwner string, renewToken string, movedTo pb.ServerAddress, err error)
- func (dlm *DistributedLockManager) SelectNotOwnedLocks(servers []pb.ServerAddress) (locks []*Lock)
- func (dlm *DistributedLockManager) Unlock(key string, token string) (movedTo pb.ServerAddress, err error)
- type Lock
- type LockManager
- func (lm *LockManager) CleanUp()
- func (lm *LockManager) GetLockOwner(key string) (owner string, err error)
- func (lm *LockManager) InsertLock(path string, expiredAtNs int64, token string, owner string)
- func (lm *LockManager) Lock(path string, expiredAtNs int64, token string, owner string) (lockOwner, renewToken string, err error)
- func (lm *LockManager) SelectLocks(selectFn func(key string) bool) (locks []*Lock)
- func (lm *LockManager) Unlock(path string, token string) (isUnlocked bool, err error)
- type LockRing
- func (r *LockRing) AddServer(server pb.ServerAddress)
- func (r *LockRing) GetSnapshot() (servers []pb.ServerAddress)
- func (r *LockRing) RemoveServer(server pb.ServerAddress)
- func (r *LockRing) SetSnapshot(servers []pb.ServerAddress)
- func (r *LockRing) SetTakeSnapshotCallback(onTakeSnapshot func(snapshot []pb.ServerAddress))
- type LockRingSnapshot
Constants ¶
View Source
const LiveLockTTL = time.Second * 7
View Source
const RenewInterval = time.Second * 3
Variables ¶
View Source
var LockErrorNonEmptyTokenOnExpiredLock = fmt.Errorf("lock: non-empty token on an expired lock")
View Source
var LockErrorNonEmptyTokenOnNewLock = fmt.Errorf("lock: non-empty token on a new lock")
View Source
var LockErrorTokenMismatch = fmt.Errorf("lock: token mismatch")
View Source
var LockNotFound = fmt.Errorf("lock not found")
View Source
var NoLockServerError = fmt.Errorf("no lock server found")
View Source
var UnlockErrorTokenMismatch = fmt.Errorf("unlock: token mismatch")
Functions ¶
This section is empty.
Types ¶
type DistributedLockManager ¶
type DistributedLockManager struct { LockRing *LockRing Host pb.ServerAddress // contains filtered or unexported fields }
func NewDistributedLockManager ¶
func NewDistributedLockManager(host pb.ServerAddress) *DistributedLockManager
func (*DistributedLockManager) CalculateTargetServer ¶
func (dlm *DistributedLockManager) CalculateTargetServer(key string, servers []pb.ServerAddress) pb.ServerAddress
func (*DistributedLockManager) FindLockOwner ¶
func (dlm *DistributedLockManager) FindLockOwner(key string) (owner string, movedTo pb.ServerAddress, err error)
func (*DistributedLockManager) InsertLock ¶
func (dlm *DistributedLockManager) InsertLock(key string, expiredAtNs int64, token string, owner string)
InsertLock is used to insert a lock to a server unconditionally It is used when a server is down and the lock is moved to another server
func (*DistributedLockManager) IsLocal ¶
func (dlm *DistributedLockManager) IsLocal(key string) bool
func (*DistributedLockManager) LockWithTimeout ¶
func (dlm *DistributedLockManager) LockWithTimeout(key string, expiredAtNs int64, token string, owner string) (lockOwner string, renewToken string, movedTo pb.ServerAddress, err error)
func (*DistributedLockManager) SelectNotOwnedLocks ¶
func (dlm *DistributedLockManager) SelectNotOwnedLocks(servers []pb.ServerAddress) (locks []*Lock)
func (*DistributedLockManager) Unlock ¶
func (dlm *DistributedLockManager) Unlock(key string, token string) (movedTo pb.ServerAddress, err error)
type LockManager ¶
type LockManager struct {
// contains filtered or unexported fields
}
LockManager local lock manager, used by distributed lock manager
func NewLockManager ¶
func NewLockManager() *LockManager
func (*LockManager) CleanUp ¶
func (lm *LockManager) CleanUp()
func (*LockManager) GetLockOwner ¶
func (lm *LockManager) GetLockOwner(key string) (owner string, err error)
func (*LockManager) InsertLock ¶
func (lm *LockManager) InsertLock(path string, expiredAtNs int64, token string, owner string)
InsertLock inserts a lock unconditionally
func (*LockManager) SelectLocks ¶
func (lm *LockManager) SelectLocks(selectFn func(key string) bool) (locks []*Lock)
SelectLocks takes out locks by key if keyFn return true, the lock will be taken out
type LockRing ¶
func NewLockRing ¶
func (*LockRing) AddServer ¶
func (r *LockRing) AddServer(server pb.ServerAddress)
AddServer adds a server to the ring if the previous snapshot passed the snapshot interval, create a new snapshot
func (*LockRing) GetSnapshot ¶
func (r *LockRing) GetSnapshot() (servers []pb.ServerAddress)
func (*LockRing) RemoveServer ¶
func (r *LockRing) RemoveServer(server pb.ServerAddress)
func (*LockRing) SetSnapshot ¶
func (r *LockRing) SetSnapshot(servers []pb.ServerAddress)
func (*LockRing) SetTakeSnapshotCallback ¶
func (r *LockRing) SetTakeSnapshotCallback(onTakeSnapshot func(snapshot []pb.ServerAddress))
type LockRingSnapshot ¶
type LockRingSnapshot struct {
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.