config

package
v3.0.1-rc1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const (
	BalancingAlgorithmRandomChoice = iota
	BalancingAlgorithmRoundRobin

	DefaultBalancingAlgorithm = BalancingAlgorithmRandomChoice
)
View Source
const (
	DefaultDiscoveryInterval = time.Minute
)

Variables

View Source
var (
	// DefaultKeepaliveInterval contains default duration between grpc keepalive
	DefaultKeepaliveInterval = 10 * time.Second
	MinKeepaliveInterval     = 10 * time.Second
	DefaultGrpcConnectionTTL = 6 * time.Minute
	DefaultGRPCMsgSize       = 64 * 1024 * 1024 // 64MB
)
View Source
var (
	DefaultBalancer = BalancerConfig{Algorithm: DefaultBalancingAlgorithm, PreferLocal: true}
)
View Source
var (
	DefaultGrpcConnectionPolicy = GrpcConnectionPolicy{
		ClientParameters: keepalive.ClientParameters{
			Time:                DefaultKeepaliveInterval,
			Timeout:             MinKeepaliveInterval,
			PermitWithoutStream: true,
		},
		TTL: DefaultGrpcConnectionTTL,
	}
)

Functions

This section is empty.

Types

type Algorithm

type Algorithm uint8

type BalancerConfig

type BalancerConfig struct {
	// Algorithm define balancing algorithm
	Algorithm Algorithm

	// PreferLocal adds endpoint selection logic when local endpoints
	// are always used first.
	// When no alive local endpoints left other endpoints will be used.
	//
	// NOTE: some balancing methods (such as p2c) also may use knowledge of
	// endpoint's locality. Difference is that with PreferLocal local
	// endpoints selected separately from others. That is, if there at least
	// one local endpoint it will be used regardless of its performance
	// indicators.
	//
	// NOTE: currently driver (and even ydb itself) does not track load factor
	// of each endpoint properly. Enabling this Option may lead to the
	// situation, when all but one nodes in local datacenter become inactive
	// and all clients will overload this single instance very quickly. That
	// is, currently this Option may be called as experimental.
	// You have been warned.
	PreferLocal bool
}

type Config

type Config interface {
	// Endpoint is a required starting endpoint for connect
	Endpoint() string

	// Database is a required database name.
	Database() string

	// Secure() is an flag for secure connection
	Secure() bool

	// Credentials is an ydb client credentials.
	// In most cases Credentials are required.
	Credentials() credentials.Credentials

	// Trace contains driver tracing options.
	Trace() trace.Driver

	// RequestTimeout is the maximum amount of time a Call() will wait for an
	// operation to complete.
	// If RequestTimeout is zero then no timeout is used.
	RequestTimeout() time.Duration

	// StreamTimeout is the maximum amount of time a StreamRead() will wait for
	// an operation to complete.
	// If StreamTimeout is zero then no timeout is used.
	StreamTimeout() time.Duration

	// OperationTimeout is the maximum amount of time a YDB server will process
	// an operation. After timeout exceeds YDB will try to cancel operation and
	// regardless of the cancellation appropriate error will be returned to
	// the client.
	// If OperationTimeout is zero then no timeout is used.
	OperationTimeout() time.Duration

	// OperationCancelAfter is the maximum amount of time a YDB server will process an
	// operation. After timeout exceeds YDB will try to cancel operation and if
	// it succeeds appropriate error will be returned to the client; otherwise
	// processing will be continued.
	// If OperationCancelAfter is zero then no timeout is used.
	OperationCancelAfter() time.Duration

	// DiscoveryInterval is the frequency of background tasks of ydb endpoints
	// discovery.
	// If DiscoveryInterval is zero then the DefaultDiscoveryInterval is used.
	// If DiscoveryInterval is negative, then no background discovery prepared.
	DiscoveryInterval() time.Duration

	// GrpcConnectionPolicy define lifecycle behavior of grpc connection
	// By default GrpcConnectionPolicy is sets to DefaultGrpcConnectionPolicy
	GrpcConnectionPolicy() GrpcConnectionPolicy

	// BalancingConfig is an optional configuration related to selected
	// BalancingMethod. That is, some balancing methods allow to be configured.
	BalancingConfig() BalancerConfig

	// RequestsType set an additional types hint to all requests.
	// It is needed only for debug purposes and advanced cases.
	RequestsType() string

	// FastDial will make dialer return Driver as soon as 1st connection succeeds.
	// NB: it may be not the fastest node to serve requests.
	FastDial() bool

	// DialTimeout is the maximum amount of time a dial will wait for a connect to
	// complete.
	// If DialTimeout is zero then no timeout is used.
	DialTimeout() time.Duration

	// TLSConfig specifies the TLS configuration to use for tls client.
	// If TLSConfig is zero then connections are insecure.
	TLSConfig() *tls.Config

	// NetDial is an optional function that may replace default network dialing
	// function such as net.Dial("tcp").
	NetDial() func(context.Context, string) (net.Conn, error)
}

Config contains driver configuration options.

func New

func New(opts ...Option) Config

type GrpcConnectionPolicy

type GrpcConnectionPolicy struct {
	keepalive.ClientParameters

	// TTL is a duration for automatically close idle connections
	// Zero TTL will disable automatically closing of idle connections
	// By default TTL is sets to DefaultGrpcConnectionTTL
	TTL time.Duration
}

type Option

type Option func(c *config)

func WithBalancingConfig

func WithBalancingConfig(balancingConfig BalancerConfig) Option

func WithCertificate

func WithCertificate(certificate *x509.Certificate) Option

func WithCredentials

func WithCredentials(credentials credentials.Credentials) Option

func WithDatabase

func WithDatabase(database string) Option

func WithDialTimeout

func WithDialTimeout(timeout time.Duration) Option

func WithDiscoveryInterval

func WithDiscoveryInterval(discoveryInterval time.Duration) Option

func WithEndpoint

func WithEndpoint(endpoint string) Option

func WithFastDial

func WithFastDial(fastDial bool) Option

func WithGrpcConnectionPolicy

func WithGrpcConnectionPolicy(grpcConnectionPolicy GrpcConnectionPolicy) Option

func WithGrpcConnectionTTL

func WithGrpcConnectionTTL(ttl time.Duration) Option

func WithNetDial

func WithNetDial(netDial func(context.Context, string) (net.Conn, error)) Option

func WithOperationCancelAfter

func WithOperationCancelAfter(operationCancelAfter time.Duration) Option

func WithOperationTimeout

func WithOperationTimeout(operationTimeout time.Duration) Option

func WithRequestTimeout

func WithRequestTimeout(requestTimeout time.Duration) Option

func WithRequestsType

func WithRequestsType(requestsType string) Option

func WithSecure

func WithSecure(secure bool) Option

func WithStreamTimeout

func WithStreamTimeout(streamTimeout time.Duration) Option

func WithTrace

func WithTrace(trace trace.Driver) Option

Jump to

Keyboard shortcuts

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