From 7e6f146cdd8e9ad3272c5407bebabd7c4fb4b5ff Mon Sep 17 00:00:00 2001 From: Haibin Xie Date: Thu, 6 Jun 2019 10:06:26 +0800 Subject: [PATCH] *: add config item for bind info lease (#10725) (#10727) --- bindinfo/handle.go | 3 +++ config/config.go | 2 ++ config/config.toml.example | 3 +++ domain/domain.go | 8 +++----- tidb-server/main.go | 2 ++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bindinfo/handle.go b/bindinfo/handle.go index 2d0712bb5fdb8..5245c9aee57ee 100644 --- a/bindinfo/handle.go +++ b/bindinfo/handle.go @@ -72,6 +72,9 @@ type BindHandle struct { lastUpdateTime types.Time } +// Lease influences the duration of loading bind info and handling invalid bind. +var Lease = 3 * time.Second + type invalidBindRecordMap struct { bindRecord *BindRecord droppedTime time.Time diff --git a/config/config.go b/config/config.go index 85384bce1f56c..743262f950df2 100644 --- a/config/config.go +++ b/config/config.go @@ -187,6 +187,7 @@ type Performance struct { QueryFeedbackLimit uint `toml:"query-feedback-limit" json:"query-feedback-limit"` PseudoEstimateRatio float64 `toml:"pseudo-estimate-ratio" json:"pseudo-estimate-ratio"` ForcePriority string `toml:"force-priority" json:"force-priority"` + BindInfoLease string `toml:"bind-info-lease" json:"bind-info-lease"` } // PlanCache is the PlanCache section of the config. @@ -352,6 +353,7 @@ var defaultConf = Config{ QueryFeedbackLimit: 1024, PseudoEstimateRatio: 0.8, ForcePriority: "NO_PRIORITY", + BindInfoLease: "3s", }, ProxyProtocol: ProxyProtocol{ Networks: "", diff --git a/config/config.toml.example b/config/config.toml.example index 08b490b60df52..0e788b089d689 100644 --- a/config/config.toml.example +++ b/config/config.toml.example @@ -168,6 +168,9 @@ pseudo-estimate-ratio = 0.8 # The value could be "NO_PRIORITY", "LOW_PRIORITY", "HIGH_PRIORITY" or "DELAYED". force-priority = "NO_PRIORITY" +# Bind info lease duration, which influences the duration of loading bind info and handling invalid bind. +bind-info-lease = "3s" + [proxy-protocol] # PROXY protocol acceptable client networks. # Empty string means disable PROXY protocol, * means all networks. diff --git a/domain/domain.go b/domain/domain.go index 8fb37b80b8945..3a1fb6368ffd8 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -794,7 +794,7 @@ func (do *Domain) LoadBindInfoLoop(ctx sessionctx.Context) error { ctx.GetSessionVars().InRestrictedSQL = true do.bindHandle = bindinfo.NewBindHandle(ctx) err := do.bindHandle.Update(true) - if err != nil { + if err != nil || bindinfo.Lease == 0 { return err } @@ -804,7 +804,6 @@ func (do *Domain) LoadBindInfoLoop(ctx sessionctx.Context) error { } func (do *Domain) loadBindInfoLoop() { - duration := 3 * time.Second do.wg.Add(1) go func() { defer do.wg.Done() @@ -813,7 +812,7 @@ func (do *Domain) loadBindInfoLoop() { select { case <-do.exit: return - case <-time.After(duration): + case <-time.After(bindinfo.Lease): } err := do.bindHandle.Update(false) if err != nil { @@ -824,7 +823,6 @@ func (do *Domain) loadBindInfoLoop() { } func (do *Domain) handleInvalidBindTaskLoop() { - handleInvalidTaskDuration := 3 * time.Second do.wg.Add(1) go func() { defer do.wg.Done() @@ -833,7 +831,7 @@ func (do *Domain) handleInvalidBindTaskLoop() { select { case <-do.exit: return - case <-time.After(handleInvalidTaskDuration): + case <-time.After(bindinfo.Lease): } do.bindHandle.DropInvalidBindRecord() } diff --git a/tidb-server/main.go b/tidb-server/main.go index 19d95a04e9702..0c8ed4dba1ba6 100644 --- a/tidb-server/main.go +++ b/tidb-server/main.go @@ -30,6 +30,7 @@ import ( "github.com/pingcap/parser/terror" "github.com/pingcap/pd/client" pumpcli "github.com/pingcap/tidb-tools/tidb-binlog/pump_client" + "github.com/pingcap/tidb/bindinfo" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl" "github.com/pingcap/tidb/domain" @@ -448,6 +449,7 @@ func setGlobalVars() { runtime.GOMAXPROCS(int(cfg.Performance.MaxProcs)) statsLeaseDuration := parseDuration(cfg.Performance.StatsLease) session.SetStatsLease(statsLeaseDuration) + bindinfo.Lease = parseDuration(cfg.Performance.BindInfoLease) domain.RunAutoAnalyze = cfg.Performance.RunAutoAnalyze statistics.FeedbackProbability.Store(cfg.Performance.FeedbackProbability) handle.MaxQueryFeedbackCount.Store(int64(cfg.Performance.QueryFeedbackLimit))