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

schedule, server: persist scheduler list to etcd #769

Merged
merged 20 commits into from Sep 30, 2017

Conversation

Connor1996
Copy link
Member

@Connor1996 Connor1996 commented Sep 26, 2017

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.

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
Copy link
Contributor

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.

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
Copy link
Contributor

Choose a reason for hiding this comment

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

remove this file

@siddontang
Copy link
Contributor

I suggest changing the name at first, then support persistence.

@Connor1996
Copy link
Member Author

OK, i will pull a new request for changing the name @siddontang

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"
Copy link
Contributor

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?

Copy link
Member Author

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
}
Copy link
Contributor

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?

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

Copy link
Contributor

@disksing disksing left a 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
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 previous check already implicitly guaranteed it is true.

@@ -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)
Copy link
Contributor

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

@@ -51,6 +51,10 @@ func (l *balanceLeaderScheduler) GetName() string {
return "balance-leader-scheduler"
}

func (l *balanceLeaderScheduler) GetType() string {
return "balanceLeader"
Copy link
Contributor

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"]
Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

nothing, just placeholder

Copy link
Contributor

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

use reflect.DeepEqual

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

server/config.go Outdated
"balance-region": toml.Primitive{},
"balance-leader": toml.Primitive{},
"hot-region": toml.Primitive{},
SchedulerConfig{Type: "balance-region"},
Copy link
Contributor

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"},
}

@siddontang
Copy link
Contributor

PTAL @disksing

@siddontang
Copy link
Contributor

LGTM

if err != nil {
log.Errorf("can not create scheduler %s: %v", name, err)
log.Errorf("can not create scheduler %s: %v", schedulerCfg.Type, err)
Copy link
Contributor

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.

@disksing
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

@Connor1996 Connor1996 merged commit 16e898c into master Sep 30, 2017
@Connor1996 Connor1996 deleted the connor/persist-scheduler branch September 30, 2017 08:13
disksing added a commit that referenced this pull request Oct 7, 2017
disksing added a commit that referenced this pull request Oct 7, 2017
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.

None yet

4 participants