Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: refine ddl error when do ddl error cause by infoschema is changed #11308

Merged
merged 12 commits into from
Jul 23, 2019

Conversation

crazycs520
Copy link
Contributor

@crazycs520 crazycs520 commented Jul 18, 2019

What problem does this PR solve?

Considering running the following 2 DDL statements in parallel:

truncate table t;
alter table t add column a int;

If "truncate table" is prior to "alter table" in the DDL job queue, "alter table" will return "Table '(Schema ID 1).(Table ID 41)' doesn't exist", the error message is confusing. "Information schema is changed" may be a better choice.

What is changed and how it works?

  • change the toErr logic in executor/ddl.go

Check List

Tests

  • Unit test

Code changes

  • Has exported function/method change

Side effects

Related changes

  • Need to cherry-pick to the release branch

@crazycs520 crazycs520 added component/DDL-need-LGT3 type/enhancement The issue or PR belongs to an enhancement. labels Jul 18, 2019
@codecov
Copy link

codecov bot commented Jul 18, 2019

Codecov Report

Merging #11308 into master will decrease coverage by 0.0429%.
The diff coverage is 100%.

@@               Coverage Diff               @@
##             master     #11308       +/-   ##
===============================================
- Coverage   81.3031%   81.2601%   -0.043%     
===============================================
  Files           423        423               
  Lines         90641      90241      -400     
===============================================
- Hits          73694      73330      -364     
+ Misses        11632      11611       -21     
+ Partials       5315       5300       -15

ddl/db_test.go Outdated
hook.OnJobRunBeforeExported = func(job *model.Job) {
if job.Type == model.ActionTruncateTable && job.State == model.JobStateNone {
wg.Add(1)
go func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible that the truncate table is executed before the add column operation?

ddl/db_change_test.go Outdated Show resolved Hide resolved
ddl/ddl.go Outdated
@@ -582,6 +582,7 @@ func (d *ddl) doDDLJob(ctx sessionctx.Context, job *model.Job) error {
return errors.Trace(err)
}
ctx.GetSessionVars().StmtCtx.IsDDLJobInQueue = true
defer func() { ctx.GetSessionVars().StmtCtx.IsDDLJobInQueue = false }()
Copy link
Contributor

Choose a reason for hiding this comment

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

IsDDLJobInQueue is used to mark whether the DDL job is put into the queue.
This originally refers to whether the DDL job has been placed in the queue, and the description may not be very clear. This variable was originally used to handle scenarios that encountered this problem before being placed on the queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I will recover this logic.

ddl/db_test.go Outdated
@@ -3387,6 +3387,38 @@ func (s *testDBSuite2) TestDDLWithInvalidTableInfo(c *C) {
c.Assert(err.Error(), Equals, "[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 94 near \"then (b / a) end));\" ")
}

// TestParallelTruncateTableAndAddColumn tests add column when truncate table.
func (s *testDBSuite5) TestParallelTruncateTableAndAddColumn(c *C) {
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 put it to db_change_test.go? The parallel DDL tests are placed in this file.

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.

@sre-bot sre-bot mentioned this pull request Jul 19, 2019
ddl/db_change_test.go Outdated Show resolved Hide resolved
@bb7133
Copy link
Member

bb7133 commented Jul 19, 2019

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

1 similar comment
@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-all-tests

@crazycs520
Copy link
Contributor Author

/run-unit-test

executor/ddl.go Outdated Show resolved Hide resolved
executor/ddl.go Outdated Show resolved Hide resolved
return e.toErr(err)
// If owner return ErrTableNotExists error when running this DDL, It maybe cause by schema changed,
// otherwise, ErrTableNotExists could return before put this DDL job to job queue.
if (e.ctx.GetSessionVars().StmtCtx.IsDDLJobInQueue && infoschema.ErrTableNotExists.Equal(err)) ||
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 we execute drop table at the same table in parallel? Add the two DDL statements all pass the check, and generate the DDL jobs. Then the second job needs to return ErrTableNotExists, but in this logical, it seems to return Information schema is changed.

Copy link
Contributor Author

@crazycs520 crazycs520 Jul 23, 2019

Choose a reason for hiding this comment

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

yep...This is a compromise. If we want to fix this problem, maybe we need a retry or other step to make this better.

executor/ddl.go Outdated
if e.ctx.GetSessionVars().StmtCtx.IsDDLJobInQueue {
return err
}

// Before the DDL job is ready, it encouters an error that may be due to the outdated schema information.
// After the DDL job is ready, the ErrInfoSchemaChanged error won't happen because we are getting the schema directly from storage.
Copy link
Contributor

@zimulala zimulala Jul 23, 2019

Choose a reason for hiding this comment

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

Do we update these comments?

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

Copy link
Contributor

@zimulala zimulala left a comment

Choose a reason for hiding this comment

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

LGTM

@zimulala zimulala added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 23, 2019
Copy link
Member

@bb7133 bb7133 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 crazycs520 added status/LGT3 The PR has already had 3 LGTM. status/all tests passed and removed status/LGT2 Indicates that a PR has LGTM 2. labels Jul 23, 2019
@crazycs520 crazycs520 merged commit 388ce88 into pingcap:master Jul 23, 2019
@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. type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants