go-dqlite: github.com/canonical/go-dqlite/client Index | Files

package client

import "github.com/canonical/go-dqlite/client"

Index

Package Files

client.go constants.go dial.go leader.go log.go store.go

Constants

const (
    Voter   = protocol.Voter
    StandBy = protocol.StandBy
    Spare   = protocol.Spare
)

Node roles

const (
    LogNone  = logging.None
    LogDebug = logging.Debug
    LogInfo  = logging.Info
    LogWarn  = logging.Warn
    LogError = logging.Error
)

Available logging levels.

Variables

var NewInmemNodeStore = protocol.NewInmemNodeStore

NewInmemNodeStore creates NodeStore which stores its data in-memory.

func DefaultDialFunc Uses

func DefaultDialFunc(ctx context.Context, address string) (net.Conn, error)

DefaultDialFunc is the default dial function, which can handle plain TCP and Unix socket endpoints. You can customize it with WithDialFunc()

func DefaultLogFunc Uses

func DefaultLogFunc(l LogLevel, format string, a ...interface{})

DefaultLogFunc doesn't emit any message.

type Client Uses

type Client struct {
    // contains filtered or unexported fields
}

Client speaks the dqlite wire protocol.

func FindLeader Uses

func FindLeader(ctx context.Context, store NodeStore, options ...Option) (*Client, error)

FindLeader returns a Client connected to the current cluster leader.

The function will iterate through to all nodes in the given store, and for each of them check if it's the current leader. If no leader is found, the function will keep retrying (with a capped exponential backoff) until the given context is canceled.

func New Uses

func New(ctx context.Context, address string, options ...Option) (*Client, error)

New creates a new client connected to the dqlite node with the given address.

func (*Client) Add Uses

func (c *Client) Add(ctx context.Context, node NodeInfo) error

Add a node to a cluster.

The new node will have the role specified in node.Role. Note that if the desired role is Voter, the node being added must be online, since it will be granted voting rights only once it catches up with the leader's log.

func (*Client) Assign Uses

func (c *Client) Assign(ctx context.Context, id uint64, role NodeRole) error

Assign a role to a node.

Possible roles are:

- Voter: the node will replicate data and participate in quorum. - StandBy: the node will replicate data but won't participate in quorum. - Spare: the node won't replicate data and won't participate in quorum.

If the target node does not exist or has already the desired role, an error is returned.

func (*Client) Close Uses

func (c *Client) Close() error

Close the client.

func (*Client) Cluster Uses

func (c *Client) Cluster(ctx context.Context) ([]NodeInfo, error)

Cluster returns information about all nodes in the cluster.

func (*Client) Describe Uses

func (c *Client) Describe(ctx context.Context) (*NodeMetadata, error)

Describe returns metadata about the node we're connected with.

func (*Client) Dump Uses

func (c *Client) Dump(ctx context.Context, dbname string) ([]File, error)

Dump the content of the database with the given name. Two files will be returned, the first is the main database file (which has the same name as the database), the second is the WAL file (which has the same name as the database plus the suffix "-wal").

func (*Client) Leader Uses

func (c *Client) Leader(ctx context.Context) (*NodeInfo, error)

Leader returns information about the current leader, if any.

func (*Client) Remove Uses

func (c *Client) Remove(ctx context.Context, id uint64) error

Remove a node from the cluster.

func (*Client) Transfer Uses

func (c *Client) Transfer(ctx context.Context, id uint64) error

Transfer leadership from the current leader to another node.

This must be invoked one client connected to the current leader.

func (*Client) Weight Uses

func (c *Client) Weight(ctx context.Context, weight uint64) error

Weight updates the weight associated to the node we're connected with.

type DatabaseNodeStore Uses

type DatabaseNodeStore struct {
    // contains filtered or unexported fields
}

DatabaseNodeStore persists a list addresses of dqlite nodes in a SQL table.

func NewNodeStore Uses

