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

scheduler: add debug log #907

Merged
merged 12 commits into from
Jan 10, 2018
Merged

scheduler: add debug log #907

merged 12 commits into from
Jan 10, 2018

Conversation

Connor1996
Copy link
Member

@Connor1996 Connor1996 commented Jan 9, 2018

this pr:

  • add some debug log in balance-leader and balance-region scheduler
  • add a log api for pd-ctl to set log level

@@ -74,6 +75,8 @@ func (l *balanceLeaderScheduler) Schedule(cluster schedule.Cluster, opInfluence

source := cluster.GetStore(region.Leader.GetStoreId())
target := cluster.GetStore(newLeader.GetStoreId())
log.Debugf("source store is %v", source)
Copy link
Contributor

Choose a reason for hiding this comment

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

please combine two logs into one, add scheduler name .

Copy link
Contributor

Choose a reason for hiding this comment

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

add [region xxx] xxx

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, but I think it's not necessary to add scheduler name, cause log will print file name

@@ -39,6 +39,8 @@ func scheduleTransferLeader(cluster schedule.Cluster, schedulerName string, s sc

mostLeaderStore := s.SelectSource(cluster, stores, filters...)
leastLeaderStore := s.SelectTarget(cluster, stores, filters...)
log.Debugf("mostLeaderStore is %v", mostLeaderStore)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

@@ -63,7 +67,7 @@ func scheduleTransferLeader(cluster schedule.Cluster, schedulerName string, s sc
region, peer = scheduleRemoveLeader(cluster, schedulerName, mostLeaderStore.GetId(), s)
}
}

log.Debugf("transfer leader select %v to be new leader for region %v", peer, region)
Copy link
Contributor

Choose a reason for hiding this comment

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

[region xxx] do ...

@Connor1996 Connor1996 requested review from nolouch and disksing January 9, 2018 05:35
return
}

level := "info"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to set log level by string. If original level is "warning" or "error", we will not able to recover after debug.

@@ -31,6 +32,7 @@ type Filter interface {
func FilterSource(opt Options, store *core.StoreInfo, filters []Filter) bool {
for _, filter := range filters {
if filter.FilterSource(opt, store) {
log.Debugf("[filter %T] filtes store %v from source", filter, store)
Copy link
Contributor

Choose a reason for hiding this comment

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

filtes -> filters.

if debug {
level = "debug"
}
h.svr.SetLogLevel(level)
Copy link
Contributor

Choose a reason for hiding this comment

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

I worry the data race here. Changing log level is not thread safe?

Copy link
Member Author

Choose a reason for hiding this comment

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

server reads cfg.Log only when initing logger, and setloglevel is not an operation with high frequency. Even if it causes write-write-conflict, it seems that it does not matter here.

@siddontang
Copy link
Contributor

please attach [region %d] at the beginning of the log if there is.

@@ -74,6 +75,7 @@ func (l *balanceLeaderScheduler) Schedule(cluster schedule.Cluster, opInfluence

source := cluster.GetStore(region.Leader.GetStoreId())
target := cluster.GetStore(newLeader.GetStoreId())
log.Debugf("source store is %v, target store is %v", source, target)
Copy link
Contributor

Choose a reason for hiding this comment

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

log store id should be enough.

@@ -117,6 +118,7 @@ func (s *balanceRegionScheduler) transferPeer(cluster schedule.Cluster, region *

target := cluster.GetStore(newPeer.GetStoreId())
avgScore := cluster.GetStoresAverageScore(core.RegionKind)
log.Debugf("source store is %v, target store is %v", source, target)
Copy link
Contributor

Choose a reason for hiding this comment

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

log store id should be enough.

@@ -31,6 +32,7 @@ type Filter interface {
func FilterSource(opt Options, store *core.StoreInfo, filters []Filter) bool {
for _, filter := range filters {
if filter.FilterSource(opt, store) {
log.Debugf("[filter %T] filters store %v from source", filter, store)
Copy link
Contributor

Choose a reason for hiding this comment

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

%T will output all the fields of the filter, is it ok here?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, it outputs like "*schedule.excludedFilter"

@@ -74,6 +75,7 @@ func (l *balanceLeaderScheduler) Schedule(cluster schedule.Cluster, opInfluence

source := cluster.GetStore(region.Leader.GetStoreId())
target := cluster.GetStore(newLeader.GetStoreId())
log.Debugf("source store id is %v, target store id is %v", source.GetId(), target.GetId())
Copy link
Contributor

Choose a reason for hiding this comment

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

add region

@@ -117,6 +118,7 @@ func (s *balanceRegionScheduler) transferPeer(cluster schedule.Cluster, region *

target := cluster.GetStore(newPeer.GetStoreId())
avgScore := cluster.GetStoresAverageScore(core.RegionKind)
log.Debugf("source store id is %v, target store id is %v", source.GetId(), target.GetId())
Copy link
Contributor

Choose a reason for hiding this comment

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

add region

@@ -39,6 +39,7 @@ func scheduleTransferLeader(cluster schedule.Cluster, schedulerName string, s sc

mostLeaderStore := s.SelectSource(cluster, stores, filters...)
leastLeaderStore := s.SelectTarget(cluster, stores, filters...)
log.Debugf("[%v] mostLeaderStore is %v, leastLeaderStore is %v", schedulerName, mostLeaderStore, leastLeaderStore)
Copy link
Contributor

Choose a reason for hiding this comment

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

[%s]

if region == nil {
log.Debugf("[%v] select no region", schedulerName)
} else {
log.Debugf("[region %v][%v] select %v to be new leader", schedulerName, region.GetId(), peer)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the parameter does not correspond.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, I mistake the order

@@ -183,6 +190,7 @@ func shouldBalance(source, target *core.StoreInfo, avgScore float64, kind core.R
sourceSizeDiff := (sourceScore - avgScore) * source.ResourceWeight(kind)
targetSizeDiff := (avgScore - targetScore) * target.ResourceWeight(kind)

log.Debugf("size diff is %v and region size is %v", math.Min(sourceSizeDiff, targetSizeDiff), float64(region.ApproximateSize)*tolerantRatio)
Copy link
Contributor

Choose a reason for hiding this comment

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

region size -> tolerable size?better to indicate region id.

@siddontang
Copy link
Contributor

LGTM

Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

LGTM

@disksing disksing merged commit f3a22e2 into tikv:master Jan 10, 2018
@Connor1996 Connor1996 deleted the debug-log branch January 15, 2018 03:07
Connor1996 added a commit to Connor1996/pd that referenced this pull request Jan 15, 2018
Connor1996 added a commit that referenced this pull request Jan 15, 2018
* scheduler: add debug log (#907)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants