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

*: support set relation job #6206

Merged
merged 5 commits into from
Apr 13, 2018
Merged

Conversation

zimulala
Copy link
Contributor

@zimulala zimulala commented Apr 2, 2018

We will initially support the parallel DDL. We need to wait for PR(#6161) to merge before we can begin.
In order to prevent conflicts, I first implement the function of setJobRelation.
setJobRelation sets the current job's relation-ID to the ID of a job that is related to the current job.

@zimulala
Copy link
Contributor Author

zimulala commented Apr 3, 2018

/run-all-tests

@zimulala
Copy link
Contributor Author

zimulala commented Apr 4, 2018

PTAL @winkyao @coocood @shenli

@coocood
Copy link
Member

coocood commented Apr 4, 2018

Have you considered DependsOn instead of RelatedTo?

if curJob.ID < job.ID {
continue
}
isRelated, err := curJob.IsRelatedJob(job)
Copy link
Contributor

Choose a reason for hiding this comment

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

if isRelated, err := curJob.IsRelatedJob(job); err == nil; {
          if isRelated {
       		curJob.RelatedID = job.ID
  			break
 		}
} else {
       return err
}

above way is more concise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The method you say can have a simpler way, as follows

if isRelated, err := curJob.IsRelatedJob(job); err == nil && isRelated; {
       curJob.RelatedID = job.ID
  	   break
} else if err != nil {
       return errors.Trace(err)
}

But, I think my method is more readable in Go's way.

@@ -91,6 +91,29 @@ func (d *ddl) isOwner() bool {
return isOwner
}

// setJobRelation sets the current job's relation-ID to the ID of a job that is related to current job.
// The related job's ID must less than the current job's ID, and we need the largest one in the list.
func setJobRelation(t *meta.Meta, curJob *model.Job) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

setJobRelation --> buildJobRelation is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Does setJobRelation run in a transaction?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used t, so it's in a transaction.

model/ddl.go Outdated
return true, nil
}
if job.Type == ActionRenameTable {
var schemaID int64
Copy link
Contributor

Choose a reason for hiding this comment

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

Name it oldSchemaID is more clear?

model/ddl.go Outdated
}

// IsRelatedJob returns whether job and job1 are related or not.
func (job *Job) IsRelatedJob(job1 *Job) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

job1 ---> other

model/ddl.go Outdated
@@ -213,6 +215,41 @@ func (job *Job) String() string {
job.ID, job.Type, job.State, job.SchemaState, job.SchemaID, job.TableID, rowCount, len(job.Args), tsConvert2Time(job.StartTS), job.Error, job.ErrorCount, job.SnapshotVer)
}

func (job *Job) isRelatedSchema(job1 *Job) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename job1 to other?


length := int(meta.RIndex - meta.LIndex)
elements := make([][]byte, 0, length)
for index := meta.RIndex - 1; index >= meta.LIndex; index-- {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you be sure it's ordered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use RPush to enqueue, so we know this order.

@@ -1,3 +1,4 @@
// LGetAll gets all elements of this list in order from left to right.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why put the comment here?

@zimulala
Copy link
Contributor Author

zimulala commented Apr 8, 2018

PTAL @coocood @winkyao @zhexuany @lamxTyler @ciscoxll

@zimulala
Copy link
Contributor Author

zimulala commented Apr 9, 2018

PTAL @coocood @winkyao

@@ -91,6 +91,29 @@ func (d *ddl) isOwner() bool {
return isOwner
}

// buildJobDependence sets the current job's dependence-ID that the current job depends on.
// The dependent job's ID must less than the current job's ID, and we need the largest one in the list.
func buildJobDependence(t *meta.Meta, curJob *model.Job) 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 comments for what is a dependence job?

model/ddl.go Outdated
@@ -127,6 +127,8 @@ type Job struct {
// StartTS uses timestamp allocated by TSO.
// Now it's the TS when we put the job to TiKV queue.
StartTS uint64 `json:"start_ts"`
// DependentID is the job's ID that the current job depends on.
DependentID int64 `json:"related_id"`
Copy link
Member

Choose a reason for hiding this comment

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

s/DependentID/DependencyID
s/related_id/dependency_id

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

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

zimulala commented Apr 9, 2018

PTAL @coocood @shenli

// buildJobDependence sets the curjob's dependency-ID.
// The dependency-job's ID must less than the current job's ID, and we need the largest one in the list.
func buildJobDependence(t *meta.Meta, curJob *model.Job) error {
jobs, err := t.GetAllDDLJobs()
Copy link
Member

Choose a reason for hiding this comment

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

Should we run this check in a transaction? For example, two DDLs come in the same time. Will this function detect the dependence?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's in a transaction. The t has a field of transaction.

@zhexuany
Copy link
Contributor

/run-all-tests tidb-test=pr/485

@shenli
Copy link
Member

shenli commented Apr 10, 2018

/run-all-tests

1 similar comment
@zimulala
Copy link
Contributor Author

/run-all-tests

@zhexuany
Copy link
Contributor

LGTM

@zhexuany zhexuany merged commit 998f696 into pingcap:master Apr 13, 2018
@zimulala zimulala deleted the ddl-set-relation-job branch August 7, 2018 06:33
@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/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants