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 ¶
GetLatest returns the most recently recorded lag measurement or error encountered.
func (*Reader) Init ¶
Init does last minute initialization of db settings, such as dbName and keyspaceShard
func (*Reader) InitDBConfig ¶
InitDBConfig must be called before Init.
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 ¶
Init runs at tablet startup and last minute initialization of db settings, and creates the necessary tables for heartbeat.
func (*Writer) InitDBConfig ¶
InitDBConfig must be called before Init.