diff --git a/server/api/label_test.go b/server/api/label_test.go index 91902f14c40..cbb2d213d32 100644 --- a/server/api/label_test.go +++ b/server/api/label_test.go @@ -24,6 +24,7 @@ import ( "github.com/pingcap/kvproto/pkg/pdpb" "github.com/tikv/pd/server" "github.com/tikv/pd/server/config" + "github.com/tikv/pd/server/core" ) var _ = Suite(&testLabelsStoreSuite{}) @@ -260,6 +261,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 { @@ -267,12 +292,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(err.Error(), t.expectError), IsTrue) + continue + } if t.valid { c.Assert(err, IsNil) } else { @@ -287,7 +316,7 @@ 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, diff --git a/server/cluster/cluster.go b/server/cluster/cluster.go index 68cc8dbe758..c557794b1c2 100644 --- a/server/cluster/cluster.go +++ b/server/cluster/cluster.go @@ -1027,6 +1027,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()),