protocol

package
v1.22.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterFormatV0 = 0
	ClusterFormatV1 = 1
)

Cluster response formats

View Source
const (
	Voter   = NodeRole(0)
	StandBy = NodeRole(1)
	Spare   = NodeRole(2)
)

Node roles

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
	RequestAdd       = 12
	RequestAssign    = 13
	RequestRemove    = 14
	RequestDump      = 15
	RequestCluster   = 16
	RequestTransfer  = 17
	RequestDescribe  = 18
	RequestWeight    = 19
)

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
	ResponseMetadata   = 10
)

Response types.

View Source
const (
	RequestDescribeFormatV0 = 0
)

Formats

View Source
const VersionLegacy = uint64(0x86104dd760433fe5)

VersionLegacy is the pre 1.0 cowsql 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 cowsql 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 DecodeMetadata

func DecodeMetadata(response *Message) (failureDomain uint64, weight uint64, err error)

DecodeMetadata decodes a Metadata response.

func DecodeNode

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

DecodeNode decodes a Node response.

func DecodeNodeCompat

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

DecodeNodeCompat handles also pre-1.0 legacy server messages.

func DecodeNodeLegacy

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

DecodeNodeLegacy decodes a NodeLegacy 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 Dial

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

Dial function handling plain TCP and Unix socket endpoints.

func EncodeAdd

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

EncodeAdd encodes a Add request.

func EncodeAssign

func EncodeAssign(request *Message, id uint64, role uint64)

EncodeAssign encodes a Assign request.

func EncodeClient

func EncodeClient(request *Message, id uint64)

EncodeClient encodes a Client request.

func EncodeCluster

func EncodeCluster(request *Message, format uint64)

EncodeCluster encodes a Cluster request.

func EncodeDescribe

func EncodeDescribe(request *Message, format uint64)

EncodeDescribe encodes a Describe request.

func EncodeDump

func EncodeDump(request *Message, name string)

EncodeDump encodes a Dump request.

func EncodeExecSQLV0

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

EncodeExecSQLV0 encodes a ExecSQL request.

func EncodeExecSQLV1

func EncodeExecSQLV1(request *Message, db uint64, sql string, values NamedValues32)

EncodeExecSQLV1 encodes a ExecSQL request.

func EncodeExecV0

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

EncodeExecV0 encodes a Exec request.

func EncodeExecV1

func EncodeExecV1(request *Message, db uint32, stmt uint32, values NamedValues32)

EncodeExecV1 encodes a Exec 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

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 EncodeQuerySQLV0

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

EncodeQuerySQLV0 encodes a QuerySQL request.

func EncodeQuerySQLV1

func EncodeQuerySQLV1(request *Message, db uint64, sql string, values NamedValues32)

EncodeQuerySQLV1 encodes a QuerySQL request.

func EncodeQueryV0

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

EncodeQueryV0 encodes a Query request.

func EncodeQueryV1

func EncodeQueryV1(request *Message, db uint32, stmt uint32, values NamedValues32)

EncodeQueryV1 encodes a Query request.

func EncodeRemove

func EncodeRemove(request *Message, id uint64)

EncodeRemove encodes a Remove request.

func EncodeTransfer

func EncodeTransfer(request *Message, id uint64)

EncodeTransfer encodes a Transfer request.

func EncodeWeight

func EncodeWeight(request *Message, weight uint64)

EncodeWeight encodes a Weight request.

Types

type Config

type Config struct {
	Dial           DialFunc      // Network dialer.
	DialTimeout    time.Duration // Timeout for establishing a network connection .
	AttemptTimeout time.Duration // Timeout for each individual attempt to probe a server's leadership.
	BackoffFactor  time.Duration // Exponential backoff factor for retries.
	BackoffCap     time.Duration // Maximum connection retry backoff value,
	RetryLimit     uint          // Maximum number of retries, or 0 for unlimited.
}

Config holds various configuration parameters for a cowsql client.

type Connector

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

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

func NewConnector

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

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

func (*Connector) Connect

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

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 Error

type Error struct {
	Code    int
	Message string
}

Error holds information about a SQLite error.

func (Error) Error

func (e Error) Error() string

type Files

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

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

func DecodeFiles

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

DecodeFiles decodes a Files response.

func (*Files) Close

func (f *Files) Close()

func (*Files) Next

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

type InmemNodeStore

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

InmemNodeStore keeps the list of servers in memory.

func NewInmemNodeStore

func NewInmemNodeStore() *InmemNodeStore

NewInmemNodeStore creates NodeStore which stores its data in-memory.

func (*InmemNodeStore) Get

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

Get the current servers.

func (*InmemNodeStore) Set

func (i *InmemNodeStore) Set(ctx context.Context, servers []NodeInfo) 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(initialBufferSize int)

Init initializes the message using the given initial size for the data buffer, which is re-used across requests or responses encoded or decoded using this message object.

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 NamedValues32

type NamedValues32 = []driver.NamedValue

type NodeInfo

type NodeInfo struct {
	ID      uint64   `yaml:"ID"`
	Address string   `yaml:"Address"`
	Role    NodeRole `yaml:"Role"`
}

NodeInfo holds information about a single server.

type NodeRole

type NodeRole int

NodeRole identifies the role of a node.

func (NodeRole) String

func (r NodeRole) String() string

String implements the Stringer interface.

type NodeStore

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 cowsql client to get an initial list of candidate cowsql 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

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

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

DecodeNodes decodes a Nodes response.

type Protocol

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

Protocol sends and receive the cowsql message on the wire.

func Handshake

func Handshake(ctx context.Context, conn net.Conn, version uint64) (*Protocol, error)

Perform the initial handshake using the given protocol version.

func (*Protocol) Call

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

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

func (*Protocol) Close

func (p *Protocol) Close() error

Close the client connection.

func (*Protocol) Interrupt

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

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

More is used when a request maps to multiple responses.

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() error

Close the result set and reset the underlying message.

func (*Rows) ColumnTypes

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

ColumnTypes returns the column types for the the result set.

func (*Rows) Next

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