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
30 changes: 20 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,26 @@ 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))
}
// 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
if b {
upgrade(s)
return
}
doDDLWorks(s)
doDMLWorks(s)
return
}
time.Sleep(200 * time.Millisecond)
}
doDDLWorks(s)
doDMLWorks(s)
}

const (
Expand Down