cluster

package
v0.0.0-...-d2438c5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count(state state.State) (int, error)

Count is a convenience for checking the current number of nodes in the cluster.

func DqliteLog

func DqliteLog(logger log.Logger) func(dqlite.LogLevel, string, ...interface{})

DqliteLog redirects dqlite's logs to our own logger

func Enabled

func Enabled(node Node) (bool, error)

Enabled is a convenience that returns true if clustering is enabled on this node.

Types

type DqliteProxyFn

type DqliteProxyFn func(net.Listener, chan net.Conn) error

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) Cert

func (g *Gateway) Cert() *cert.Info

Cert returns the cert associated with the node

func (*Gateway) Clustered

func (g *Gateway) Clustered() bool

Clustered returns if the Gateway is in a cluster or not

func (*Gateway) Context

func (g *Gateway) Context() context.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) DB

func (g *Gateway) DB() Node

DB returns the underlying database node

func (*Gateway) DialFunc

func (g *Gateway) DialFunc() dqlite.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

func (g *Gateway) Init(cert *cert.Info) error

Init the gateway, creating a new raft factory and server (if this node is a database node), and a dialer.

func (*Gateway) IsDatabaseNode

func (g *Gateway) IsDatabaseNode() bool

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

func (g *Gateway) LeaderAddress() (string, error)

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) RaftNodes

func (g *Gateway) RaftNodes() ([]db.RaftNode, error)

RaftNodes returns the nodes currently part of the raft cluster.

func (*Gateway) Reset

func (g *Gateway) Reset(cert *cert.Info) error

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

func (g *Gateway) Shutdown() error

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

func (g *Gateway) WaitLeadership() error

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 WithCert

func WithCert(cert *cert.Info) Option

WithCert sets the cert on the options

func WithFileSystem

func WithFileSystem(fileSystem fsys.FileSystem) Option

WithFileSystem sets the fileSystem on the options

func WithLatency

func WithLatency(latency float64) Option

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

func WithLogger(logger log.Logger) Option

WithLogger sets the logger on the options

func WithNet

func WithNet(netProvider Net) Option

WithNet sets the netProvider on the options

func WithNode

func WithNode(database Node) Option

WithNode sets the database node on the options

func WithNodeConfigSchema

func WithNodeConfigSchema(nodeConfigSchema config.Schema) Option

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

func WithSleeper(sleeper clock.Sleeper) Option

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

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.

Jump to

Keyboard shortcuts

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