Skip to content

Commit

Permalink
This is an automated cherry-pick of tikv#8486
Browse files Browse the repository at this point in the history
close tikv#8480

Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
rleungx authored and ti-chi-bot committed Aug 27, 2024
1 parent ea57f5e commit 271f445
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
56 changes: 56 additions & 0 deletions server/api/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
<<<<<<< HEAD

Check failure on line 24 in server/api/label_test.go

View workflow job for this annotation

GitHub Actions / statics

expected 'STRING', found '<<'

Check failure on line 24 in server/api/label_test.go

View workflow job for this annotation

GitHub Actions / statics

expected 'STRING', found '<<'
tu "github.com/tikv/pd/pkg/testutil"
=======
"github.com/stretchr/testify/suite"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/pkg/response"
tu "github.com/tikv/pd/pkg/utils/testutil"
>>>>>>> c8ad186c3 (server: skip the engine key when match store label (#8486))
"github.com/tikv/pd/server"
"github.com/tikv/pd/server/config"
)
Expand Down Expand Up @@ -264,12 +271,37 @@ 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 {
resp, err := s.grpcSvr.PutStore(context.Background(), &pdpb.PutStoreRequest{
Header: &pdpb.RequestHeader{ClusterId: s.svr.ClusterID()},
Store: &metapb.Store{
<<<<<<< HEAD
Id: t.store.Id,
Address: fmt.Sprintf("tikv%d", t.store.Id),
State: t.store.State,
Expand All @@ -279,6 +311,22 @@ func (s *testStrictlyLabelsStoreSuite) TestStoreMatch(c *C) {
})
if t.valid {
c.Assert(err, IsNil)
=======
Id: 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 {
re.NoError(err)
re.Nil(resp.GetHeader().GetError())
>>>>>>> c8ad186c3 (server: skip the engine key when match store label (#8486))
} else {
c.Assert(resp.GetHeader().GetError(), NotNil)
}
Expand All @@ -290,11 +338,19 @@ func (s *testStrictlyLabelsStoreSuite) TestStoreMatch(c *C) {
resp, err := s.grpcSvr.PutStore(context.Background(), &pdpb.PutStoreRequest{
Header: &pdpb.RequestHeader{ClusterId: s.svr.ClusterID()},
Store: &metapb.Store{
<<<<<<< HEAD
Id: t.store.Id,
Address: fmt.Sprintf("tikv%d", t.store.Id),
State: t.store.State,
Labels: t.store.Labels,
Version: t.store.Version,
=======
Id: testCase.store.Id,
Address: testCase.store.Address,
State: testCase.store.State,
Labels: testCase.store.Labels,
Version: testCase.store.Version,
>>>>>>> c8ad186c3 (server: skip the engine key when match store label (#8486))
},
})
if t.valid {
Expand Down
3 changes: 3 additions & 0 deletions server/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down

0 comments on commit 271f445

Please sign in to comment.