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, meta: clean the jobs in adding index queue #6161

Merged
merged 10 commits into from
Apr 4, 2018

Conversation

zimulala
Copy link
Contributor

@zimulala zimulala commented Mar 27, 2018

We will initially support the parallel DDL. So we will introduce the adding index queue.
This PR deals with the compatibility when the user chooses to downgrade.

job.State = model.JobStateRollingback
job.Args = []interface{}{indexInfo.Name}
// If add index job rollbacks, its work is the same as drop index job do.
// When it's not in None state, the next state can be delete only state.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this way is more friendly for reader? // When it's not in "None" state, the next state can be "delete only" state.

@zimulala
Copy link
Contributor Author

PTAL @winkyao @coocood @zhexuany

@zimulala
Copy link
Contributor Author

/run-all-tests

@zimulala
Copy link
Contributor Author

/run-all-tests

@zhexuany
Copy link
Contributor

Please fix CI @zimulala

@zimulala
Copy link
Contributor Author

/run-integration-common-test

@zimulala zimulala added the DDL label Mar 30, 2018
@@ -91,7 +91,6 @@ func checkHistoryJob(c *C, job *model.Job) {
}

func checkHistoryJobArgs(c *C, ctx sessionctx.Context, id int64, args *historyJobArgs) {
c.Assert(ctx.NewTxn(), IsNil)
Copy link
Contributor

Choose a reason for hiding this comment

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

why remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make TestCleanJobs stable.
I want to get schema version and check history job's schema version in a transaction.

return errors.Trace(err)
}
indexInfo := findIndexByName(indexName.L, tblInfo.Indices)
job.State = model.JobStateRollingback
Copy link
Contributor

Choose a reason for hiding this comment

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

why not use ddl.convert2RollbackJob ?

log.Infof("[ddl] cleaning job %v in the adding index queue.", job)

// The types of these jobs must be ActionAddIndex.
if job.SchemaState == model.StatePublic || job.SchemaState == model.StateNone {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to rollback or cancel the add index ddl job? What about enqueueing these jobs to default job list

Copy link
Contributor Author

@zimulala zimulala Apr 2, 2018

Choose a reason for hiding this comment

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

@winkyao @coocood
If we put it in the default jobs list, we need to consider the order. And I hope this PR will change the original logic as little as possible.

Copy link
Member

@coocood coocood Apr 2, 2018

Choose a reason for hiding this comment

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

If we just put all the add index jobs at the end of the default list, what the worst-case result would be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@coocood
Added an index that should not be added.
e.g.
original order: drop column col1 -> add index idx1(col1) should be failed -> add column col1
current order: drop column col1 -> add column col1 -> add index idx1(col1) successful

@coocood
Copy link
Member

coocood commented Mar 31, 2018

@zimulala
Would it be safe and simpler if we just move all the jobs in AddIdx queue to default queue?

@@ -221,6 +221,7 @@ LOOP:
case <-ticker.C:
d.Stop()
d.start(context.Background())
time.Sleep(time.Millisecond * 20)
Copy link
Member

Choose a reason for hiding this comment

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

Why add sleep?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we add check add index list, it makes processing the first job a bit slower.

meta/meta.go Outdated
mDDLJobHistoryKey = []byte("DDLJobHistory")
mDDLJobReorgKey = []byte("DDLJobReorg")
mDDLJobListKey = []byte("DDLJobList")
mAddIdxDDLJobListKey = []byte("AddIdxDDLJobList")
Copy link
Member

Choose a reason for hiding this comment

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

How about DDLJobAddIdxList?

@@ -191,7 +193,7 @@ func (d *ddl) getHistoryDDLJob(id int64) (*model.Job, error) {
return job, errors.Trace(err)
}

func (d *ddl) handleDDLJobQueue() error {
func (d *ddl) handleDDLJobQueue(shouldCleanJobs *bool) error {
Copy link
Member

Choose a reason for hiding this comment

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

Add a comment for the new parameter.

Copy link
Member

Choose a reason for hiding this comment

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

Use return value to control the outer for loop.

@zimulala
Copy link
Contributor Author

zimulala commented Apr 3, 2018

PTAL @winkyao @coocood @shenli

if err != nil {
log.Errorf("[ddl] handle ddl job err %v", errors.ErrorStack(err))
} else {
shouldCleanJobs = !isCleaned
Copy link
Member

Choose a reason for hiding this comment

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

It's possible that the shouldCleanJobs is false, but isCleaned return false, then we will clean job again.

Copy link
Member

Choose a reason for hiding this comment

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

If err is nil, can we safely set shouldCleanJobs to false?
Then we can remove the bool return value.

@coocood
Copy link
Member

coocood commented Apr 3, 2018

LGTM

@zimulala zimulala added the status/LGT1 Indicates that a PR has LGTM 1. label Apr 3, 2018
@zimulala
Copy link
Contributor Author

zimulala commented Apr 3, 2018

PTAL @winkyao @shenli

1 similar comment
@zimulala
Copy link
Contributor Author

zimulala commented Apr 4, 2018

PTAL @winkyao @shenli

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

rest LGTM

continue
}

// When the job not in "none" state, we need to rollback it.
Copy link
Contributor

Choose a reason for hiding this comment

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

"none" and "public" ?

@@ -52,6 +52,8 @@ func (d *ddl) onDDLWorker() {
metrics.PanicCounter.WithLabelValues(metrics.LabelDDL).Inc()
}
}()

shouldCleanJobs := true
Copy link
Contributor

Choose a reason for hiding this comment

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

may add a comment for this to explain why we need this.

winkyao
winkyao previously approved these changes Apr 4, 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.

LGTM

@XuHuaiyu XuHuaiyu dismissed winkyao’s stale review April 4, 2018 07:33

comment to be addressed

@zimulala
Copy link
Contributor Author

zimulala commented Apr 4, 2018

/run-all-tests

@zimulala
Copy link
Contributor Author

zimulala commented Apr 4, 2018

/integration-common-test

@zimulala
Copy link
Contributor Author

zimulala commented Apr 4, 2018

/run-integration-common-test

@zimulala zimulala added status/LGT2 Indicates that a PR has LGTM 2. all-tests-passed and removed status/LGT1 Indicates that a PR has LGTM 1. labels Apr 4, 2018
@zimulala zimulala merged commit cb04e97 into pingcap:master Apr 4, 2018
@zimulala zimulala deleted the ddl-compatibility branch April 4, 2018 11:04
@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/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants