lock

package
v1.0.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	BatchDeleteLockByBranchID = `delete from lock_table where xid = ? AND branch_id = ?`
	GetLockDOCount            = "select count(1) as total from lock_table"
)
View Source
const BucketPerTable = 128
View Source
const LOCK_SPLIT = "^^^"

Variables

This section is empty.

Functions

func Init

func Init()

Types

type DataBaseLocker

type DataBaseLocker struct {
	LockStore LockStore
}

func (*DataBaseLocker) AcquireLock

func (locker *DataBaseLocker) AcquireLock(branchSession *session.BranchSession) bool

func (*DataBaseLocker) CleanAllLocks

func (locker *DataBaseLocker) CleanAllLocks()

func (*DataBaseLocker) GetLockKeyCount

func (locker *DataBaseLocker) GetLockKeyCount() int64

func (*DataBaseLocker) IsLockable

func (locker *DataBaseLocker) IsLockable(xid string, resourceID string, lockKey string) bool

func (*DataBaseLocker) ReleaseGlobalSessionLock

func (locker *DataBaseLocker) ReleaseGlobalSessionLock(globalSession *session.GlobalSession) bool

func (*DataBaseLocker) ReleaseLock

func (locker *DataBaseLocker) ReleaseLock(branchSession *session.BranchSession) bool

type LockManager

type LockManager interface {
	// AcquireLock Acquire lock boolean.
	AcquireLock(branchSession *session.BranchSession) bool

	// ReleaseLock Unlock boolean.
	ReleaseLock(branchSession *session.BranchSession) bool

	// GlobalSession 是没有锁的,所有的锁都在 BranchSession 上,因为
	// BranchSession 才持有资源,释放 GlobalSession 锁是指释放它所有
	// 的 BranchSession 上的锁.
	// ReleaseGlobalSessionLock Unlock boolean.
	ReleaseGlobalSessionLock(globalSession *session.GlobalSession) bool

	// IsLockable Is lockable boolean.
	IsLockable(xid string, resourceID string, lockKey string) bool

	// CleanAllLocks Clean all locks.
	CleanAllLocks()

	GetLockKeyCount() int64
}

func GetLockManager

func GetLockManager() LockManager

type LockStore

type LockStore interface {
	AcquireLockByLockDO(lockDO *model.LockDO) bool
	AcquireLock(lockDOs []*model.LockDO) bool
	UnLockByLockDO(lockDO *model.LockDO) bool
	UnLock(lockDOs []*model.LockDO) bool
	UnLockByXIDAndBranchID(xid string, branchID int64) bool
	UnLockByXIDAndBranchIDs(xid string, branchIDs []int64) bool
	IsLockable(lockDOs []*model.LockDO) bool
	GetLockCount() int64
}

type LockStoreDataBaseDao

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

func (*LockStoreDataBaseDao) AcquireLock

func (dao *LockStoreDataBaseDao) AcquireLock(lockDOs []*model.LockDO) bool

func (*LockStoreDataBaseDao) AcquireLockByLockDO

func (dao *LockStoreDataBaseDao) AcquireLockByLockDO(lockDO *model.LockDO) bool

func (*LockStoreDataBaseDao) GetLockCount

func (dao *LockStoreDataBaseDao) GetLockCount() int64

func (*LockStoreDataBaseDao) IsLockable

func (dao *LockStoreDataBaseDao) IsLockable(lockDOs []*model.LockDO) bool

func (*LockStoreDataBaseDao) UnLock

func (dao *LockStoreDataBaseDao) UnLock(lockDOs []*model.LockDO) bool

func (*LockStoreDataBaseDao) UnLockByLockDO

func (dao *LockStoreDataBaseDao) UnLockByLockDO(lockDO *model.LockDO) bool

func (*LockStoreDataBaseDao) UnLockByXIDAndBranchID

func (dao *LockStoreDataBaseDao) UnLockByXIDAndBranchID(xid string, branchID int64) bool

func (*LockStoreDataBaseDao) UnLockByXIDAndBranchIDs

func (dao *LockStoreDataBaseDao) UnLockByXIDAndBranchIDs(xid string, branchIDs []int64) bool

type MemoryLocker

type MemoryLocker struct {
	LockMap *sync.Map
	// 高流量下,锁资源越多,BucketHolder 的性能越下降
	BucketHolder *sync.Map

	LockKeyCount int64
}

func (*MemoryLocker) AcquireLock

func (ml *MemoryLocker) AcquireLock(branchSession *session.BranchSession) bool

func (*MemoryLocker) CleanAllLocks

func (ml *MemoryLocker) CleanAllLocks()

func (*MemoryLocker) GetLockKeyCount

func (ml *MemoryLocker) GetLockKeyCount() int64

func (*MemoryLocker) IsLockable

func (ml *MemoryLocker) IsLockable(xid string, resourceID string, lockKey string) bool

func (*MemoryLocker) ReleaseGlobalSessionLock

func (ml *MemoryLocker) ReleaseGlobalSessionLock(globalSession *session.GlobalSession) bool

func (*MemoryLocker) ReleaseLock

func (ml *MemoryLocker) ReleaseLock(branchSession *session.BranchSession) bool

type RowLock

type RowLock struct {
	XID string

	TransactionID int64

	BranchID int64

	ResourceID string

	TableName string

	Pk string

	RowKey string

	Feature string
}

Jump to

Keyboard shortcuts

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