From 14669af2b3c0c013bdd5e36f578ebb31e0a45588 Mon Sep 17 00:00:00 2001 From: aiden <62856980+aidendou@users.noreply.github.com> Date: Sat, 12 Aug 2023 04:13:57 -0700 Subject: [PATCH 1/2] This is an automated cherry-pick of #45802 Signed-off-by: ti-chi-bot --- domain/BUILD.bazel | 3 +++ domain/domain.go | 41 +++++++++++++++++++++++++++++++++++------ domain/domain_test.go | 14 ++++++++++++++ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/domain/BUILD.bazel b/domain/BUILD.bazel index 56e3bffedde31..88ea6a98a728a 100644 --- a/domain/BUILD.bazel +++ b/domain/BUILD.bazel @@ -113,13 +113,16 @@ go_test( "//metrics", "//parser/ast", "//parser/model", + "//parser/mysql", "//parser/terror", "//server", "//session", + "//sessionctx/stmtctx", "//sessionctx/variable", "//store/mockstore", "//testkit", "//testkit/testsetup", + "//types", "//util", "//util/mock", "@com_github_ngaut_pools//:pools", diff --git a/domain/domain.go b/domain/domain.go index f01cbbfb326bd..d55c398394155 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -112,6 +112,7 @@ type Domain struct { expensiveQueryHandle *expensivequery.Handle memoryUsageAlarmHandle *memoryusagealarm.Handle serverMemoryLimitHandle *servermemorylimit.Handle +<<<<<<< HEAD wg util.WaitGroupWrapper statsUpdating atomicutil.Int32 cancel context.CancelFunc @@ -122,6 +123,29 @@ type Domain struct { logBackupAdvancer *daemon.OwnerDaemon historicalStatsWorker *HistoricalStatsWorker ttlJobManager *ttlworker.JobManager +======= + // TODO: use Run for each process in future pr + wg *util.WaitGroupEnhancedWrapper + statsUpdating atomicutil.Int32 + cancel context.CancelFunc + indexUsageSyncLease time.Duration + dumpFileGcChecker *dumpFileGcChecker + planReplayerHandle *planReplayerHandle + extractTaskHandle *ExtractHandle + expiredTimeStamp4PC struct { + // let `expiredTimeStamp4PC` use its own lock to avoid any block across domain.Reload() + // and compiler.Compile(), see issue https://github.com/pingcap/tidb/issues/45400 + sync.RWMutex + expiredTimeStamp types.Time + } + + logBackupAdvancer *daemon.OwnerDaemon + historicalStatsWorker *HistoricalStatsWorker + ttlJobManager atomic.Pointer[ttlworker.JobManager] + runawayManager *resourcegroup.RunawayManager + runawaySyncer *runawaySyncer + resourceGroupsController *rmclient.ResourceGroupsController +>>>>>>> 29727caacb8 (domain: use dedicated lock for expiredTimeStamp4PC (#45802)) serverID uint64 serverIDSession *concurrency.Session @@ -394,18 +418,18 @@ func (do *Domain) GetSnapshotMeta(startTS uint64) (*meta.Meta, error) { // ExpiredTimeStamp4PC gets expiredTimeStamp4PC from domain. func (do *Domain) ExpiredTimeStamp4PC() types.Time { - do.m.Lock() - defer do.m.Unlock() + do.expiredTimeStamp4PC.RLock() + defer do.expiredTimeStamp4PC.RUnlock() - return do.expiredTimeStamp4PC + return do.expiredTimeStamp4PC.expiredTimeStamp } // SetExpiredTimeStamp4PC sets the expiredTimeStamp4PC from domain. func (do *Domain) SetExpiredTimeStamp4PC(time types.Time) { - do.m.Lock() - defer do.m.Unlock() + do.expiredTimeStamp4PC.Lock() + defer do.expiredTimeStamp4PC.Unlock() - do.expiredTimeStamp4PC = time + do.expiredTimeStamp4PC.expiredTimeStamp = time } // DDL gets DDL from domain. @@ -897,8 +921,12 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio infoCache: infoschema.NewCache(16), slowQuery: newTopNSlowQueries(30, time.Hour*24*7, 500), indexUsageSyncLease: idxUsageSyncLease, +<<<<<<< HEAD dumpFileGcChecker: &dumpFileGcChecker{gcLease: dumpFileGcLease, paths: []string{GetPlanReplayerDirName(), GetOptimizerTraceDirName()}}, expiredTimeStamp4PC: types.NewTime(types.ZeroCoreTime, mysql.TypeTimestamp, types.DefaultFsp), +======= + dumpFileGcChecker: &dumpFileGcChecker{gcLease: dumpFileGcLease, paths: []string{replayer.GetPlanReplayerDirName(), GetOptimizerTraceDirName(), GetExtractTaskDirName()}}, +>>>>>>> 29727caacb8 (domain: use dedicated lock for expiredTimeStamp4PC (#45802)) mdlCheckTableInfo: &mdlCheckTableInfo{ mu: sync.Mutex{}, jobsVerMap: make(map[int64]int64), @@ -913,6 +941,7 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio do.serverMemoryLimitHandle = servermemorylimit.NewServerMemoryLimitHandle(do.exit) do.sysProcesses = SysProcesses{mu: &sync.RWMutex{}, procMap: make(map[uint64]sessionctx.Context)} do.initDomainSysVars() + do.expiredTimeStamp4PC.expiredTimeStamp = types.NewTime(types.ZeroCoreTime, mysql.TypeTimestamp, types.DefaultFsp) return do } diff --git a/domain/domain_test.go b/domain/domain_test.go index bd9287fe730ec..5ae256a277fb4 100644 --- a/domain/domain_test.go +++ b/domain/domain_test.go @@ -34,8 +34,11 @@ import ( "github.com/pingcap/tidb/metrics" "github.com/pingcap/tidb/parser/ast" "github.com/pingcap/tidb/parser/model" + "github.com/pingcap/tidb/parser/mysql" + "github.com/pingcap/tidb/sessionctx/stmtctx" "github.com/pingcap/tidb/sessionctx/variable" "github.com/pingcap/tidb/store/mockstore" + "github.com/pingcap/tidb/types" "github.com/pingcap/tidb/util/mock" dto "github.com/prometheus/client_model/go" "github.com/stretchr/testify/require" @@ -187,6 +190,17 @@ func TestStatWorkRecoverFromPanic(t *testing.T) { scope := dom.GetScope("status") require.Equal(t, variable.DefaultStatusVarScopeFlag, scope) + // default expiredTimeStamp4PC = "0000-00-00 00:00:00" + ts := types.NewTime(types.ZeroCoreTime, mysql.TypeTimestamp, types.DefaultFsp) + expiredTimeStamp := dom.ExpiredTimeStamp4PC() + require.Equal(t, expiredTimeStamp, ts) + + // set expiredTimeStamp4PC to "2023-08-02 12:15:00" + ts, _ = types.ParseTimestamp(&stmtctx.StatementContext{TimeZone: time.UTC}, "2023-08-02 12:15:00") + dom.SetExpiredTimeStamp4PC(ts) + expiredTimeStamp = dom.ExpiredTimeStamp4PC() + require.Equal(t, expiredTimeStamp, ts) + err = store.Close() require.NoError(t, err) From 8687d35adb00d124672139f8b7bbbb43639ee028 Mon Sep 17 00:00:00 2001 From: Jack Yu Date: Fri, 18 Aug 2023 11:08:48 +0800 Subject: [PATCH 2/2] resolve conflicts Signed-off-by: Jack Yu --- domain/domain.go | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/domain/domain.go b/domain/domain.go index d55c398394155..67ec0eb3f5449 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -112,40 +112,21 @@ type Domain struct { expensiveQueryHandle *expensivequery.Handle memoryUsageAlarmHandle *memoryusagealarm.Handle serverMemoryLimitHandle *servermemorylimit.Handle -<<<<<<< HEAD wg util.WaitGroupWrapper statsUpdating atomicutil.Int32 cancel context.CancelFunc indexUsageSyncLease time.Duration dumpFileGcChecker *dumpFileGcChecker planReplayerHandle *planReplayerHandle - expiredTimeStamp4PC types.Time - logBackupAdvancer *daemon.OwnerDaemon - historicalStatsWorker *HistoricalStatsWorker - ttlJobManager *ttlworker.JobManager -======= - // TODO: use Run for each process in future pr - wg *util.WaitGroupEnhancedWrapper - statsUpdating atomicutil.Int32 - cancel context.CancelFunc - indexUsageSyncLease time.Duration - dumpFileGcChecker *dumpFileGcChecker - planReplayerHandle *planReplayerHandle - extractTaskHandle *ExtractHandle - expiredTimeStamp4PC struct { + expiredTimeStamp4PC struct { // let `expiredTimeStamp4PC` use its own lock to avoid any block across domain.Reload() // and compiler.Compile(), see issue https://github.com/pingcap/tidb/issues/45400 sync.RWMutex expiredTimeStamp types.Time } - - logBackupAdvancer *daemon.OwnerDaemon - historicalStatsWorker *HistoricalStatsWorker - ttlJobManager atomic.Pointer[ttlworker.JobManager] - runawayManager *resourcegroup.RunawayManager - runawaySyncer *runawaySyncer - resourceGroupsController *rmclient.ResourceGroupsController ->>>>>>> 29727caacb8 (domain: use dedicated lock for expiredTimeStamp4PC (#45802)) + logBackupAdvancer *daemon.OwnerDaemon + historicalStatsWorker *HistoricalStatsWorker + ttlJobManager *ttlworker.JobManager serverID uint64 serverIDSession *concurrency.Session @@ -921,12 +902,7 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio infoCache: infoschema.NewCache(16), slowQuery: newTopNSlowQueries(30, time.Hour*24*7, 500), indexUsageSyncLease: idxUsageSyncLease, -<<<<<<< HEAD dumpFileGcChecker: &dumpFileGcChecker{gcLease: dumpFileGcLease, paths: []string{GetPlanReplayerDirName(), GetOptimizerTraceDirName()}}, - expiredTimeStamp4PC: types.NewTime(types.ZeroCoreTime, mysql.TypeTimestamp, types.DefaultFsp), -======= - dumpFileGcChecker: &dumpFileGcChecker{gcLease: dumpFileGcLease, paths: []string{replayer.GetPlanReplayerDirName(), GetOptimizerTraceDirName(), GetExtractTaskDirName()}}, ->>>>>>> 29727caacb8 (domain: use dedicated lock for expiredTimeStamp4PC (#45802)) mdlCheckTableInfo: &mdlCheckTableInfo{ mu: sync.Mutex{}, jobsVerMap: make(map[int64]int64),