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
schedule, server: persist scheduler list to etcd #769
Conversation
…e empty in clone() of ReplicationConfig
c52f5b3
to
da092b3
Compare
conf/config.toml
Outdated
# if empty, it will use balanceLeader, balanceRegion, hotReadRegion, hotWriteRegion as default | ||
[schedule.schedulers] | ||
# [schedule.schedulers.balanceLeader] | ||
# if empty, it will use balance-leader, balance-region, hot-region as default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use two PRs, one is to change the name, the other is to persist the config.
da092b3
to
35beed9
Compare
make.out
Outdated
@@ -0,0 +1 @@ | |||
GOPATH=/Users/Connor/Coding/src/github.com/pingcap/pd/_vendor go build -ldflags '-X "github.com/pingcap/pd/server.PDBuildTS=2017-09-26 08:17:22" -X "github.com/pingcap/pd/server.PDGitHash=d9704080e36f0adde864ffaac24a11b3cc9f0a1c" -X "github.com/pingcap/pd/server.PDGitBranch=connor/persist-scheduler"' -o bin/pd-server cmd/pd-server/main.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this file
I suggest changing the name at first, then support persistence. |
OK, i will pull a new request for changing the name @siddontang |
e6b198a
to
349d872
Compare
server/config.go
Outdated
for _, schedulerCfg := range v.Schedulers { | ||
// comparing args is to cover the case that there are schedulers in same type but not with same name | ||
// such as two schedulers of type evictLeader, | ||
// one name is "evict-leader-scheduler-1" and the other is "evict-leader-scheduler-2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just compare their names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming that we are going to add two schedulers, "evict-leader-scheduler-1" and "evict-leader-scheduler-2", but when creating them we should pass "evit-leader" to CreateScheduler() not their name. And schedulers reloading will call CreateScheduler(), thus the name store in schedulerCfg is their type "evit-leader", not their name "evict-leader-scheduler-1" or "evict-leader-scheduler-2". And for here, "evit-leader" is not enough to distinguish "evict-leader-scheduler-1" with "evict-leader-scheduler-2"
server/config.go
Outdated
// one name is "evict-leader-scheduler-1" and the other is "evict-leader-scheduler-2" | ||
if schedulerCfg.Type == tp && stringSliceEqual(schedulerCfg.Args, args) { | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about add a Equals
method to SchedulerConfig
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest LGTM.
server/config.go
Outdated
return false | ||
} | ||
if (a == nil) != (b == nil) { | ||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think previous check already implicitly guaranteed it is true.
server/coordinator.go
Outdated
@@ -270,6 +270,9 @@ func (c *coordinator) addScheduler(scheduler schedule.Scheduler, interval time.D | |||
c.wg.Add(1) | |||
go c.runScheduler(s) | |||
c.schedulers[s.GetName()] = s | |||
if c.opt.AddSchedulerCfg(s.GetType(), args) { | |||
c.opt.persist(c.kv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print a log if persist meet error
server/schedulers/balance_leader.go
Outdated
@@ -51,6 +51,10 @@ func (l *balanceLeaderScheduler) GetName() string { | |||
return "balance-leader-scheduler" | |||
} | |||
|
|||
func (l *balanceLeaderScheduler) GetType() string { | |||
return "balanceLeader" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use kebab-case.
conf/config.toml
Outdated
# [schedule.schedulers.balance-leader] | ||
# [[schedule.schedulers]] | ||
# type = "balance-leader" | ||
# args = ["foo", "bar"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bad arg name example, what does foo or bar mean here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing, just placeholder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use more meaningful argument names if possible or remove these.
server/config.go
Outdated
|
||
// Equals is to compare whether two ScheduleConfig is same or not | ||
func (c *SchedulerConfig) Equals(s SchedulerConfig) bool { | ||
stringSliceEqual := func(a, b []string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use reflect.DeepEqual
aa6d4fc
to
5f70e77
Compare
5f70e77
to
dacd8c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
server/config.go
Outdated
"balance-region": toml.Primitive{}, | ||
"balance-leader": toml.Primitive{}, | ||
"hot-region": toml.Primitive{}, | ||
SchedulerConfig{Type: "balance-region"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seem you can use
SchedulerConfigs {
{Type:"xxx"},
{Type:"xxx"},
}
PTAL @disksing |
LGTM |
2900eb8
to
8bf0508
Compare
if err != nil { | ||
log.Errorf("can not create scheduler %s: %v", name, err) | ||
log.Errorf("can not create scheduler %s: %v", schedulerCfg.Type, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe you can remove invalid persist schedulers in here according to the error types.
LGTM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
persist scheduler list to etcd to make sure the schedulers added or removed in dynamic way can still be recreated after leader change or pd-server restart.