Skip to content

Commit

Permalink
*: redact arguments for Error (#20436)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunRunAway authored Oct 21, 2020
1 parent 04d38f5 commit 2f067c0
Show file tree
Hide file tree
Showing 57 changed files with 1,710 additions and 1,598 deletions.
23 changes: 1 addition & 22 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ const (
DefStatusHost = "0.0.0.0"
// DefStoreLivenessTimeout is the default value for store liveness timeout.
DefStoreLivenessTimeout = "5s"
// DefTiDBRedactLog is the default value for redact log.
DefTiDBRedactLog = 0
)

// Valid config maps
Expand Down Expand Up @@ -164,8 +162,6 @@ type Config struct {
EnableGlobalIndex bool `toml:"enable-global-index" json:"enable-global-index"`
// DeprecateIntegerDisplayWidth indicates whether deprecating the max display length for integer.
DeprecateIntegerDisplayWidth bool `toml:"deprecate-integer-display-length" json:"deprecate-integer-display-length"`
// EnableRedactLog indicates that whether redact log, 0 is disable. 1 is enable.
EnableRedactLog int32 `toml:"enable-redact-log" json:"enable-redact-log"`
}

// UpdateTempStoragePath is to update the `TempStoragePath` if port/statusPort was changed
Expand Down Expand Up @@ -759,7 +755,6 @@ var defaultConf = Config{
SpilledFileEncryptionMethod: SpilledFileEncryptionMethodPlaintext,
},
DeprecateIntegerDisplayWidth: false,
EnableRedactLog: DefTiDBRedactLog,
}

var (
Expand Down Expand Up @@ -795,6 +790,7 @@ var deprecatedConfig = map[string]struct{}{
"performance.max-memory": {},
"max-txn-time-use": {},
"experimental.allow-auto-random": {},
"enable-redact-log": {}, // use variable tidb_redact_log instead
}

func isAllDeprecatedConfigItems(items []string) bool {
Expand Down Expand Up @@ -1013,23 +1009,6 @@ var TableLockDelayClean = func() uint64 {
return GetGlobalConfig().DelayCleanTableLock
}

// RedactLogEnabled uses to check whether enabled the log redact.
func RedactLogEnabled() bool {
return atomic.LoadInt32(&GetGlobalConfig().EnableRedactLog) == 1
}

// SetRedactLog uses to set log redact status.
func SetRedactLog(enable bool) {
value := int32(0)
if enable {
value = 1
}
g := GetGlobalConfig()
newConf := *g
newConf.EnableRedactLog = value
StoreGlobalConfig(&newConf)
}

// ToLogConfig converts *Log to *logutil.LogConfig.
func (l *Log) ToLogConfig() *logutil.LogConfig {
return logutil.NewLogConfig(l.Level, l.Format, l.SlowQueryFile, l.File, l.getDisableTimestamp(), func(config *zaplog.Config) { config.DisableErrorVerbose = l.getDisableErrorStack() })
Expand Down
9 changes: 5 additions & 4 deletions ddl/column_type_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tidb/util/testkit"
)

Expand Down Expand Up @@ -283,8 +284,8 @@ var mockTerrorMap = make(map[string]*terror.Error)

func init() {
// Since terror new action will cause data race with other test suite (getTerrorCode) in parallel, we init it all here.
mockTerrorMap[model.StateNone.String()] = terror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateNone.String())
mockTerrorMap[model.StateDeleteOnly.String()] = terror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateDeleteOnly.String())
mockTerrorMap[model.StateWriteOnly.String()] = terror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateWriteOnly.String())
mockTerrorMap[model.StateWriteReorganization.String()] = terror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateWriteReorganization.String())
mockTerrorMap[model.StateNone.String()] = dbterror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateNone.String())
mockTerrorMap[model.StateDeleteOnly.String()] = dbterror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateDeleteOnly.String())
mockTerrorMap[model.StateWriteOnly.String()] = dbterror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateWriteOnly.String())
mockTerrorMap[model.StateWriteReorganization.String()] = dbterror.ClassDDL.New(1, "MockRollingBackInCallBack-"+model.StateWriteReorganization.String())
}
3 changes: 2 additions & 1 deletion ddl/ddl_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
tidbutil "github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tidb/util/logutil"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -737,7 +738,7 @@ func toTError(err error) *terror.Error {
}

// TODO: Add the error code.
return terror.ClassDDL.Synthesize(terror.CodeUnknown, err.Error())
return dbterror.ClassDDL.Synthesize(terror.CodeUnknown, err.Error())
}

// waitSchemaChanged waits for the completion of updating all servers' schema. In order to make sure that happens,
Expand Down
279 changes: 140 additions & 139 deletions ddl/error.go

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions distsql/select_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/memory"
Expand All @@ -42,8 +43,10 @@ import (
)

