cluster

package
v8.23.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package cluster supports intracluster control messaging.

Index

Constants

View Source
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

View Source
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")
)
View Source
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

func CreateRaftDialer(cert, key, caCert, serverName string, Insecure bool) (*tcp.Dialer, error)

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

type AddressProvider interface {
	Lookup() ([]string, error)
}

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

type Bootstrapper struct {
	Interval time.Duration
	// contains filtered or unexported fields
}

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

func NewClient(dl Dialer, t time.Duration) *Client

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.

func (*Client) SetLocal

func (c *Client) SetLocal(nodeAddr string, serv *Service) error

SetLocal informs the client instance of the node address for the node using this client. Along with the Service instance it allows this client to serve requests for this node locally without the network hop.

func (*Client) Stats

func (c *Client) Stats() (map[string]interface{}, error)

Stats returns stats on the Client instance

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 NewJoiner

func NewJoiner(client *Client, numAttempts int, attemptInterval time.Duration) *Joiner

NewJoiner returns an instantiated Joiner.

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

func NewRemover(client *Client, timeout time.Duration, control Control) *Remover

/ NewRemover returns an instantiated Remover.

func (*Remover) Do

func (r *Remover) Do(id string, confirm bool) error

Do executes the node-removal operation.

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 New

func New(ln net.Listener, db Database, m Manager, credentialStore CredentialStore) *Service

New returns a new instance of the cluster service

func (*Service) Addr

func (s *Service) Addr() string

Addr returns the address the service is listening on.

func (*Service) Close

func (s *Service) Close() error

Close closes the service.

func (*Service) EnableHTTPS

func (s *Service) EnableHTTPS(b bool)

EnableHTTPS tells the cluster service the API serves HTTPS.

func (*Service) GetAPIAddr

func (s *Service) GetAPIAddr() string

GetAPIAddr returns the previously-set API address

func (*Service) GetNodeAPIURL

func (s *Service) GetNodeAPIURL() string

GetNodeAPIURL returns fully-specified HTTP(S) API URL for the node running this service.

func (*Service) Open

func (s *Service) Open() error

Open opens the Service.

func (*Service) SetAPIAddr

func (s *Service) SetAPIAddr(addr string)

SetAPIAddr sets the API address the cluster service returns.

func (*Service) Stats

func (s *Service) Stats() (map[string]interface{}, error)

Stats returns status of the Service.

type Suffrage added in v8.13.5

type Suffrage int

Suffrage is the type of suffrage -- voting or non-voting -- a node has.

const (
	SuffrageUnknown Suffrage = iota
	Voter
	NonVoter
)

func VoterSuffrage added in v8.13.5

func VoterSuffrage(b bool) Suffrage

VoterSuffrage returns a Suffrage based on the given boolean.

func (Suffrage) IsNonVoter added in v8.13.5

func (s Suffrage) IsNonVoter() bool

IsNonVoter returns whether the Suffrage is a NonVoter.

func (Suffrage) IsVoter added in v8.13.5

func (s Suffrage) IsVoter() bool

IsVoter returns whether the Suffrage is a Voter.

func (Suffrage) String added in v8.13.5

func (s Suffrage) String() string

String returns a string representation of the Suffrage.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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