throttler

package
v0.1.0-prerelease Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package throttler contains code to throttle the rate of writes to a table.

Index

Constants

View Source
const MySQL8LagQuery = `` /* 1097-byte string literal not displayed */

MySQL8LagQuery is a query that is used to get the lag between the source and the replica. The implementation is described in https://github.com/cashapp/spirit/issues/286 It uses performance_schema instead of a heartbeat injection or seconds_behind_source.

Variables

This section is empty.

Functions

This section is empty.

Types

type MySQL80Replica

type MySQL80Replica struct {
	Repl
	// contains filtered or unexported fields
}

func (*MySQL80Replica) Close

func (l *MySQL80Replica) Close() error

func (*MySQL80Replica) Open

func (l *MySQL80Replica) Open() error

Open starts the lag monitor. This is not gh-ost. The lag monitor is primitive because the requirement is only for DR, and not for up-to-date read-replicas. Because chunk-sizes are typically 500ms, getting fine-grained metrics is not realistic. We only check the replica every 5 seconds, and typically allow up to 120s of replica lag, which is a lot.

func (*MySQL80Replica) UpdateLag

func (l *MySQL80Replica) UpdateLag() error

UpdateLag is a MySQL 8.0+ implementation of lag that is a better approximation than "seconds_behind_source". It requires performance_schema to be enabled.

type Noop

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

func (*Noop) BlockWait

func (t *Noop) BlockWait()

func (*Noop) Close

func (t *Noop) Close() error

func (*Noop) IsThrottled

func (t *Noop) IsThrottled() bool

func (*Noop) Open

func (t *Noop) Open() error

func (*Noop) UpdateLag

func (t *Noop) UpdateLag() error

type Repl

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

func (*Repl) BlockWait

func (l *Repl) BlockWait()

BlockWait blocks until the lag is within the tolerance, or up to 60s to allow some progress to be made.

func (*Repl) IsThrottled

func (l *Repl) IsThrottled() bool

type Throttler

type Throttler interface {
	Open() error
	Close() error
	IsThrottled() bool
	BlockWait()
	UpdateLag() error
}

func NewReplicationThrottler

func NewReplicationThrottler(replica *sql.DB, lagTolerance time.Duration, logger loggers.Advanced) (Throttler, error)

NewReplicationThrottler returns a Throttler that is appropriate for the current replica. It will return a MySQL80Replica throttler if the version is detected as 8.0, and a MySQL57Replica throttler otherwise. It returns an error if querying for either fails, i.e. it might not be a valid DB connection.

Jump to

Keyboard shortcuts

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