Skip to content
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

*: region filter #5135

Merged
merged 21 commits into from Jul 15, 2022
Merged

*: region filter #5135

merged 21 commits into from Jul 15, 2022

Conversation

CabinfeverB
Copy link
Member

@CabinfeverB CabinfeverB commented Jun 9, 2022

Signed-off-by: Cabinfever_B cabinfeveroier@gmail.com

What problem does this PR solve?

Issue Number: ref #5257

What is changed and how does it work?

remove RegionOption, and add RegionFilter

remove `RegionOption`, and add `RegionFilter`

Check List

Tests

  • Unit test

Release note

 None.

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Jun 9, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • AndreMouche
  • rleungx

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note The PR should write the release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jun 9, 2022
@codecov
Copy link

codecov bot commented Jun 9, 2022

Codecov Report

Merging #5135 (987a1fa) into master (8ab5c16) will decrease coverage by 0.02%.
The diff coverage is 80.11%.

@@            Coverage Diff             @@
##           master    #5135      +/-   ##
==========================================
- Coverage   75.69%   75.66%   -0.03%     
==========================================
  Files         311      312       +1     
  Lines       30909    30962      +53     
==========================================
+ Hits        23396    23427      +31     
- Misses       5503     5523      +20     
- Partials     2010     2012       +2     
Flag Coverage Δ
unittests 75.66% <80.11%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
server/core/region_option.go 83.17% <ø> (ø)
server/handler.go 52.58% <0.00%> (ø)
server/schedule/plan/status.go 77.77% <ø> (ø)
server/schedulers/hot_region.go 84.17% <0.00%> (+0.25%) ⬆️
server/storage/endpoint/meta.go 63.63% <ø> (-0.41%) ⬇️
server/schedule/checker/merge_checker.go 69.69% <50.00%> (ø)
server/storage/storage.go 71.15% <50.00%> (+0.88%) ⬆️
server/region_syncer/server.go 87.36% <66.66%> (+4.21%) ⬆️
server/server.go 74.76% <71.42%> (+0.62%) ⬆️
server/schedule/filter/region_filters.go 77.41% <77.41%> (ø)
... and 42 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6aaff24...987a1fa. Read the comment docs.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 23, 2022
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 5, 2022
@CabinfeverB CabinfeverB marked this pull request as ready for review July 5, 2022 09:50
@ti-chi-bot ti-chi-bot added release-note-none and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-linked-issue release-note The PR should write the release note. labels Jul 5, 2022
@CabinfeverB CabinfeverB requested review from rleungx and AndreMouche and removed request for nolouch and lhy1024 July 5, 2022 09:52
@CabinfeverB CabinfeverB changed the title region filter *: region filter Jul 5, 2022
@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 12, 2022
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

--wip-- [skip ci]
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
)

// IsRegionHealthy checks if a region is healthy for scheduling. It requires the
// region does not have any down or pending peers.
func IsRegionHealthy(region *core.RegionInfo) bool {
return IsRegionHealthyAllowPending(region) && len(region.GetPendingPeers()) == 0
pendingFilter := filter.NewRegionPengdingFilter("option")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not keep them as it is?

}

// Cluster provides an overview of a cluster's regions distribution.
type Cluster interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid defining this interface?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defined this because of avoiding import cycles

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defining this interface looks ok to me, However could we make the interface private?

@@ -137,7 +137,7 @@ func Target(opt *config.PersistOptions, store *core.StoreInfo, filters []Filter)
storeAddress := store.GetAddress()
storeID := strconv.FormatUint(store.GetID(), 10)
for _, filter := range filters {
if !filter.Target(opt, store).IsOK() {
if filter.Target(opt, store) != statusStoreOK {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use IsOK?

statusPauseLeader = plan.NewStatus(plan.StatusStoreBlocked, "the store is not allowed to transfer leader, there might be an evict-leader-scheduler")
statusRejectLeader = plan.NewStatus(plan.StatusStoreBlocked, "the store is not allowed to transfer leader, please check 'label-property'")
statusSlowStore = plan.NewStatus(plan.StatusStoreBlocked, "the store is slow and are evicting leaders, there might be an evict-slow-store-scheduler")
statusStoreOK = plan.NewStatus(plan.StatusOK)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we merge statusStoreOK with statusRegionOK?
How about defining a single file status.go to store these status variables?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that only statusOK needs a single file, is it necessary?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about put all status into that file?

return statusRegionOK
}

// isEmptyRegionAllowBalance checks if a region is an empty region and can be balanced.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// isEmptyRegionAllowBalance checks if a region is an empty region and can be balanced.
// isEmptyRegionAllowBalance returns true if the region is not empty or the number of regions is too small.

}

// Cluster provides an overview of a cluster's regions distribution.
type Cluster interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defining this interface looks ok to me, However could we make the interface private?

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 13, 2022
return cluster.GetRuleManager().FitRegion(cluster, region).IsSatisfied()
}
return len(region.GetLearners()) == 0 && len(region.GetPeers()) == cluster.GetOpts().GetMaxReplicas()
filter := filter.NewRegionReplicatedFilter("option", cluster)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Replicated is a more complex logic than PendingPeer or DownPeer, so I only want to maintain it in one place

}
return statusNoNeed
return statusStoreNoNeed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about keep using statusNoNeed?

}

// cluster provides an overview of a cluster's regions distribution.
type regionFilterCluster interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem that some interfaces are not used

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
return hasDownPeers(region)
}

func hasPendingPeers(region *core.RegionInfo) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name doesn't match the implementation.

return len(region.GetPendingPeers()) == 0
}

func hasDownPeers(region *core.RegionInfo) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member

@AndreMouche AndreMouche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 14, 2022
return statusOK
}
if !isRegionReplicasSatisfied(f.cluster, region) {
return statusRegionIsolation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it related to isolation?

// RegionFilter is an interface to filter region.
type RegionFilter interface {
// RegionFilter is used to indicate where the filter will act on.
Scope() string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed?


import "github.com/tikv/pd/server/schedule/plan"

var (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not put them together if you use a separate file to define the status?

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -46,6 +46,8 @@ const (
StatusRegionUnhealthy
// StatusRegionEmpty represents the region cannot be selected due to the region is empty.
StatusRegionEmpty
// StatusRegionUnReplicated represents the region does not have enough replicas.
StatusRegionUnReplicated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
StatusRegionUnReplicated
StatusRegionNotReplicated

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link
Member

@rleungx rleungx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest LGTM.

@@ -505,17 +483,17 @@ func (f *StoreStateFilter) Source(opts *config.PersistOptions, store *core.Store
// target.
func (f *StoreStateFilter) Target(opts *config.PersistOptions, store *core.StoreInfo) (status plan.Status) {
if f.TransferLeader {
if status = f.anyConditionMatch(leaderTarget, opts, store); !status.IsOK() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change it back?

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 14, 2022
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@rleungx
Copy link
Member

rleungx commented Jul 15, 2022

/merge

@ti-chi-bot
Copy link
Member

@rleungx: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 987a1fa

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 15, 2022
@ti-chi-bot ti-chi-bot merged commit 05444e2 into tikv:master Jul 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants