From b07200812829fa8b2322d665dc45a5f4e28963d1 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 6 Dec 2022 17:28:03 +0800 Subject: [PATCH 1/2] statistics: reduce the call times of `DefaultAntiCount` (#5760) ref tikv/pd#5692 Signed-off-by: Ryan Leung --- server/statistics/hot_peer_cache.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/statistics/hot_peer_cache.go b/server/statistics/hot_peer_cache.go index 1b0a1481d90..b55df21133e 100644 --- a/server/statistics/hot_peer_cache.go +++ b/server/statistics/hot_peer_cache.go @@ -98,11 +98,12 @@ func NewHotPeerCache(kind RWType) *hotPeerCache { // RegionStats returns hot items func (f *hotPeerCache) RegionStats(minHotDegree int) map[uint64][]*HotPeerStat { res := make(map[uint64][]*HotPeerStat) + defaultAntiCount := f.kind.DefaultAntiCount() for storeID, peers := range f.peersOfStore { values := peers.GetAll() stat := make([]*HotPeerStat, 0, len(values)) for _, v := range values { - if peer := v.(*HotPeerStat); peer.HotDegree >= minHotDegree && !peer.inCold && peer.AntiCount == f.kind.DefaultAntiCount() { + if peer := v.(*HotPeerStat); peer.HotDegree >= minHotDegree && !peer.inCold && peer.AntiCount == defaultAntiCount { stat = append(stat, peer) } } From 268c2b675a6a65df30819e7421ded8f5d98c83c7 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Thu, 8 Dec 2022 14:52:04 +0800 Subject: [PATCH 2/2] pkg: move the election to pkg (#5767) ref tikv/pd#5766 Signed-off-by: Ryan Leung --- {server => pkg}/election/leadership.go | 0 {server => pkg}/election/leadership_test.go | 0 {server => pkg}/election/lease.go | 0 {server => pkg}/election/lease_test.go | 0 server/encryptionkm/key_manager.go | 2 +- server/encryptionkm/key_manager_test.go | 2 +- server/member/member.go | 2 +- server/tso/allocator_manager.go | 2 +- server/tso/global_allocator.go | 2 +- server/tso/local_allocator.go | 2 +- server/tso/tso.go | 2 +- 11 files changed, 7 insertions(+), 7 deletions(-) rename {server => pkg}/election/leadership.go (100%) rename {server => pkg}/election/leadership_test.go (100%) rename {server => pkg}/election/lease.go (100%) rename {server => pkg}/election/lease_test.go (100%) diff --git a/server/election/leadership.go b/pkg/election/leadership.go similarity index 100% rename from server/election/leadership.go rename to pkg/election/leadership.go diff --git a/server/election/leadership_test.go b/pkg/election/leadership_test.go similarity index 100% rename from server/election/leadership_test.go rename to pkg/election/leadership_test.go diff --git a/server/election/lease.go b/pkg/election/lease.go similarity index 100% rename from server/election/lease.go rename to pkg/election/lease.go diff --git a/server/election/lease_test.go b/pkg/election/lease_test.go similarity index 100% rename from server/election/lease_test.go rename to pkg/election/lease_test.go diff --git a/server/encryptionkm/key_manager.go b/server/encryptionkm/key_manager.go index 671034721bf..3e5128e3b9e 100644 --- a/server/encryptionkm/key_manager.go +++ b/server/encryptionkm/key_manager.go @@ -22,11 +22,11 @@ import ( "github.com/gogo/protobuf/proto" "github.com/pingcap/kvproto/pkg/encryptionpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/encryption" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/etcdutil" "github.com/tikv/pd/pkg/syncutil" - "github.com/tikv/pd/server/election" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/mvcc/mvccpb" "go.uber.org/zap" diff --git a/server/encryptionkm/key_manager_test.go b/server/encryptionkm/key_manager_test.go index 714b4f1f980..a8b16caad18 100644 --- a/server/encryptionkm/key_manager_test.go +++ b/server/encryptionkm/key_manager_test.go @@ -28,12 +28,12 @@ import ( "github.com/gogo/protobuf/proto" "github.com/pingcap/kvproto/pkg/encryptionpb" "github.com/stretchr/testify/require" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/encryption" "github.com/tikv/pd/pkg/etcdutil" "github.com/tikv/pd/pkg/tempurl" "github.com/tikv/pd/pkg/typeutil" "github.com/tikv/pd/server/core" - "github.com/tikv/pd/server/election" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/embed" ) diff --git a/server/member/member.go b/server/member/member.go index 470ee6330b1..ba31262e71e 100644 --- a/server/member/member.go +++ b/server/member/member.go @@ -29,10 +29,10 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/etcdutil" "github.com/tikv/pd/server/config" - "github.com/tikv/pd/server/election" "github.com/tikv/pd/server/storage/kv" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/embed" diff --git a/server/tso/allocator_manager.go b/server/tso/allocator_manager.go index 8ce1b898287..3dbe86fbb40 100644 --- a/server/tso/allocator_manager.go +++ b/server/tso/allocator_manager.go @@ -28,13 +28,13 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/etcdutil" "github.com/tikv/pd/pkg/grpcutil" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/syncutil" "github.com/tikv/pd/server/config" - "github.com/tikv/pd/server/election" "github.com/tikv/pd/server/member" "github.com/tikv/pd/server/storage/kv" "go.etcd.io/etcd/clientv3" diff --git a/server/tso/global_allocator.go b/server/tso/global_allocator.go index 8e035808317..54682fa767f 100644 --- a/server/tso/global_allocator.go +++ b/server/tso/global_allocator.go @@ -25,11 +25,11 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/slice" "github.com/tikv/pd/pkg/tsoutil" "github.com/tikv/pd/pkg/typeutil" - "github.com/tikv/pd/server/election" "go.uber.org/zap" "google.golang.org/grpc" ) diff --git a/server/tso/local_allocator.go b/server/tso/local_allocator.go index a18ebf960bc..43369dddc09 100644 --- a/server/tso/local_allocator.go +++ b/server/tso/local_allocator.go @@ -22,10 +22,10 @@ import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/tsoutil" "github.com/tikv/pd/pkg/typeutil" - "github.com/tikv/pd/server/election" "go.etcd.io/etcd/clientv3" "go.uber.org/zap" ) diff --git a/server/tso/tso.go b/server/tso/tso.go index a19252962e9..57d6bd97476 100644 --- a/server/tso/tso.go +++ b/server/tso/tso.go @@ -24,12 +24,12 @@ import ( "github.com/pingcap/failpoint" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/pingcap/log" + "github.com/tikv/pd/pkg/election" "github.com/tikv/pd/pkg/errs" "github.com/tikv/pd/pkg/etcdutil" "github.com/tikv/pd/pkg/syncutil" "github.com/tikv/pd/pkg/tsoutil" "github.com/tikv/pd/pkg/typeutil" - "github.com/tikv/pd/server/election" "go.etcd.io/etcd/clientv3" "go.uber.org/zap" )