db

package
v4.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDBPollSeconds               = 10
	DefaultDBHeartbeatSeconds          = 60
	DefaultDBInactiveControllerSeconds = 600
)
View Source
const (
	LimitNameField = "name"
	LimitSizeField = "sizelimit"

	StateNameField       = "name"
	StateKeyField        = "workflowkey"
	StateControllerField = "controller"
	StateHeldField       = "held"
	StatePriorityField   = "priority"
	StateTimeField       = "time"

	ControllerNameField = "controller"
	ControllerTimeField = "time"

	LockNameField       = "name"
	LockControllerField = "controller"
)

Field name constants

Variables

This section is empty.

Functions

func DBConfigFromConfig

func DBConfigFromConfig(config *config.SyncConfig) dbConfig

func DBSessionFromConfig

func DBSessionFromConfig(ctx context.Context, kubectlConfig kubernetes.Interface, namespace string, config *config.SyncConfig) db.Session

func DBSessionFromConfigWithCreds

func DBSessionFromConfigWithCreds(config *config.SyncConfig, username, password string) db.Session

func NewSyncQueries

func NewSyncQueries(session db.Session, config dbConfig) *syncQueries

NewSyncQueries creates a new syncQueries instance

func SecondsToDurationWithDefault

func SecondsToDurationWithDefault(value *int, defaultSeconds int) time.Duration

Types

type ControllerHealthRecord

type ControllerHealthRecord struct {
	Controller string    `db:"controller"` // controller where the workflow is running
	Time       time.Time `db:"time"`       // timestamp of creation or last update
}

type DBInfo

type DBInfo struct {
	Config  dbConfig
	Session db.Session
}

func (*DBInfo) Migrate

func (d *DBInfo) Migrate(ctx context.Context)

type LimitRecord

type LimitRecord struct {
	Name      string `db:"name"`
	SizeLimit int    `db:"sizelimit"`
}

Record types for database operations

type LockRecord

type LockRecord struct {
	Name       string    `db:"name"`       // semaphore name identifier
	Controller string    `db:"controller"` // controller where the workflow is running
	Time       time.Time `db:"time"`       // timestamp of creation
}

type StateRecord

type StateRecord struct {
	Name       string    `db:"name"`        // semaphore name identifier
	Key        string    `db:"workflowkey"` // workflow key holding or waiting for the lock of the form <namespace>/<name>
	Controller string    `db:"controller"`  // controller where the workflow is running
	Held       bool      `db:"held"`
	Priority   int32     `db:"priority"` // higher number = higher priority in queue
	Time       time.Time `db:"time"`     // timestamp of creation or last update
}

type SyncQueries

type SyncQueries interface {
	CreateSemaphoreLimit(ctx context.Context, name string, sizeLimit int) error
	UpdateSemaphoreLimit(ctx context.Context, name string, sizeLimit int) error
	DeleteSemaphoreLimit(ctx context.Context, name string) error
	GetSemaphoreLimit(ctx context.Context, dbKey string) (*LimitRecord, error)

	GetCurrentState(ctx context.Context, session db.Session, semaphoreName string, held bool) ([]StateRecord, error)
	GetCurrentHolders(ctx context.Context, session db.Session, semaphoreName string) ([]StateRecord, error)
	GetCurrentPending(ctx context.Context, semaphoreName string) ([]StateRecord, error)
	GetOrderedQueue(ctx context.Context, session db.Session, semaphoreName string, inactiveTimeout time.Duration) ([]StateRecord, error)
	AddToQueue(ctx context.Context, record *StateRecord) error
	RemoveFromQueue(ctx context.Context, semaphoreName, holderKey string) error
	CheckQueueExists(ctx context.Context, semaphoreName, holderKey, controllerName string) ([]StateRecord, error)
	UpdateStateToHeld(ctx context.Context, session db.Session, semaphoreName, holderKey, controllerName string) error
	InsertHeldState(ctx context.Context, session db.Session, record *StateRecord) error
	GetPendingInQueue(ctx context.Context, session db.Session, semaphoreName, holderKey, controllerName string) ([]StateRecord, error)
	ReleaseHeld(ctx context.Context, semaphoreName, key, controllerName string) error

	GetExistingLocks(ctx context.Context, lockName, controllerName string) ([]LockRecord, error)
	InsertLock(ctx context.Context, record *LockRecord) error
	DeleteLock(ctx context.Context, lockName string) error
	ExpireInactiveLocks(ctx context.Context, inactiveTimeout time.Duration) (int64, error)

	InsertControllerHealth(ctx context.Context, record *ControllerHealthRecord) error
	UpdateControllerTimestamp(ctx context.Context, controllerName string, timestamp time.Time) error

	GetPendingInQueueWithSession(ctx context.Context, session db.Session, semaphoreName, holderKey, controllerName string) ([]StateRecord, error)
	UpdateStateToHeldWithSession(ctx context.Context, session db.Session, semaphoreName, holderKey, controllerName string) error
	InsertHeldStateWithSession(ctx context.Context, session db.Session, record *StateRecord) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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