protocol

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Integer = 1
	Float   = 2
	Text    = 3
	Blob    = 4
	Null    = 5
)

SQLite datatype codes

View Source
const (
	UnixTime = 9
	ISO8601  = 10
	Boolean  = 11
)

Special data types for time values.

View Source
const (
	RequestLeader    = 0
	RequestClient    = 1
	RequestHeartbeat = 2
	RequestOpen      = 3
	RequestPrepare   = 4
	RequestExec      = 5
	RequestQuery     = 6
	RequestFinalize  = 7
	RequestExecSQL   = 8
	RequestQuerySQL  = 9
	RequestInterrupt = 10
	RequestJoin      = 12
	RequestPromote   = 13
	RequestRemove    = 14
	RequestDump      = 15
	RequestCluster   = 16
)

Request types.

View Source
const (
	ResponseFailure    = 0
	ResponseNode       = 1
	ResponseNodeLegacy = 1
	ResponseWelcome    = 2
	ResponseNodes      = 3
	ResponseDb         = 4
	ResponseStmt       = 5
	ResponseResult     = 6
	ResponseRows       = 7
	ResponseEmpty      = 8
	ResponseFiles      = 9
)

Response types.

View Source
const VersionLegacy = uint64(0x86104dd760433fe5)

VersionLegacy is the pre 1.0 dqlite server protocol version.

View Source
const VersionOne = uint64(1)

VersionOne is version 1 of the server protocol.

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 added in v1.0.0

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

DecodeDb decodes a Db response.

func DecodeEmpty added in v1.0.0

func DecodeEmpty(response *Message) (err error)

DecodeEmpty decodes a Empty response.

func DecodeFailure added in v1.0.0

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

DecodeFailure decodes a Failure response.

func DecodeNode added in v1.0.0

func DecodeNode(response *Message) (id uint64, address string, err error)

DecodeNode decodes a Node response.

func DecodeNodeCompat added in v1.0.0

func DecodeNodeCompat(protocol *Protocol, response *Message) (uint64, string, error)

DecodeNodeCompat handles also pre-1.0 legacy server messages.

func DecodeNodeLegacy added in v1.0.0

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

DecodeNodeLegacy decodes a NodeLegacy response.

func DecodeStmt added in v1.0.0

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

DecodeStmt decodes a Stmt response.

func DecodeWelcome added in v1.0.0

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

DecodeWelcome decodes a Welcome response.

func EncodeClient added in v1.0.0

func EncodeClient(request *Message, id uint64)

EncodeClient encodes a Client request.

func EncodeCluster added in v1.0.0

func EncodeCluster(request *Message)

EncodeCluster encodes a Cluster request.

func EncodeDump added in v1.0.0

func EncodeDump(request *Message, name string)

EncodeDump encodes a Dump request.

func EncodeExec added in v1.0.0

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

EncodeExec encodes a Exec request.

func EncodeExecSQL added in v1.0.0

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

EncodeExecSQL encodes a ExecSQL request.

func EncodeFinalize added in v1.0.0

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

EncodeFinalize encodes a Finalize request.

func EncodeHeartbeat added in v1.0.0

func EncodeHeartbeat(request *Message, timestamp uint64)

EncodeHeartbeat encodes a Heartbeat request.

func EncodeInterrupt added in v1.0.0

func EncodeInterrupt(request *Message, db uint64)

EncodeInterrupt encodes a Interrupt request.

func EncodeJoin added in v1.0.0

func EncodeJoin(request *Message, id uint64, address string)

EncodeJoin encodes a Join request.

func EncodeLeader added in v1.0.0

func EncodeLeader(request *Message)

EncodeLeader encodes a Leader request.

func EncodeOpen added in v1.0.0

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

EncodeOpen encodes a Open request.

func EncodePrepare added in v1.0.0

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

EncodePrepare encodes a Prepare request.

func EncodePromote added in v1.0.0

func EncodePromote(request *Message, id uint64)

EncodePromote encodes a Promote request.

func EncodeQuery added in v1.0.0

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

EncodeQuery encodes a Query request.

func EncodeQuerySQL added in v1.0.0

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

EncodeQuerySQL encodes a QuerySQL request.

