Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: add some logs about boostrap #10546

Merged
merged 5 commits into from
May 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ func (d *ddl) close() {
d.delRangeMgr.clear()
}

logutil.Logger(ddlLogCtx).Info("[ddl] closing DDL", zap.String("ID", d.uuid), zap.Duration("takeTime", time.Since(startTime)))
logutil.Logger(ddlLogCtx).Info("[ddl] DDL closed", zap.String("ID", d.uuid), zap.Duration("take time", time.Since(startTime)))
}

// GetLease implements DDL.GetLease interface.
Expand Down
8 changes: 6 additions & 2 deletions ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ func (w *worker) String() string {
}

func (w *worker) close() {
startTime := time.Now()
close(w.quitCh)
w.wg.Wait()
logutil.Logger(w.logCtx).Info("[ddl] close DDL worker")
logutil.Logger(w.logCtx).Info("[ddl] DDL worker closed", zap.Duration("take time", time.Since(startTime)))
}

// start is used for async online schema changing, it will try to become the owner firstly,
Expand Down Expand Up @@ -637,7 +638,10 @@ func (w *worker) waitSchemaChanged(ctx context.Context, d *ddlCtx, waitTime time
return
}
}
logutil.Logger(w.logCtx).Info("[ddl] wait latest schema version changed", zap.Int64("ver", latestSchemaVersion), zap.Duration("takeTime", time.Since(timeStart)), zap.String("job", job.String()))
logutil.Logger(w.logCtx).Info("[ddl] wait latest schema version changed",
zap.Int64("ver", latestSchemaVersion),
zap.Duration("take time", time.Since(timeStart)),
zap.String("job", job.String()))
}

// waitSchemaSynced handles the following situation:
Expand Down
3 changes: 2 additions & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@ func (do *Domain) mustReload() (exitLoop bool) {

// Close closes the Domain and release its resource.
func (do *Domain) Close() {
startTime := time.Now()
if do.ddl != nil {
terror.Log(do.ddl.Stop())
}
Expand All @@ -548,7 +549,7 @@ func (do *Domain) Close() {
do.sysSessionPool.Close()
do.slowQuery.Close()
do.wg.Wait()
logutil.Logger(context.Background()).Info("domain closed")
logutil.Logger(context.Background()).Info("domain closed", zap.Duration("take time", time.Since(startTime)))
}

type ddlCallback struct {
Expand Down
3 changes: 2 additions & 1 deletion owner/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ func (m *ownerManager) campaignLoop(ctx context.Context, etcdSession *concurrenc
return
}
case <-ctx.Done():
logutil.Logger(logCtx).Info("break campaign loop, context is done")
m.revokeSession(logPrefix, etcdSession.Lease())
return
default:
Expand Down Expand Up @@ -288,7 +289,7 @@ func (m *ownerManager) revokeSession(logPrefix string, leaseID clientv3.LeaseID)
time.Duration(ManagerSessionTTL)*time.Second)
_, err := m.etcdCli.Revoke(cancelCtx, leaseID)
cancel()
logutil.Logger(m.logCtx).Info("break campaign loop, revoke err", zap.Error(err))
logutil.Logger(m.logCtx).Info("revoke session", zap.Error(err))
}

// GetOwnerID implements Manager.GetOwnerID interface.
Expand Down
23 changes: 16 additions & 7 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ const (

// bootstrap initiates system DB for a store.
func bootstrap(s Session) {
startTime := time.Now()
dom := domain.GetDomain(s)
for {
b, err := checkBootstrapped(s)
Expand All @@ -273,13 +274,17 @@ func bootstrap(s Session) {
// For rolling upgrade, we can't do upgrade only in the owner.
if b {
upgrade(s)
logutil.Logger(context.Background()).Info("upgrade successful in bootstrap",
zap.Duration("take time", time.Since(startTime)))
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)
logutil.Logger(context.Background()).Info("bootstrap successful",
zap.Duration("take time", time.Since(startTime)))
return
}
time.Sleep(200 * time.Millisecond)
Expand Down Expand Up @@ -522,18 +527,20 @@ func upgrade(s Session) {
_, err = s.Execute(context.Background(), "COMMIT")

if err != nil {
time.Sleep(1 * time.Second)
sleepTime := 1 * time.Second
logutil.Logger(context.Background()).Info("update bootstrap ver failed",
zap.Error(err), zap.Duration("sleeping time", sleepTime))
time.Sleep(sleepTime)
// Check if TiDB is already upgraded.
v, err1 := getBootstrapVersion(s)
if err1 != nil {
logutil.Logger(context.Background()).Fatal("upgrade error",
zap.Error(err1))
logutil.Logger(context.Background()).Fatal("upgrade failed", zap.Error(err1))
}
if v >= currentBootstrapVersion {
// It is already bootstrapped/upgraded by a higher version TiDB server.
return
}
logutil.Logger(context.Background()).Fatal("[Upgrade] upgrade error",
logutil.Logger(context.Background()).Fatal("[Upgrade] upgrade failed",
zap.Int64("from", ver),
zap.Int("to", currentBootstrapVersion),
zap.Error(err))
Expand Down Expand Up @@ -912,16 +919,18 @@ func doDMLWorks(s Session) {
writeSystemTZ(s)
_, err := s.Execute(context.Background(), "COMMIT")
if err != nil {
time.Sleep(1 * time.Second)
sleepTime := 1 * time.Second
logutil.Logger(context.Background()).Info("doDMLWorks failed", zap.Error(err), zap.Duration("sleeping time", sleepTime))
time.Sleep(sleepTime)
// Check if TiDB is already bootstrapped.
b, err1 := checkBootstrapped(s)
if err1 != nil {
logutil.Logger(context.Background()).Fatal("doDMLWorks error", zap.Error(err1))
logutil.Logger(context.Background()).Fatal("doDMLWorks failed", zap.Error(err1))
}
if b {
return
}
logutil.Logger(context.Background()).Fatal("doDMLWorks error", zap.Error(err))
logutil.Logger(context.Background()).Fatal("doDMLWorks failed", zap.Error(err))
}
}

Expand Down