Skip to content

Commit

Permalink
refine
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Aug 9, 2024
1 parent 29122de commit 5473978
Show file tree
Hide file tree
Showing 44 changed files with 1,440 additions and 1,297 deletions.
2 changes: 1 addition & 1 deletion pkg/ddl/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ go_library(
"//pkg/disttask/framework/taskexecutor/execute",
"//pkg/disttask/operator",
"//pkg/domain/infosync",
"//pkg/domain/resourcegroup",
"//pkg/errctx",
"//pkg/expression",
"//pkg/expression/context",
Expand Down Expand Up @@ -158,6 +157,7 @@ go_library(
"//pkg/util/memory",
"//pkg/util/mock",
"//pkg/util/ranger",
"//pkg/util/resourcegroup",
"//pkg/util/resourcegrouptag",
"//pkg/util/rowDecoder",
"//pkg/util/rowcodec",
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/pingcap/tidb/pkg/ddl/resourcegroup"
sess "github.com/pingcap/tidb/pkg/ddl/session"
ddlutil "github.com/pingcap/tidb/pkg/ddl/util"
rg "github.com/pingcap/tidb/pkg/domain/resourcegroup"
"github.com/pingcap/tidb/pkg/errctx"
"github.com/pingcap/tidb/pkg/expression"
"github.com/pingcap/tidb/pkg/infoschema"
Expand Down Expand Up @@ -68,6 +67,7 @@ import (
"github.com/pingcap/tidb/pkg/util/generic"
"github.com/pingcap/tidb/pkg/util/intest"
"github.com/pingcap/tidb/pkg/util/mathutil"
rg "github.com/pingcap/tidb/pkg/util/resourcegroup"
"github.com/pingcap/tidb/pkg/util/stringutil"
"github.com/tikv/client-go/v2/oracle"
clientv3 "go.etcd.io/etcd/client/v3"
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ import (
"github.com/pingcap/tidb/pkg/ddl/logutil"
"github.com/pingcap/tidb/pkg/ddl/resourcegroup"
"github.com/pingcap/tidb/pkg/domain/infosync"
rg "github.com/pingcap/tidb/pkg/domain/resourcegroup"
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/meta"
"github.com/pingcap/tidb/pkg/parser/ast"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/util/dbterror"
rg "github.com/pingcap/tidb/pkg/util/resourcegroup"
kvutil "github.com/tikv/client-go/v2/util"
"go.uber.org/zap"
)
Expand Down
12 changes: 6 additions & 6 deletions pkg/ddl/tests/resourcegroup/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,9 @@ func testResourceGroupNameFromIS(t *testing.T, ctx sessionctx.Context, name stri
}

func TestResourceGroupRunaway(t *testing.T) {
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/domain/FastRunawayGC", `return(true)`))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/util/resourcegroup/runaway/FastRunawayGC", `return(true)`))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/domain/FastRunawayGC"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/util/resourcegroup/runaway/FastRunawayGC"))
}()
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
Expand Down Expand Up @@ -361,17 +361,17 @@ func TestResourceGroupRunaway(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/copr/sleepCoprRequest"))

tk.MustExec("create resource group rg4 BURSTABLE RU_PER_SEC=2000 QUERY_LIMIT=(EXEC_ELAPSED='50ms' action KILL WATCH EXACT)")
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/store/copr/sleepCoprAfterReq", fmt.Sprintf("return(%d)", 50)))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/util/resourcegroup/runaway/sleepCoprAfterReq", fmt.Sprintf("return(%d)", 50)))
tk.MustQuery("select /*+ resource_group(rg4) */ * from t").Check(testkit.Rows("1"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/copr/sleepCoprAfterReq"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/util/resourcegroup/runaway/sleepCoprAfterReq"))

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/store/copr/sleepCoprAfterReq", fmt.Sprintf("return(%d)", 60)))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/util/resourcegroup/runaway/sleepCoprAfterReq", fmt.Sprintf("return(%d)", 60)))
err = tk.QueryToErr("select /*+ resource_group(rg4) */ * from t")
require.ErrorContains(t, err, "Query execution was interrupted, identified as runaway query")
tk.MustGetErrCode("select /*+ resource_group(rg4) */ * from t", mysql.ErrResourceGroupQueryRunawayQuarantine)
tk.EventuallyMustQueryAndCheck("select SQL_NO_CACHE resource_group_name, watch_text from mysql.tidb_runaway_watch", nil,
testkit.Rows("rg3 select /*+ resource_group(rg3) */ * from t", "rg4 select /*+ resource_group(rg4) */ * from t"), maxWaitDuration, tryInterval)
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/copr/sleepCoprAfterReq"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/util/resourcegroup/runaway/sleepCoprAfterReq"))
}