func NewNodeStore(db *sql.DB, schema, table, column string, options ...NodeStoreOption) *DatabaseNodeStore

NewNodeStore creates a new NodeStore.

func (*DatabaseNodeStore) Get Uses

func (d *DatabaseNodeStore) Get(ctx context.Context) ([]NodeInfo, error)

Get the current servers.

func (*DatabaseNodeStore) Set Uses

func (d *DatabaseNodeStore) Set(ctx context.Context, servers []NodeInfo) error

Set the servers addresses.

type DialFunc Uses

type DialFunc = protocol.DialFunc

DialFunc is a function that can be used to establish a network connection.

func DialFuncWithTLS Uses

func DialFuncWithTLS(dial DialFunc, config *tls.Config) DialFunc

DialFuncWithTLS returns a dial function that uses TLS encryption.

The given dial function will be used to establish the network connection, and the given TLS config will be used for encryption.

type File Uses

type File struct {
    Name string
    Data []byte
}

File holds the content of a single database file.

type InmemNodeStore Uses

type InmemNodeStore = protocol.InmemNodeStore

InmemNodeStore keeps the list of target dqlite nodes in memory.

type LogFunc Uses

type LogFunc = logging.Func

LogFunc is a function that can be used for logging.

type LogLevel Uses

type LogLevel = logging.Level

LogLevel defines the logging level.

type NodeInfo Uses

type NodeInfo = protocol.NodeInfo

NodeInfo holds information about a single server.

type NodeMetadata Uses

type NodeMetadata struct {
    FailureDomain uint64
    Weight        uint64
}

NodeMetadata user-defined node-level metadata.

type NodeRole Uses

type NodeRole = protocol.NodeRole

NodeRole identifies the role of a node.

type NodeStore Uses

type NodeStore = protocol.NodeStore

NodeStore is used by a dqlite client to get an initial list of candidate dqlite nodes that it can dial in order to find a leader dqlite node to use.

func DefaultNodeStore Uses

func DefaultNodeStore(filename string) (NodeStore, error)

DefaultNodeStore creates a new NodeStore using the given filename.

If the filename ends with ".yaml" then the YamlNodeStore implementation will be used. Otherwise the SQLite-based one will be picked, with default names for the schema, table and column parameters.

It also creates the table if it doesn't exist yet.

type NodeStoreOption Uses

type NodeStoreOption func(*nodeStoreOptions)

Option that can be used to tweak node store parameters.

func WithNodeStoreWhereClause Uses

func WithNodeStoreWhereClause(where string) NodeStoreOption

WithNodeStoreWhereClause configures the node store to append the given hard-coded where clause to the SELECT query used to fetch nodes. Only the clause itself must be given, without the "WHERE" prefix.

type Option Uses

type Option func(*options)

Option that can be used to tweak client parameters.

func WithDialFunc Uses

func WithDialFunc(dial DialFunc) Option

WithDialFunc sets a custom dial function for creating the client network connection.

func WithLogFunc Uses

func WithLogFunc(log LogFunc) Option

WithLogFunc sets a custom log function. connection.

type YamlNodeStore Uses

type YamlNodeStore struct {
    // contains filtered or unexported fields
}

Persists a list addresses of dqlite nodes in a YAML file.

func NewYamlNodeStore Uses

func NewYamlNodeStore(path string) (*YamlNodeStore, error)

NewYamlNodeStore creates a new YamlNodeStore backed by the given YAML file.

func (*YamlNodeStore) Get Uses

func (s *YamlNodeStore) Get(ctx context.Context) ([]NodeInfo, error)

Get the current servers.

func (*YamlNodeStore) Set Uses

func (s *YamlNodeStore) Set(ctx context.Context, servers []NodeInfo) error

Set the servers addresses.

Package client imports 14 packages (graph) and is imported by 19 packages. Updated 2020-06-28. Refresh now. Tools for package owners.