From 7adcba505c3943a0286ee48dfc39640a8a3b66c5 Mon Sep 17 00:00:00 2001 From: Sugu Sougoumarane Date: Tue, 14 Apr 2020 17:39:45 -0700 Subject: [PATCH] yaml: heartbet Signed-off-by: Sugu Sougoumarane --- go/vt/vttablet/heartbeat/reader.go | 7 +++-- go/vt/vttablet/heartbeat/reader_test.go | 2 +- go/vt/vttablet/heartbeat/writer.go | 7 +++-- go/vt/vttablet/heartbeat/writer_test.go | 2 +- .../tabletmanager/heartbeat_reporter.go | 2 +- .../vttablet/tabletserver/tabletenv/config.go | 29 ++++++++++--------- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/go/vt/vttablet/heartbeat/reader.go b/go/vt/vttablet/heartbeat/reader.go index b224c40585f..80b2f08d8fb 100644 --- a/go/vt/vttablet/heartbeat/reader.go +++ b/go/vt/vttablet/heartbeat/reader.go @@ -72,16 +72,17 @@ type Reader struct { // NewReader returns a new heartbeat reader. func NewReader(env tabletenv.Env) *Reader { config := env.Config() - if !config.HeartbeatEnable { + if config.HeartbeatIntervalMilliseconds == 0 { return &Reader{} } + heartbeatInterval := time.Duration(config.HeartbeatIntervalMilliseconds) * time.Millisecond return &Reader{ env: env, enabled: true, now: time.Now, - interval: config.HeartbeatInterval, - ticks: timer.NewTimer(config.HeartbeatInterval), + interval: heartbeatInterval, + ticks: timer.NewTimer(heartbeatInterval), errorLog: logutil.NewThrottledLogger("HeartbeatReporter", 60*time.Second), pool: connpool.New(env, "HeartbeatReadPool", tabletenv.ConnPoolConfig{ Size: 1, diff --git a/go/vt/vttablet/heartbeat/reader_test.go b/go/vt/vttablet/heartbeat/reader_test.go index 3cf1aa666e4..d3d7da107ea 100644 --- a/go/vt/vttablet/heartbeat/reader_test.go +++ b/go/vt/vttablet/heartbeat/reader_test.go @@ -101,7 +101,7 @@ func TestReaderReadHeartbeatError(t *testing.T) { func newReader(db *fakesqldb.DB, nowFunc func() time.Time) *Reader { config := tabletenv.NewDefaultConfig() - config.HeartbeatEnable = true + config.HeartbeatIntervalMilliseconds = 1000 params, _ := db.ConnParams().MysqlParams() cp := *params dbc := dbconfigs.NewTestDBConfigs(cp, cp, "") diff --git a/go/vt/vttablet/heartbeat/writer.go b/go/vt/vttablet/heartbeat/writer.go index 228c622ec0a..ffa3e8f31b6 100644 --- a/go/vt/vttablet/heartbeat/writer.go +++ b/go/vt/vttablet/heartbeat/writer.go @@ -73,16 +73,17 @@ type Writer struct { // NewWriter creates a new Writer. func NewWriter(env tabletenv.Env, alias topodatapb.TabletAlias) *Writer { config := env.Config() - if !config.HeartbeatEnable { + if config.HeartbeatIntervalMilliseconds == 0 { return &Writer{} } + heartbeatInterval := time.Duration(config.HeartbeatIntervalMilliseconds) * time.Millisecond return &Writer{ env: env, enabled: true, tabletAlias: alias, now: time.Now, - interval: config.HeartbeatInterval, - ticks: timer.NewTimer(config.HeartbeatInterval), + interval: heartbeatInterval, + ticks: timer.NewTimer(heartbeatInterval), errorLog: logutil.NewThrottledLogger("HeartbeatWriter", 60*time.Second), pool: connpool.New(env, "HeartbeatWritePool", tabletenv.ConnPoolConfig{ Size: 1, diff --git a/go/vt/vttablet/heartbeat/writer_test.go b/go/vt/vttablet/heartbeat/writer_test.go index 813b22f44b8..d19cce64c36 100644 --- a/go/vt/vttablet/heartbeat/writer_test.go +++ b/go/vt/vttablet/heartbeat/writer_test.go @@ -105,7 +105,7 @@ func TestWriteHeartbeatError(t *testing.T) { func newTestWriter(db *fakesqldb.DB, nowFunc func() time.Time) *Writer { config := tabletenv.NewDefaultConfig() - config.HeartbeatEnable = true + config.HeartbeatIntervalMilliseconds = 1000 params, _ := db.ConnParams().MysqlParams() cp := *params diff --git a/go/vt/vttablet/tabletmanager/heartbeat_reporter.go b/go/vt/vttablet/tabletmanager/heartbeat_reporter.go index 9f9d78fd692..4db1aa8ac0f 100644 --- a/go/vt/vttablet/tabletmanager/heartbeat_reporter.go +++ b/go/vt/vttablet/tabletmanager/heartbeat_reporter.go @@ -34,7 +34,7 @@ type Reporter struct { // RegisterReporter registers the heartbeat reader as a healthcheck reporter so that its // measurements will be picked up in healthchecks. func registerHeartbeatReporter(controller tabletserver.Controller) { - if !tabletenv.NewCurrentConfig().HeartbeatEnable { + if tabletenv.NewCurrentConfig().HeartbeatIntervalMilliseconds == 0 { return } diff --git a/go/vt/vttablet/tabletserver/tabletenv/config.go b/go/vt/vttablet/tabletserver/tabletenv/config.go index c7e7c9fed16..0b8358b4ef6 100644 --- a/go/vt/vttablet/tabletserver/tabletenv/config.go +++ b/go/vt/vttablet/tabletserver/tabletenv/config.go @@ -67,6 +67,8 @@ var ( enableHotRowProtectionDryRun bool enableConsolidator bool enableConsolidatorReplicas bool + enableHeartbeat bool + heartbeatInterval time.Duration ) func init() { @@ -126,8 +128,8 @@ func init() { flag.BoolVar(¤tConfig.TransactionLimitByComponent, "transaction_limit_by_component", defaultConfig.TransactionLimitByComponent, "Include CallerID.component when considering who the user is for the purpose of transaction limit.") flag.BoolVar(¤tConfig.TransactionLimitBySubcomponent, "transaction_limit_by_subcomponent", defaultConfig.TransactionLimitBySubcomponent, "Include CallerID.subcomponent when considering who the user is for the purpose of transaction limit.") - flag.BoolVar(¤tConfig.HeartbeatEnable, "heartbeat_enable", defaultConfig.HeartbeatEnable, "If true, vttablet records (if master) or checks (if replica) the current time of a replication heartbeat in the table _vt.heartbeat. The result is used to inform the serving state of the vttablet via healthchecks.") - flag.DurationVar(¤tConfig.HeartbeatInterval, "heartbeat_interval", defaultConfig.HeartbeatInterval, "How frequently to read and write replication heartbeat.") + flag.BoolVar(&enableHeartbeat, "heartbeat_enable", false, "If true, vttablet records (if master) or checks (if replica) the current time of a replication heartbeat in the table _vt.heartbeat. The result is used to inform the serving state of the vttablet via healthchecks.") + flag.DurationVar(&heartbeatInterval, "heartbeat_interval", 1*time.Second, "How frequently to read and write replication heartbeat.") flag.BoolVar(¤tConfig.EnforceStrictTransTables, "enforce_strict_trans_tables", defaultConfig.EnforceStrictTransTables, "If true, vttablet requires MySQL to run with STRICT_TRANS_TABLES or STRICT_ALL_TABLES on. It is recommended to not turn this flag off. Otherwise MySQL may alter your supplied values before saving them to the database.") flag.BoolVar(&enableConsolidator, "enable-consolidator", true, "This option enables the query consolidator.") @@ -160,6 +162,10 @@ func Init() { currentConfig.Consolidator = Disable } + if enableHeartbeat { + currentConfig.HeartbeatIntervalMilliseconds = int(heartbeatInterval / time.Millisecond) + } + switch *streamlog.QueryLogFormat { case streamlog.QueryLogFormatText: case streamlog.QueryLogFormatJSON: @@ -178,12 +184,13 @@ func Init() { // TabletConfig contains all the configuration for query service type TabletConfig struct { - OltpReadPool ConnPoolConfig `json:"oltpReadPool,omitempty"` - OlapReadPool ConnPoolConfig `json:"olapReadPool,omitempty"` - TxPool ConnPoolConfig `json:"txPool,omitempty"` - Oltp OltpConfig `json:"oltp,omitempty"` - HotRowProtection HotRowProtectionConfig `json:"hotRowProtection,omitempty"` - Consolidator string `json:"consolidator,omitempty"` + OltpReadPool ConnPoolConfig `json:"oltpReadPool,omitempty"` + OlapReadPool ConnPoolConfig `json:"olapReadPool,omitempty"` + TxPool ConnPoolConfig `json:"txPool,omitempty"` + Oltp OltpConfig `json:"oltp,omitempty"` + HotRowProtection HotRowProtectionConfig `json:"hotRowProtection,omitempty"` + Consolidator string `json:"consolidator,omitempty"` + HeartbeatIntervalMilliseconds int `json:"heartbeatIntervalMilliseconds,omitempty"` MessagePostponeCap int `json:"-"` TxShutDownGracePeriod float64 `json:"-"` @@ -206,9 +213,6 @@ type TabletConfig struct { TransactionLimitConfig `json:"-"` - HeartbeatEnable bool `json:"-"` - HeartbeatInterval time.Duration `json:"-"` - EnforceStrictTransTables bool `json:"-"` EnableQueryPlanFieldCaching bool `json:"-"` } @@ -374,9 +378,6 @@ var defaultConfig = TabletConfig{ TransactionLimitConfig: defaultTransactionLimitConfig(), - HeartbeatEnable: false, - HeartbeatInterval: 1 * time.Second, - EnforceStrictTransTables: true, EnableQueryPlanFieldCaching: true, }