Skip to content

Commit

Permalink
server: only owner do bootstrap (#10029)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored Apr 11, 2019
1 parent e90f3b9 commit 5a34c4b
Showing 1 changed file with 21 additions and 10 deletions.
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)
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() {
doDDLWorks(s)
doDMLWorks(s)
return
}
time.Sleep(200 * time.Millisecond)
}
doDDLWorks(s)
doDMLWorks(s)
}

const (
Expand Down

0 comments on commit 5a34c4b

Please sign in to comment.