func EncodeRemove added in v1.0.0

func EncodeRemove(request *Message, id uint64)

EncodeRemove encodes a Remove request.

func TCPDial added in v1.0.0

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 added in v1.0.0

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 Config added in v1.0.0

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 added in v1.0.0

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 added in v1.0.0

func NewConnector(id uint64, store NodeStore, 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 added in v1.0.0

func (c *Connector) Connect(ctx context.Context) (*Protocol, 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 added in v1.0.0

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

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

type ErrRequest added in v1.0.0

type ErrRequest struct {
	Code        uint64
	Description string
}

ErrRequest is returned in case of request failure.

func (ErrRequest) Error added in v1.0.0

func (e ErrRequest) Error() string

type Files added in v1.0.0

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

Files holds a set of files encoded in a message body.

func DecodeFiles added in v1.0.0

func DecodeFiles(response *Message) (files Files, err error)

DecodeFiles decodes a Files response.

func (*Files) Close added in v1.0.0

func (f *Files) Close()

func (*Files) Next added in v1.0.0

func (f *Files) Next() (string, []byte)

type InmemNodeStore added in v1.0.0

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

InmemNodeStore keeps the list of servers in memory.

func NewInmemNodeStore added in v1.0.0

func NewInmemNodeStore() *InmemNodeStore

NewInmemNodeStore creates NodeStore which stores its data in-memory.

func (*InmemNodeStore) Get added in v1.0.0

func (i *InmemNodeStore) Get(ctx context.Context) ([]NodeInfo, error)

Get the current servers.

func (*InmemNodeStore) Set added in v1.0.0

func (i *InmemNodeStore) Set(ctx context.Context, servers []NodeInfo) error

Set the servers.

type Message added in v1.0.0

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

Message holds data about a single request or response.

func (*Message) Init added in v1.0.0

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 added in v1.0.0

func (m *Message) Reset()

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

type NamedValues added in v1.0.0

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 NodeInfo added in v1.0.0

type NodeInfo struct {
	ID      uint64
	Address string
}

NodeInfo holds information about a single server.

type NodeStore added in v1.0.0

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

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

NodeStore 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 Nodes added in v1.0.0

type Nodes []NodeInfo

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

func DecodeNodes added in v1.0.0

func DecodeNodes(response *Message) (servers Nodes, err error)

DecodeNodes decodes a Nodes response.

type Protocol added in v1.0.0

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

Protocol sends and receive the dqlite message on the wire.

func Connect added in v1.0.0

func Connect(ctx context.Context, dial DialFunc, address string, version uint64) (*Protocol, error)

Connect establishes a connection with a dqlite node.

func NewProtocol added in v1.0.0

func NewProtocol(version uint64, conn net.Conn) *Protocol

func (*Protocol) Call added in v1.0.0

func (p *Protocol) Call(ctx context.Context, request, response *Message) (err error)

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

func (*Protocol) Close added in v1.0.0

func (p *Protocol) Close() error

Close the client connection.

func (*Protocol) Interrupt added in v1.0.0

func (p *Protocol) Interrupt(ctx context.Context, request *Message, response *Message) error

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

func (*Protocol) More added in v1.0.0

func (p *Protocol) More(ctx context.Context, response *Message) error

More is used when a request maps to multiple responses.

func (*Protocol) SetContextTimeout added in v1.0.0

func (p *Protocol) SetContextTimeout(timeout time.Duration)

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

type Result added in v1.0.0

type Result struct {
	LastInsertID uint64
	RowsAffected uint64
}

Result holds the result of a statement.

func DecodeResult added in v1.0.0

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

DecodeResult decodes a Result response.

type Rows added in v1.0.0

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

Rows holds a result set encoded in a message body.

func DecodeRows added in v1.0.0

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

DecodeRows decodes a Rows response.

func (*Rows) Close added in v1.0.0

func (r *Rows) Close() error

Close the result set and reset the underlying message.

func (*Rows) ColumnTypes added in v1.2.0

func (r *Rows) ColumnTypes() ([]string, error)

ColumnTypes returns the column types for the the result set.

func (*Rows) Next added in v1.0.0

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

Next returns the next row in the result set.

Jump to

Keyboard shortcuts

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