From 4b097bd3894a9972d6a319dab7f81ba77a53a124 Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Mon, 30 Dec 2024 19:21:45 +0800 Subject: [PATCH] planner: fix DATA RACE on global binding (#58618) close pingcap/tidb#58616 --- pkg/domain/domain.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/domain/domain.go b/pkg/domain/domain.go index 174c2cb22d667..adf850f6a7eab 100644 --- a/pkg/domain/domain.go +++ b/pkg/domain/domain.go @@ -146,7 +146,7 @@ type Domain struct { store kv.Storage infoCache *infoschema.InfoCache privHandle *privileges.Handle - bindHandle bindinfo.GlobalBindingHandle + bindHandle atomic.Value statsHandle atomic.Pointer[handle.Handle] statsLease time.Duration ddl ddl.DDL @@ -2080,13 +2080,17 @@ func (do *Domain) PrivilegeHandle() *privileges.Handle { // BindHandle returns domain's bindHandle. func (do *Domain) BindHandle() bindinfo.GlobalBindingHandle { - return do.bindHandle + v := do.bindHandle.Load() + if v == nil { + return nil + } + return v.(bindinfo.GlobalBindingHandle) } // InitBindingHandle create a goroutine loads BindInfo in a loop, it should // be called only once in BootstrapSession. func (do *Domain) InitBindingHandle() error { - do.bindHandle = bindinfo.NewGlobalBindingHandle(do.sysSessionPool) + do.bindHandle.Store(bindinfo.NewGlobalBindingHandle(do.sysSessionPool)) err := do.BindHandle().LoadFromStorageToCache(true) if err != nil || bindinfo.Lease == 0 { return err