Skip to content

Commit

Permalink
server: only owner do bootstrap (#10029) (#10426)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored and jackysp committed May 13, 2019
1 parent 71c8e1e commit 570a315
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 @@ -30,6 +30,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 @@ -214,17 +215,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 570a315

Please sign in to comment.