lock

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QueryLockDO               = "select row_key, xid, transaction_id, branch_id, resource_id, table_name, pk, gmt_create, gmt_modified from lock_table"
	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 {
	// Acquire lock boolean.
	AcquireLock(branchSession *session.BranchSession) bool

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

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

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

	// 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