Skip to content

*: redact arguments for Error (#20436)#21106

Closed
ti-srebot wants to merge 1 commit intopingcap:release-4.0from
ti-srebot:release-4.0-2f067c054255
Closed

*: redact arguments for Error (#20436)#21106
ti-srebot wants to merge 1 commit intopingcap:release-4.0from
ti-srebot:release-4.0-2f067c054255

Conversation

@ti-srebot
Copy link
Contributor

cherry-pick #20436 to release-4.0


What problem does this PR solve?

Issue Number: part of #18566

Problem Summary:

What is changed and how it works?

Proposal: xxx

What's Changed:

  • changes in "github.com/pingcap/errors" Redact arguments for Error errors#27
    • redact errors in Error.GenWithStackByArgs & Error.FastGenByArgs
  • changes in "github.com/pingcap/parser" *: redact arguments for Error parser#1051
    • define mysql.Message to bind redactArgs which means which arguments of the error need to be redacted with each error message
    • MySQLErrName should be defined with mysql.Message.
    • ErrClass.NewStd considers redactArgs
    • All errors uses ErrClass.NewStd or mysql.Message to consider error redaction
  • changes in "github.com/pingcap/tidb" *: redact arguments for Error #20436
    • inherit ErrClass.NewStd
    • All errors uses ErrClass.NewStd or mysql.Message to consider error redaction
      How it Works:

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn: To be added

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)
Case 1
mysql> create table t (a int, unique key (a));
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values (1),(1);
ERROR 1062 (23000): Duplicate entry '1' for key 'a'
mysql> set @@session.tidb_redact_log=1;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into t values (1),(1);
ERROR 1062 (23000): Duplicate entry '?' for key '?'

log:

[2020/10/21 14:40:05.368 +08:00] [INFO] [tidb.go:222] ["rollbackTxn for ddl/autocommit failed"]
[2020/10/21 14:40:05.368 +08:00] [INFO] [conn.go:800] ["command dispatched failed"] [conn=1] [connInfo="id:1, addr:127.0.0.1:53367 status:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="insert into t values (1),(1)"] [txn_mode=OPTIMISTIC] [err="[kv:1062]Duplicate entry '1' for key 'a'"]
[2020/10/21 14:40:14.104 +08:00] [INFO] [tidb.go:222] ["rollbackTxn for ddl/autocommit failed"]
[2020/10/21 14:40:14.104 +08:00] [INFO] [conn.go:800] ["command dispatched failed"] [conn=1] [connInfo="id:1, addr:127.0.0.1:53367 status:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="insert into t values ( ? ) , ( ? )"] [txn_mode=OPTIMISTIC] [err="[kv:1062]Duplicate entry '?' for key '?'"]
Case 2

Client 1:

mysql> set @@global.tidb_redact_log=1;
Query OK, 0 rows affected (0.00 sec)

Then start client 2:

mysql> insert into t values (1),(1);
ERROR 1062 (23000): Duplicate entry '?' for key '?'

log:

[2020/10/21 14:41:20.513 +08:00] [INFO] [set.go:216] ["set global var"] [conn=3] [name=tidb_redact_log] [val=1]
[2020/10/21 14:41:23.552 +08:00] [INFO] [tidb.go:222] ["rollbackTxn for ddl/autocommit failed"]
[2020/10/21 14:41:23.552 +08:00] [INFO] [conn.go:800] ["command dispatched failed"] [conn=4] [connInfo="id:4, addr:127.0.0.1:53636 status:10, collation:utf8_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="insert into t values ( ? ) , ( ? )"] [txn_mode=OPTIMISTIC] [err="[kv:1062]Duplicate entry '?' for key '?'"]

Release note

  • No release note

Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor Author

/run-all-tests

@ti-srebot
Copy link
Contributor Author

@SunRunAway you're already a collaborator in bot's repo.

@SunRunAway SunRunAway closed this Nov 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants