Documentation ¶
Index ¶
- func Count(state state.State) (int, error)
- func DqliteLog(logger log.Logger) func(dqlite.LogLevel, string, ...interface{})
- func Enabled(node Node) (bool, error)
- type DqliteProxyFn
- type Gateway
- func (g *Gateway) Cert() *cert.Info
- func (g *Gateway) Clustered() bool
- func (g *Gateway) Context() context.Context
- func (g *Gateway) DB() Node
- func (g *Gateway) DialFunc() dqlite.DialFunc
- func (g *Gateway) HandlerFuncs() map[string]http.HandlerFunc
- func (g *Gateway) Init(cert *cert.Info) error
- func (g *Gateway) IsDatabaseNode() bool
- func (g *Gateway) Kill()
- func (g *Gateway) LeaderAddress() (string, error)
- func (g *Gateway) Raft() RaftInstance
- func (g *Gateway) RaftNodes() ([]db.RaftNode, error)
- func (g *Gateway) Reset(cert *cert.Info) error
- func (g *Gateway) ServerStore() cluster.ServerStore
- func (g *Gateway) Shutdown() error
- func (g *Gateway) Sync()
- func (g *Gateway) WaitLeadership() error
- func (g *Gateway) WaitUpgradeNotification()
- type Net
- type Node
- type Option
- func WithCert(cert *cert.Info) Option
- func WithFileSystem(fileSystem fsys.FileSystem) Option
- func WithLatency(latency float64) Option
- func WithLogger(logger log.Logger) Option
- func WithNet(netProvider Net) Option
- func WithNode(database Node) Option
- func WithNodeConfigSchema(nodeConfigSchema config.Schema) Option
- func WithRaftProvider(raftProvider RaftProvider) Option
- func WithServerProvider(serverProvider ServerProvider) Option
- func WithSleeper(sleeper clock.Sleeper) Option
- func WithStoreProvider(storeProvider StoreProvider) Option
- type RaftInstance
- type RaftProvider
- type Server
- type ServerProvider
- type ServerStore
- type StoreProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DqliteProxyFn ¶
DqliteProxyFn is an alias for the type returned by a DqliteProxy
func DqliteProxy ¶
func DqliteProxy(logger log.Logger, provider Net) DqliteProxyFn
DqliteProxy creates a proxy between a provider and a listener. It copies information from a destination and a source, before closing both sides.
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
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).
func NewGateway ¶
func NewGateway(database Node, nodeConfigSchema config.Schema, fileSystem fsys.FileSystem, options ...Option) *Gateway
NewGateway creates a new Gateway for managing access to the dqlite cluster.
When a new gateway is created, the node-level database is queried to check what kind of role this node plays and if it's exposed over the network. It will initialize internal data structures accordingly, for example starting a dqlite driver if this node is a database node.
After creation, the Daemon is expected to expose whatever http handlers the HandlerFuncs method returns and to access the dqlite cluster using the gRPC dialer returned by the Dialer method.
func (*Gateway) Context ¶
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.
func (*Gateway) DialFunc ¶
DialFunc returns a dial function that can be used to connect to one of the dqlite nodes.
func (*Gateway) HandlerFuncs ¶
func (g *Gateway) HandlerFuncs() map[string]http.HandlerFunc
HandlerFuncs returns the HTTP handlers that should be added to the REST API endpoint in order to handle database-related requests.
There are two handlers, one for the /internal/raft endpoint and the other for /internal/db, which handle respectively raft and gRPC-SQL requests.
These handlers might return 404, either because this node is a non-clustered node not available over the network or because it is not a database node part of the dqlite cluster.
func (*Gateway) Init ¶
Init the gateway, creating a new raft factory and server (if this node is a database node), and a dialer.
func (*Gateway) IsDatabaseNode ¶
IsDatabaseNode returns true if this gateway also run acts a raft database node.
func (*Gateway) Kill ¶
func (g *Gateway) Kill()
Kill is an API that the daemon calls before it actually shuts down and calls Shutdown(). It will abort any ongoing or new attempt to establish a SQL gRPC connection with the dialer (typically for running some pre-shutdown queries).
func (*Gateway) LeaderAddress ¶
LeaderAddress returns the address of the current raft leader.
func (*Gateway) Raft ¶
func (g *Gateway) Raft() RaftInstance
Raft returns the underlying raft instance
func (*Gateway) Reset ¶
Reset the gateway, shutting it down and starting against from scratch using the given certificate.
This is used when disabling clustering on a node.
func (*Gateway) ServerStore ¶
func (g *Gateway) ServerStore() cluster.ServerStore
ServerStore returns a dqlite server store that can be used to lookup the addresses of known database nodes.
func (*Gateway) Shutdown ¶
Shutdown this gateway, stopping the gRPC server and possibly the raft factory.
func (*Gateway) Sync ¶
func (g *Gateway) Sync()
Sync dumps the content of the database to disk. This is useful for inspection purposes, and it's also needed by the activateifneeded command so it can inspect the database in order to decide whether to activate the daemon or not.
func (*Gateway) WaitLeadership ¶
WaitLeadership should wait for the raft node to become leader. Should ideally only be used by Bootstrap, since we know that we'll self elect.
func (*Gateway) WaitUpgradeNotification ¶
func (g *Gateway) WaitUpgradeNotification()
WaitUpgradeNotification waits for a notification from another node that all nodes in the cluster should now have been upgraded and have matching schema and API versions.
type Net ¶
type Net interface { // UnixListen returns a net.Listener based on the address // UnixListen announces on the local network address. UnixListen(string) (net.Listener, error) // UnixDial returns a net.Conn based on the address // UnixDial connects to the address on the named network. UnixDial(string) (net.Conn, error) }
Net provides functions for acessing unix connections or sockets
type Node ¶
type Node interface { database.DBAccessor db.NodeOpener db.NodeTransactioner // Dir returns the directory of the underlying database file. Dir() string // Close the database facade. Close() error }
Node mediates access to the data stored in the node-local SQLite database.
type Option ¶
type Option func(*options)
Option to be passed to NewGateway to customize the resulting instance.
func WithFileSystem ¶
func WithFileSystem(fileSystem fsys.FileSystem) Option
WithFileSystem sets the fileSystem on the options
func WithLatency ¶
WithLatency is a coarse grain measure of how fast/reliable network links are. This is used to tweak the various timeouts parameters of the raft algorithm. See the raft.Config structure for more details. A value of 1.0 means use the default values from hashicorp's raft package. Values closer to 0 reduce the values of the various timeouts (useful when running unit tests in-memory).
func WithLogger ¶
WithLogger sets the logger on the options
func WithNodeConfigSchema ¶
WithNodeConfigSchema sets the node configuration schema on the options
func WithRaftProvider ¶
func WithRaftProvider(raftProvider RaftProvider) Option
WithRaftProvider sets the raftProvider on the options
func WithServerProvider ¶
func WithServerProvider(serverProvider ServerProvider) Option
WithServerProvider sets the serverProvider on the options
func WithSleeper ¶
WithSleeper sets the sleeper on the options
func WithStoreProvider ¶
func WithStoreProvider(storeProvider StoreProvider) Option
WithStoreProvider sets the storeProvider on the options
type RaftInstance ¶
type RaftInstance interface { // Init the raft instance and all its dependencies, to be used as backend for // the dqlite driver running on this node. Init() error // HandlerFunc can be used to handle HTTP requests performed against the // API RaftEndpoint ("/internal/raft"), in order to join/leave/form the raft // cluster. // // If it returns nil, it means that this node is not supposed to expose a raft // endpoint over the network, because it's running as a non-clustered single // node. HandlerFunc() http.HandlerFunc // Raft returns the actual underlying raft instance Raft() *hashiraft.Raft // Registry returns the Registry associated with the raft instance. Registry() *dqlite.Registry // Servers returns the servers that are currently part of the cluster. // // If this raft instance is not the leader, an error is returned. Servers() ([]hashiraft.Server, error) // Shutdown raft and any raft-related resource we have instantiated. Shutdown() error // MembershipChanger returns the underlying rafthttp.Layer, which can be used // to change the membership of this node in the cluster. MembershipChanger() raftmembership.Changer }
RaftInstance and all its dependencies, to be used as backend for the dqlite driver running on this node.
type RaftProvider ¶
type RaftProvider interface { // New creates a new raft instance to be used as a backend for the dqlite // driver running on the node New(Node, *cert.Info, config.Schema, fsys.FileSystem, log.Logger, float64) RaftInstance }
RaftProvider allows the creation of new raft instances
type Server ¶
type Server interface { // Dump the files of a database to disk. Dump(string, string) error // Close the server, releasing all resources it created. Close() error }
Server implements the dqlite network protocol.
type ServerProvider ¶
type ServerProvider interface { // New creates a new Server instance. New(RaftInstance, net.Listener, *raft.AddressProvider, log.Logger) (Server, error) }
ServerProvider creates a new Server instance.
type ServerStore ¶
type ServerStore struct {
// contains filtered or unexported fields
}
ServerStore uses the in-memory or the on-disk server store conditionally
func (*ServerStore) Get ¶
func (s *ServerStore) Get(ctx context.Context) ([]cluster.ServerInfo, error)
Get return the list of known servers.
func (*ServerStore) Set ¶
func (s *ServerStore) Set(ctx context.Context, servers []cluster.ServerInfo) error
Set updates the list of known cluster servers.
type StoreProvider ¶
type StoreProvider interface { // Memory creates ServerStore which stores its data in-memory. Memory() cluster.ServerStore // Disk is used by a dqlite client to get an initial list of candidate // dqlite server addresses that it can dial in order to find a leader dqlite // server to use. Disk(database.DB) (cluster.ServerStore, error) }
StoreProvider provides a way to create different store types depending on the requirements of the gateway
Directories ¶
Path | Synopsis |
---|---|
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |