From 1a101859b6d4deae1b1f7ecb651f726c8ba3a62a Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 17 Jan 2023 11:37:20 +0800 Subject: [PATCH 1/2] testkit: reset the resource manager after test finishes Signed-off-by: Weizhen Wang --- resourcemanager/rm.go | 5 +++++ testkit/BUILD.bazel | 1 + testkit/mockstore.go | 2 ++ 3 files changed, 8 insertions(+) diff --git a/resourcemanager/rm.go b/resourcemanager/rm.go index aa2af6f949465..f9da72bcdacf4 100644 --- a/resourcemanager/rm.go +++ b/resourcemanager/rm.go @@ -85,3 +85,8 @@ func (r *ResourceManager) registerPool(name string, pool *util.PoolContainer) er func (r *ResourceManager) Unregister(name string) { r.poolMap.Del(name) } + +// Reset is to Reset resource manager. it is just for test. +func (r *ResourceManager) Reset() { + r.poolMap = util.NewShardPoolMap() +} diff --git a/testkit/BUILD.bazel b/testkit/BUILD.bazel index 4e0e24091db27..c28ef0614eb04 100644 --- a/testkit/BUILD.bazel +++ b/testkit/BUILD.bazel @@ -21,6 +21,7 @@ go_library( "//parser/ast", "//parser/terror", "//planner/core", + "//resourcemanager", "//session", "//session/txninfo", "//sessionctx/variable", diff --git a/testkit/mockstore.go b/testkit/mockstore.go index 12afe0e0f2f68..9756d5bb65804 100644 --- a/testkit/mockstore.go +++ b/testkit/mockstore.go @@ -24,6 +24,7 @@ import ( "github.com/pingcap/tidb/ddl/schematracker" "github.com/pingcap/tidb/domain" "github.com/pingcap/tidb/kv" + "github.com/pingcap/tidb/resourcemanager" "github.com/pingcap/tidb/session" "github.com/pingcap/tidb/store/driver" "github.com/pingcap/tidb/store/mockstore" @@ -91,6 +92,7 @@ func bootstrap(t testing.TB, store kv.Storage, lease time.Duration) *domain.Doma err := store.Close() require.NoError(t, err) view.Stop() + resourcemanager.GlobalResourceManager.Reset() }) return dom } From 90f0da6ac63a3454bf0656999187d87f13dca808 Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Tue, 17 Jan 2023 12:39:43 +0800 Subject: [PATCH 2/2] update Signed-off-by: Weizhen Wang --- resourcemanager/BUILD.bazel | 1 + resourcemanager/rm.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/resourcemanager/BUILD.bazel b/resourcemanager/BUILD.bazel index 968a73b4a0f95..c6e7983df34be 100644 --- a/resourcemanager/BUILD.bazel +++ b/resourcemanager/BUILD.bazel @@ -13,6 +13,7 @@ go_library( "//resourcemanager/util", "//util", "//util/cpu", + "@com_github_google_uuid//:uuid", "@com_github_pingcap_log//:log", "@org_uber_go_zap//:zap", ], diff --git a/resourcemanager/rm.go b/resourcemanager/rm.go index f9da72bcdacf4..ed73cda8e1abf 100644 --- a/resourcemanager/rm.go +++ b/resourcemanager/rm.go @@ -17,6 +17,7 @@ package resourcemanager import ( "time" + "github.com/google/uuid" "github.com/pingcap/tidb/resourcemanager/scheduler" "github.com/pingcap/tidb/resourcemanager/util" tidbutil "github.com/pingcap/tidb/util" @@ -26,6 +27,11 @@ import ( // GlobalResourceManager is a global resource manager var GlobalResourceManager = NewResourceManger() +// RandomName is to get a random name for register pool. It is just for test. +func RandomName() string { + return uuid.New().String() +} + // ResourceManager is a resource manager type ResourceManager struct { poolMap *util.ShardPoolMap