Documentation ¶
Index ¶
- Constants
- type Accept
- type AcceptOption
- type Bootstrap
- type BootstrapOption
- func WithCertForBootstrap(certInfo *cert.Info) BootstrapOption
- func WithConfigForBootstrap(config NodeConfigProvider) BootstrapOption
- func WithFileSystemForBootstrap(fileSystem fsys.FileSystem) BootstrapOption
- func WithGatewayForBootstrap(gateway Gateway) BootstrapOption
- func WithNodeConfigSchemaForBootstrap(nodeConfigSchema config.Schema) BootstrapOption
- func WithStateForBootstrap(state State) BootstrapOption
- type Cluster
- type ClusterConfigProvider
- type ClusterMember
- type Collapse
- type CollapseOption
- func WithConfigForCollapse(config NodeConfigProvider) CollapseOption
- func WithEndpointsForCollapse(endpoints Endpoints) CollapseOption
- func WithFileSystemForCollapse(fileSystem fsys.FileSystem) CollapseOption
- func WithGatewayForCollapse(gateway Gateway) CollapseOption
- func WithLoggerForCollapse(logger log.Logger) CollapseOption
- func WithNodeConfigSchemaForCollapse(nodeConfigSchema config.Schema) CollapseOption
- func WithStateForCollapse(state State) CollapseOption
- type Count
- type CountOption
- type DialerProvider
- type Enabled
- type EnabledOption
- type Endpoints
- type Gateway
- type Join
- type JoinOption
- func WithConfigForJoin(config NodeConfigProvider) JoinOption
- func WithFileSystemForJoin(fileSystem fsys.FileSystem) JoinOption
- func WithGatewayForJoin(gateway Gateway) JoinOption
- func WithLoggerForJoin(logger log.Logger) JoinOption
- func WithNodeConfigSchemaForJoin(nodeConfigSchema config.Schema) JoinOption
- func WithStateForJoin(state State) JoinOption
- type Leave
- type LeaveOption
- type List
- type ListOption
- type Membership
- type Node
- type NodeConfigProvider
- type OS
- type Promote
- type PromoteOption
- type Purge
- type PurgeOption
- type RaftInstance
- type Rebalance
- type RebalanceOption
- func WithClockForRebalance(clock clock.Clock) RebalanceOption
- func WithConfigForRebalance(config ClusterConfigProvider) RebalanceOption
- func WithGatewayForRebalance(gateway Gateway) RebalanceOption
- func WithLoggerForRebalance(logger log.Logger) RebalanceOption
- func WithSchemaForRebalance(schema config.Schema) RebalanceOption
- func WithStateForRebalance(state State) RebalanceOption
- type Request
- type RequestChanger
- type State
Constants ¶
const ( // StatusOnline represents a node online StatusOnline = "online" // StatusOffline represents a node offline StatusOffline = "offline" // StatusBroken represents a node broken state StatusBroken = "broken" // StatusBlocked represents a node blocked state StatusBlocked = "blocked" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Accept ¶
type Accept struct {
// contains filtered or unexported fields
}
Accept a new node and add it to the cluster.
This instance must already be clustered.
Return an updated list raft database nodes (possibly including the newly accepted node).
type AcceptOption ¶
type AcceptOption func(*acceptOptions)
AcceptOption to be passed to NewAccept to customize the resulting instance.
func WithGatewayForAccept ¶
func WithGatewayForAccept(gateway Gateway) AcceptOption
WithGatewayForAccept sets the gateway on the options
func WithStateForAccept ¶
func WithStateForAccept(state State) AcceptOption
WithStateForAccept sets the state on the options
type Bootstrap ¶
type Bootstrap struct {
// contains filtered or unexported fields
}
Bootstrap turns a non-clustered instance into the first (and leader) node of a new cluster.
This instance must already have its core.https_address set and be listening on the associated network address.
func NewBootstrap ¶
func NewBootstrap( state State, gateway Gateway, certInfo *cert.Info, nodeConfigSchema config.Schema, options ...BootstrapOption, ) *Bootstrap
NewBootstrap creates a Bootstrap with sane defaults.
type BootstrapOption ¶
type BootstrapOption func(*bootstrapOptions)
BootstrapOption to be passed to NewBootstrap to customize the resulting instance.
func WithCertForBootstrap ¶
func WithCertForBootstrap(certInfo *cert.Info) BootstrapOption
WithCertForBootstrap sets the certInfo on the options
func WithConfigForBootstrap ¶
func WithConfigForBootstrap(config NodeConfigProvider) BootstrapOption
WithConfigForBootstrap sets the config on the options
func WithFileSystemForBootstrap ¶
func WithFileSystemForBootstrap(fileSystem fsys.FileSystem) BootstrapOption
WithFileSystemForBootstrap sets the fileSystem on the options
func WithGatewayForBootstrap ¶
func WithGatewayForBootstrap(gateway Gateway) BootstrapOption
WithGatewayForBootstrap sets the gateway on the options
func WithNodeConfigSchemaForBootstrap ¶
func WithNodeConfigSchemaForBootstrap(nodeConfigSchema config.Schema) BootstrapOption
WithNodeConfigSchemaForBootstrap sets the nodeConfigSchema on the options
func WithStateForBootstrap ¶
func WithStateForBootstrap(state State) BootstrapOption
WithStateForBootstrap sets the state on the options
type Cluster ¶
type Cluster interface { db.ClusterOpener db.ClusterTransactioner db.ClusterExclusiveLocker // NodeID sets the the node NodeID associated with this cluster instance. // It's used for backward-compatibility of all db-related APIs that were // written before clustering and don't accept a node NodeID, so in those // cases we automatically use this value as implicit node NodeID. NodeID(int64) // DB returns the underlying db DB() database.DB // SchemaVersion returns the underlying schema version for the cluster SchemaVersion() int // Close the database facade. Close() error }
Cluster mediates access to data stored in the cluster dqlite database.
type ClusterConfigProvider ¶
type ClusterConfigProvider interface { // ConfigLoad loads a new Config object with the current node-local // configuration values fetched from the database. An optional list of // config value triggers can be passed, each config key must have at most // one trigger. ConfigLoad(*db.ClusterTx, config.Schema) (*clusterconfig.Config, error) }
ClusterConfigProvider holds cluster configuration values for a certain instance.
type ClusterMember ¶
type ClusterMember struct { ServerName string URL string Database bool Status string Message string }
ClusterMember represents a node in the cluster.
type Collapse ¶
type Collapse struct {
// contains filtered or unexported fields
}
Collapse turns a clustered instance into a non-clustered instance, by collapsing the cluster.
This instance must already have its core.https_address set and be listening on the associated network address.
func NewCollapse ¶
func NewCollapse( state State, gateway Gateway, endpoints Endpoints, nodeConfigSchema config.Schema, options ...CollapseOption, ) *Collapse
NewCollapse creates a Collapse with sane defaults.
type CollapseOption ¶
type CollapseOption func(*collapseOptions)
CollapseOption to be passed to NewCollapse to customize the resulting instance.
func WithConfigForCollapse ¶
func WithConfigForCollapse(config NodeConfigProvider) CollapseOption
WithConfigForCollapse sets the config on the options
func WithEndpointsForCollapse ¶
func WithEndpointsForCollapse(endpoints Endpoints) CollapseOption
WithEndpointsForCollapse sets the endpoints on the options
func WithFileSystemForCollapse ¶
func WithFileSystemForCollapse(fileSystem fsys.FileSystem) CollapseOption
WithFileSystemForCollapse sets the fileSystem on the options
func WithGatewayForCollapse ¶
func WithGatewayForCollapse(gateway Gateway) CollapseOption
WithGatewayForCollapse sets the gateway on the options
func WithLoggerForCollapse ¶
func WithLoggerForCollapse(logger log.Logger) CollapseOption
WithLoggerForCollapse sets the logger on the options
func WithNodeConfigSchemaForCollapse ¶
func WithNodeConfigSchemaForCollapse(nodeConfigSchema config.Schema) CollapseOption
WithNodeConfigSchemaForCollapse sets the nodeConfigSchema on the options
func WithStateForCollapse ¶
func WithStateForCollapse(state State) CollapseOption
WithStateForCollapse sets the state on the options
type Count ¶
type Count struct {
// contains filtered or unexported fields
}
Count queries the number of nodes in the cluster database.
func NewCount ¶
func NewCount(state State, options ...CountOption) *Count
NewCount creates a Count with sane defaults.
type CountOption ¶
type CountOption func(*countOptions)
CountOption to be passed to NewCount to customize the resulting instance.
func WithStateForCount ¶
func WithStateForCount(state State) CountOption
WithStateForCount sets the state on the options
type DialerProvider ¶
type DialerProvider interface { // Dial creates a rafthttp.Dial function that connects over TLS using the given // cluster (and optionally CA) certificate both as client and remote // certificate. Dial(certInfo *cert.Info) (rafthttp.Dial, error) }
DialerProvider provides a way to create a dialer for a raft cluster
type Enabled ¶
type Enabled struct {
// contains filtered or unexported fields
}
Enabled is a convenience that returns true if clustering is enabled on this node.
func NewEnabled ¶
func NewEnabled(state State, options ...EnabledOption) *Enabled
NewEnabled creates a Enabled with sane defaults.
type EnabledOption ¶
type EnabledOption func(*enabledOptions)
EnabledOption to be passed to NewEnabled to customize the resulting instance.
func WithStateForEnabled ¶
func WithStateForEnabled(state State) EnabledOption
WithStateForEnabled sets the state on the options
type Endpoints ¶
type Endpoints interface { // NetworkCert returns the full TLS certificate information for this // endpoint. NetworkCert() *cert.Info // NetworkUpdateCert updates the cert for the network endpoint, // shutting it down and restarting it. NetworkUpdateCert(*cert.Info) error }
Endpoints are in charge of bringing up and down the HTTP endpoints for serving the RESTful API.
type Gateway ¶
type Gateway interface { // Init the gateway, creating a new raft factory and gRPC server (if this // node is a database node), and a gRPC dialer. Init(*cert.Info) error // Shutdown this gateway, stopping the gRPC server and possibly the raft // factory. Shutdown() error // WaitLeadership will wait for the raft node to become leader. Should only // be used by Bootstrap, since we know that we'll self elect. WaitLeadership() error // RaftNodes returns information about the nodes that a currently // part of the raft cluster, as configured in the raft log. It returns an // error if this node is not the leader. RaftNodes() ([]db.RaftNode, error) // Raft returns the raft instance Raft() RaftInstance // DB returns the the underlying db node DB() Node // IsDatabaseNode returns true if this gateway also run acts a raft database // node. IsDatabaseNode() bool // Cert returns the currently available cert in the gateway Cert() *cert.Info // Reset the gateway, shutting it down and starting against from scratch // using the given certificate. // // This is used when disabling clustering on a node. Reset(cert *cert.Info) error // DialFunc returns a dial function that can be used to connect to one of // the dqlite nodes. DialFunc() dqlite.DialFunc // ServerStore returns a dqlite server store that can be used to lookup the // addresses of known database nodes. ServerStore() querycluster.ServerStore // Context returns a cancellation context to pass to dqlite.NewDriver as // option. // // This context gets cancelled by Gateway.Kill() and at that point any // connection failure won't be retried. Context() context.Context }
Gateway mediates access to the dqlite cluster using a gRPC SQL client, and possibly runs a dqlite replica on this node (if we're configured to do so).
type Join ¶
type Join struct {
// contains filtered or unexported fields
}
Join makes a non-clustered node join an existing cluster.
It's assumed that Accept() was previously called against the target node, which handed the raft server ID.
The cert parameter must contain the keypair/CA material of the cluster being joined.
type JoinOption ¶
type JoinOption func(*joinOptions)
JoinOption to be passed to NewJoin to customize the resulting instance.
func WithConfigForJoin ¶
func WithConfigForJoin(config NodeConfigProvider) JoinOption
WithConfigForJoin sets the config on the options
func WithFileSystemForJoin ¶
func WithFileSystemForJoin(fileSystem fsys.FileSystem) JoinOption
WithFileSystemForJoin sets the fileSystem on the options
func WithGatewayForJoin ¶
func WithGatewayForJoin(gateway Gateway) JoinOption
WithGatewayForJoin sets the gateway on the options
func WithLoggerForJoin ¶
func WithLoggerForJoin(logger log.Logger) JoinOption
WithLoggerForJoin sets the logger on the options
func WithNodeConfigSchemaForJoin ¶
func WithNodeConfigSchemaForJoin(nodeConfigSchema config.Schema) JoinOption
WithNodeConfigSchemaForJoin sets the nodeConfigSchema on the options
func WithStateForJoin ¶
func WithStateForJoin(state State) JoinOption
WithStateForJoin sets the state on the options
type Leave ¶
type Leave struct {
// contains filtered or unexported fields
}
Leave a cluster.
If the force flag is true, the node will leave even if it still has containers and images.
The node will only leave the raft cluster, and won't be removed from the database. That's done by Purge().
Upon success, return the address of the leaving node.
type LeaveOption ¶
type LeaveOption func(*leaveOptions)
LeaveOption to be passed to NewLeave to customize the resulting instance.
func WithDialerProviderForLeave ¶
func WithDialerProviderForLeave(dialerProvider DialerProvider) LeaveOption
WithDialerProviderForLeave sets the dialerProvider on the options
func WithGatewayForLeave ¶
func WithGatewayForLeave(gateway Gateway) LeaveOption
WithGatewayForLeave sets the gateway on the options
func WithLoggerForLeave ¶
func WithLoggerForLeave(logger log.Logger) LeaveOption
WithLoggerForLeave sets the logger on the options
func WithMembershipForLeave ¶
func WithMembershipForLeave(membership Membership) LeaveOption
WithMembershipForLeave sets the membership on the options
func WithStateForLeave ¶
func WithStateForLeave(state State) LeaveOption
WithStateForLeave sets the state on the options
type List ¶
type List struct {
// contains filtered or unexported fields
}
List the nodes of the cluster.
func NewList ¶
func NewList(state State, options ...ListOption) *List
NewList creates a List with sane defaults.
func (*List) Run ¶
func (l *List) Run() ([]ClusterMember, error)
Run executes the promote and returns an error if something goes wrong
type ListOption ¶
type ListOption func(*listOptions)
ListOption to be passed to NewList to customize the resulting instance.
func WithClockForList ¶
func WithClockForList(clock clock.Clock) ListOption
WithClockForList sets the clock on the options
func WithLoggerForList ¶
func WithLoggerForList(logger log.Logger) ListOption
WithLoggerForList sets the logger on the options
func WithStateForList ¶
func WithStateForList(state State) ListOption
WithStateForList sets the state on the options
type Membership ¶
type Membership interface { // Change can be used to join or leave a cluster over HTTP. Change( dial rafthttp.Dial, id raft.ServerID, address, target string, timeout time.Duration) error }
Membership defines an interface for change membership of a cluster
type Node ¶
type Node interface { db.NodeTransactioner }
Node mediates access to the data stored in the node-local SQLite database.
type NodeConfigProvider ¶
type NodeConfigProvider interface { // ConfigLoad loads a new Config object with the current node-local // configuration values fetched from the database. An optional list of // config value triggers can be passed, each config key must have at most // one trigger. ConfigLoad(*db.NodeTx, config.Schema) (*node.Config, error) }
NodeConfigProvider holds node-local configuration values for a certain instance.
type OS ¶
type OS interface { // LocalDatabasePath returns the path of the local database file. LocalDatabasePath() string // GlobalDatabaseDir returns the path of the global database directory. GlobalDatabaseDir() string // GlobalDatabasePath returns the path of the global database SQLite file // managed by dqlite. GlobalDatabasePath() string // VarDir represents the Data directory (e.g. /var/lib/therm/). VarDir() string // Hostname returns the host name reported by the kernel. Hostname() (string, error) // HostNames will generate a list of names for which the certificate will be // valid. // This will include the hostname and ip address HostNames() ([]string, error) // User returns the current user. User() (*user.User, error) }
OS is a high-level facade for accessing all operating-system level functionality that therm uses.
type Promote ¶
type Promote struct {
// contains filtered or unexported fields
}
Promote makes a node which is not a database node, become part of the raft cluster.
func NewPromote ¶
func NewPromote(state State, gateway Gateway, options ...PromoteOption) *Promote
NewPromote creates a Promote with sane defaults.
type PromoteOption ¶
type PromoteOption func(*promoteOptions)
PromoteOption to be passed to NewPromote to customize the resulting instance.
func WithFileSystemForPromote ¶
func WithFileSystemForPromote(fileSystem fsys.FileSystem) PromoteOption
WithFileSystemForPromote sets the fileSystem on the options
func WithGatewayForPromote ¶
func WithGatewayForPromote(gateway Gateway) PromoteOption
WithGatewayForPromote sets the gateway on the options
func WithLoggerForPromote ¶
func WithLoggerForPromote(logger log.Logger) PromoteOption
WithLoggerForPromote sets the logger on the options
func WithStateForPromote ¶
func WithStateForPromote(state State) PromoteOption
WithStateForPromote sets the state on the options
type Purge ¶
type Purge struct {
// contains filtered or unexported fields
}
Purge removes a node entirely from the cluster database.
func NewPurge ¶
func NewPurge(state State, options ...PurgeOption) *Purge
NewPurge creates a Purge with sane defaults.
type PurgeOption ¶
type PurgeOption func(*purgeOptions)
PurgeOption to be passed to NewPurge to customize the resulting instance.
func WithStateForPurge ¶
func WithStateForPurge(state State) PurgeOption
WithStateForPurge sets the state on the options
type RaftInstance ¶
type RaftInstance interface { // MembershipChanger returns the underlying rafthttp.Layer, which can be // used to change the membership of this node in the cluster. MembershipChanger() raftmembership.Changer }
RaftInstance is a specific wrapper around raft.Raft, which also holds a reference to its network transport and dqlite FSM.
type Rebalance ¶
type Rebalance struct {
// contains filtered or unexported fields
}
Rebalance the raft cluster, trying to see if we have a spare online node that we can promote to database node if we are below membershipQuorumRaftNodes.
If there's such spare node, return its address as well as the new list of raft nodes.
func NewRebalance ¶
func NewRebalance(state State, gateway Gateway, schema config.Schema, options ...RebalanceOption) *Rebalance
NewRebalance creates a Rebalance with sane defaults
type RebalanceOption ¶
type RebalanceOption func(*rebalanceOptions)
RebalanceOption to be passed to NewRebalance to customize the resulting instance.
func WithClockForRebalance ¶
func WithClockForRebalance(clock clock.Clock) RebalanceOption
WithClockForRebalance sets the clock on the options
func WithConfigForRebalance ¶
func WithConfigForRebalance(config ClusterConfigProvider) RebalanceOption
WithConfigForRebalance sets the config on the options
func WithGatewayForRebalance ¶
func WithGatewayForRebalance(gateway Gateway) RebalanceOption
WithGatewayForRebalance sets the gateway on the options
func WithLoggerForRebalance ¶
func WithLoggerForRebalance(logger log.Logger) RebalanceOption
WithLoggerForRebalance sets the logger on the options
func WithSchemaForRebalance ¶
func WithSchemaForRebalance(schema config.Schema) RebalanceOption
WithSchemaForRebalance sets the schema on the options
func WithStateForRebalance ¶
func WithStateForRebalance(state State) RebalanceOption
WithStateForRebalance sets the state on the options
type RequestChanger ¶
type RequestChanger struct {
// contains filtered or unexported fields
}
RequestChanger represents a way to propagate requests for changing of a membership with in the underlying raft
func NewRequestChanger ¶
func NewRequestChanger(request Request) RequestChanger
NewRequestChanger creates a new RequestChanger with sane defaults
type State ¶
type State interface { // Node returns the underlying Node Node() Node // Cluster returns the underlying Cluster Cluster() Cluster // OS returns the underlying OS values OS() OS }
State is a gateway to the two main stateful components, the database and the operating system. It's typically used by model entities in order to perform changes.