transport

package
v0.0.0-...-ce81923 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package transport implements networking and routing for the Scylla Go driver.

Index

Constants

View Source
const UnknownShard = uint16(1<<16 - 1)

Variables

View Source
var (
	ErrComprCorrupt = errors.New("compression: corrupt input")
	ErrComprUnknown = errors.New("compression: unknown algorithm")
)
View Source
var Now = time.Now

Functions

func RandomShardPort

func RandomShardPort(si ShardInfo) uint16

RandomShardPort returns randomly generated port that can be used to establish connection to a specific shard on scylla node.

func ShardPortIterator

func ShardPortIterator(si ShardInfo) func() uint16

ShardPortIterator returns iterator for consecutive ports that are mapped to a specific shard on scylla node.

func WrapTLS

func WrapTLS(ctx context.Context, conn *net.TCPConn, cfg ConnConfig) (net.Conn, error)

Types

type Cluster

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

func NewCluster

func NewCluster(ctx context.Context, cfg ConnConfig, p HostSelectionPolicy, e []frame.EventType, hosts ...string) (*Cluster, error)

NewCluster also creates control connection and starts handling events and refreshing topology.

func (*Cluster) Close

func (c *Cluster) Close()

func (*Cluster) NewControl

func (c *Cluster) NewControl(ctx context.Context) (*Conn, error)

func (*Cluster) NewQueryInfo

func (c *Cluster) NewQueryInfo() QueryInfo

func (*Cluster) NewTokenAwareQueryInfo

func (c *Cluster) NewTokenAwareQueryInfo(t Token, ks string) (QueryInfo, error)

func (*Cluster) RequestRefresh

func (c *Cluster) RequestRefresh()

func (*Cluster) RequestReopenControl

func (c *Cluster) RequestReopenControl()

func (*Cluster) Topology

func (c *Cluster) Topology() *topology

type Conn

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

func OpenConn

func OpenConn(ctx context.Context, addr string, localAddr *net.TCPAddr, cfg ConnConfig) (*Conn, error)

OpenConn opens connection with specific local address. In case lAddr is nil, random local address is used.

If error and connection are returned the connection is not valid and must be closed by the caller.

func OpenLocalPortConn

func OpenLocalPortConn(ctx context.Context, addr string, localPort uint16, cfg ConnConfig) (*Conn, error)

OpenLocalPortConn opens connection on a given local port.

If error and connection are returned the connection is not valid and must be closed by the caller.

func OpenShardConn

func OpenShardConn(ctx context.Context, addr string, si ShardInfo, cfg ConnConfig) (*Conn, error)

OpenShardConn opens connection mapped to a specific shard on Scylla node.

func WrapConn

func WrapConn(ctx context.Context, conn net.Conn, cfg ConnConfig) (*Conn, error)

WrapConn transforms tcp connection to a working Scylla connection. If error and connection are returned the connection is not valid and must be closed by the caller.

func (*Conn) AsyncExecute

func (c *Conn) AsyncExecute(ctx context.Context, s Statement, pagingState frame.Bytes, h ResponseHandler)

func (*Conn) AsyncQuery

func (c *Conn) AsyncQuery(ctx context.Context, s Statement, pagingState frame.Bytes, h ResponseHandler)

func (*Conn) AuthResponse

func (c *Conn) AuthResponse(ctx context.Context, a *Authenticate) error

func (*Conn) Close

func (c *Conn) Close()

Close closes connection and terminates reader and writer go routines.

func (*Conn) Event

func (c *Conn) Event() ConnEvent

func (*Conn) Execute

func (c *Conn) Execute(ctx context.Context, s Statement, pagingState frame.Bytes) (QueryResult, error)

func (*Conn) Prepare

func (c *Conn) Prepare(ctx context.Context, s Statement) (Statement, error)

func (*Conn) Query

func (c *Conn) Query(ctx context.Context, s Statement, pagingState frame.Bytes) (QueryResult, error)

