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

server: only owner do bootstrap #10029

Merged
merged 13 commits into from
Apr 11, 2019
31 changes: 21 additions & 10 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/util/chunk"
Expand Down Expand Up @@ -250,17 +251,27 @@ const (

// bootstrap initiates system DB for a store.
func bootstrap(s Session) {
b, err := checkBootstrapped(s)
if err != nil {
logutil.Logger(context.Background()).Fatal("check bootstrap error",
zap.Error(err))
}
if b {
upgrade(s)
return
dom := domain.GetDomain(s)
for {
b, err := checkBootstrapped(s)
if err != nil {
logutil.Logger(context.Background()).Fatal("check bootstrap error",
zap.Error(err))
}
// For rolling upgrade, we can't do upgrade only in the owner.
if b {
upgrade(s)
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
return
}
// To reduce conflict when multiple TiDB-server start at the same time.
// Actually only one server need to do the bootstrap. So we chose DDL owner to do this.
if dom.DDL().OwnerManager().IsOwner() {
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
doDDLWorks(s)
doDMLWorks(s)
return
}
time.Sleep(200 * time.Millisecond)
}
doDDLWorks(s)
doDMLWorks(s)
}

const (
Expand Down