sync

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2025 License: Apache-2.0 Imports: 11 Imported by: 1

README

Lock Infrastructure

While working with multi threaded programing, one heavily relies and make use of mutex, to take a lock/ownership ensuring some sort of synchronization construct between the different threads or go routines or concurrent tasks. Which enables taking care of break condition between them ensuring no over stepping between concurrent executors.

While there is nothing standard that exists providing the necessary synchronization between different processes, running on same machine or different. When working with kubernetes applications using microservices based arhitecture, with horizontal scaling capabilities would be running multiple instances of the same application, where each instance with same logic would try to perform same kind of operations based on the events received, which would required a mutex like construct to function across microservices for synchronization between two different processes, possibly running on different nodes of the kubernetes cluster

TODO(Prabhjot) insert a diagram of every process interacting with synchronizer

Solution

As a base construct Database is one of the entity every process or microservice instance interacts with, where Database ensures reliability, consistency as part of its internal processes. While working with databases, it also ensures for every entry written to it won't allow if a conflicting Key already exits in the database, which provides the base fundamental construct needed for enabling mutex functionality across process. Thus Database is a strong candidate that provides the synchronizer contructs.

TODO(Prabhjot) insert a diagram of every process interacting with database as synchronizer

However, one of the basic implicit construct of mutex is being ephermal, so if a process restarts the constructs of mutex is lost and everything will start afresh but this becomes now tricky in case of database based entries as whenever a process dies while holding a mutex or lock, someone needs to ensure sanity of the system by identifying that the lock is held by a process which is no longer active and thus clears it up allowing the continuity of operations

TODO(Prabhjot) add details of the lock owner handling details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeOwner

func InitializeOwner(ctx context.Context, store db.Store, name string) error

Initialize the Sync Owner management constructs, anyone while working with this library requires to use this function before actually start consuming any functionality from here. Also it is callers responsibility to ensure providing uniform store definition for all the consuming processes to ensure synchronisation to work in a seemless manner

func InitializeOwnerTableDefault

func InitializeOwnerTableDefault(ctx context.Context, client db.StoreClient, name string) error

Initialize the Sync Owner management constructs, anyone while working with this library requires to use this function before actually start consuming any functionality from here. This function falls back to using the default database, ensuring common definition for all the consuming processes to ensure synchronisation to work in a seemless manner

func InitializeOwnerWithUpdateInterval

func InitializeOwnerWithUpdateInterval(ctx context.Context, store db.Store, name string, interval time.Duration) error

Initialize the Owner management constructs, anyone while working with this library requires to use this function before actually start consuming any functionality from here. This also allows specifying the interval to ensuring configurability Also it is callers responsibility to ensure providing uniform store definition for all the consuming processes to ensure synchronisation to work in a seemless manner

Types

type Lock

type Lock interface {
	Close() error
}

type LockTable

type LockTable[K any] struct {
	// contains filtered or unexported fields
}

func LocateLockTable

func LocateLockTable[K any](store db.Store, name string) (*LockTable[K], error)

LocateLockTable

func (*LockTable[K]) Callback

func (t *LockTable[K]) Callback(op string, wKey interface{})

func (*LockTable[K]) TryAcquire

func (t *LockTable[K]) TryAcquire(ctx context.Context, key *K) (Lock, error)

type Provider

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

func (*Provider) Close

func (p *Provider) Close() error

type ProviderTable

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

func LocateProviderTable

func LocateProviderTable(store db.Store) (*ProviderTable, error)

Locate Provider table with pre-specified table name while working out of standard provider table

func LocateProviderTableWithName

func LocateProviderTableWithName(store db.Store, name string) (*ProviderTable, error)

Locate Provider table with specific table name meant for consumers want to work out of non standard Provider tables

func (*ProviderTable) Callback

func (t *ProviderTable) Callback(op string, wKey interface{})

Provider Table callback function, currently meant for clearing providers once the owner corresponding to those providers no longer exists eventually we will handle observers also as part of this

func (*ProviderTable) CreateProvider

func (t *ProviderTable) CreateProvider(ctx context.Context, extKey any) (*Provider, error)

create provider based on the specified key, typically a string, Returns Provider handle, allowing to close the provider

func (*ProviderTable) GetProviderList

func (t *ProviderTable) GetProviderList() []any

Get List of Providers

func (*ProviderTable) IsProviderAvailable

func (t *ProviderTable) IsProviderAvailable(key any) bool

Checks if provider exists

func (*ProviderTable) Register

func (t *ProviderTable) Register(name string, crtl reconciler.Controller) error

Allow a reconciler controller to register and get notified for availability and unavailability of providers

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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