Documentation ¶
Overview ¶
Package cluster supports intracluster control messaging.
Index ¶
- Constants
- Variables
- func CreateRaftDialer(cert, key, caCert, serverName string, Insecure bool) (*tcp.Dialer, error)
- func CredentialsFor(credStr *auth.CredentialsStore, username string) *proto.Credentials
- type AddressProvider
- type BootStatus
- type Bootstrapper
- type Client
- func (c *Client) Backup(br *command.BackupRequest, nodeAddr string, creds *proto.Credentials, ...) error
- func (c *Client) Execute(er *command.ExecuteRequest, nodeAddr string, creds *proto.Credentials, ...) ([]*command.ExecuteQueryResponse, error)
- func (c *Client) GetNodeAPIAddr(nodeAddr string, retries int, timeout time.Duration) (string, error)
- func (c *Client) Join(jr *command.JoinRequest, nodeAddr string, creds *proto.Credentials, ...) error
- func (c *Client) Load(lr *command.LoadRequest, nodeAddr string, creds *proto.Credentials, ...) error
- func (c *Client) Notify(nr *command.NotifyRequest, nodeAddr string, creds *proto.Credentials, ...) error
- func (c *Client) Query(qr *command.QueryRequest, nodeAddr string, creds *proto.Credentials, ...) ([]*command.QueryRows, error)
- func (c *Client) RemoveNode(rn *command.RemoveNodeRequest, nodeAddr string, creds *proto.Credentials, ...) error
- func (c *Client) Request(r *command.ExecuteQueryRequest, nodeAddr string, creds *proto.Credentials, ...) ([]*command.ExecuteQueryResponse, error)
- func (c *Client) SetLocal(nodeAddr string, serv *Service) error
- func (c *Client) Stats() (map[string]interface{}, error)
- type Control
- type CredentialStore
- type Database
- type Dialer
- type Joiner
- type Manager
- type Remover
- type Service
- func (s *Service) Addr() string
- func (s *Service) Close() error
- func (s *Service) EnableHTTPS(b bool)
- func (s *Service) GetAPIAddr() string
- func (s *Service) GetNodeAPIURL() string
- func (s *Service) Open() error
- func (s *Service) SetAPIAddr(addr string)
- func (s *Service) Stats() (map[string]interface{}, error)
- type Suffrage
Constants ¶
const ( // MuxRaftHeader is the byte used to indicate internode Raft communications. MuxRaftHeader = 1 // MuxClusterHeader is the byte used to request internode cluster state information. MuxClusterHeader = 2 // Cluster state communications )
Variables ¶
var ( // ErrBootTimeout is returned when a boot operation does not // complete within the timeout. ErrBootTimeout = errors.New("boot timeout") // ErrBootCanceled is returned when a boot operation is // canceled. ErrBootCanceled = errors.New("boot canceled") )
var ( // ErrNodeIDRequired is returned a join request doesn't supply a node ID ErrNodeIDRequired = errors.New("node required") // ErrJoinFailed is returned when a node fails to join a cluster ErrJoinFailed = errors.New("failed to join cluster") // ErrJoinCanceled is returned when a join operation is canceled ErrJoinCanceled = errors.New("join operation canceled") // ErrNotifyFailed is returned when a node fails to notify another node ErrNotifyFailed = errors.New("failed to notify node") )
Functions ¶
func CreateRaftDialer ¶ added in v8.13.5
CreateRaftDialer creates a dialer for connecting to other nodes' Raft service. If the cert and key arguments are not set, then the returned dialer will not use TLS.
func CredentialsFor ¶ added in v8.13.5
func CredentialsFor(credStr *auth.CredentialsStore, username string) *proto.Credentials
CredentialsFor returns a Credentials instance for the given username, or nil if the given CredentialsStore is nil, or the username is not found.
Types ¶
type AddressProvider ¶
AddressProvider is the interface types must implement to provide addresses to a Bootstrapper.
func NewAddressProviderString ¶
func NewAddressProviderString(ss []string) AddressProvider
NewAddressProviderString wraps an AddressProvider around a string slice.
type BootStatus ¶
type BootStatus int
BootStatus is the reason the boot process completed.
const ( // BootUnknown is the initial state of the boot process. BootUnknown BootStatus = iota // BootJoin means boot completed due to a successful join. BootJoin // BootDone means boot completed due to Done being "true". BootDone // BootTimeout means the boot process timed out. BootTimeout // BootCanceled means the boot process was canceled. BootCanceled )
func (BootStatus) String ¶
func (b BootStatus) String() string
String returns a string representation of the BootStatus.
type Bootstrapper ¶
Bootstrapper performs a bootstrap of this node.
func NewBootstrapper ¶
func NewBootstrapper(p AddressProvider, client *Client) *Bootstrapper
NewBootstrapper returns an instance of a Bootstrapper.
func (*Bootstrapper) Boot ¶
func (b *Bootstrapper) Boot(ctx context.Context, id, raftAddr string, suf Suffrage, done func() bool, timeout time.Duration) error
Boot performs the bootstrapping process for this node. This means it will ensure this node becomes part of a cluster. It does this by either:
- joining an existing cluster by explicitly joining it through a node returned by the AddressProvider, or
- if it's a Voting node, notifying all nodes returned by the AddressProvider that it exists, potentially allowing a cluster-wide bootstrap take place which will include this node.
Returns nil if the boot operation was successful, or if done() ever returns true. done() is periodically polled by the boot process. Returns an error the boot process encounters an unrecoverable error, or booting does not occur within the given timeout. If booting was canceled, ErrBootCanceled is returned unless done() returns true at the time of cancelation, in which case no error is returned.
id and raftAddr are those of the node calling Boot. suf is whether this node is a Voter or NonVoter.
func (*Bootstrapper) SetCredentials ¶
func (b *Bootstrapper) SetCredentials(creds *proto.Credentials)
SetCredentials sets the credentials for the Bootstrapper.
func (*Bootstrapper) Status ¶
func (b *Bootstrapper) Status() BootStatus
Status returns the reason for the boot process completing.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client allows communicating with a remote node.
func NewClient ¶
NewClient returns a client instance for talking to a remote node. Clients will retry certain commands if they fail, to allow for remote node restarts. Cluster management operations such as joining and removing nodes are not retried, to make it clear to the operator that the operation failed. In addition, higher-level code will usually retry these operations.
func (*Client) Backup ¶
func (c *Client) Backup(br *command.BackupRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration, w io.Writer) error
Backup retrieves a backup from a remote node and writes to the io.Writer
func (*Client) Execute ¶
func (c *Client) Execute(er *command.ExecuteRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration, retries int) ([]*command.ExecuteQueryResponse, error)
Execute performs an Execute on a remote node. If username is an empty string no credential information will be included in the Execute request to the remote node.
func (*Client) GetNodeAPIAddr ¶
func (c *Client) GetNodeAPIAddr(nodeAddr string, retries int, timeout time.Duration) (string, error)
GetNodeAPIAddr retrieves the API Address for the node at nodeAddr
func (*Client) Join ¶
func (c *Client) Join(jr *command.JoinRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration) error
Join joins this node to a cluster at the remote address nodeAddr.
func (*Client) Load ¶
func (c *Client) Load(lr *command.LoadRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration, retries int) error
Load loads a SQLite file into the database.
func (*Client) Notify ¶
func (c *Client) Notify(nr *command.NotifyRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration) error
Notify notifies a remote node that this node is ready to bootstrap.
func (*Client) Query ¶
func (c *Client) Query(qr *command.QueryRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration) ([]*command.QueryRows, error)
Query performs a Query on a remote node.
func (*Client) RemoveNode ¶
func (c *Client) RemoveNode(rn *command.RemoveNodeRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration) error
RemoveNode removes a node from the cluster
func (*Client) Request ¶
func (c *Client) Request(r *command.ExecuteQueryRequest, nodeAddr string, creds *proto.Credentials, timeout time.Duration, retries int) ([]*command.ExecuteQueryResponse, error)
Request performs an ExecuteQuery on a remote node.
type Control ¶
type Control interface { WaitForLeader(time.Duration) (string, error) WaitForRemoval(string, time.Duration) error }
Control is an interface for interacting with a cluster.
type CredentialStore ¶
type CredentialStore interface { // AA authenticates and checks authorization for the given perm. AA(username, password, perm string) bool }
CredentialStore is the interface credential stores must support.
type Database ¶
type Database interface { // Execute executes a slice of SQL statements. Execute(er *command.ExecuteRequest) ([]*command.ExecuteQueryResponse, error) // Query executes a slice of queries, each of which returns rows. Query(qr *command.QueryRequest) ([]*command.QueryRows, error) // Request processes a request that can both executes and queries. Request(rr *command.ExecuteQueryRequest) ([]*command.ExecuteQueryResponse, error) // Backup writes a backup of the database to the writer. Backup(br *command.BackupRequest, dst io.Writer) error // Loads an entire SQLite file into the database Load(lr *command.LoadRequest) error }
Database is the interface any queryable system must implement
type Dialer ¶
type Dialer interface { // Dial is used to create a connection to a service listening // on an address. Dial(address string, timeout time.Duration) (net.Conn, error) }
Dialer is the interface dialers must implement.
type Joiner ¶
type Joiner struct {
// contains filtered or unexported fields
}
Joiner executes a node-join operation.
func (*Joiner) Do ¶
func (j *Joiner) Do(ctx context.Context, targetAddrs []string, id, addr string, suf Suffrage) (string, error)
Do makes the actual join request. If the join is successful with any address, that address is returned. Otherwise, an error is returned.
func (*Joiner) SetCredentials ¶
func (j *Joiner) SetCredentials(creds *proto.Credentials)
SetCredentials sets the credentials for the Joiner.
type Manager ¶
type Manager interface { // LeaderAddr returns the Raft address of the leader of the cluster. LeaderAddr() (string, error) // CommitIndex returns the Raft commit index of the cluster. CommitIndex() (uint64, error) // Remove removes the node, given by id, from the cluster Remove(rn *command.RemoveNodeRequest) error // Notify notifies this node that a remote node is ready // for bootstrapping. Notify(n *command.NotifyRequest) error // Join joins a remote node to the cluster. Join(n *command.JoinRequest) error }
Manager is the interface node-management systems must implement
type Remover ¶
type Remover struct {
// contains filtered or unexported fields
}
Remover executes a node-removal operation.
func NewRemover ¶
/ NewRemover returns an instantiated Remover.
func (*Remover) SetCredentials ¶
func (r *Remover) SetCredentials(creds *proto.Credentials)
SetCredentials sets the credentials for the Remover.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides information about the node and cluster.
func (*Service) EnableHTTPS ¶
EnableHTTPS tells the cluster service the API serves HTTPS.
func (*Service) GetAPIAddr ¶
GetAPIAddr returns the previously-set API address
func (*Service) GetNodeAPIURL ¶
GetNodeAPIURL returns fully-specified HTTP(S) API URL for the node running this service.
func (*Service) SetAPIAddr ¶
SetAPIAddr sets the API address the cluster service returns.
type Suffrage ¶ added in v8.13.5
type Suffrage int
Suffrage is the type of suffrage -- voting or non-voting -- a node has.
func VoterSuffrage ¶ added in v8.13.5
VoterSuffrage returns a Suffrage based on the given boolean.
func (Suffrage) IsNonVoter ¶ added in v8.13.5
IsNonVoter returns whether the Suffrage is a NonVoter.