Documentation
¶
Index ¶
- Variables
- type CallBackFunc
- type Executor
- type LocalShardStore
- type Lock
- type LockType
- type Locker
- type ManagerConfig
- type ManagerStatus
- type MutexEntry
- type MutexRefreshTask
- type NodeLockManager
- type Priority
- type RefreshPriorityQueue
- func (pq *RefreshPriorityQueue) BatchPop(batchSize int) []*RefreshTask
- func (pq *RefreshPriorityQueue) Clear()
- func (pq *RefreshPriorityQueue) Contains(key string) bool
- func (pq *RefreshPriorityQueue) GetNextRefreshTime() (int64, bool)
- func (pq *RefreshPriorityQueue) Len() int
- func (pq *RefreshPriorityQueue) Peek() (*RefreshTask, bool)
- func (pq *RefreshPriorityQueue) Push(key string, nextRefreshAt int64)
- func (pq *RefreshPriorityQueue) Remove(key string) bool
- type RefreshTask
- type Shard
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrLockExisted = errors.New("lock already exists")
Functions ¶
This section is empty.
Types ¶
type LocalShardStore ¶
type LocalShardStore struct {
// contains filtered or unexported fields
}
LocalShardStore 锁的本地分片存储器
type LockType ¶
type LockType string
LockType 锁的类型
const ( LockTypeExclusive LockType = "exclusive" )
type ManagerConfig ¶
type ManagerConfig struct {
// 锁的前缀
Prefix string
// 管理器节点标识
NodeID string
// 分片的数量
ShardCount int
// 每一个分片下的Worker数量,这个Worker是处理同一批
// 的锁的续约的功能,这里定义的是最多有几个
ShardWorkers int
// 每一个分片下的优先级队列的长度,每一个分片有一个
QueueSize int
// 每一个分片批次续约的锁数量
BatchSize int
// 单节点的最大锁数量
MaxLocks int
// 批次续约的时间间隔,比如每一轮次续约需要间隔(休眠)100毫秒
RefreshInterval time.Duration
}
type ManagerStatus ¶
type ManagerStatus bool
const ( ManagerStatusRunning ManagerStatus = true ManagerStatusStopped ManagerStatus = false )
func (ManagerStatus) Bool ¶
func (ms ManagerStatus) Bool() bool
func (ManagerStatus) String ¶
func (ms ManagerStatus) String() string
type MutexEntry ¶
type MutexEntry struct {
// contains filtered or unexported fields
}
type MutexRefreshTask ¶
type MutexRefreshTask struct {
// contains filtered or unexported fields
}
type NodeLockManager ¶
type NodeLockManager struct {
// contains filtered or unexported fields
}
func NewNodeLockManagerWithClient ¶
func NewNodeLockManagerWithClient(cfg *ManagerConfig, l logger.Logger, client redis.Cmdable) (*NodeLockManager, error)
NewNodeLockManagerWithClient 创建一个锁管理器,基于单机的Redis客户端
func NewNodeLockManagerWithCluster ¶
func NewNodeLockManagerWithCluster(cfg *ManagerConfig, l logger.Logger, client redis.Cmdable) (*NodeLockManager, error)
NewNodeLockManagerWithCluster 创建一个锁管理器,基于Redis集群客户端
func (*NodeLockManager) Acquire ¶
func (lm *NodeLockManager) Acquire(ctx context.Context, resource string, expiration time.Duration, callback CallBackFunc) (Lock, error)
func (*NodeLockManager) Release ¶
func (lm *NodeLockManager) Release(ctx context.Context, key, token string) error
func (*NodeLockManager) Stop ¶
func (lm *NodeLockManager) Stop()
type RefreshPriorityQueue ¶
type RefreshPriorityQueue struct {
// contains filtered or unexported fields
}
RefreshPriorityQueue 基于下次续约时间的优先级队列
func (*RefreshPriorityQueue) BatchPop ¶
func (pq *RefreshPriorityQueue) BatchPop(batchSize int) []*RefreshTask
BatchPop 批量获取到期的任务
func (*RefreshPriorityQueue) Contains ¶
func (pq *RefreshPriorityQueue) Contains(key string) bool
Contains 检查key是否存在
func (*RefreshPriorityQueue) GetNextRefreshTime ¶
func (pq *RefreshPriorityQueue) GetNextRefreshTime() (int64, bool)
GetNextRefreshTime 获取下一个任务的刷新时间
func (*RefreshPriorityQueue) Peek ¶
func (pq *RefreshPriorityQueue) Peek() (*RefreshTask, bool)
Peek 查看最早到期的任务(不移除)
func (*RefreshPriorityQueue) Push ¶
func (pq *RefreshPriorityQueue) Push(key string, nextRefreshAt int64)
Push 添加或更新任务
func (*RefreshPriorityQueue) Remove ¶
func (pq *RefreshPriorityQueue) Remove(key string) bool
Remove 移除指定key的任务
type RefreshTask ¶
type RefreshTask struct {
Key string // 锁的key
NextRefreshAt int64 // 下次续约时间戳(毫秒)
// contains filtered or unexported fields
}
RefreshTask 续约任务
Source Files
¶
Click to show internal directories.
Click to hide internal directories.
