lock_manager

package
v0.0.0-...-45e1a9a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

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 Lock

type Lock struct {
	Token       string
	ExpiredAtNs int64
	Key         string // only used for moving locks
	Owner       string
}

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) Lock

func (lm *LockManager) Lock(path string, expiredAtNs int64, token string, owner string) (lockOwner, renewToken string, err error)

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

func (*LockManager) Unlock

func (lm *LockManager) Unlock(path string, token string) (isUnlocked bool, err error)

type LockRing

type LockRing struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewLockRing

func NewLockRing(snapshotInterval time.Duration) *LockRing

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL