Skip to content

Commit

Permalink
*: replace 'logutil.Logger(context.Background())' with 'logutil.BgLo…
Browse files Browse the repository at this point in the history
…gger()' (pingcap#10866)
  • Loading branch information
lonng authored and crazycs520 committed Jun 21, 2019
1 parent 10e0086 commit c8d1ff7
Show file tree
Hide file tree
Showing 101 changed files with 466 additions and 505 deletions.
4 changes: 2 additions & 2 deletions bindinfo/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (h *BindHandle) Update(fullLoad bool) (err error) {
h.lastUpdateTime = meta.UpdateTime
}
if err != nil {
logutil.Logger(context.Background()).Error("update bindinfo failed", zap.Error(err))
logutil.BgLogger().Error("update bindinfo failed", zap.Error(err))
continue
}

Expand Down Expand Up @@ -246,7 +246,7 @@ func (h *BindHandle) DropInvalidBindRecord() {
if invalidBindRecord.droppedTime.IsZero() {
err := h.DropBindRecord(invalidBindRecord.bindRecord)
if err != nil {
logutil.Logger(context.Background()).Error("DropInvalidBindRecord failed", zap.Error(err))
logutil.BgLogger().Error("DropInvalidBindRecord failed", zap.Error(err))
}
invalidBindRecord.droppedTime = time.Now()
continue
Expand Down
3 changes: 1 addition & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package config

import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
"fmt"
Expand Down Expand Up @@ -471,7 +470,7 @@ func ReloadGlobalConfig() error {

confReloader(nc, c)
globalConf.Store(nc)
logutil.Logger(context.Background()).Info("reload config changes" + formattedDiff.String())
logutil.BgLogger().Info("reload config changes" + formattedDiff.String())
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func onAddColumn(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, err error)
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
}
logutil.Logger(ddlLogCtx).Info("[ddl] run add column job", zap.String("job", job.String()), zap.Reflect("columnInfo", *columnInfo), zap.Int("offset", offset))
logutil.BgLogger().Info("[ddl] run add column job", zap.String("job", job.String()), zap.Reflect("columnInfo", *columnInfo), zap.Int("offset", offset))
// Set offset arg to job.
if offset != 0 {
job.Args = []interface{}{columnInfo, pos, offset}
Expand Down
27 changes: 12 additions & 15 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ var (
// a newly created table. It takes effect only if the Storage supports split
// region.
EnableSplitTableRegion = uint32(0)

// ddlLogCtx uses for log.
ddlLogCtx = context.Background()
)

var (
Expand Down Expand Up @@ -310,7 +307,7 @@ type ddlCtx struct {

func (dc *ddlCtx) isOwner() bool {
isOwner := dc.ownerManager.IsOwner()
logutil.Logger(ddlLogCtx).Debug("[ddl] check whether is the DDL owner", zap.Bool("isOwner", isOwner), zap.String("selfID", dc.uuid))
logutil.BgLogger().Debug("[ddl] check whether is the DDL owner", zap.Bool("isOwner", isOwner), zap.String("selfID", dc.uuid))
if isOwner {
metrics.DDLCounter.WithLabelValues(metrics.DDLOwner + "_" + mysql.TiDBReleaseVersion).Inc()
}
Expand Down Expand Up @@ -339,7 +336,7 @@ func asyncNotifyEvent(d *ddlCtx, e *util.Event) {
case d.ddlEventCh <- e:
return
default:
logutil.Logger(ddlLogCtx).Warn("[ddl] fail to notify DDL event", zap.String("event", e.String()))
logutil.BgLogger().Warn("[ddl] fail to notify DDL event", zap.String("event", e.String()))
time.Sleep(time.Microsecond * 10)
}
}
Expand Down Expand Up @@ -400,15 +397,15 @@ func (d *ddl) Stop() error {
defer d.m.Unlock()

d.close()
logutil.Logger(ddlLogCtx).Info("[ddl] stop DDL", zap.String("ID", d.uuid))
logutil.BgLogger().Info("[ddl] stop DDL", zap.String("ID", d.uuid))
return nil
}

func (d *ddl) newDeleteRangeManager(mock bool) delRangeManager {
var delRangeMgr delRangeManager
if !mock {
delRangeMgr = newDelRangeManager(d.store, d.sessPool)
logutil.Logger(ddlLogCtx).Info("[ddl] start delRangeManager OK", zap.Bool("is a emulator", !d.store.SupportDeleteRange()))
logutil.BgLogger().Info("[ddl] start delRangeManager OK", zap.Bool("is a emulator", !d.store.SupportDeleteRange()))
} else {
delRangeMgr = newMockDelRangeManager()
}
Expand All @@ -420,7 +417,7 @@ func (d *ddl) newDeleteRangeManager(mock bool) delRangeManager {
// start campaigns the owner and starts workers.
// ctxPool is used for the worker's delRangeManager and creates sessions.
func (d *ddl) start(ctx context.Context, ctxPool *pools.ResourcePool) {
logutil.Logger(ddlLogCtx).Info("[ddl] start DDL", zap.String("ID", d.uuid), zap.Bool("runWorker", RunWorker))
logutil.BgLogger().Info("[ddl] start DDL", zap.String("ID", d.uuid), zap.Bool("runWorker", RunWorker))
d.quitCh = make(chan struct{})

// If RunWorker is true, we need campaign owner and do DDL job.
Expand Down Expand Up @@ -456,7 +453,7 @@ func (d *ddl) start(ctx context.Context, ctxPool *pools.ResourcePool) {
func() { d.schemaSyncer.StartCleanWork() },
func(r interface{}) {
if r != nil {
logutil.Logger(ddlLogCtx).Error("[ddl] DDL syncer clean worker meet panic",
logutil.BgLogger().Error("[ddl] DDL syncer clean worker meet panic",
zap.String("ID", d.uuid), zap.Reflect("r", r), zap.Stack("stack trace"))
metrics.PanicCounter.WithLabelValues(metrics.LabelDDLSyncer).Inc()
}
Expand All @@ -476,7 +473,7 @@ func (d *ddl) close() {
d.schemaSyncer.CloseCleanWork()
err := d.schemaSyncer.RemoveSelfVersionPath()
if err != nil {
logutil.Logger(ddlLogCtx).Error("[ddl] remove self version path failed", zap.Error(err))
logutil.BgLogger().Error("[ddl] remove self version path failed", zap.Error(err))
}

for _, worker := range d.workers {
Expand All @@ -491,7 +488,7 @@ func (d *ddl) close() {
d.sessPool.close()
}

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

// GetLease implements DDL.GetLease interface.
Expand Down Expand Up @@ -587,7 +584,7 @@ func (d *ddl) doDDLJob(ctx sessionctx.Context, job *model.Job) error {

// Notice worker that we push a new job and wait the job done.
d.asyncNotifyWorker(job.Type)
logutil.Logger(ddlLogCtx).Info("[ddl] start DDL job", zap.String("job", job.String()), zap.String("query", job.Query))
logutil.BgLogger().Info("[ddl] start DDL job", zap.String("job", job.String()), zap.String("query", job.Query))

var historyJob *model.Job
jobID := job.ID
Expand All @@ -610,16 +607,16 @@ func (d *ddl) doDDLJob(ctx sessionctx.Context, job *model.Job) error {

historyJob, err = d.getHistoryDDLJob(jobID)
if err != nil {
logutil.Logger(ddlLogCtx).Error("[ddl] get history DDL job failed, check again", zap.Error(err))
logutil.BgLogger().Error("[ddl] get history DDL job failed, check again", zap.Error(err))
continue
} else if historyJob == nil {
logutil.Logger(ddlLogCtx).Debug("[ddl] DDL job is not in history, maybe not run", zap.Int64("jobID", jobID))
logutil.BgLogger().Debug("[ddl] DDL job is not in history, maybe not run", zap.Int64("jobID", jobID))
continue
}

// If a job is a history job, the state must be JobStateSynced or JobStateRollbackDone or JobStateCancelled.
if historyJob.IsSynced() {
logutil.Logger(ddlLogCtx).Info("[ddl] DDL job is finished", zap.Int64("jobID", jobID))
logutil.BgLogger().Info("[ddl] DDL job is finished", zap.Int64("jobID", jobID))
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,11 @@ func setTimestampDefaultValue(c *table.Column, hasDefaultValue bool, setOnUpdate
if setOnUpdateNow {
if err := c.SetDefaultValue(types.ZeroDatetimeStr); err != nil {
context.Background()
logutil.Logger(ddlLogCtx).Error("set default value failed", zap.Error(err))
logutil.BgLogger().Error("set default value failed", zap.Error(err))
}
} else {
if err := c.SetDefaultValue(strings.ToUpper(ast.CurrentTimestamp)); err != nil {
logutil.Logger(ddlLogCtx).Error("set default value failed", zap.Error(err))
logutil.BgLogger().Error("set default value failed", zap.Error(err))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func buildJobDependence(t *meta.Meta, curJob *model.Job) error {
return errors.Trace(err)
}
if isDependent {
logutil.Logger(ddlLogCtx).Info("[ddl] current DDL job depends on other job", zap.String("currentJob", curJob.String()), zap.String("dependentJob", job.String()))
logutil.BgLogger().Info("[ddl] current DDL job depends on other job", zap.String("currentJob", curJob.String()), zap.String("dependentJob", job.String()))
curJob.DependencyID = job.ID
break
}
Expand Down Expand Up @@ -335,7 +335,7 @@ func isDependencyJobDone(t *meta.Meta, job *model.Job) (bool, error) {
if historyJob == nil {
return false, nil
}
logutil.Logger(ddlLogCtx).Info("[ddl] current DDL job dependent job is finished", zap.String("currentJob", job.String()), zap.Int64("dependentJobID", job.DependencyID))
logutil.BgLogger().Info("[ddl] current DDL job dependent job is finished", zap.String("currentJob", job.String()), zap.Int64("dependentJobID", job.DependencyID))
job.DependencyID = noneDependencyJob
return true, nil
}
Expand Down
20 changes: 10 additions & 10 deletions ddl/delete_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (dr *delRange) addDelRangeJob(job *model.Job) error {
if !dr.storeSupport {
dr.emulatorCh <- struct{}{}
}
logutil.Logger(ddlLogCtx).Info("[ddl] add job into delete-range table", zap.Int64("jobID", job.ID), zap.String("jobType", job.Type.String()))
logutil.BgLogger().Info("[ddl] add job into delete-range table", zap.Int64("jobID", job.ID), zap.String("jobType", job.Type.String()))
return nil
}

Expand All @@ -120,7 +120,7 @@ func (dr *delRange) start() {

// clear implements delRangeManager interface.
func (dr *delRange) clear() {
logutil.Logger(ddlLogCtx).Info("[ddl] closing delRange")
logutil.BgLogger().Info("[ddl] closing delRange")
close(dr.quitCh)
dr.wait.Wait()
}
Expand All @@ -130,7 +130,7 @@ func (dr *delRange) clear() {
// deletes all keys in each DelRangeTask.
func (dr *delRange) startEmulator() {
defer dr.wait.Done()
logutil.Logger(ddlLogCtx).Info("[ddl] start delRange emulator")
logutil.BgLogger().Info("[ddl] start delRange emulator")
for {
select {
case <-dr.emulatorCh:
Expand Down Expand Up @@ -162,20 +162,20 @@ func IsEmulatorGCEnable() bool {
func (dr *delRange) doDelRangeWork() error {
ctx, err := dr.sessPool.get()
if err != nil {
logutil.Logger(ddlLogCtx).Error("[ddl] delRange emulator get session failed", zap.Error(err))
logutil.BgLogger().Error("[ddl] delRange emulator get session failed", zap.Error(err))
return errors.Trace(err)
}
defer dr.sessPool.put(ctx)

ranges, err := util.LoadDeleteRanges(ctx, math.MaxInt64)
if err != nil {
logutil.Logger(ddlLogCtx).Error("[ddl] delRange emulator load tasks failed", zap.Error(err))
logutil.BgLogger().Error("[ddl] delRange emulator load tasks failed", zap.Error(err))
return errors.Trace(err)
}

for _, r := range ranges {
if err := dr.doTask(ctx, r); err != nil {
logutil.Logger(ddlLogCtx).Error("[ddl] delRange emulator do task failed", zap.Error(err))
logutil.BgLogger().Error("[ddl] delRange emulator do task failed", zap.Error(err))
return errors.Trace(err)
}
}
Expand Down Expand Up @@ -221,14 +221,14 @@ func (dr *delRange) doTask(ctx sessionctx.Context, r util.DelRangeTask) error {
}
if finish {
if err := util.CompleteDeleteRange(ctx, r); err != nil {
logutil.Logger(ddlLogCtx).Error("[ddl] delRange emulator complete task failed", zap.Error(err))
logutil.BgLogger().Error("[ddl] delRange emulator complete task failed", zap.Error(err))
return errors.Trace(err)
}
logutil.Logger(ddlLogCtx).Info("[ddl] delRange emulator complete task", zap.Int64("jobID", r.JobID), zap.Int64("elementID", r.ElementID))
logutil.BgLogger().Info("[ddl] delRange emulator complete task", zap.Int64("jobID", r.JobID), zap.Int64("elementID", r.ElementID))
break
}
if err := util.UpdateDeleteRange(ctx, r, newStartKey, oldStartKey); err != nil {
logutil.Logger(ddlLogCtx).Error("[ddl] delRange emulator update task failed", zap.Error(err))
logutil.BgLogger().Error("[ddl] delRange emulator update task failed", zap.Error(err))
}
oldStartKey = newStartKey
}
Expand Down Expand Up @@ -334,7 +334,7 @@ func insertJobIntoDeleteRangeTable(ctx sessionctx.Context, job *model.Job) error
}

func doInsert(s sqlexec.SQLExecutor, jobID int64, elementID int64, startKey, endKey kv.Key, ts uint64) error {
logutil.Logger(ddlLogCtx).Info("[ddl] insert into delete-range table", zap.Int64("jobID", jobID), zap.Int64("elementID", elementID))
logutil.BgLogger().Info("[ddl] insert into delete-range table", zap.Int64("jobID", jobID), zap.Int64("elementID", elementID))
startKeyEncoded := hex.EncodeToString(startKey)
endKeyEncoded := hex.EncodeToString(endKey)
sql := fmt.Sprintf(insertDeleteRangeSQL, jobID, elementID, startKeyEncoded, endKeyEncoded, ts)
Expand Down
Loading

0 comments on commit c8d1ff7

Please sign in to comment.