From 064986b06c52e963380d9e51bd51854f5a7b4e8b Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Wed, 28 Aug 2024 15:46:48 +0800 Subject: [PATCH] server: skip the engine key when match store label (#8486) (#8573) close tikv/pd#8480 Signed-off-by: ti-chi-bot Signed-off-by: Ryan Leung Co-authored-by: Ryan Leung --- server/api/label_test.go | 35 +++++++++++++++++++++++++++++++++-- server/cluster/cluster.go | 3 +++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/server/api/label_test.go b/server/api/label_test.go index 9acddae8436..2fc2e5eef8f 100644 --- a/server/api/label_test.go +++ b/server/api/label_test.go @@ -17,6 +17,7 @@ package api import ( "context" "fmt" + "strings" . "github.com/pingcap/check" "github.com/pingcap/kvproto/pkg/metapb" @@ -24,6 +25,7 @@ import ( tu "github.com/tikv/pd/pkg/testutil" "github.com/tikv/pd/server" "github.com/tikv/pd/server/config" + "github.com/tikv/pd/server/core" ) var _ = Suite(&testLabelsStoreSuite{}) @@ -264,6 +266,30 @@ func (s *testStrictlyLabelsStoreSuite) TestStoreMatch(c *C) { valid: false, expectError: "key matching the label was not found", }, + { + store: &metapb.Store{ + Id: 3, + Address: "tiflash1", + State: metapb.StoreState_Up, + Labels: []*metapb.StoreLabel{ + { + Key: "zone", + Value: "us-west-1", + }, + { + Key: "disk", + Value: "ssd", + }, + { + Key: core.EngineKey, + Value: core.EngineTiFlash, + }, + }, + Version: "3.0.0", + }, + valid: true, + expectError: "placement rules is disabled", + }, } for _, t := range cases { @@ -271,12 +297,16 @@ func (s *testStrictlyLabelsStoreSuite) TestStoreMatch(c *C) { Header: &pdpb.RequestHeader{ClusterId: s.svr.ClusterID()}, Store: &metapb.Store{ Id: t.store.Id, - Address: fmt.Sprintf("tikv%d", t.store.Id), + Address: t.store.Address, State: t.store.State, Labels: t.store.Labels, Version: t.store.Version, }, }) + if t.store.Address == "tiflash1" { + c.Assert(strings.Contains(resp.GetHeader().GetError().String(), t.expectError), IsTrue) + continue + } if t.valid { c.Assert(err, IsNil) } else { @@ -291,12 +321,13 @@ func (s *testStrictlyLabelsStoreSuite) TestStoreMatch(c *C) { Header: &pdpb.RequestHeader{ClusterId: s.svr.ClusterID()}, Store: &metapb.Store{ Id: t.store.Id, - Address: fmt.Sprintf("tikv%d", t.store.Id), + Address: t.store.Address, State: t.store.State, Labels: t.store.Labels, Version: t.store.Version, }, }) + if t.valid { c.Assert(err, IsNil) } else { diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index efc6be2ae81..a97d4408536 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -1130,6 +1130,9 @@ func (c *RaftCluster) checkStoreLabels(s *core.StoreInfo) error { } for _, label := range s.GetLabels() { key := label.GetKey() + if key == core.EngineKey { + continue + } if _, ok := keysSet[key]; !ok { log.Warn("not found the key match with the store label", zap.Stringer("store", s.GetMeta()),