From 33da90faec1ce371c1740cb46522c259884286e8 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Mon, 13 May 2019 10:20:54 +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 9f1d51f6e99da..109e8bf73989f 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -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" @@ -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 (