func TestAlreadyExistsDefaultResourceGroup(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/distsql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ go_test(
shard_count = 27,
deps = [
"//pkg/distsql/context",
"//pkg/domain/resourcegroup",
"//pkg/errctx",
"//pkg/kv",
"//pkg/parser/charset",
Expand All @@ -94,6 +93,7 @@ go_test(
"//pkg/util/mock",
"//pkg/util/paging",
"//pkg/util/ranger",
"//pkg/util/resourcegroup",
"@com_github_pingcap_tipb//go-tipb",
"@com_github_stretchr_testify//require",
"@com_github_tikv_client_go_v2//kv",
Expand Down
2 changes: 1 addition & 1 deletion pkg/distsql/context/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ go_library(
importpath = "github.com/pingcap/tidb/pkg/distsql/context",
visibility = ["//visibility:public"],
deps = [
"//pkg/domain/resourcegroup",
"//pkg/errctx",
"//pkg/kv",
"//pkg/parser/mysql",
"//pkg/util/context",
"//pkg/util/execdetails",
"//pkg/util/memory",
"//pkg/util/resourcegroup",
"//pkg/util/sqlkiller",
"//pkg/util/tiflash",
"//pkg/util/topsql/stmtstats",
Expand Down
4 changes: 2 additions & 2 deletions pkg/distsql/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ package context
import (
"time"

"github.com/pingcap/tidb/pkg/domain/resourcegroup"
"github.com/pingcap/tidb/pkg/errctx"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/parser/mysql"
contextutil "github.com/pingcap/tidb/pkg/util/context"
"github.com/pingcap/tidb/pkg/util/execdetails"
"github.com/pingcap/tidb/pkg/util/memory"
"github.com/pingcap/tidb/pkg/util/resourcegroup"
"github.com/pingcap/tidb/pkg/util/sqlkiller"
"github.com/pingcap/tidb/pkg/util/tiflash"
"github.com/pingcap/tidb/pkg/util/topsql/stmtstats"
Expand Down Expand Up @@ -75,7 +75,7 @@ type DistSQLContext struct {
StoreBatchSize int
ResourceGroupName string
LoadBasedReplicaReadThreshold time.Duration
RunawayChecker *resourcegroup.RunawayChecker
RunawayChecker resourcegroup.RunawayChecker
TiKVClientReadTimeout uint64

ReplicaClosestReadThreshold int64
Expand Down
2 changes: 1 addition & 1 deletion pkg/distsql/request_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"testing"
"time"

"github.com/pingcap/tidb/pkg/domain/resourcegroup"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
Expand All @@ -30,6 +29,7 @@ import (
"github.com/pingcap/tidb/pkg/util/memory"
"github.com/pingcap/tidb/pkg/util/paging"
"github.com/pingcap/tidb/pkg/util/ranger"
"github.com/pingcap/tidb/pkg/util/resourcegroup"
"github.com/pingcap/tipb/go-tipb"
"github.com/stretchr/testify/require"
)
Expand Down
5 changes: 1 addition & 4 deletions pkg/domain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ go_library(
"//pkg/domain/globalconfigsync",
"//pkg/domain/infosync",
"//pkg/domain/metrics",
"//pkg/domain/resourcegroup",
"//pkg/errno",
"//pkg/infoschema",
"//pkg/infoschema/metrics",
Expand Down Expand Up @@ -65,8 +64,6 @@ go_library(
"//pkg/statistics/handle/logutil",
"//pkg/statistics/handle/util",
"//pkg/store/helper",
"//pkg/ttl/cache",
"//pkg/ttl/sqlbuilder",
"//pkg/ttl/ttlworker",
"//pkg/types",
"//pkg/util",
Expand All @@ -87,6 +84,7 @@ go_library(
"//pkg/util/memoryusagealarm",
"//pkg/util/printer",
"//pkg/util/replayer",
"//pkg/util/resourcegroup/runaway",
"//pkg/util/servermemorylimit",
"//pkg/util/sqlexec",
"//pkg/util/sqlkiller",
Expand All @@ -97,7 +95,6 @@ go_library(
"@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",
Expand Down
7 changes: 3 additions & 4 deletions pkg/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ import (
"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"
Expand Down Expand Up @@ -89,6 +88,7 @@ import (
"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/resourcegroup/runaway"
"github.com/pingcap/tidb/pkg/util/servermemorylimit"
"github.com/pingcap/tidb/pkg/util/sqlkiller"
"github.com/pingcap/tidb/pkg/util/syncutil"
Expand Down Expand Up @@ -191,8 +191,7 @@ type Domain struct {
logBackupAdvancer *daemon.OwnerDaemon
historicalStatsWorker *HistoricalStatsWorker
ttlJobManager atomic.Pointer[ttlworker.JobManager]
runawayManager *resourcegroup.RunawayManager
runawaySyncer *runawaySyncer
runawayManager *runaway.Manager
resourceGroupsController *rmclient.ResourceGroupsController

serverID uint64
Expand Down Expand Up @@ -2072,7 +2071,7 @@ func (do *Domain) SetupPlanReplayerHandle(collectorSctx sessionctx.Context, work
}

// RunawayManager returns the runaway manager.
func (do *Domain) RunawayManager() *resourcegroup.RunawayManager {
func (do *Domain) RunawayManager() *runaway.Manager {
return do.runawayManager
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/infosync/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ go_library(
"//pkg/ddl/label",
"//pkg/ddl/placement",
"//pkg/ddl/util",
"//pkg/domain/resourcegroup",
"//pkg/errno",
"//pkg/kv",
"//pkg/metrics",
Expand All @@ -38,6 +37,7 @@ go_library(
"//pkg/util/engine",
"//pkg/util/hack",
"//pkg/util/logutil",
"//pkg/util/resourcegroup",
"//pkg/util/syncutil",
"//pkg/util/versioninfo",
"@com_github_golang_protobuf//proto",
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"github.com/pingcap/tidb/pkg/ddl/label"
"github.com/pingcap/tidb/pkg/ddl/placement"
"github.com/pingcap/tidb/pkg/ddl/util"
"github.com/pingcap/tidb/pkg/domain/resourcegroup"
"github.com/pingcap/tidb/pkg/errno"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/metrics"
Expand All @@ -52,6 +51,7 @@ import (
"github.com/pingcap/tidb/pkg/util/engine"
"github.com/pingcap/tidb/pkg/util/hack"
"github.com/pingcap/tidb/pkg/util/logutil"
"github.com/pingcap/tidb/pkg/util/resourcegroup"
"github.com/pingcap/tidb/pkg/util/versioninfo"
"github.com/tikv/client-go/v2/oracle"
"github.com/tikv/client-go/v2/tikv"
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/infosync/resource_manager_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/pingcap/kvproto/pkg/meta_storagepb"
rmpb "github.com/pingcap/kvproto/pkg/resource_manager"
"github.com/pingcap/tidb/pkg/domain/resourcegroup"
"github.com/pingcap/tidb/pkg/util/resourcegroup"
pd "github.com/tikv/pd/client"
)

Expand Down
Loading

0 comments on commit 5473978

Please sign in to comment.