Skip to content

Commit

Permalink
address
Browse files Browse the repository at this point in the history
Signed-off-by: nolouch <[email protected]>
  • Loading branch information
nolouch committed Apr 29, 2024
1 parent 949d15b commit add0dbc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
23 changes: 13 additions & 10 deletions pkg/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,23 +1371,23 @@ func (r *RegionsInfo) GetStoreRegions(storeID uint64) []*RegionInfo {
// SubTreeRegionType is the type of sub tree region.
type SubTreeRegionType int

var (
const (
// AllInSubTree is all sub trees.
AllInSubTree SubTreeRegionType = 0
AllInSubTree SubTreeRegionType = iota
// LeaderInSubTree is the leader sub tree.
LeaderInSubTree SubTreeRegionType = 1
LeaderInSubTree
// FollowerInSubTree is the follower sub tree.
FollowerInSubTree SubTreeRegionType = 2
FollowerInSubTree
// LearnerInSubTree is the learner sub tree.
LearnerInSubTree SubTreeRegionType = 3
LearnerInSubTree
// WitnessInSubTree is the witness sub tree.
WitnessInSubTree SubTreeRegionType = 4
WitnessInSubTree
// PendingPeerInSubTree is the pending peer sub tree.
PendingPeerInSubTree SubTreeRegionType = 5
PendingPeerInSubTree
)

// GetStoreRegions gets all RegionInfo with a given storeID
func (r *RegionsInfo) GetStoreRegionsByTypeInSubTree(storeID uint64, typ SubTreeRegionType) []*RegionInfo {
func (r *RegionsInfo) GetStoreRegionsByTypeInSubTree(storeID uint64, typ SubTreeRegionType) ([]*RegionInfo, err) {

Check failure on line 1390 in pkg/core/region.go

View workflow job for this annotation

GitHub Actions / statics

undefined: err
r.st.RLock()
var regions []*RegionInfo
switch typ {
Expand All @@ -1413,10 +1413,13 @@ func (r *RegionsInfo) GetStoreRegionsByTypeInSubTree(storeID uint64, typ SubTree
}
case AllInSubTree:
r.st.RUnlock()
return r.GetStoreRegions(storeID)
return r.GetStoreRegions(storeID), nil
default:
return nil, errors.Errorf("unknown sub tree region type %v", typ)
}

r.st.RUnlock()
return regions
return regions, nil
}

// GetStoreLeaderRegionSize get total size of store's leader regions
Expand Down
6 changes: 5 additions & 1 deletion server/api/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ func (h *regionsHandler) GetStoreRegions(w http.ResponseWriter, r *http.Request)
if err != nil {
typID = int(core.AllInSubTree)
}
regions := rc.GetStoreRegionsByTypeInSubTree(uint64(id), core.SubTreeRegionType(typID))
regions, err := rc.GetStoreRegionsByTypeInSubTree(uint64(id), core.SubTreeRegionType(typID))
if err != nil {
h.rd.JSON(w, http.StatusBadRequest, err.Error())
return
}
b, err := response.MarshalRegionsInfoJSON(r.Context(), regions)
if err != nil {
h.rd.JSON(w, http.StatusInternalServerError, err.Error())
Expand Down

0 comments on commit add0dbc

Please sign in to comment.