Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei committed Mar 8, 2024
1 parent b5f60c3 commit 36de00e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
10 changes: 5 additions & 5 deletions pkg/bindinfo/binding_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ type fuzzyBindingCache struct {
sql2FuzzyDigest map[string]string // sqlDigest --> fuzzyDigest

// loadBindingFromStorageFunc is used to load binding from storage if cache miss.
loadBindingFromStorageFunc func(sqlDigest string) (Bindings, error)
loadBindingFromStorageFunc func(sctx sessionctx.Context, sqlDigest string) (Bindings, error)
}

func newFuzzyBindingCache(loadBindingFromStorageFunc func(string) (Bindings, error)) FuzzyBindingCache {
func newFuzzyBindingCache(loadBindingFromStorageFunc func(sessionctx.Context, string) (Bindings, error)) FuzzyBindingCache {
return &fuzzyBindingCache{
BindingCache: newBindCache(),
fuzzy2SQLDigests: make(map[string][]string),
Expand All @@ -78,7 +78,7 @@ func (fbc *fuzzyBindingCache) FuzzyMatchingBinding(sctx sessionctx.Context, fuzz
if fbc.loadBindingFromStorageFunc == nil {
return
}
fbc.loadFromStore(missingSQLDigest) // loadFromStore's SetBinding has a Mutex inside, so it's safe to call it without lock
fbc.loadFromStore(sctx, missingSQLDigest) // loadFromStore's SetBinding has a Mutex inside, so it's safe to call it without lock
matchedBinding, isMatched, missingSQLDigest = fbc.getFromMemory(sctx, fuzzyDigest, tableNames, false)
if !isMatched && len(missingSQLDigest) != 0 {
isMissed = true
Expand Down Expand Up @@ -123,10 +123,10 @@ func (fbc *fuzzyBindingCache) getFromMemory(sctx sessionctx.Context, fuzzyDigest
return matchedBinding, isMatched, missingSQLDigest
}

func (fbc *fuzzyBindingCache) loadFromStore(missingSQLDigest []string) {
func (fbc *fuzzyBindingCache) loadFromStore(sctx sessionctx.Context, missingSQLDigest []string) {
for _, sqlDigest := range missingSQLDigest {
start := time.Now()
bindings, err := fbc.loadBindingFromStorageFunc(sqlDigest)
bindings, err := fbc.loadBindingFromStorageFunc(sctx, sqlDigest)
if err != nil {
logutil.BgLogger().Warn("loadBindingFromStorageFunc failed",
zap.String("sqlDigest", sqlDigest),
Expand Down
5 changes: 3 additions & 2 deletions pkg/bindinfo/global_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,11 @@ func (h *globalBindingHandle) Stats(_ *variable.SessionVars) (map[string]any, er
}

// LoadBindingsFromStorageToCache loads global bindings from storage to the memory cache.
func (h *globalBindingHandle) LoadBindingsFromStorage(sqlDigest string) (Bindings, error) {
func (h *globalBindingHandle) LoadBindingsFromStorage(sctx sessionctx.Context, sqlDigest string) (Bindings, error) {
if sqlDigest == "" {
return nil, nil
}
timeout := time.Duration(sctx.GetSessionVars().LoadBindTimeout) * time.Millisecond
resultChan := h.syncBindingSingleflight.DoChan(sqlDigest, func() (any, error) {
return h.loadBindingsFromStorageInternal(sqlDigest)
})
Expand All @@ -704,7 +705,7 @@ func (h *globalBindingHandle) LoadBindingsFromStorage(sqlDigest string) (Binding
return nil, nil
}
return bindings.(Bindings), nil
case <-time.After(1 * time.Second):
case <-time.After(timeout):
return nil, errors.New("load bindings from storage timeout")
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,9 @@ type SessionVars struct {
// See https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_max_execution_time
MaxExecutionTime uint64

// LoadBindTimeout is the timeout for loading the bind info.
LoadBindTimeout uint64

// TiKVClientReadTimeout is the timeout for readonly kv request in milliseconds, 0 means using default value
// See https://github.com/pingcap/tidb/blob/7105505a78fc886c33258caa5813baf197b15247/docs/design/2023-06-30-configurable-kv-timeout.md?plain=1#L14-L15
TiKVClientReadTimeout uint64
Expand Down
7 changes: 7 additions & 0 deletions pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,11 @@ var defaultSysVars = []*SysVar{
s.SetStatusFlag(mysql.ServerStatusNoBackslashEscaped, sqlMode.HasNoBackslashEscapesMode())
return nil
}},
{Scope: ScopeGlobal, Name: TiDBLoadBindTimeout, Value: "200", Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt32, IsHintUpdatableVerfied: false, SetSession: func(s *SessionVars, val string) error {
timeoutMS := tidbOptPositiveInt32(val, 0)
s.LoadBindTimeout = uint64(timeoutMS)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: MaxExecutionTime, Value: "0", Type: TypeUnsigned, MinValue: 0, MaxValue: math.MaxInt32, IsHintUpdatableVerfied: true, SetSession: func(s *SessionVars, val string) error {
timeoutMS := tidbOptPositiveInt32(val, 0)
s.MaxExecutionTime = uint64(timeoutMS)
Expand Down Expand Up @@ -3407,6 +3412,8 @@ const (
MaxExecutionTime = "max_execution_time"
// TiKVClientReadTimeout is the name of the 'tikv_client_read_timeout' system variable.
TiKVClientReadTimeout = "tikv_client_read_timeout"
// TiDBLoadBindTimeout is the name of the 'tidb_load_bind_timeout' system variable.
TiDBLoadBindTimeout = "tidb_load_bind_timeout"
// ReadOnly is the name of the 'read_only' system variable.
ReadOnly = "read_only"
// DefaultAuthPlugin is the name of 'default_authentication_plugin' system variable.
Expand Down

0 comments on commit 36de00e

Please sign in to comment.