database

package
v0.0.0-...-d78cc51 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 5 Imported by: 71

Documentation

Index

Constants

View Source
const (
	// ErrChangeStreamDying is used to indicate to *third parties* that the
	// change-stream worker is dying, instead of catacomb.ErrDying, which is
	// unsuitable for propagating inter-worker.
	// This error indicates to consuming workers that their dependency has
	// become unmet and a restart by the dependency engine is imminent.
	ErrChangeStreamDying = errors.ConstError("change-stream worker is dying")

	// ErrEventMultiplexerDying is used to indicate to *third parties* that the
	// event multiplexer worker is dying, instead of catacomb.ErrDying, which
	// is unsuitable for propagating inter-worker.
	// This error indicates to consuming workers that their dependency has
	// become unmet and a restart by the dependency engine is imminent.
	ErrEventMultiplexerDying = errors.ConstError("event multiplexer worker is dying")
)
View Source
const (
	// ControllerNS is the namespace for the controller database.
	ControllerNS = "controller"

	// ErrDBAccessorDying is used to indicate to *third parties* that the
	// db-accessor worker is dying, instead of catacomb.ErrDying, which is
	// unsuitable for propagating inter-worker. This error indicates to
	// consuming workers that their dependency has become unmet and a restart by
	// the dependency engine is imminent.
	ErrDBAccessorDying = errors.ConstError("db-accessor worker is dying")

	// ErrDBReplAccessorDying is used to indicate to *third parties* that the
	// db-repl-accessor worker is dying, instead of catacomb.ErrDying, which is
	// unsuitable for propagating inter-worker. This error indicates to
	// consuming workers that their dependency has become unmet and a restart by
	// the dependency engine is imminent.
	ErrDBReplAccessorDying = errors.ConstError("db-repl-accessor worker is dying")

	// ErrDBDead is used to indicate that the database is dead and should no
	// longer be used.
	ErrDBDead = errors.ConstError("database is dead")

	// ErrDBNotFound is used to indicate that the requested database does not
	// exist.
	ErrDBNotFound = errors.ConstError("database not found")
)

Variables

This section is empty.

Functions

func ShortNamespace

func ShortNamespace(namespace string) string

ShortNamespace returns a short version of the namespace. If the namespace is the controller namespace, then it returns the controller namespace. Otherwise, it returns a short version of the model UUID.

Types

type ClusterDescriber

type ClusterDescriber interface {
	// ClusterDetails returns the node information for
	// Dqlite nodes configured to be in the cluster.
	ClusterDetails(context.Context) ([]ClusterNodeInfo, error)
}

ClusterDescriber describes the ability to get cluster details.

type ClusterNodeInfo

type ClusterNodeInfo struct {
	ID   uint64
	Role NodeRole
}

ClusterNodeInfo describes a dqlite cluster node.

type DBDeleter

type DBDeleter interface {
	// DeleteDB deletes the dqlite-backed database that contains the data for
	// the specified namespace.
	// There are currently a set of limitations on the namespaces that can be
	// deleted:
	//  - It is not possible to delete the controller database.
	//  - It currently doesn't support the actual deletion of the database
	//    just the removal of the worker. Deletion of the database will be
	//    handled once it's supported by dqlite.
	DeleteDB(namespace string) error
}

DBDeleter describes the ability to delete a database.

type DBGetter

type DBGetter interface {
	// GetDB returns a TransactionRunner for the dqlite-backed database
	// that contains the data for the specified namespace.
	// A NotFound error is returned if the worker is unaware of the
	// requested DB.
	GetDB(ctx context.Context, namespace string) (TxnRunner, error)
}

DBGetter describes the ability to supply a transaction runner for a particular database.

type NodeRole

type NodeRole string

NodeRole describes the role of a dqlite node.

const (
	Voter   NodeRole = "voter"
	Standby NodeRole = "standby"
	Spare   NodeRole = "spare"
)

Dqlite node roles.

func (NodeRole) HasVote

func (r NodeRole) HasVote() bool

HasVote returns whether the node role has voting rights.

func (NodeRole) String

func (r NodeRole) String() string

type NoopSlowQueryLogger

type NoopSlowQueryLogger struct{}

NoopSlowQueryLogger is a logger that can be substituted for a SlowQueryLogger when slow query logging is not desired.

func (NoopSlowQueryLogger) RecordSlowQuery

func (NoopSlowQueryLogger) RecordSlowQuery(string, string, []any, float64)

RecordSlowQuery logs the slow query, with the given arguments.

type SlowQueryLogger

type SlowQueryLogger interface {
	// RecordSlowQuery logs the slow query, with the given arguments.
	RecordSlowQuery(msg, stmt string, args []any, duration float64)
}

SlowQueryLogger is a logger that can be used to log slow operations.

type TxnRunner

type TxnRunner interface {
	// Txn manages the application of a SQLair transaction within which the
	// input function is executed. See https://github.com/canonical/sqlair.
	// The input context can be used by the caller to cancel this process.
	Txn(context.Context, func(context.Context, *sqlair.TX) error) error

	// StdTxn manages the application of a standard library transaction within
	// which the input function is executed.
	// The input context can be used by the caller to cancel this process.
	StdTxn(context.Context, func(context.Context, *sql.Tx) error) error

	// Dying returns a channel that is closed when the database connection
	// is no longer usable. This can be used to detect when the database is
	// shutting down or has been closed.
	Dying() <-chan struct{}
}

TxnRunner defines an interface for running transactions against a database.

type TxnRunnerFactory

type TxnRunnerFactory = func(context.Context) (TxnRunner, error)

TxnRunnerFactory aliases a function that returns a database.TxnRunner or an error.

func NewTxnRunnerFactoryForNamespace

func NewTxnRunnerFactoryForNamespace[T TxnRunner](f func(context.Context, string) (T, error), ns string) TxnRunnerFactory

NewTxnRunnerFactoryForNamespace returns a TxnRunnerFactory for the input namespaced factory function and namespace.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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