From fa644aea0cf15cc0c789d01a32150b0f1cc01e48 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 6 Aug 2024 12:35:08 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #8486 close tikv/pd#8480 Signed-off-by: ti-chi-bot --- server/api/label_test.go | 37 +++++++++++++++++++++++++++++++++++-- server/cluster/cluster.go | 3 +++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/server/api/label_test.go b/server/api/label_test.go index 9bcd40aac01..68b5a07b618 100644 --- a/server/api/label_test.go +++ b/server/api/label_test.go @@ -22,6 +22,11 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/suite" +<<<<<<< HEAD +======= + "github.com/tikv/pd/pkg/core" + "github.com/tikv/pd/pkg/response" +>>>>>>> c8ad186c3 (server: skip the engine key when match store label (#8486)) tu "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server" "github.com/tikv/pd/server/config" @@ -274,6 +279,30 @@ func (suite *strictlyLabelsStoreTestSuite) TestStoreMatch() { 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 _, testCase := range testCases { @@ -281,12 +310,16 @@ func (suite *strictlyLabelsStoreTestSuite) TestStoreMatch() { Header: &pdpb.RequestHeader{ClusterId: suite.svr.ClusterID()}, Store: &metapb.Store{ Id: testCase.store.Id, - Address: fmt.Sprintf("tikv%d", testCase.store.Id), + Address: testCase.store.Address, State: testCase.store.State, Labels: testCase.store.Labels, Version: testCase.store.Version, }, }) + if testCase.store.Address == "tiflash1" { + re.Contains(resp.GetHeader().GetError().String(), testCase.expectError) + continue + } if testCase.valid { suite.NoError(err) suite.Nil(resp.GetHeader().GetError()) @@ -306,7 +339,7 @@ func (suite *strictlyLabelsStoreTestSuite) TestStoreMatch() { Header: &pdpb.RequestHeader{ClusterId: suite.svr.ClusterID()}, Store: &metapb.Store{ Id: testCase.store.Id, - Address: fmt.Sprintf("tikv%d", testCase.store.Id), + Address: testCase.store.Address, State: testCase.store.State, Labels: testCase.store.Labels, Version: testCase.store.Version, diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 660e7347bd2..3ed7718f69a 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -1379,6 +1379,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()), From a0bec547cf024dd4a1559bfb824a8affae446e1c Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Tue, 27 Aug 2024 16:39:18 +0800 Subject: [PATCH 2/2] fix Signed-off-by: Ryan Leung --- server/api/label_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/server/api/label_test.go b/server/api/label_test.go index 68b5a07b618..3de04720379 100644 --- a/server/api/label_test.go +++ b/server/api/label_test.go @@ -22,11 +22,7 @@ import ( "github.com/pingcap/kvproto/pkg/metapb" "github.com/pingcap/kvproto/pkg/pdpb" "github.com/stretchr/testify/suite" -<<<<<<< HEAD -======= "github.com/tikv/pd/pkg/core" - "github.com/tikv/pd/pkg/response" ->>>>>>> c8ad186c3 (server: skip the engine key when match store label (#8486)) tu "github.com/tikv/pd/pkg/utils/testutil" "github.com/tikv/pd/server" "github.com/tikv/pd/server/config" @@ -317,7 +313,7 @@ func (suite *strictlyLabelsStoreTestSuite) TestStoreMatch() { }, }) if testCase.store.Address == "tiflash1" { - re.Contains(resp.GetHeader().GetError().String(), testCase.expectError) + suite.Contains(resp.GetHeader().GetError().String(), testCase.expectError) continue } if testCase.valid {