go-vitess.v1: gopkg.in/src-d/go-vitess.v1/vt/vttablet/heartbeat Index | Files

package heartbeat

import "gopkg.in/src-d/go-vitess.v1/vt/vttablet/heartbeat"

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

Package Files

heartbeat.go reader.go writer.go

type Reader Uses

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 Uses

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

NewReader returns a new heartbeat reader.

func (*Reader) Close Uses

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 Uses

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

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

func (*Reader) Init Uses

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

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

func (*Reader) InitDBConfig Uses

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

InitDBConfig must be called before Init.

func (*Reader) IsOpen Uses

func (r *Reader) IsOpen() bool

func (*Reader) Open Uses

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 Uses

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 Uses

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

NewWriter creates a new Writer.

func (*Writer) Close Uses

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 Uses

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 Uses

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

InitDBConfig must be called before Init.

func (*Writer) Open Uses

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.

Package heartbeat imports 19 packages (graph) and is imported by 1 packages. Updated 2019-06-13. Refresh now. Tools for package owners.