client

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAvailableLeader = fmt.Errorf("no available dqlite leader server found")
)

Client errors.

View Source
var ErrRowsPart = fmt.Errorf("not all rows were returned in this response")

ErrRowsPart is returned when the first batch of a multi-response result batch is done.

Functions

func DecodeDb

func DecodeDb(response *Message) (id uint32, err error)

DecodeDb decodes a Db response.

func DecodeEmpty

func DecodeEmpty(response *Message) (err error)

DecodeEmpty decodes a Empty response.

func DecodeFailure

func DecodeFailure(response *Message) (code uint64, message string, err error)

DecodeFailure decodes a Failure response.

func DecodeServer

func DecodeServer(response *Message) (address string, err error)

DecodeServer decodes a Server response.

func DecodeStmt

func DecodeStmt(response *Message) (db uint32, id uint32, params uint64, err error)

DecodeStmt decodes a Stmt response.

func DecodeWelcome

func DecodeWelcome(response *Message) (heartbeatTimeout uint64, err error)

DecodeWelcome decodes a Welcome response.

func EncodeClient

func EncodeClient(request *Message, id uint64)

EncodeClient encodes a Client request.

func EncodeExec

func EncodeExec(request *Message, db uint32, stmt uint32, values NamedValues)

EncodeExec encodes a Exec request.

func EncodeExecSQL

func EncodeExecSQL(request *Message, db uint64, sql string, values NamedValues)

EncodeExecSQL encodes a ExecSQL request.

func EncodeFinalize

func EncodeFinalize(request *Message, db uint32, stmt uint32)

EncodeFinalize encodes a Finalize request.

func EncodeHeartbeat

func EncodeHeartbeat(request *Message, timestamp uint64)

EncodeHeartbeat encodes a Heartbeat request.

func EncodeInterrupt added in v0.2.1

func EncodeInterrupt(request *Message, db uint64)

EncodeInterrupt encodes a Interrupt request.

func EncodeLeader

func EncodeLeader(request *Message)

EncodeLeader encodes a Leader request.

func EncodeOpen

func EncodeOpen(request *Message, name string, flags uint64, vfs string)

EncodeOpen encodes a Open request.

func EncodePrepare

func EncodePrepare(request *Message, db uint64, sql string)

EncodePrepare encodes a Prepare request.

func EncodeQuery

func EncodeQuery(request *Message, db uint32, stmt uint32, values NamedValues)

EncodeQuery encodes a Query request.

func EncodeQuerySQL

func EncodeQuerySQL(request *Message, db uint64, sql string, values NamedValues)

EncodeQuerySQL encodes a QuerySQL request.

func TCPDial

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

TCPDial is a dial function using plain TCP to establish the network connection.

func UnixDial

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

UnixDial is a dial function using Unix sockets to establish the network connection.

Types

type Client

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

Client connecting to a dqlite server and speaking the dqlite wire protocol.

func (*Client) Call

func (c *Client) Call(ctx context.Context, request, response *Message) error

Call invokes a dqlite RPC, sending a request message and receiving a response message.

func (*Client) Close

func (c *Client) Close() error

Close the client connection.

func (*Client) Interrupt added in v0.2.1

func (c *Client) Interrupt(ctx context.Context, request *Message, response *Message) error

Interrupt sends an interrupt request and awaits for the server's empty response.

func (*Client) More

func (c *Client) More(ctx context.Context, response *Message) error

More is used when a request maps to multiple responses.

func (*Client) SetContextTimeout added in v0.2.2

func (c *Client) SetContextTimeout(timeout time.Duration)

SetContextTimeout sets the default context timeout when no deadline is provided.

type Config

type Config struct {
	Dial            DialFunc            // Network dialer.
	AttemptTimeout  time.Duration       // Timeout for each individual Dial attempt.
	RetryStrategies []strategy.Strategy // Strategies used for retrying to connect to a leader.
}

Config holds various configuration parameters for a dqlite client.

type Connector

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

Connector is in charge of creating a dqlite SQL client connected to the current leader of a cluster.

func NewConnector

func NewConnector(id uint64, store ServerStore, config Config, log logging.Func) *Connector

NewConnector returns a new connector that can be used by a dqlite driver to create new clients connected to a leader dqlite server.

func (*Connector) Connect

func (c *Connector) Connect(ctx context.Context) (*Client, error)

Connect finds the leader server and returns a connection to it.

If the connector is stopped before a leader is found, nil is returned.

type DialFunc

type DialFunc func(context.Context, string) (net.Conn, error)

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

type ErrRequest

type ErrRequest struct {
	Code        uint64
	Description string
}

ErrRequest is returned in case of request failure.

func (ErrRequest) Error

func (e ErrRequest) Error() string

type InmemServerStore

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

InmemServerStore keeps the list of servers in memory.

func NewInmemServerStore

func NewInmemServerStore() *InmemServerStore

NewInmemServerStore creates ServerStore which stores its data in-memory.

func (*InmemServerStore) Get

func (i *InmemServerStore) Get(ctx context.Context) ([]ServerInfo, error)

Get the current servers.

func (*InmemServerStore) Set

func (i *InmemServerStore) Set(ctx context.Context, servers []ServerInfo) error

Set the servers.

type Message

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

Message holds data about a single request or response.

func (*Message) Init

func (m *Message) Init(staticSize int)

Init initializes the message using the given size of the statically allocated buffer (i.e. a buffer which is re-used across requests or responses encoded or decoded using this message object).

func (*Message) Reset

func (m *Message) Reset()

Reset the state of the message so it can be used to encode or decode again.

type NamedValues

type NamedValues = []driver.NamedValue

NamedValues is a type alias of a slice of driver.NamedValue. It's used by schema.sh to generate encoding logic for statement parameters.

type Result

type Result struct {
	LastInsertID uint64
	RowsAffected uint64
}

Result holds the result of a statement.

func DecodeResult

func DecodeResult(response *Message) (result Result, err error)

DecodeResult decodes a Result response.

type Rows

type Rows struct {
	Columns []string
	// contains filtered or unexported fields
}

Rows holds a result set encoded in a message body.

func DecodeRows

func DecodeRows(response *Message) (rows Rows, err error)

DecodeRows decodes a Rows response.

func (*Rows) Close

func (r *Rows) Close()

Close the result set and reset the underlying message.

func (*Rows) Next

func (r *Rows) Next(dest []driver.Value) error

Next returns the next row in the result set.

type ServerInfo

type ServerInfo = bindings.ServerInfo

ServerInfo holds information about a single server.

type ServerStore

type ServerStore interface {
	// Get return the list of known servers.
	Get(context.Context) ([]ServerInfo, error)

	// Set updates the list of known cluster servers.
	Set(context.Context, []ServerInfo) error
}

ServerStore is used by a dqlite client to get an initial list of candidate dqlite servers that it can dial in order to find a leader server to connect to.

Once connected, the client periodically updates the server addresses in the store by querying the leader about changes in the cluster (such as servers being added or removed).

type Servers

type Servers []bindings.ServerInfo

Servers is a type alias of a slice of bindings.ServerInfo. It's used by schema.sh to generate decoding logic for the heartbeat response.

func DecodeServers

func DecodeServers(response *Message) (servers Servers, err error)

DecodeServers decodes a Servers response.

Jump to

Keyboard shortcuts

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