var (
errQueryInterrupted = terror.ClassExecutor.NewStd(errno.ErrQueryInterrupted)
errQueryInterrupted = dbterror.ClassExecutor.NewStd(errno.ErrQueryInterrupted)
)

var (
coprCacheHistogramHit = metrics.DistSQLCoprCacheHistogram.WithLabelValues("hit")
coprCacheHistogramMiss = metrics.DistSQLCoprCacheHistogram.WithLabelValues("miss")
)
Expand Down Expand Up @@ -132,15 +135,15 @@ func (r *selectResult) fetchResp(ctx context.Context) error {
atomic.StoreInt64(&r.selectRespSize, respSize)
r.memConsume(respSize)
if err := r.selectResp.Error; err != nil {
return terror.ClassTiKV.Synthesize(terror.ErrCode(err.Code), err.Msg)
return dbterror.ClassTiKV.Synthesize(terror.ErrCode(err.Code), err.Msg)
}
sessVars := r.ctx.GetSessionVars()
if atomic.LoadUint32(&sessVars.Killed) == 1 {
return errors.Trace(errQueryInterrupted)
}
sc := sessVars.StmtCtx
for _, warning := range r.selectResp.Warnings {
sc.AppendWarning(terror.ClassTiKV.Synthesize(terror.ErrCode(warning.Code), warning.Msg))
sc.AppendWarning(dbterror.ClassTiKV.Synthesize(terror.ErrCode(warning.Code), warning.Msg))
}
if r.feedback != nil {
r.feedback.Update(resultSubset.GetStartKey(), r.selectResp.OutputCounts)
Expand Down
3 changes: 2 additions & 1 deletion distsql/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tipb/go-tipb"
)

Expand Down Expand Up @@ -97,7 +98,7 @@ func (r *streamResult) readDataFromResponse(ctx context.Context, resp kv.Respons
return false, errors.Errorf("stream response error: [%d]%s\n", stream.Error.Code, stream.Error.Msg)
}
for _, warning := range stream.Warnings {
r.ctx.GetSessionVars().StmtCtx.AppendWarning(terror.ClassTiKV.Synthesize(terror.ErrCode(warning.Code), warning.Msg))
r.ctx.GetSessionVars().StmtCtx.AppendWarning(dbterror.ClassTiKV.Synthesize(terror.ErrCode(warning.Code), warning.Msg))
}

err = result.Unmarshal(stream.Data)
Expand Down
8 changes: 5 additions & 3 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/bindinfo"
"github.com/pingcap/tidb/config"
Expand All @@ -46,6 +47,7 @@ import (
"github.com/pingcap/tidb/store/tikv"
"github.com/pingcap/tidb/telemetry"
"github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tidb/util/domainutil"
"github.com/pingcap/tidb/util/expensivequery"
"github.com/pingcap/tidb/util/logutil"
Expand Down Expand Up @@ -1279,8 +1281,8 @@ func (do *Domain) NotifyUpdatePrivilege(ctx sessionctx.Context) {

var (
// ErrInfoSchemaExpired returns the error that information schema is out of date.
ErrInfoSchemaExpired = terror.ClassDomain.New(errno.ErrInfoSchemaExpired, errno.MySQLErrName[errno.ErrInfoSchemaExpired])
ErrInfoSchemaExpired = dbterror.ClassDomain.NewStd(errno.ErrInfoSchemaExpired)
// ErrInfoSchemaChanged returns the error that information schema is changed.
ErrInfoSchemaChanged = terror.ClassDomain.New(errno.ErrInfoSchemaChanged,
errno.MySQLErrName[errno.ErrInfoSchemaChanged]+". "+kv.TxnRetryableMark)
ErrInfoSchemaChanged = dbterror.ClassDomain.NewStdErr(errno.ErrInfoSchemaChanged,
mysql.Message(errno.MySQLErrName[errno.ErrInfoSchemaChanged].Raw+". "+kv.TxnRetryableMark, nil), "", "")
)
3 changes: 2 additions & 1 deletion domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/store/tikv/oracle"
util2 "github.com/pingcap/tidb/util"
"github.com/pingcap/tidb/util/dbterror"
"github.com/pingcap/tidb/util/hack"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/pdapi"
Expand Down Expand Up @@ -79,7 +80,7 @@ const (
)

// ErrPrometheusAddrIsNotSet is the error that Prometheus address is not set in PD and etcd
var ErrPrometheusAddrIsNotSet = terror.ClassDomain.New(errno.ErrPrometheusAddrIsNotSet, errno.MySQLErrName[errno.ErrPrometheusAddrIsNotSet])
var ErrPrometheusAddrIsNotSet = dbterror.ClassDomain.NewStd(errno.ErrPrometheusAddrIsNotSet)

// errPlacementRulesDisabled is exported for internal usage, indicating PD rejected the request due to disabled placement feature.
var errPlacementRulesDisabled = errors.New("placement rules feature is disabled")
Expand Down
Loading

0 comments on commit 2f067c0

Please sign in to comment.