sync

package
v0.0.0-...-9b598c7 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DistributedLock

type DistributedLock interface {
	Lock() error
	Unlock() error
	// contains filtered or unexported methods
}

DistributedLock manages locks on the database through the usage of the `distributed_lock` table. It works similarly to a sync.Mutex, allowing for locking and unlocking. The lock is acquired by executing an "INSERT INTO ... ON CONFLICT DO NOTHING" command on the database. WARNING: a lock can only be released by the instance that initially created it.

func NewDistributedLock

func NewDistributedLock(db *gorm.DB, lockID string) DistributedLock

NewDistributedLock returns a new instance of DistributedLock db - the connection to the database lockID - the ID of the lock. When multiple threads request to use the Lock function with the same lock ID, only the first thread is granted access while the remaining threads must wait until the lock is released before proceeding.

type DistributedLockMgr

type DistributedLockMgr interface {
	// The Lock function is designed to activate the lock identified by the given ID.
	// If the lock is already activated, this method will block until the lock is available
	Lock(lockID string) error
	// The Unlock function is used to release the lock associated with the given ID. Once the lock is released,
	// it will be removed from the list of managed locks.
	Unlock(lockID string) error
}

DistributedLockMgr manages a list of DistributedLock objects. The DistributedLock object is automatically removed from the list when the Unlock method is called.

func NewDistributedLockMgr

func NewDistributedLockMgr(db *gorm.DB) DistributedLockMgr

Jump to

Keyboard shortcuts

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