database

package
v0.0.0-...-c325cbb Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BootstrapDqlite

func BootstrapDqlite(
	ctx context.Context,
	mgr bootstrapNodeManager,
	logger Logger,
	ops ...func(db *sql.DB) error,
) error

BootstrapDqlite opens a new database for the controller, and runs the DDL to create its schema.

It accepts an optional list of functions to perform operations on the controller database.

func IsErrConstraintUnique

func IsErrConstraintUnique(err error) bool

IsErrConstraintUnique returns true if the input error was returned by SQLite due to violation of a unique constraint.

func Retry

func Retry(ctx context.Context, fn func() error) error

Retry defines a generic retry function for applying transactions on a given database. It expects that no individual transaction function should take longer than the default timeout.

This should not be used directly, instead the TrackedDB should be used to handle transactions.

func Txn

func Txn(ctx context.Context, db *sql.DB, fn func(context.Context, *sql.Tx) error) error

Txn defines a generic txn function for applying transactions on a given database. It expects that no individual transaction function should take longer than the default timeout. There are no retry semantics for running the function.

This should not be used directly, instead the TrackedDB should be used to handle transactions.

Types

type DBMigration

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

DBMigration is used to apply a series of deltas to a database.

func NewDBMigration

func NewDBMigration(db *sql.DB, logger Logger, deltas ...[]string) *DBMigration

NewDBMigration returns a reference to a new migration that is used to apply the input deltas to the input database. The deltas are applied in the order supplied.

func (*DBMigration) Apply

func (m *DBMigration) Apply() error

Apply executes all deltas against the database inside a transaction.

type Logger

type Logger interface {
	Errorf(string, ...interface{})
	Warningf(string, ...interface{})
	Debugf(string, ...interface{})

	// Logf is used to proxy Dqlite logs via this logger.
	Logf(level loggo.Level, msg string, args ...interface{})
}

Logger describes methods for emitting log output.

type NodeManager

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

NodeManager is responsible for interrogating a single Dqlite node, and emitting configuration for starting its Dqlite `App` based on operational requirements and controller agent config.

func NewNodeManager

func NewNodeManager(cfg agent.Config, isLoopbackPreferred bool, logger Logger, slowQueryLogger coredatabase.SlowQueryLogger) *NodeManager

NewNodeManager returns a new NodeManager reference based on the input agent configuration.

If isLoopbackPreferred is true, we bind Dqlite to 127.0.0.1 and eschew TLS termination. This is useful primarily in unit testing and a temporary workaround for CAAS, which does not yet support enable-ha.

If it is false, we attempt to identify a unique local-cloud address. If we find one, we use it as the bind address. Otherwise, we fall back to the loopback binding.

func (*NodeManager) ClusterServers

func (m *NodeManager) ClusterServers(ctx context.Context) ([]dqlite.NodeInfo, error)

ClusterServers returns the node information for Dqlite nodes configured to be in the cluster.

func (*NodeManager) EnsureDataDir

func (m *NodeManager) EnsureDataDir() (string, error)

EnsureDataDir ensures that a directory for Dqlite data exists at a path determined by the agent config, then returns that path.

func (*NodeManager) IsExistingNode

func (m *NodeManager) IsExistingNode() (bool, error)

IsExistingNode returns true if this machine or container has ever started a Dqlite `App` before. Specifically, this is whether the Dqlite data directory is empty.

func (*NodeManager) IsLoopbackBound

func (m *NodeManager) IsLoopbackBound(ctx context.Context) (bool, error)

IsLoopbackBound returns true if we are a cluster of one, and bound to the loopback IP address.

func (*NodeManager) IsLoopbackPreferred

func (m *NodeManager) IsLoopbackPreferred() bool

IsLoopbackPreferred returns true if we should prefer to bind Dqlite to the loopback IP address. This is currently true for CAAS and unit testing. Once CAAS supports enable-ha we'll have to revisit this.

func (*NodeManager) NodeInfo

func (m *NodeManager) NodeInfo() (dqlite.NodeInfo, error)

NodeInfo reads the local node information file in the Dqlite directory and returns the dqlite.NodeInfo represented by its contents.

func (*NodeManager) SetClusterServers

func (m *NodeManager) SetClusterServers(ctx context.Context, servers []dqlite.NodeInfo) error

SetClusterServers reconfigures the Dqlite cluster by writing the input servers to Dqlite's Raft log and the local node YAML store. This should only be called on a stopped Dqlite node.

func (*NodeManager) SetClusterToLocalNode

func (m *NodeManager) SetClusterToLocalNode(ctx context.Context) error

SetClusterToLocalNode reconfigures the Dqlite cluster so that it has the local node as its only member. This is intended as a disaster recovery utility, and should only be called: 1. At great need. 2. With steadfast guarantees of data integrity.

func (*NodeManager) SetNodeInfo

func (m *NodeManager) SetNodeInfo(server dqlite.NodeInfo) error

SetNodeInfo rewrites the local node information file in the Dqlite data directory, so that it matches the input NodeInfo. This should only be called on a stopped Dqlite node.

func (*NodeManager) WithAddressOption

func (m *NodeManager) WithAddressOption(ip string) app.Option

WithAddressOption returns a Dqlite application Option for specifying the local address:port to use.

func (*NodeManager) WithClusterOption

func (m *NodeManager) WithClusterOption(addrs []string) app.Option

WithClusterOption returns a Dqlite application Option for initialising Dqlite as the member of a cluster with peers representing other controllers.

func (*NodeManager) WithLogFuncOption

func (m *NodeManager) WithLogFuncOption() app.Option

WithLogFuncOption returns a Dqlite application Option that will proxy Dqlite log output via this factory's logger where the level is recognised.

func (*NodeManager) WithLoopbackAddressOption

func (m *NodeManager) WithLoopbackAddressOption() app.Option

WithLoopbackAddressOption returns a Dqlite application Option that will bind Dqlite to the loopback IP.

func (*NodeManager) WithPreferredCloudLocalAddressOption

func (m *NodeManager) WithPreferredCloudLocalAddressOption(source corenetwork.ConfigSource) (app.Option, error)

WithPreferredCloudLocalAddressOption uses the input network config source to return a local-cloud address to which to bind Dqlite, provided that a unique one can be determined. If there are zero or multiple local-cloud addresses detected on the host, we fall back to binding to the loopback address. This method is only relevant to bootstrap. At all other times (such as when joining a cluster) the bind address is determined externally and passed as the argument to WithAddressOption.

func (*NodeManager) WithTLSOption

func (m *NodeManager) WithTLSOption() (app.Option, error)

WithTLSOption returns a Dqlite application Option for TLS encryption of traffic between clients and clustered application nodes.

func (*NodeManager) WithTracingOption

func (m *NodeManager) WithTracingOption() app.Option

WithTracingOption returns a Dqlite application Option that will enable tracing of Dqlite queries.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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