From 62113441d215f36ef9d5327933fd92b6b022c999 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Wed, 3 Apr 2019 19:12:02 +0800 Subject: [PATCH 1/5] server: only owner do bootstrap --- session/bootstrap.go | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index 97dcfe9c71d35..e80f97282eacc 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,24 @@ 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)) + } + if b { + upgrade(s) + return + } + if dom.DDL().OwnerManager().IsOwner() { + doDDLWorks(s) + doDMLWorks(s) + return + } + time.Sleep(50 * time.Millisecond) } - doDDLWorks(s) - doDMLWorks(s) } const ( From 7057924448224f694e30a1c04861c31451a9c10a Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Mon, 8 Apr 2019 11:59:19 +0800 Subject: [PATCH 2/5] Address comment --- session/bootstrap.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/session/bootstrap.go b/session/bootstrap.go index e80f97282eacc..75475b4b951a3 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -262,6 +262,8 @@ func bootstrap(s Session) { 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) From 67e3f76255ce7da85b358c4117644a569fb0ddc5 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Tue, 9 Apr 2019 17:14:07 +0800 Subject: [PATCH 3/5] address comment --- session/bootstrap.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index 75475b4b951a3..7e06c4438aa93 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -258,13 +258,13 @@ func bootstrap(s Session) { logutil.Logger(context.Background()).Fatal("check bootstrap error", zap.Error(err)) } - 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() { + if b { + upgrade(s) + return + } doDDLWorks(s) doDMLWorks(s) return From ee7fd24281edf689dca7709d3368e52f44e5ab09 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Wed, 10 Apr 2019 14:41:19 +0800 Subject: [PATCH 4/5] enlarge sleep time when bootstrap --- session/bootstrap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index 7e06c4438aa93..44b72d5f77700 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -269,7 +269,7 @@ func bootstrap(s Session) { doDMLWorks(s) return } - time.Sleep(50 * time.Millisecond) + time.Sleep(200 * time.Millisecond) } } From 45d052f351a872e3333ea9e6d1681750a39880b3 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Wed, 10 Apr 2019 18:51:15 +0800 Subject: [PATCH 5/5] fix bug for upgrade --- session/bootstrap.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index 44b72d5f77700..e19f2631a6977 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -258,13 +258,14 @@ func bootstrap(s Session) { 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() { - if b { - upgrade(s) - return - } doDDLWorks(s) doDMLWorks(s) return