Skip to content

Commit

Permalink
*: add config item for bind info lease (pingcap#10725) (pingcap#10727)
Browse files Browse the repository at this point in the history
  • Loading branch information
alivxxx authored and zz-jason committed Jun 6, 2019
1 parent ab2fd4d commit 7e6f146
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions bindinfo/handle.go
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Expand Up @@ -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.
Expand Down Expand Up @@ -352,6 +353,7 @@ var defaultConf = Config{
QueryFeedbackLimit: 1024,
PseudoEstimateRatio: 0.8,
ForcePriority: "NO_PRIORITY",
BindInfoLease: "3s",
},
ProxyProtocol: ProxyProtocol{
Networks: "",
Expand Down
3 changes: 3 additions & 0 deletions config/config.toml.example
Expand Up @@ -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.
Expand Down
8 changes: 3 additions & 5 deletions domain/domain.go
Expand Up @@ -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
}

Expand All @@ -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()
Expand All @@ -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 {
Expand All @@ -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()
Expand All @@ -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()
}
Expand Down
2 changes: 2 additions & 0 deletions tidb-server/main.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 7e6f146

Please sign in to comment.