From 4e400681bc252b56d5bedcefbe77da69afa9be75 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Thu, 8 Jun 2023 22:02:46 +0800 Subject: [PATCH] domain: avoid using unsafe (#44524) --- domain/domain.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/domain/domain.go b/domain/domain.go index 6563f6c8a4..3fcd2c1d18 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -25,7 +25,6 @@ import ( "sync" "sync/atomic" "time" - "unsafe" "github.com/ngaut/pools" "github.com/pingcap/errors" @@ -126,7 +125,7 @@ type Domain struct { infoCache *infoschema.InfoCache privHandle *privileges.Handle bindHandle atomic.Pointer[bindinfo.BindHandle] - statsHandle unsafe.Pointer + statsHandle atomic.Pointer[handle.Handle] statsLease time.Duration ddl ddl.DDL info *infosync.InfoSyncer @@ -2069,7 +2068,7 @@ func (do *Domain) StartHistoricalStatsWorker() { // StatsHandle returns the statistic handle. func (do *Domain) StatsHandle() *handle.Handle { - return (*handle.Handle)(atomic.LoadPointer(&do.statsHandle)) + return do.statsHandle.Load() } // CreateStatsHandle is used only for test. @@ -2078,7 +2077,7 @@ func (do *Domain) CreateStatsHandle(ctx, initStatsCtx sessionctx.Context) error if err != nil { return err } - atomic.StorePointer(&do.statsHandle, unsafe.Pointer(h)) + do.statsHandle.Store(h) return nil } @@ -2154,7 +2153,7 @@ func (do *Domain) UpdateTableStatsLoop(ctx, initStatsCtx sessionctx.Context) err if err != nil { return err } - atomic.StorePointer(&do.statsHandle, unsafe.Pointer(statsHandle)) + do.statsHandle.Store(statsHandle) do.ddl.RegisterStatsHandle(statsHandle) // Negative stats lease indicates that it is in test, it does not need update. if do.statsLease >= 0 {