heartbeat

package
v3.0.0-rc.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package heartbeat contains a writer and reader of heartbeats for a master-slave cluster. This is similar to Percona's pt-heartbeat, and is meant to supplement the information returned from SHOW SLAVE STATUS. In some circumstances, lag returned from SHOW SLAVE STATUS is incorrect and is at best only at 1 second resolution. The heartbeat package directly tests replication by writing a record with a timestamp on the master, and comparing that timestamp after reading it on the slave. This happens at the interval defined by heartbeat_interval. Note: the lag reported will be affected by clock drift, so it is recommended to run ntpd or similar.

The data collected by the heartbeat package is made available in /debug/vars in counters prefixed by Heartbeat*. It's additionally used as a source for healthchecks and will impact the serving state of a tablet, if enabled. The heartbeat interval is purposefully kept distinct from the health check interval because lag measurement requires more frequent polling that the healthcheck typically is configured for.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reader

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

Reader reads the heartbeat table at a configured interval in order to calculate replication lag. It is meant to be run on a slave, and paired with a Writer on a master. It's primarily created and launched from Reporter. Lag is calculated by comparing the most recent timestamp in the heartbeat table against the current time at read time. This value is reported in metrics and also to the healthchecks.

func NewReader

func NewReader(checker connpool.MySQLChecker, config tabletenv.TabletConfig) *Reader

NewReader returns a new heartbeat reader.

func (*Reader) Close

func (r *Reader) Close()

Close cancels the watchHeartbeat periodic ticker and closes the db pool. A reader object can be re-opened after closing.

func (*Reader) GetLatest

func (r *Reader) GetLatest() (time.Duration, error)

GetLatest returns the most recently recorded lag measurement or error encountered.

func (*Reader) Init

func (r *Reader) Init(target querypb.Target)

Init does last minute initialization of db settings, such as dbName and keyspaceShard

func (*Reader) InitDBConfig

func (r *Reader) InitDBConfig(dbcfgs *dbconfigs.DBConfigs)

InitDBConfig must be called before Init.

func (*Reader) Open

func (r *Reader) Open()

Open starts the heartbeat ticker and opens the db pool. It may be called multiple times, as long as it was closed since last invocation.

type Writer

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

Writer runs on master tablets and writes heartbeats to the _vt.heartbeat table at a regular interval, defined by heartbeat_interval.

func NewWriter

func NewWriter(checker connpool.MySQLChecker, alias topodatapb.TabletAlias, config tabletenv.TabletConfig) *Writer

NewWriter creates a new Writer.

func (*Writer) Close

func (w *Writer) Close()

Close closes the Writer's db connection and stops the periodic ticker. A writer object can be re-opened after closing.

func (*Writer) Init

func (w *Writer) Init(target querypb.Target) error

Init runs at tablet startup and last minute initialization of db settings, and creates the necessary tables for heartbeat.

func (*Writer) InitDBConfig

func (w *Writer) InitDBConfig(dbcfgs *dbconfigs.DBConfigs)

InitDBConfig must be called before Init.

func (*Writer) Open

func (w *Writer) Open()

Open sets up the Writer's db connection and launches the ticker responsible for periodically writing to the heartbeat table. Open may be called multiple times, as long as it was closed since last invocation.

Jump to

Keyboard shortcuts

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