func (*Conn) RegisterEventHandler

func (c *Conn) RegisterEventHandler(ctx context.Context, h func(context.Context, response), e ...frame.EventType) error

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) Shard

func (c *Conn) Shard() int

func (*Conn) Startup

func (c *Conn) Startup(ctx context.Context, options frame.StartupOptions) error

func (*Conn) String

func (c *Conn) String() string

func (*Conn) Supported

func (c *Conn) Supported(ctx context.Context) (*Supported, error)

func (*Conn) UseKeyspace

func (c *Conn) UseKeyspace(ctx context.Context, ks string) error

func (*Conn) Waiting

func (c *Conn) Waiting() int

type ConnConfig

type ConnConfig struct {
	// Default: cassandra
	Username string
	// Default: cassandra
	Password string
	Keyspace string
	// Default: true
	TCPNoDelay bool
	// Default: 500 milliseconds.
	Timeout time.Duration

	// If not nil, all connections will use TLS according to TLSConfig,
	// please note that the default port (9042) may not support TLS.
	TLSConfig *tls.Config
	// Default: Local Quorum
	DefaultConsistency frame.Consistency
	// Default: "9042"
	DefaultPort string

	Compression     frame.Compression
	ComprBufferSize int

	// Default: LoggingConnObserver
	ConnObserver ConnObserver
	Logger       log.Logger
}

func DefaultConnConfig

func DefaultConnConfig(keyspace string) ConnConfig

type ConnEvent

type ConnEvent struct {
	Addr  string
	Shard uint16
}

func (ConnEvent) String

func (ev ConnEvent) String() string

type ConnObserver

type ConnObserver interface {
	OnConnect(ev ConnectEvent)
	OnPickReplacedWithLessBusyConn(ev ConnEvent)
}

type ConnPool

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

func NewConnPool

func NewConnPool(ctx context.Context, host string, cfg ConnConfig) (*ConnPool, error)

func (*ConnPool) Close

func (p *ConnPool) Close()

func (*ConnPool) Conn

func (p *ConnPool) Conn(token Token) (*Conn, error)

func (*ConnPool) LeastBusyConn

func (p *ConnPool) LeastBusyConn() (*Conn, error)

func (*ConnPool) String

func (p *ConnPool) String() string

type ConnectEvent

type ConnectEvent struct {
	ConnEvent

	// Err is the connection error (if any).
	Err error
	// contains filtered or unexported fields
}

func (*ConnectEvent) Duration

func (s *ConnectEvent) Duration() time.Duration

type DefaultRetryDecider

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

func (*DefaultRetryDecider) Decide

func (*DefaultRetryDecider) Reset

func (d *DefaultRetryDecider) Reset()

type DefaultRetryPolicy

type DefaultRetryPolicy struct{}

func (*DefaultRetryPolicy) NewRetryDecider

func (*DefaultRetryPolicy) NewRetryDecider() RetryDecider

type FallthroughRetryDecider

type FallthroughRetryDecider struct{}

func (FallthroughRetryDecider) Decide

func (FallthroughRetryDecider) Reset

func (FallthroughRetryDecider) Reset()

type FallthroughRetryPolicy

type FallthroughRetryPolicy struct{}

func (*FallthroughRetryPolicy) NewRetryDecider

func (*FallthroughRetryPolicy) NewRetryDecider() RetryDecider

type HostSelectionPolicy

type HostSelectionPolicy interface {
	// Returns i-th node of the host selection plan, returns nil after going through the whole plan.
	Node(QueryInfo, int) *Node
}

HostSelectionPolicy decides which node the query should be routed to.

type LoggingConnObserver

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

func (LoggingConnObserver) OnConnect

func (o LoggingConnObserver) OnConnect(ev ConnectEvent)

func (LoggingConnObserver) OnPickReplacedWithLessBusyConn

func (o LoggingConnObserver) OnPickReplacedWithLessBusyConn(ev ConnEvent)

