Skip to content

Commit

Permalink
*: add some comments to exported function, part 2 of enable revive.ex…
Browse files Browse the repository at this point in the history
…ported (tikv#8481)

ref tikv#8458

Signed-off-by: okJiang <819421878@qq.com>

Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
  • Loading branch information
okJiang and ti-chi-bot[bot] authored Aug 5, 2024
1 parent aa85b6c commit 1335ff9
Show file tree
Hide file tree
Showing 43 changed files with 493 additions and 406 deletions.
5 changes: 3 additions & 2 deletions pkg/core/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import (
const (
randomRegionMaxRetry = 10
scanRegionLimit = 1000
CollectFactor = 0.9
// CollectFactor is the factor to collect the count of region.
CollectFactor = 0.9
)

// errRegionIsStale is error info for region is stale.
Expand Down Expand Up @@ -721,7 +722,7 @@ func (r *RegionInfo) isRegionRecreated() bool {
return r.GetRegionEpoch().GetVersion() == 1 && r.GetRegionEpoch().GetConfVer() == 1 && (len(r.GetStartKey()) != 0 || len(r.GetEndKey()) != 0)
}

func (r *RegionInfo) Contains(key []byte) bool {
func (r *RegionInfo) contain(key []byte) bool {
start, end := r.GetStartKey(), r.GetEndKey()
return bytes.Compare(key, start) >= 0 && (len(end) == 0 || bytes.Compare(key, end) < 0)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/core/region_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func (t *regionTree) find(item *regionItem) *regionItem {
return false
})

if result == nil || !result.Contains(item.GetStartKey()) {
if result == nil || !result.contain(item.GetStartKey()) {
return nil
}

Expand Down Expand Up @@ -370,7 +370,7 @@ func (t *regionTree) RandomRegions(n int, ranges []KeyRange) []*RegionInfo {
// we need to check if the previous item contains the key.
if startIndex != 0 && startItem == nil {
region = t.tree.GetAt(startIndex - 1).RegionInfo
if region.Contains(startKey) {
if region.contain(startKey) {
startIndex--
}
}
Expand Down
14 changes: 7 additions & 7 deletions pkg/core/region_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ func TestRegionItem(t *testing.T) {
re.False(item.Less(newRegionItem([]byte("b"), []byte{})))
re.True(item.Less(newRegionItem([]byte("c"), []byte{})))

re.False(item.Contains([]byte("a")))
re.True(item.Contains([]byte("b")))
re.True(item.Contains([]byte("c")))
re.False(item.contain([]byte("a")))
re.True(item.contain([]byte("b")))
re.True(item.contain([]byte("c")))

item = newRegionItem([]byte("b"), []byte("d"))
re.False(item.Contains([]byte("a")))
re.True(item.Contains([]byte("b")))
re.True(item.Contains([]byte("c")))
re.False(item.Contains([]byte("d")))
re.False(item.contain([]byte("a")))
re.True(item.contain([]byte("b")))
re.True(item.contain([]byte("c")))
re.False(item.contain([]byte("d")))
}

func newRegionWithStat(start, end string, size, keys int64) *RegionInfo {
Expand Down
6 changes: 4 additions & 2 deletions pkg/mcs/scheduling/server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var SetUpRestHandler = func(*Service) (http.Handler, apiutil.APIServiceGroup) {

type dummyRestService struct{}

// ServeHTTP implements the http.Handler interface.
func (dummyRestService) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusNotImplemented)
w.Write([]byte("not implemented"))
Expand Down Expand Up @@ -83,6 +84,7 @@ type heartbeatServer struct {
closed int32
}

// Send implements the HeartbeatStream interface.
func (s *heartbeatServer) Send(m core.RegionHeartbeatResponse) error {
if atomic.LoadInt32(&s.closed) == 1 {
return io.EOF
Expand All @@ -106,7 +108,7 @@ func (s *heartbeatServer) Send(m core.RegionHeartbeatResponse) error {
}
}

func (s *heartbeatServer) Recv() (*schedulingpb.RegionHeartbeatRequest, error) {
func (s *heartbeatServer) recv() (*schedulingpb.RegionHeartbeatRequest, error) {
if atomic.LoadInt32(&s.closed) == 1 {
return nil, io.EOF
}
Expand All @@ -133,7 +135,7 @@ func (s *Service) RegionHeartbeat(stream schedulingpb.Scheduling_RegionHeartbeat
}()

for {
request, err := server.Recv()
request, err := server.recv()
if err == io.EOF {
return nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/ratelimit/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type taskID struct {
name string
}

// ConcurrentRunner is a task runner that limits the number of concurrent tasks.
type ConcurrentRunner struct {
ctx context.Context
cancel context.CancelFunc
Expand Down
20 changes: 10 additions & 10 deletions pkg/schedule/filter/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func SelectUnavailableTargetStores(stores []*core.StoreInfo, filters []Filter, c
cfilter, ok := filters[i].(comparingFilter)
sourceID := uint64(0)
if ok {
sourceID = cfilter.GetSourceStoreID()
sourceID = cfilter.getSourceStoreID()
}
if counter != nil {
counter.inc(target, filters[i].Type(), sourceID, s.GetID())
Expand Down Expand Up @@ -99,7 +99,7 @@ func SelectTargetStores(stores []*core.StoreInfo, filters []Filter, conf config.
cfilter, ok := filter.(comparingFilter)
sourceID := uint64(0)
if ok {
sourceID = cfilter.GetSourceStoreID()
sourceID = cfilter.getSourceStoreID()
}
if counter != nil {
counter.inc(target, filter.Type(), sourceID, s.GetID())
Expand Down Expand Up @@ -141,8 +141,8 @@ type Filter interface {
// comparingFilter is an interface to filter target store by comparing source and target stores
type comparingFilter interface {
Filter
// GetSourceStoreID returns the source store when comparing.
GetSourceStoreID() uint64
// getSourceStoreID returns the source store when comparing.
getSourceStoreID() uint64
}

// Target checks if store can pass all Filters as target store.
Expand All @@ -156,7 +156,7 @@ func Target(conf config.SharedConfigProvider, store *core.StoreInfo, filters []F
targetID := storeID
sourceID := ""
if ok {
sourceID = strconv.FormatUint(cfilter.GetSourceStoreID(), 10)
sourceID = strconv.FormatUint(cfilter.getSourceStoreID(), 10)
}
filterCounter.WithLabelValues(target.String(), filter.Scope(), filter.Type().String(), sourceID, targetID).Inc()
}
Expand Down Expand Up @@ -319,8 +319,8 @@ func (f *distinctScoreFilter) Target(_ config.SharedConfigProvider, store *core.
return statusStoreNotMatchIsolation
}

// GetSourceStoreID implements the ComparingFilter
func (f *distinctScoreFilter) GetSourceStoreID() uint64 {
// getSourceStoreID implements the ComparingFilter
func (f *distinctScoreFilter) getSourceStoreID() uint64 {
return f.srcStore
}

Expand Down Expand Up @@ -669,8 +669,8 @@ func (f *ruleFitFilter) Target(_ config.SharedConfigProvider, store *core.StoreI
return statusStoreNotMatchRule
}

// GetSourceStoreID implements the ComparingFilter
func (f *ruleFitFilter) GetSourceStoreID() uint64 {
// getSourceStoreID implements the ComparingFilter
func (f *ruleFitFilter) getSourceStoreID() uint64 {
return f.srcStore
}

Expand Down Expand Up @@ -730,7 +730,7 @@ func (f *ruleLeaderFitFilter) Target(_ config.SharedConfigProvider, store *core.
return statusStoreNotMatchRule
}

func (f *ruleLeaderFitFilter) GetSourceStoreID() uint64 {
func (f *ruleLeaderFitFilter) getSourceStoreID() uint64 {
return f.srcLeaderStoreID
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/schedule/filter/region_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func NewRegionEmptyFilter(cluster sche.SharedCluster) RegionFilter {
return &regionEmptyFilter{cluster: cluster}
}

// Select implements the RegionFilter interface.
func (f *regionEmptyFilter) Select(region *core.RegionInfo) *plan.Status {
if !isEmptyRegionAllowBalance(f.cluster, region) {
return statusRegionEmpty
Expand All @@ -163,6 +164,7 @@ func NewRegionWitnessFilter(storeID uint64) RegionFilter {
return &regionWitnessFilter{storeID: storeID}
}

// Select implements the RegionFilter interface.
func (f *regionWitnessFilter) Select(region *core.RegionInfo) *plan.Status {
if region.GetStoreWitness(f.storeID) != nil {
return statusRegionWitnessPeer
Expand Down
Loading

0 comments on commit 1335ff9

Please sign in to comment.