proxy

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: Apache-2.0 Imports: 33 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrProxyAlreadyConnected = errors.New("proxy already connected")
View Source
var ErrProxyClosed = errors.New("proxy closed")
View Source
var ErrProxyNotConnected = errors.New("proxy not connected")

Functions

func NewDefaultPreparedCache

func NewDefaultPreparedCache(size int) (proxycore.PreparedCache, error)

NewDefaultPreparedCache creates a new default prepared cache capping the max item capacity to `size`.

func Run added in v0.1.0

func Run(ctx context.Context, args []string) int

Run starts the proxy command. 'args' shouldn't include the executable (i.e. os.Args[1:]). It returns the exit code for the proxy.

Types

type Config

type Config struct {
	Version           primitive.ProtocolVersion
	MaxVersion        primitive.ProtocolVersion
	Auth              proxycore.Authenticator
	Resolver          proxycore.EndpointResolver
	ReconnectPolicy   proxycore.ReconnectPolicy
	RetryPolicy       RetryPolicy
	IdempotentGraph   bool
	NumConns          int
	Logger            *zap.Logger
	HeartBeatInterval time.Duration
	ConnectTimeout    time.Duration
	IdleTimeout       time.Duration
	RPCAddr           string
	DC                string
	Tokens            []string
	Peers             []PeerConfig
	// PreparedCache a cache that stores prepared queries. If not set it uses the default implementation with a max
	// capacity of ~100MB.
	PreparedCache proxycore.PreparedCache
}

type PeerConfig added in v0.1.2

type PeerConfig struct {
	RPCAddr string   `yaml:"rpc-address"`
	DC      string   `yaml:"data-center,omitempty"`
	Tokens  []string `yaml:"tokens,omitempty"`
}

type Proxy

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

func NewProxy

func NewProxy(ctx context.Context, config Config) *Proxy

func (*Proxy) Close added in v0.1.1

func (p *Proxy) Close() error

func (*Proxy) Connect added in v0.1.3

func (p *Proxy) Connect() error

func (*Proxy) OnEvent

func (p *Proxy) OnEvent(event proxycore.Event)

func (*Proxy) OutageDuration added in v0.1.0

func (p *Proxy) OutageDuration() time.Duration

func (*Proxy) Ready added in v0.1.0

func (p *Proxy) Ready() bool

func (*Proxy) Serve

func (p *Proxy) Serve(l net.Listener) (err error)

Serve the proxy using the specified listener. It can be called multiple times with different listeners allowing them to share the same backend clusters.

type RetryDecision added in v0.1.0

type RetryDecision int

RetryDecision is a type used for deciding what to do when a request has failed.

const (
	// RetrySame should be returned when a request should be retried on the same host.
	RetrySame RetryDecision = iota
	// RetryNext should be returned when a request should be retried on the next host according to the request's query
	// plan.
	RetryNext
	// ReturnError should be returned when a request's original error should be forwarded along to the client.
	ReturnError
)

func (RetryDecision) String added in v0.1.0

func (r RetryDecision) String() string

type RetryPolicy added in v0.1.0

type RetryPolicy interface {
	// OnReadTimeout handles the retry decision for a server-side read timeout error (Read_timeout = 0x1200).
	// This occurs when a replica read request times out during a read query.
	OnReadTimeout(msg *message.ReadTimeout, retryCount int) RetryDecision

	// OnWriteTimeout handles the retry decision for a server-side write timeout error (Write_timeout = 0x1100).
	// This occurs when a replica write request times out during a write query.
	OnWriteTimeout(msg *message.WriteTimeout, retryCount int) RetryDecision

	// OnUnavailable handles the retry decision for a server-side unavailable exception (Unavailable = 0x1000).
	// This occurs when a coordinator determines that there are not enough replicas to handle a query at the requested
	// consistency level.
	OnUnavailable(msg *message.Unavailable, retryCount int) RetryDecision

	// OnErrorResponse handles the retry decision for other potentially recoverable errors.
	// This can be called for the following error types: server error (ServerError = 0x0000),
	// overloaded (Overloaded = 0x1001), truncate error (Truncate_error = 0x1003), read failure (Read_failure = 0x1300),
	// and write failure (Write_failure = 0x1500).
	OnErrorResponse(msg message.Error, retryCount int) RetryDecision
}

RetryPolicy is an interface for defining retry behavior when a server-side error occurs.

func NewDefaultRetryPolicy added in v0.1.0

func NewDefaultRetryPolicy() RetryPolicy

NewDefaultRetryPolicy creates a new default retry policy. The default retry policy takes a conservative approach to retrying requests. In most cases it retries only once in cases where a retry is likely to succeed.

Jump to

Keyboard shortcuts

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