Documentation ¶
Index ¶
Constants ¶
const ( // PollInterval is the amount of time to wait between polling the database. PollInterval = time.Second * 10 // DefaultVerifyAttempts is the number of attempts to verify the database, // by opening a new database on verification failure. DefaultVerifyAttempts = 3 )
Variables ¶
This section is empty.
Functions ¶
func Manifold ¶
func Manifold(config ManifoldConfig) dependency.Manifold
Manifold returns a dependency manifold that runs the dbaccessor worker, using the resource names defined in the supplied config.
Types ¶
type Client ¶
type Client interface { // Cluster returns the current state of the Dqlite cluster. Cluster(context.Context) ([]dqlite.NodeInfo, error) // Leader returns information about the current leader, if any. Leader(ctx context.Context) (*dqlite.NodeInfo, error) }
Client describes a client that speaks the Dqlite wire protocol, and can retrieve cluster information.
type Collector ¶
type Collector struct { DBRequests *prometheus.GaugeVec DBDuration *prometheus.HistogramVec TxnRequests *prometheus.CounterVec }
Collector defines a prometheus collector for the dbaccessor.
func NewMetricsCollector ¶
func NewMetricsCollector() *Collector
NewMetricsCollector returns a new Collector.
func (*Collector) Collect ¶
func (c *Collector) Collect(ch chan<- prometheus.Metric)
Collect is part of the prometheus.Collector interface.
func (*Collector) Describe ¶
func (c *Collector) Describe(ch chan<- *prometheus.Desc)
Describe is part of the prometheus.Collector interface.
type DBApp ¶
type DBApp interface { // Open the dqlite database with the given name Open(context.Context, string) (*sql.DB, error) // Ready can be used to wait for a node to complete tasks that // are initiated at startup. For example a new node will attempt // to join the cluster, a restarted node will check if it should // assume some particular role, etc. // // If this method returns without error it means that those initial // tasks have succeeded and follow-up operations like Open() are more // likely to succeed quickly. Ready(context.Context) error // Client returns a client that can be used // to interrogate the Dqlite cluster. Client(ctx context.Context) (Client, error) // Handover transfers all responsibilities for this node (such has // leadership and voting rights) to another node, if one is available. // // This method should always be called before invoking Close(), // in order to gracefully shut down a node. Handover(context.Context) error // ID returns the dqlite ID of this application node. ID() uint64 // Close the application node, releasing all resources it created. Close() error }
DBApp describes methods of a Dqlite database application, required to run this host as a Dqlite node.
type DBGetter ¶
type DBGetter interface { // GetDB returns a sql.DB reference 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(namespace string) (database.TrackedDB, error) }
DBGetter describes the ability to supply a sql.DB reference for a particular database.
type Hub ¶
type Hub interface { Subscribe(topic string, handler interface{}) (func(), error) Publish(topic string, data interface{}) (func(), error) }
Hub defines the methods of the API server central hub that the DB accessor requires.
type Logger ¶
type Logger interface { Errorf(message string, args ...interface{}) Warningf(message string, args ...interface{}) Infof(message string, args ...interface{}) Debugf(message string, args ...interface{}) Tracef(message string, args ...interface{}) // Logf is used to proxy Dqlite logs via this logger. Logf(level loggo.Level, msg string, args ...interface{}) IsTraceEnabled() bool }
Logger represents the logging methods called.
type ManifoldConfig ¶
type ManifoldConfig struct { AgentName string QueryLoggerName string Clock clock.Clock Hub Hub Logger Logger LogDir string PrometheusRegisterer prometheus.Registerer NewApp func(string, ...app.Option) (DBApp, error) NewDBWorker func(context.Context, DBApp, string, ...TrackedDBWorkerOption) (TrackedDB, error) NewNodeManager func(agent.Config, Logger, coredatabase.SlowQueryLogger) NodeManager NewMetricsCollector func() *Collector }
ManifoldConfig contains: - The names of other manifolds on which the DB accessor depends. - Other dependencies from ManifoldsConfig required by the worker.
func (ManifoldConfig) Validate ¶
func (cfg ManifoldConfig) Validate() error
type NodeManager ¶
type NodeManager interface { // IsExistingNode returns true if this machine of container has run a // Dqlite node in the past. IsExistingNode() (bool, error) // IsLoopbackPreferred returns true if the Dqlite application should // be bound to the loopback address. IsLoopbackPreferred() bool // IsLoopbackBound returns true if we are a cluster of one, // and bound to the loopback IP address. IsLoopbackBound(context.Context) (bool, error) // EnsureDataDir ensures that a directory for Dqlite data exists at // a path determined by the agent config, then returns that path. EnsureDataDir() (string, error) // ClusterServers returns the node information for // Dqlite nodes configured to be in the cluster. ClusterServers(context.Context) ([]dqlite.NodeInfo, error) //SetClusterServers reconfigures the Dqlite cluster members. SetClusterServers(context.Context, []dqlite.NodeInfo) error // SetNodeInfo rewrites the local node information // file in the Dqlite data directory. SetNodeInfo(dqlite.NodeInfo) error // SetClusterToLocalNode reconfigures the Dqlite cluster // so that it has the local node as its only member. SetClusterToLocalNode(ctx context.Context) error // WithLogFuncOption returns a Dqlite application Option that will proxy Dqlite // log output via this factory's logger where the level is recognised. WithLogFuncOption() app.Option // WithTracingOption returns a Dqlite application Option // that will enable tracing of Dqlite operations. WithTracingOption() app.Option // WithAddressOption returns a Dqlite application Option // for specifying the local address:port to use. WithAddressOption(string) app.Option // WithTLSOption returns a Dqlite application Option for TLS encryption // of traffic between clients and clustered application nodes. WithTLSOption() (app.Option, error) // WithClusterOption returns a Dqlite application Option for initialising // Dqlite as the member of a cluster with peers representing other controllers. WithClusterOption([]string) app.Option }
NodeManager creates Dqlite `App` initialisation arguments and options.
func CAASNodeManager ¶
func CAASNodeManager(cfg agent.Config, logger Logger, slowQueryLogger coredatabase.SlowQueryLogger) NodeManager
CAASNodeManager returns a NodeManager that is configured to use the loopback address for Dqlite.
func IAASNodeManager ¶
func IAASNodeManager(cfg agent.Config, logger Logger, slowQueryLogger coredatabase.SlowQueryLogger) NodeManager
IAASNodeManager returns a NodeManager that is configured to use the cloud-local TLS terminated address for Dqlite.
type TrackedDB ¶
type TrackedDB interface { coredatabase.TrackedDB worker.Worker }
TrackedDB defines the union of a TrackedDB and a worker.Worker interface. This is local to the package, allowing for better testing of the underlying trackerDB worker.
func NewTrackedDBWorker ¶
func NewTrackedDBWorker(ctx context.Context, dbApp DBApp, namespace string, opts ...TrackedDBWorkerOption) (TrackedDB, error)
NewTrackedDBWorker creates a new TrackedDBWorker
type TrackedDBWorkerOption ¶
type TrackedDBWorkerOption func(*trackedDBWorker)
TrackedDBWorkerOption is a function that configures a TrackedDBWorker.
func WithClock ¶
func WithClock(clock clock.Clock) TrackedDBWorkerOption
WithClock sets the clock used by the worker.
func WithLogger ¶
func WithLogger(logger Logger) TrackedDBWorkerOption
WithLogger sets the logger used by the worker.
func WithMetricsCollector ¶
func WithMetricsCollector(metrics *Collector) TrackedDBWorkerOption
WithMetricsCollector sets the metrics collector used by the worker.
func WithPingDBFunc ¶
WithPingDBFunc sets the function used to verify the database connection.
type WorkerConfig ¶
type WorkerConfig struct { NodeManager NodeManager Clock clock.Clock MetricsCollector *Collector // Hub is the pub/sub central hub used to receive notifications // about API server topology changes. Hub Hub Logger Logger NewApp func(string, ...app.Option) (DBApp, error) NewDBWorker func(context.Context, DBApp, string, ...TrackedDBWorkerOption) (TrackedDB, error) // ControllerID uniquely identifies the controller that this // worker is running on. It is equivalent to the machine ID. ControllerID string }
WorkerConfig encapsulates the configuration options for the dbaccessor worker.
func (*WorkerConfig) Validate ¶
func (c *WorkerConfig) Validate() error
Validate ensures that the config values are valid.