executor: add retriver for tikv_region_peers #30657
executor: add retriver for tikv_region_peers #30657ti-chi-bot merged 30 commits intopingcap:masterfrom
Conversation
ref: pingcap#28330 Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
|
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. DetailsReviewer can indicate their review by submitting an approval review. |
|
Please follow PR Title Format:
Or if the count of mainly changed packages are more than 3, use
After you have format title, you can leave a comment |
|
/rebuild |
|
The rest LGTM basically. |
Co-authored-by: JmPotato <ghzpotato@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
|
/run-all-tests |
|
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/334e618c39f0b1701174adccbe537030dd1d96ed |
executor/memtable_reader.go
Outdated
| if len(e.extractor.RegionIDs) < 1 { | ||
| return e.packTiKVRegionPeersRows(regionsInfoByStoreID) | ||
| } |
There was a problem hiding this comment.
(1/3) I think this judgment is unnecessary since it will not enter the len(e.extractor.RegionIDs) > 0 logic below either.
There was a problem hiding this comment.
Refactor and move them before intersect.
The predicates extract by extractor is and case only, and len(regionsInfoByStoreID) == 0 may include two cases:
- no store_id predicate: Do not intersect
- no corresponding store regionsInfo: Intersect
so we should check the length of extracted predicate rather than result slice regionsInfoByStoreID or regionsInfoByRegionID.
// len(regionsInfoByStoreID) == 0 include two cases:
// 1. no store_id predicate 2. no corresponding store regionsInfo
if len(e.extractor.RegionIDs) == 0 {
return e.packTiKVRegionPeersRows(regionsInfoByStoreID)
}
if len(e.extractor.StoreIDs) == 0 {
return e.packTiKVRegionPeersRows(regionsInfoByRegionID)
}
// intersect
for _, region := range regionsInfoByRegionID {
if _, ok := regionMap[region.ID]; ok {
regionsInfo = append(regionsInfo, region)
}
}There was a problem hiding this comment.
Oh, I missed that part. Nice catch 👍. But what about the or condition 🤔?
There was a problem hiding this comment.
Oh, I missed that part. Nice catch 👍. But what about the
orcondition 🤔?
if len(e.extractor.RegionIDs) < 1 {
return e.packTiKVRegionPeersRows(regionsInfoByStoreID)
}In origin version implemention,the use of regionsInfoByStoreID and regionsInfoByRegionID make or difficult to use.
There was a problem hiding this comment.
How about the newest verion of implmention. I think we need to exclude unwanted regions got from store_id by region_id when specify both store_id and region_id, so I keep the regionsInfoByStoreID.
executor/memtable_reader.go
Outdated
| if len(e.extractor.StoreIDs) < 1 { | ||
| return e.packTiKVRegionPeersRows(regionsInfoByRegionID) | ||
| } |
executor/memtable_reader.go
Outdated
| // intersect | ||
| for _, region := range regionsInfoByRegionID { | ||
| if _, ok := regionMap[region.ID]; ok { | ||
| regionsInfo = append(regionsInfo, region) | ||
| } | ||
| } | ||
| return e.packTiKVRegionPeersRows(regionsInfo) |
There was a problem hiding this comment.
(3/3) We can intersect both regionsInfoByStoreID and regionsInfoByRegionID here, which would make the code more easy and clear.
Co-authored-by: JmPotato <ghzpotato@gmail.com>
util/pdapi/const.go
Outdated
| HotHistory = "/pd/api/v1/hotspot/regions/history" | ||
| Regions = "/pd/api/v1/regions" | ||
| RegionByID = "/pd/api/v1/region/id/" | ||
| StoreRegions = "/pd/api/v1/regions/store/" |
There was a problem hiding this comment.
Prefer to keep the same format, e.g. /pd/api/v1/regions/store
There was a problem hiding this comment.
Done, and hence add + "/" in implemention code
pdapi.StoreRegions+"/"+strconv.FormatUint(storeID, 10), nil, ®ionsInfo)
pdapi.RegionByID+"/"+strconv.FormatUint(regionID, 10), nil, ®ionInfo)| if e.extractor.SkipRequest || e.retrieved { | ||
| return nil, nil | ||
| } | ||
| e.retrieved = true |
There was a problem hiding this comment.
We should change it to true when it is actually retrieved
There was a problem hiding this comment.
The position of clusterServerInfoRetriever is at the begining too. More specifically, tikvRegionsPeersRetriver's implementation has many return cases, it would be redundant if put e.retrieved = true before returns.
executor/memtable_reader.go
Outdated
|
|
||
| var regionsInfo, regionsInfoByStoreID, regionsInfoByRegionID []helper.RegionInfo | ||
| regionMap := make(map[int64]struct{}) | ||
| if len(e.extractor.StoreIDs) > 0 { |
There was a problem hiding this comment.
Refactor and remove if len(e.extractor.StoreIDs) > 0 {.
Signed-off-by: IcePigZDB <icepigzdb@gmail.com>
|
/merge |
|
@JmPotato: DetailsIn response to this:
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. |
|
/merge |
|
This pull request has been accepted and is ready to merge. DetailsCommit hash: d81c254 |
|
/merge |
|
/merge |
1 similar comment
|
/merge |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
|
cherry pick to release-5.4 in PR #32132 |
ref: #28330
What problem does this PR solve?
Issue Number: close #31050
Problem Summary:
The optimization idea is to add
TikvRegionPeersExtractorto push downSTORE_IDandREGION_IDand addtikvRegionPeersRetrieverto fetch regions information from PD.What is changed and how it works?
Time cost comparison:
Check List
Tests
Side effects
Documentation
Release note