Skip to content

Comments

ddl: Add admin check before drop table using building flag.#7343

Merged
tiancaiamao merged 15 commits intopingcap:masterfrom
crazycs520:add_admin_check_before_drop
Aug 14, 2018
Merged

ddl: Add admin check before drop table using building flag.#7343
tiancaiamao merged 15 commits intopingcap:masterfrom
crazycs520:add_admin_check_before_drop

Conversation

@crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Aug 9, 2018

What have you changed? (mandatory)

Add admin check table before 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)

@crazycs520
Copy link
Contributor Author

@winkyao @zimulala @shenli PTAL

executor/ddl.go Outdated
return errors.Trace(err)
}

if os.Getenv("TIDB_CHECK_BEFORE_DROP") == "1" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a log here. I suggest using the warn log level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

defer func() { e.done = true }()
dbName := model.NewCIStr(e.ctx.GetSessionVars().CurrentDB)
for _, t := range e.tables {
if dbName.L == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a bug-fix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ye~
If use e.ctx.(sqlexec.RestrictedSQLExecutor).ExecRestrictedSQL(e.ctx, "admin check table test.t1") ,here dbName.L is "".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use t.DBInfo.Name directly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// 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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test case that meet error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@pingcap pingcap deleted a comment from crazycs520 Aug 10, 2018
Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reset LGTM


os.Setenv("TIDB_CHECK_BEFORE_DROP", "1")
r, err = tk.Exec("drop table admin_test")
c.Assert(err, NotNil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the content of the error to make sure it is thrown by the consistent checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@winkyao
Copy link
Contributor

winkyao commented Aug 10, 2018

@crazycs520 Please add the proper label.

@jackysp
Copy link
Contributor

jackysp commented Aug 10, 2018

I think it's better to use a building flag for this check.

@zz-jason
Copy link
Member

depends on os environment variable is not a good practice.

@crazycs520
Copy link
Contributor Author

@jackysp @zz-jason @tiancaiamao PTAL

@crazycs520 crazycs520 force-pushed the add_admin_check_before_drop branch from ca822df to 40f5584 Compare August 10, 2018 06:20
@crazycs520 crazycs520 force-pushed the add_admin_check_before_drop branch from 40f5584 to 2472f38 Compare August 10, 2018 06:21
@winkyao
Copy link
Contributor

winkyao commented Aug 10, 2018

@crazycs520 Please change the pr title.

config/config.go Outdated

func init() {
if CheckBeforeDropLDFlag == "1" {
CheckBeforeDrop = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use atomic to protect CheckBeforeDrop, or the data race test perhaps reports error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

func (s *testSuite) TestAdmin(c *C) {
origin := config.CheckBeforeDrop
defer func() {
config.CheckBeforeDrop = origin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about Check Table Before Drop: %v?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

executor/ddl.go Outdated
}

if config.CheckBeforeDrop {
log.Warnf("admin check table before drop was on")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to add more info in this log, e.g. the table name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@crazycs520 crazycs520 changed the title ddl: Add admin check before drop table uses OS environment variable. ddl: Add admin check before drop table useing building flag. Aug 10, 2018
defer func() { e.done = true }()
dbName := model.NewCIStr(e.ctx.GetSessionVars().CurrentDB)
for _, t := range e.tables {
dbName := t.DBInfo.Name
Copy link
Contributor

@jackysp jackysp Aug 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally, it was fixed. 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I think we need a test case for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crazycs520
Copy link
Contributor Author

@winkyao PTAL again. I add ldflags to test and remove atomic set.

@crazycs520 crazycs520 closed this Aug 11, 2018
@crazycs520 crazycs520 reopened this Aug 11, 2018
config/config.go Outdated
"tikv": true,
}
// checkTableBeforeDrop enable to execute `admin check table` before `drop table`.
CheckTableBeforeDrop = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be false by default.

tk.MustExec(`admin check table t;`)

tk = testkit.NewTestKit(c, s.store)
tk.MustExec(`admin check table test.t;`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to check the table from the other database.

@jackysp
Copy link
Contributor

jackysp commented Aug 13, 2018

/run-all-tests

Copy link
Contributor

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

config/config.go Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this variable be in lower case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. PTAL

@crazycs520 crazycs520 force-pushed the add_admin_check_before_drop branch from 49a5c68 to f150a4b Compare August 13, 2018 06:41
@zz-jason
Copy link
Member

should we also add some UTs to make sure the ldflags take effect?

@tiancaiamao
Copy link
Contributor

LGTM
It's hard to use unit test to check ldflags, we have to do it manually or in the integrated test. @zz-jason

@zz-jason
Copy link
Member

@tiancaiamao If we run make test, the global config config.CheckTableBeforeDrop should always be true, maybe we can check this? @crazycs520 How do you think?

@crazycs520 crazycs520 added status/LGT2 Indicates that a PR has LGTM 2. status/LGT3 The PR has already had 3 LGTM. and removed status/LGT2 Indicates that a PR has LGTM 2. labels Aug 14, 2018
@ngaut ngaut changed the title ddl: Add admin check before drop table useing building flag. ddl: Add admin check before drop table using building flag. Aug 14, 2018
@tiancaiamao
Copy link
Contributor

/run-all-tests

@zz-jason
Copy link
Member

LGTM

@tiancaiamao tiancaiamao merged commit 5404e2e into pingcap:master Aug 14, 2018
@you06 you06 added the sig/sql-infra SIG: SQL Infra label Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sig/sql-infra SIG: SQL Infra status/LGT3 The PR has already had 3 LGTM.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants