ddl: Add admin check before drop table using building flag.#7343
ddl: Add admin check before drop table using building flag.#7343tiancaiamao merged 15 commits intopingcap:masterfrom
Conversation
…igint have admin check bug
…in_check_before_drop
executor/ddl.go
Outdated
| return errors.Trace(err) | ||
| } | ||
|
|
||
| if os.Getenv("TIDB_CHECK_BEFORE_DROP") == "1" { |
There was a problem hiding this comment.
Please add a log here. I suggest using the warn log level.
executor/executor.go
Outdated
| defer func() { e.done = true }() | ||
| dbName := model.NewCIStr(e.ctx.GetSessionVars().CurrentDB) | ||
| for _, t := range e.tables { | ||
| if dbName.L == "" { |
There was a problem hiding this comment.
Ye~
If use e.ctx.(sqlexec.RestrictedSQLExecutor).ExecRestrictedSQL(e.ctx, "admin check table test.t1") ,here dbName.L is "".
There was a problem hiding this comment.
Could we use t.DBInfo.Name directly?
executor/executor_test.go
Outdated
| // For "checksum_without_index", we only have one checksum, so the result will be 1. | ||
| res.Sort().Check(testkit.Rows("test checksum_with_index 0 2 2", "test checksum_without_index 1 1 1")) | ||
|
|
||
| tk.MustExec("drop table if exists admin_test") |
There was a problem hiding this comment.
Could you add a test case that meet error?
executor/executor_test.go
Outdated
|
|
||
| os.Setenv("TIDB_CHECK_BEFORE_DROP", "1") | ||
| r, err = tk.Exec("drop table admin_test") | ||
| c.Assert(err, NotNil) |
There was a problem hiding this comment.
Please check the content of the error to make sure it is thrown by the consistent checking.
|
@crazycs520 Please add the proper label. |
|
I think it's better to use a building flag for this check. |
|
depends on os environment variable is not a good practice. |
ca822df to
40f5584
Compare
40f5584 to
2472f38
Compare
|
@crazycs520 Please change the pr title. |
config/config.go
Outdated
|
|
||
| func init() { | ||
| if CheckBeforeDropLDFlag == "1" { | ||
| CheckBeforeDrop = true |
There was a problem hiding this comment.
use atomic to protect CheckBeforeDrop, or the data race test perhaps reports error.
executor/executor_test.go
Outdated
| func (s *testSuite) TestAdmin(c *C) { | ||
| origin := config.CheckBeforeDrop | ||
| defer func() { | ||
| config.CheckBeforeDrop = origin |
util/printer/printer.go
Outdated
| log.Infof("UTC Build Time: %s", TiDBBuildTS) | ||
| log.Infof("GoVersion: %s", GoVersion) | ||
| log.Infof("Race Enabled: %v", israce.RaceEnabled) | ||
| log.Infof("Admin check table before drop is %v", config.CheckBeforeDrop) |
There was a problem hiding this comment.
How about Check Table Before Drop: %v?
executor/ddl.go
Outdated
| } | ||
|
|
||
| if config.CheckBeforeDrop { | ||
| log.Warnf("admin check table before drop was on") |
There was a problem hiding this comment.
It's better to add more info in this log, e.g. the table name.
| defer func() { e.done = true }() | ||
| dbName := model.NewCIStr(e.ctx.GetSessionVars().CurrentDB) | ||
| for _, t := range e.tables { | ||
| dbName := t.DBInfo.Name |
There was a problem hiding this comment.
Finally, it was fixed. 👍
There was a problem hiding this comment.
Btw, I think we need a test case for it.
|
@winkyao PTAL again. I add |
config/config.go
Outdated
| "tikv": true, | ||
| } | ||
| // checkTableBeforeDrop enable to execute `admin check table` before `drop table`. | ||
| CheckTableBeforeDrop = true |
| tk.MustExec(`admin check table t;`) | ||
|
|
||
| tk = testkit.NewTestKit(c, s.store) | ||
| tk.MustExec(`admin check table test.t;`) |
There was a problem hiding this comment.
It's better to check the table from the other database.
|
/run-all-tests |
config/config.go
Outdated
There was a problem hiding this comment.
Could this variable be in lower case ?
…in_check_before_drop
49a5c68 to
f150a4b
Compare
|
should we also add some UTs to make sure the |
|
LGTM |
|
@tiancaiamao If we run |
|
/run-all-tests |
|
LGTM |
What have you changed? (mandatory)
Add
admin check tablebefore drop table according to the ldflags when building.Does this PR affect tidb-ansible update? (mandatory)
No
Does this PR need to be added to the release notes? (mandatory)
No
Refer to a related PR or issue link (optional)
Benchmark result if necessary (optional)
Add a few positive/negative examples (optional)