Skip to content

Commit

Permalink
This is an automated cherry-pick of #55062
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
hawkingrei authored and ti-chi-bot committed Sep 6, 2024
1 parent 973b215 commit 5fb65bf
Show file tree
Hide file tree
Showing 6 changed files with 1,386 additions and 0 deletions.
80 changes: 80 additions & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/pingcap/tidb/bindinfo"
"github.com/pingcap/tidb/br/pkg/streamhelper"
"github.com/pingcap/tidb/br/pkg/streamhelper/daemon"
<<<<<<< HEAD:domain/domain.go
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/placement"
Expand Down Expand Up @@ -73,6 +74,66 @@ import (
"github.com/pingcap/tidb/util/memoryusagealarm"
"github.com/pingcap/tidb/util/servermemorylimit"
"github.com/pingcap/tidb/util/sqlexec"
=======
"github.com/pingcap/tidb/pkg/bindinfo"
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/ddl"
"github.com/pingcap/tidb/pkg/ddl/placement"
"github.com/pingcap/tidb/pkg/ddl/schematracker"
"github.com/pingcap/tidb/pkg/ddl/systable"
ddlutil "github.com/pingcap/tidb/pkg/ddl/util"
"github.com/pingcap/tidb/pkg/disttask/framework/scheduler"
"github.com/pingcap/tidb/pkg/disttask/framework/storage"
"github.com/pingcap/tidb/pkg/disttask/framework/taskexecutor"
"github.com/pingcap/tidb/pkg/domain/globalconfigsync"
"github.com/pingcap/tidb/pkg/domain/infosync"
"github.com/pingcap/tidb/pkg/domain/resourcegroup"
"github.com/pingcap/tidb/pkg/errno"
"github.com/pingcap/tidb/pkg/infoschema"
infoschema_metrics "github.com/pingcap/tidb/pkg/infoschema/metrics"
"github.com/pingcap/tidb/pkg/infoschema/perfschema"
"github.com/pingcap/tidb/pkg/keyspace"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta"
"github.com/pingcap/tidb/pkg/meta/autoid"
"github.com/pingcap/tidb/pkg/metrics"
"github.com/pingcap/tidb/pkg/owner"
"github.com/pingcap/tidb/pkg/parser"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/parser/terror"
metrics2 "github.com/pingcap/tidb/pkg/planner/core/metrics"
"github.com/pingcap/tidb/pkg/privilege/privileges"
"github.com/pingcap/tidb/pkg/sessionctx"
"github.com/pingcap/tidb/pkg/sessionctx/sessionstates"
"github.com/pingcap/tidb/pkg/sessionctx/sysproctrack"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/statistics/handle"
"github.com/pingcap/tidb/pkg/statistics/handle/autoanalyze"
statslogutil "github.com/pingcap/tidb/pkg/statistics/handle/logutil"
handleutil "github.com/pingcap/tidb/pkg/statistics/handle/util"
"github.com/pingcap/tidb/pkg/store/helper"
"github.com/pingcap/tidb/pkg/ttl/ttlworker"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util"
"github.com/pingcap/tidb/pkg/util/dbterror"
disttaskutil "github.com/pingcap/tidb/pkg/util/disttask"
"github.com/pingcap/tidb/pkg/util/domainutil"
"github.com/pingcap/tidb/pkg/util/engine"
"github.com/pingcap/tidb/pkg/util/etcd"
"github.com/pingcap/tidb/pkg/util/expensivequery"
"github.com/pingcap/tidb/pkg/util/gctuner"
"github.com/pingcap/tidb/pkg/util/globalconn"
"github.com/pingcap/tidb/pkg/util/intest"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/pingcap/tidb/pkg/util/memory"
"github.com/pingcap/tidb/pkg/util/memoryusagealarm"
"github.com/pingcap/tidb/pkg/util/replayer"
"github.com/pingcap/tidb/pkg/util/servermemorylimit"
"github.com/pingcap/tidb/pkg/util/sqlkiller"
"github.com/pingcap/tidb/pkg/util/syncutil"
>>>>>>> b066365ef36 (*: kill auto analyze out of the auto analyze time windows (#55062)):pkg/domain/domain.go
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/txnkv/transaction"
pd "github.com/tikv/pd/client"
Expand Down Expand Up @@ -673,6 +734,24 @@ func (do *Domain) topologySyncerKeeper() {
}
}

// CheckAutoAnalyzeWindows checks the auto analyze windows and kill the auto analyze process if it is not in the window.
func (do *Domain) CheckAutoAnalyzeWindows() {
se, err := do.sysSessionPool.Get()

if err != nil {
logutil.BgLogger().Warn("get system session failed", zap.Error(err))
return
}
// Make sure the session is new.
sctx := se.(sessionctx.Context)
defer do.sysSessionPool.Put(se)
if !autoanalyze.CheckAutoAnalyzeWindow(sctx) {
for _, id := range handleutil.GlobalAutoAnalyzeProcessList.All() {
do.SysProcTracker().KillSysProcess(id)
}
}
}

func (do *Domain) refreshMDLCheckTableInfo() {
se, err := do.sysSessionPool.Get()

Expand Down Expand Up @@ -2097,6 +2176,7 @@ func (do *Domain) updateStatsWorker(ctx sessionctx.Context, owner owner.Manager)
if err != nil {
logutil.BgLogger().Debug("GC stats failed", zap.Error(err))
}
do.CheckAutoAnalyzeWindows()
case <-dumpColStatsUsageTicker.C:
err := statsHandle.DumpColStatsUsageToKV()
if err != nil {
Expand Down
177 changes: 177 additions & 0 deletions pkg/domain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "domain",
srcs = [
"domain.go",
"domain_sysvars.go",
"domainctx.go",
"extract.go",
"historical_stats.go",
"optimize_trace.go",
"plan_replayer.go",
"plan_replayer_dump.go",
"ru_stats.go",
"runaway.go",
"schema_checker.go",
"schema_validator.go",
"sysvar_cache.go",
"test_helper.go",
"topn_slow_query.go",
],
importpath = "github.com/pingcap/tidb/pkg/domain",
visibility = ["//visibility:public"],
deps = [
"//br/pkg/streamhelper",
"//br/pkg/streamhelper/daemon",
"//pkg/bindinfo",
"//pkg/config",
"//pkg/ddl",
"//pkg/ddl/placement",
"//pkg/ddl/schematracker",
"//pkg/ddl/systable",
"//pkg/ddl/util",
"//pkg/disttask/framework/scheduler",
"//pkg/disttask/framework/storage",
"//pkg/disttask/framework/taskexecutor",
"//pkg/domain/globalconfigsync",
"//pkg/domain/infosync",
"//pkg/domain/metrics",
"//pkg/domain/resourcegroup",
"//pkg/errno",
"//pkg/infoschema",
"//pkg/infoschema/metrics",
"//pkg/infoschema/perfschema",
"//pkg/keyspace",
"//pkg/kv",
"//pkg/meta",
"//pkg/meta/autoid",
"//pkg/metrics",
"//pkg/owner",
"//pkg/parser",
"//pkg/parser/ast",
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/parser/terror",
"//pkg/planner/core/metrics",
"//pkg/privilege/privileges",
"//pkg/sessionctx",
"//pkg/sessionctx/sessionstates",
"//pkg/sessionctx/sysproctrack",
"//pkg/sessionctx/variable",
"//pkg/statistics",
"//pkg/statistics/handle",
"//pkg/statistics/handle/autoanalyze",
"//pkg/statistics/handle/logutil",
"//pkg/statistics/handle/util",
"//pkg/store/helper",
"//pkg/ttl/cache",
"//pkg/ttl/sqlbuilder",
"//pkg/ttl/ttlworker",
"//pkg/types",
"//pkg/util",
"//pkg/util/chunk",
"//pkg/util/context",
"//pkg/util/dbterror",
"//pkg/util/disttask",
"//pkg/util/domainutil",
"//pkg/util/engine",
"//pkg/util/etcd",
"//pkg/util/execdetails",
"//pkg/util/expensivequery",
"//pkg/util/gctuner",
"//pkg/util/globalconn",
"//pkg/util/intest",
"//pkg/util/logutil",
"//pkg/util/memory",
"//pkg/util/memoryusagealarm",
"//pkg/util/printer",
"//pkg/util/replayer",
"//pkg/util/servermemorylimit",
"//pkg/util/sqlexec",
"//pkg/util/sqlkiller",
"//pkg/util/syncutil",
"@com_github_burntsushi_toml//:toml",
"@com_github_ngaut_pools//:pools",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pingcap_kvproto//pkg/metapb",
"@com_github_pingcap_kvproto//pkg/pdpb",
"@com_github_pingcap_kvproto//pkg/resource_manager",
"@com_github_pingcap_log//:log",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//oracle",
"@com_github_tikv_client_go_v2//tikv",
"@com_github_tikv_client_go_v2//txnkv/transaction",
"@com_github_tikv_pd_client//:client",
"@com_github_tikv_pd_client//http",
"@com_github_tikv_pd_client//resource_group/controller",
"@io_etcd_go_etcd_client_v3//:client",
"@io_etcd_go_etcd_client_v3//concurrency",
"@org_golang_google_grpc//:grpc",
"@org_golang_google_grpc//backoff",
"@org_golang_google_grpc//keepalive",
"@org_uber_go_atomic//:atomic",
"@org_uber_go_zap//:zap",
],
)

go_test(
name = "domain_test",
timeout = "short",
srcs = [
"db_test.go",
"domain_test.go",
"domain_utils_test.go",
"domainctx_test.go",
"extract_test.go",
"main_test.go",
"plan_replayer_handle_test.go",
"plan_replayer_test.go",
"ru_stats_test.go",
"schema_checker_test.go",
"schema_validator_test.go",
"topn_slow_query_test.go",
],
embed = [":domain"],
flaky = True,
shard_count = 28,
deps = [
"//pkg/config",
"//pkg/ddl",
"//pkg/domain/infosync",
"//pkg/errno",
"//pkg/infoschema",
"//pkg/keyspace",
"//pkg/kv",
"//pkg/metrics",
"//pkg/parser/ast",
"//pkg/parser/auth",
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/parser/terror",
"//pkg/server",
"//pkg/session",
"//pkg/sessionctx/variable",
"//pkg/store/mockstore",
"//pkg/testkit",
"//pkg/testkit/testsetup",
"//pkg/types",
"//pkg/util",
"//pkg/util/mock",
"//pkg/util/replayer",
"//pkg/util/stmtsummary/v2:stmtsummary",
"@com_github_ngaut_pools//:pools",
"@com_github_pingcap_errors//:errors",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_pingcap_kvproto//pkg/metapb",
"@com_github_pingcap_kvproto//pkg/resource_manager",
"@com_github_prometheus_client_model//go",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//oracle",
"@com_github_tikv_client_go_v2//txnkv/transaction",
"@com_github_tikv_pd_client//:client",
"@io_etcd_go_etcd_tests_v3//integration",
"@org_uber_go_goleak//:goleak",
],
)
Loading

0 comments on commit 5fb65bf

Please sign in to comment.