type Node

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

func (*Node) Close

func (n *Node) Close()

func (*Node) Conn

func (n *Node) Conn(qi QueryInfo) (*Conn, error)

func (*Node) FetchSchemaVersion

func (n *Node) FetchSchemaVersion(ctx context.Context) (frame.UUID, error)

func (*Node) Init

func (n *Node) Init(ctx context.Context, cfg ConnConfig)

func (*Node) IsUp

func (n *Node) IsUp() bool

func (*Node) LeastBusyConn

func (n *Node) LeastBusyConn() (*Conn, error)

func (*Node) Prepare

func (n *Node) Prepare(ctx context.Context, s Statement) (Statement, error)

type PoolRefiller

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

type QueryInfo

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

QueryInfo represents data required for host selection policy to create query plan. Token and strategy are only necessary for token aware policies.

type QueryResult

type QueryResult struct {
	Rows         []frame.Row
	Warnings     []string
	TracingID    frame.UUID
	HasMorePages bool
	PagingState  frame.Bytes
	ColSpec      []frame.ColumnSpec
	SchemaChange *SchemaChange
}

func MakeQueryResult

func MakeQueryResult(res frame.Response, meta *frame.ResultMetadata) (QueryResult, error)

type ResponseHandler

type ResponseHandler chan response

func MakeResponseHandler

func MakeResponseHandler() ResponseHandler

func MakeResponseHandlerWithError

func MakeResponseHandlerWithError(err error) ResponseHandler

type RetryDecider

type RetryDecider interface {
	Decide(RetryInfo) RetryDecision
	Reset()
}

RetryDecider should be used for just one query that we want to retry. After that it should be discarded or reset.

type RetryDecision

type RetryDecision byte
const (
	RetrySameNode RetryDecision = iota
	RetryNextNode
	DontRetry
)

type RetryInfo

type RetryInfo struct {
	Error       error             // Failed query error.
	Idempotent  bool              // Is set to true only if we are sure that the query is idempotent.
	Consistency frame.Consistency // Failed query consistency.
}

type RetryPolicy

type RetryPolicy interface {
	NewRetryDecider() RetryDecider
}

func NewDefaultRetryPolicy

func NewDefaultRetryPolicy() RetryPolicy

func NewFallthroughRetryPolicy

func NewFallthroughRetryPolicy() RetryPolicy

type Ring

type Ring []RingEntry

func (Ring) Len

func (r Ring) Len() int

func (Ring) Less

func (r Ring) Less(i, j int) bool

func (Ring) Swap

func (r Ring) Swap(i, j int)

type RingEntry

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

func (RingEntry) Less

func (r RingEntry) Less(i RingEntry) bool

type ShardInfo

type ShardInfo struct {
	Shard     uint16
	NrShards  uint16
	MsbIgnore uint8
}

type Statement

type Statement struct {
	ID                frame.Bytes
	Content           string
	Values            []frame.Value
	PkIndexes         []frame.Short
	PkCnt             frame.Int
	PageSize          frame.Int
	Consistency       frame.Consistency
	SerialConsistency frame.Consistency
	Tracing           bool
	Compression       bool
	Idempotent        bool
	Metadata          *frame.ResultMetadata
}

func (Statement) Clone

func (s Statement) Clone() Statement

Clone makes new Values to avoid data overwrite in binding. ID and PkIndexes stay the same, as they are immutable.

type Token

type Token int64

Token is used to identify both nodes and partitions, it's value is hashed partition key.

func MurmurToken

func MurmurToken(partitionKey []byte) Token

MurmurToken is a function which given partition key hashes it, using Murmurhash3.

type TokenAwarePolicy

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

func NewTokenAwarePolicy

func NewTokenAwarePolicy(localDC string) *TokenAwarePolicy

func (*TokenAwarePolicy) Node

func (p *TokenAwarePolicy) Node(qi QueryInfo, offset int) *Node

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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