Skip to content

Commit

Permalink
log: let Write Conflict error message respect redact setting (pingcap…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot committed May 6, 2023
1 parent 35f7d3a commit 3fa4fb9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
27 changes: 21 additions & 6 deletions kv/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ var (
// ErrTxnRetryable is used when KV store occurs retryable error which SQL layer can safely retry the transaction.
// When using TiKV as the storage node, the error is returned ONLY when lock not found (txnLockNotFound) in Commit,
// subject to change it in the future.
ErrTxnRetryable = dbterror.ClassKV.NewStdErr(mysql.ErrTxnRetryable,
pmysql.Message(mysql.MySQLErrName[mysql.ErrTxnRetryable].Raw+TxnRetryableMark, []int{0}))
ErrTxnRetryable = dbterror.ClassKV.NewStdErr(
mysql.ErrTxnRetryable,
pmysql.Message(
mysql.MySQLErrName[mysql.ErrTxnRetryable].Raw+TxnRetryableMark,
mysql.MySQLErrName[mysql.ErrTxnRetryable].RedactArgPos,
),
)
// ErrCannotSetNilValue is the error when sets an empty value.
ErrCannotSetNilValue = dbterror.ClassKV.NewStd(mysql.ErrCannotSetNilValue)
// ErrInvalidTxn is the error when commits or rollbacks in an invalid transaction.
Expand All @@ -47,11 +52,21 @@ var (
// ErrNotImplemented returns when a function is not implemented yet.
ErrNotImplemented = dbterror.ClassKV.NewStd(mysql.ErrNotImplemented)
// ErrWriteConflict is the error when the commit meets an write conflict error.
ErrWriteConflict = dbterror.ClassKV.NewStdErr(mysql.ErrWriteConflict,
pmysql.Message(mysql.MySQLErrName[mysql.ErrWriteConflict].Raw+" "+TxnRetryableMark, []int{3}))
ErrWriteConflict = dbterror.ClassKV.NewStdErr(
mysql.ErrWriteConflict,
pmysql.Message(
mysql.MySQLErrName[mysql.ErrWriteConflict].Raw+" "+TxnRetryableMark,
mysql.MySQLErrName[mysql.ErrWriteConflict].RedactArgPos,
),
)
// ErrWriteConflictInTiDB is the error when the commit meets an write conflict error when local latch is enabled.
ErrWriteConflictInTiDB = dbterror.ClassKV.NewStdErr(mysql.ErrWriteConflictInTiDB,
pmysql.Message(mysql.MySQLErrName[mysql.ErrWriteConflictInTiDB].Raw+" "+TxnRetryableMark, nil))
ErrWriteConflictInTiDB = dbterror.ClassKV.NewStdErr(
mysql.ErrWriteConflictInTiDB,
pmysql.Message(
mysql.MySQLErrName[mysql.ErrWriteConflictInTiDB].Raw+" "+TxnRetryableMark,
mysql.MySQLErrName[mysql.ErrWriteConflictInTiDB].RedactArgPos,
),
)
// ErrLockExpire is the error when the lock is expired.
ErrLockExpire = dbterror.ClassTiKV.NewStd(mysql.ErrLockExpire)
// ErrAssertionFailed is the error when an assertion fails.
Expand Down
10 changes: 10 additions & 0 deletions store/driver/txn/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package txn
import (
"testing"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/tidb/kv"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -66,4 +67,13 @@ func TestWriteConflictPrettyFormat(t *testing.T) {
"reason=Optimistic " +
kv.TxnRetryableMark
require.EqualError(t, newWriteConflictError(conflict), expectedStr)

// test log redaction
original := errors.RedactLogEnabled.Load()
errors.RedactLogEnabled.Store(true)
defer func() { errors.RedactLogEnabled.Store(original) }()
expectedStr = "[kv:9007]Write conflict, " +
"txnStartTS=399402937522847774, conflictStartTS=399402937719455772, conflictCommitTS=399402937719455773, " +
"key=????, reason=Optimistic " + kv.TxnRetryableMark
require.EqualError(t, newWriteConflictError(conflict), expectedStr)
}

0 comments on commit 3fa4fb9

Please sign in to comment.