distlock

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: BSD-3-Clause Imports: 7 Imported by: 5

Documentation

Index

Constants

View Source
const TRY_INTERVAL time.Duration = 10 * time.Millisecond

Variables

View Source
var LockFailed = errors.New("Lock failed")

Functions

This section is empty.

Types

type DistLock

type DistLock interface {
	// Keep renew a lock held already for another {expire} time
	Keep(target interface{})
	// Lock try to lock the specified resource in {wait} time or return a LockFailed error
	Lock(target interface{}, wait time.Duration) error
	TryLock(target interface{}) bool
	// UnLock releases the lock of specified resource id and return true for success
	UnLock(target interface{}) bool
	Close()
}

func NewMutex

func NewMutex(namespace string, expire time.Duration, store Store) DistLock

NewMutex returns a non-reentry distributed lock

namespace is used to separate different projects
expire indicates the expiration of an active lock and it will be removed if no {Keep} and {Unlock} was invoked during this.
store decides which storage it uses

func NewReentry

func NewReentry(namespace string, expire time.Duration, store Store) DistLock

NewMutex returns a reentry distributed lock

namespace is used to separate different projects
expire indicates the expiration of an active lock and it will be removed if no {Keep} and {Unlock} was invoked during this.
store decides which storage it uses

type DistLockImpl

type DistLockImpl struct {
	// contains filtered or unexported fields
}

func (*DistLockImpl) Close

func (l *DistLockImpl) Close()

func (*DistLockImpl) Keep

func (l *DistLockImpl) Keep(target interface{})

func (*DistLockImpl) Lock

func (l *DistLockImpl) Lock(target interface{}, wait time.Duration) error

func (*DistLockImpl) TryLock

func (l *DistLockImpl) TryLock(target interface{}) bool

func (*DistLockImpl) UnLock

func (l *DistLockImpl) UnLock(target interface{}) bool

type LockKey

type LockKey struct {
	Namespace, Key string
}

func (*LockKey) String

func (lk *LockKey) String() string

type Store

type Store interface {
	// Keep ensures the lock data in storage won't disappear during the period and update the content
	Keep(lockKey *LockKey, val string, expire time.Duration)
	// Exists return the existence of specified key
	Exists(lockKey *LockKey) bool
	Get(lockKey *LockKey) string
	SetIfAbsent(lockKey *LockKey, val string, expire time.Duration) bool
	Set(lockKey *LockKey, val string, expire time.Duration)
	Delete(lockKey *LockKey)
	Close()
}

Directories

Path Synopsis
database module
etcdv2 module
etcdv3 module
redis module
zookeeper module

Jump to

Keyboard shortcuts

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