Skip to content

Commit 570a315

Browse files
crazycs520jackysp
authored andcommitted
server: only owner do bootstrap (#10029) (#10426)
1 parent 71c8e1e commit 570a315

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

session/bootstrap.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/pingcap/parser/mysql"
3131
"github.com/pingcap/parser/terror"
3232
"github.com/pingcap/tidb/ddl"
33+
"github.com/pingcap/tidb/domain"
3334
"github.com/pingcap/tidb/infoschema"
3435
"github.com/pingcap/tidb/sessionctx/variable"
3536
"github.com/pingcap/tidb/util/chunk"
@@ -214,17 +215,27 @@ const (
214215

215216
// bootstrap initiates system DB for a store.
216217
func bootstrap(s Session) {
217-
b, err := checkBootstrapped(s)
218-
if err != nil {
219-
logutil.Logger(context.Background()).Fatal("check bootstrap error",
220-
zap.Error(err))
221-
}
222-
if b {
223-
upgrade(s)
224-
return
218+
dom := domain.GetDomain(s)
219+
for {
220+
b, err := checkBootstrapped(s)
221+
if err != nil {
222+
logutil.Logger(context.Background()).Fatal("check bootstrap error",
223+
zap.Error(err))
224+
}
225+
// For rolling upgrade, we can't do upgrade only in the owner.
226+
if b {
227+
upgrade(s)
228+
return
229+
}
230+
// To reduce conflict when multiple TiDB-server start at the same time.
231+
// Actually only one server need to do the bootstrap. So we chose DDL owner to do this.
232+
if dom.DDL().OwnerManager().IsOwner() {
233+
doDDLWorks(s)
234+
doDMLWorks(s)
235+
return
236+
}
237+
time.Sleep(200 * time.Millisecond)
225238
}
226-
doDDLWorks(s)
227-
doDMLWorks(s)
228239
}
229240

230241
const (

0 commit comments

Comments
 (0)