-
Notifications
You must be signed in to change notification settings - Fork 721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opt, schedulers: consider placement rules when verify region healthy #1897
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
42ea7bb
opt, schedulers: consider placement rules when verify region healthy
disksing c6c5a60
Merge branch 'master' into placement10
disksing 7650300
Merge branch 'master' into placement10
disksing 1a9c90e
Merge branch 'placement10' of https://github.com/disksing/pd into pla…
disksing 103bc88
fix format
disksing 4f3e76b
resolve conflicts
disksing 26fa785
address comments
disksing 4561c25
Merge branch 'master' into placement10
sre-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opt | ||
|
||
import "github.com/pingcap/pd/server/core" | ||
|
||
// IsRegionHealthy checks if a region is healthy for scheduling. It requires the | ||
// region does not have any down or pending peers. And when placement rules | ||
// feature is disabled, it requires the region does not have any learner peer. | ||
func IsRegionHealthy(cluster Cluster, region *core.RegionInfo) bool { | ||
return IsHealthyAllowPending(cluster, region) && len(region.GetPendingPeers()) == 0 | ||
} | ||
|
||
// IsHealthyAllowPending checks if a region is healthy for scheduling. | ||
// Differs from IsRegionHealthy, it allows the region to have pending peers. | ||
func IsHealthyAllowPending(cluster Cluster, region *core.RegionInfo) bool { | ||
if !cluster.IsPlacementRulesEnabled() && len(region.GetLearners()) > 0 { | ||
return false | ||
} | ||
return len(region.GetDownPeers()) == 0 | ||
} | ||
|
||
// HealthRegion returns a function that checks if a region is healthy for | ||
// scheduling. It requires the region does not have any down or pending peers, | ||
// and does not have any learner peers when placement rules is disabled. | ||
func HealthRegion(cluster Cluster) func(*core.RegionInfo) bool { | ||
return func(region *core.RegionInfo) bool { return IsRegionHealthy(cluster, region) } | ||
} | ||
|
||
// HealthAllowPending returns a function that checks if a region is | ||
// healthy for scheduling. Differs from HealthRegion, it allows the region | ||
// to have pending peers. | ||
func HealthAllowPending(cluster Cluster) func(*core.RegionInfo) bool { | ||
return func(region *core.RegionInfo) bool { return IsHealthyAllowPending(cluster, region) } | ||
} | ||
|
||
// IsRegionReplicated checks if a region is fully replicated. When placement | ||
// rules is enabled, its peers should fit corresponding rules. When placement | ||
// rules is disabled, it should have enough replicas and no any learner peer. | ||
func IsRegionReplicated(cluster Cluster, region *core.RegionInfo) bool { | ||
if cluster.IsPlacementRulesEnabled() { | ||
return cluster.FitRegion(region).IsSatisfied() | ||
} | ||
return len(region.GetLearners()) == 0 && len(region.GetPeers()) == cluster.GetMaxReplicas() | ||
} | ||
|
||
// ReplicatedRegion returns a function that checks if a region is fully replicated. | ||
func ReplicatedRegion(cluster Cluster) func(*core.RegionInfo) bool { | ||
return func(region *core.RegionInfo) bool { return IsRegionReplicated(cluster, region) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2019 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package opt | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/pingcap/check" | ||
"github.com/pingcap/kvproto/pkg/metapb" | ||
"github.com/pingcap/kvproto/pkg/pdpb" | ||
"github.com/pingcap/pd/pkg/mock/mockcluster" | ||
"github.com/pingcap/pd/pkg/mock/mockoption" | ||
"github.com/pingcap/pd/server/core" | ||
) | ||
|
||
func TestOpt(t *testing.T) { | ||
TestingT(t) | ||
} | ||
|
||
var _ = Suite(&testRegionHealthySuite{}) | ||
|
||
type testRegionHealthySuite struct{} | ||
|
||
func (s *testRegionHealthySuite) TestIsRegionHealthy(c *C) { | ||
c.Skip("enable it after rule fit merged") | ||
|
||
peers := func(ids ...uint64) []*metapb.Peer { | ||
var peers []*metapb.Peer | ||
for _, id := range ids { | ||
p := &metapb.Peer{ | ||
Id: id, | ||
StoreId: id, | ||
} | ||
peers = append(peers, p) | ||
} | ||
return peers | ||
} | ||
|
||
region := func(peers []*metapb.Peer, opts ...core.RegionCreateOption) *core.RegionInfo { | ||
return core.NewRegionInfo(&metapb.Region{Peers: peers}, peers[0], opts...) | ||
} | ||
|
||
type testCase struct { | ||
region *core.RegionInfo | ||
// disable placement rules | ||
healthy1 bool | ||
healthyAllowPending1 bool | ||
replicated1 bool | ||
// enable placement rules | ||
healthy2 bool | ||
healthyAllowPending2 bool | ||
replicated2 bool | ||
} | ||
|
||
cases := []testCase{ | ||
{region(peers(1, 2, 3)), true, true, true, true, true, true}, | ||
{region(peers(1, 2, 3), core.WithPendingPeers(peers(1))), false, true, true, false, true, true}, | ||
{region(peers(1, 2, 3), core.WithLearners(peers(1))), false, false, false, true, true, false}, | ||
{region(peers(1, 2, 3), core.WithDownPeers([]*pdpb.PeerStats{{Peer: peers(1)[0]}})), false, false, true, false, false, true}, | ||
{region(peers(1, 2)), true, true, false, true, true, false}, | ||
{region(peers(1, 2, 3, 4), core.WithLearners(peers(1))), false, false, false, true, true, false}, | ||
} | ||
|
||
opt := mockoption.NewScheduleOptions() | ||
tc := mockcluster.NewCluster(opt) | ||
tc.AddRegionStore(1, 1) | ||
tc.AddRegionStore(2, 1) | ||
tc.AddRegionStore(3, 1) | ||
tc.AddRegionStore(4, 1) | ||
for _, t := range cases { | ||
opt.EnablePlacementRules = false | ||
c.Assert(IsRegionHealthy(tc, t.region), Equals, t.healthy1) | ||
c.Assert(IsHealthyAllowPending(tc, t.region), Equals, t.healthyAllowPending1) | ||
c.Assert(IsRegionReplicated(tc, t.region), Equals, t.replicated1) | ||
opt.EnablePlacementRules = true | ||
c.Assert(IsRegionHealthy(tc, t.region), Equals, t.healthy2) | ||
c.Assert(IsHealthyAllowPending(tc, t.region), Equals, t.healthyAllowPending2) | ||
c.Assert(IsRegionReplicated(tc, t.region), Equals, t.replicated2) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just mention it, why not try to keep the same style of the loop like
for j := range learners
, then uselearners[j]
later instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only because
l
is shorter thanlearners[j]
.