From 5a34c4b9d2e9aebb2ba132745af5634a52cdefe8 Mon Sep 17 00:00:00 2001 From: crazycs Date: Thu, 11 Apr 2019 11:04:34 +0800 Subject: [PATCH] server: only owner do bootstrap (#10029) --- session/bootstrap.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index 97dcfe9c71d35..e19f2631a6977 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -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" @@ -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 (