buffer

package
v0.17.6 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Overview

Package buffer provides a buffer for PRIMARY traffic during failovers.

Instead of returning an error to the application (when the vttablet primary becomes unavailable), the buffer will automatically retry buffered requests after the end of the failover was detected.

Buffering (stalling) requests will increase the number of requests in flight within vtgate and at upstream layers. Therefore, it is important to limit the size of the buffer and the buffering duration (window) per request. See the file flags.go for the available configuration and its defaults.

Index

Constants

This section is empty.

Variables

View Source
var (
	ShardMissingError = vterrors.New(vtrpcpb.Code_UNAVAILABLE, "destination shard is missing after a resharding operation")
)

Functions

func CausedByFailover added in v0.11.0

func CausedByFailover(err error) bool

CausedByFailover returns true if "err" was supposedly caused by a failover. To simplify things, we've merged the detection for different MySQL flavors in one function. Supported flavors: MariaDB, MySQL

func SetBufferingModeInTestingEnv added in v0.13.0

func SetBufferingModeInTestingEnv(enabled bool)

SetBufferingModeInTestingEnv should only be used from testing code to change the flag (enable_buffer) default value

Types

type Buffer

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

Buffer is used to track ongoing PRIMARY tablet failovers and buffer requests while the PRIMARY tablet is unavailable. Once the new PRIMARY starts accepting requests, buffering stops and requests queued so far will be automatically retried.

There should be exactly one instance of this buffer. For each failover, an instance of "ShardBuffer" will be created.

func New

func New(cfg *Config) *Buffer

New creates a new Buffer object.

func (*Buffer) HandleKeyspaceEvent added in v0.12.0

func (b *Buffer) HandleKeyspaceEvent(ksevent *discovery.KeyspaceEvent)

func (*Buffer) ProcessPrimaryHealth added in v0.12.0

func (b *Buffer) ProcessPrimaryHealth(th *discovery.TabletHealth)

ProcessPrimaryHealth notifies the buffer to record a new primary and end any failover buffering that may be in progress

func (*Buffer) Shutdown

func (b *Buffer) Shutdown()

Shutdown blocks until all pending ShardBuffer objects are shut down. In particular, it guarantees that all launched Go routines are stopped after it returns.

func (*Buffer) WaitForFailoverEnd

func (b *Buffer) WaitForFailoverEnd(ctx context.Context, keyspace, shard string, err error) (RetryDoneFunc, error)

WaitForFailoverEnd blocks until a pending buffering due to a failover for keyspace/shard is over. If there is no ongoing failover, "err" is checked. If it's caused by a failover, buffering may be started. It returns an error if buffering failed (e.g. buffer full). If it does not return an error, it may return a RetryDoneFunc which must be called after the request was retried.

type Config added in v0.12.0

type Config struct {
	Enabled bool
	DryRun  bool

	Window                  time.Duration
	Size                    int
	MaxFailoverDuration     time.Duration
	MinTimeBetweenFailovers time.Duration

	DrainConcurrency int

	// keyspaces has the same purpose as "shards" but applies to a whole keyspace.
	Keyspaces map[string]bool
	// shards is a set of keyspace/shard entries to which buffering is limited.
	// If empty (and *enabled==true), buffering is enabled for all shards.
	Shards map[string]bool
	// contains filtered or unexported fields
}

func NewConfigFromFlags added in v0.12.0

func NewConfigFromFlags() *Config

func NewDefaultConfig added in v0.12.0

func NewDefaultConfig() *Config

type RetryDoneFunc

type RetryDoneFunc context.CancelFunc

RetryDoneFunc will be returned for each buffered request and must be called after the buffered request was retried. Without this signal, the buffer would not know how many buffered requests are currently retried.

Jump to

Keyboard shortcuts

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