buffer

package
v0.15.10 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

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

View Source
const (
	ClusterEventReshardingInProgress = "current keyspace is being resharded"
	ClusterEventReparentInProgress   = "primary is not serving, there may be a reparent operation in progress"
	ClusterEventMoveTables           = "disallowed due to rule"
)

Variables

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

Functions

func CausedByFailover

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

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) GetConfig

func (b *Buffer) GetConfig() *Config

func (*Buffer) HandleKeyspaceEvent

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

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

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

func NewConfigFromFlags() *Config

func NewDefaultConfig

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