-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Changes from 2 commits
f799bdb
48100a8
d2d7d6e
5d92f39
2687e91
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
jobs, err := t.GetAllDDLJobs() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's in a transaction. The |
||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
for _, job := range jobs { | ||
if curJob.ID < job.ID { | ||
continue | ||
} | ||
isDependent, err := curJob.IsDependentOn(job) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
if isDependent { | ||
curJob.DependentID = job.ID | ||
break | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// addDDLJob gets a global job ID and puts the DDL job in the DDL queue. | ||
func (d *ddl) addDDLJob(ctx sessionctx.Context, job *model.Job) error { | ||
startTime := time.Now() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/DependentID/DependencyID |
||
// Query string of the ddl job. | ||
Query string `json:"query"` | ||
BinlogInfo *HistoryInfo `json:"binlog"` | ||
|
@@ -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) hasDependentSchema(other *Job) (bool, error) { | ||
if other.Type == ActionDropSchema || other.Type == ActionCreateSchema { | ||
if other.SchemaID == job.SchemaID { | ||
return true, nil | ||
} | ||
if job.Type == ActionRenameTable { | ||
var oldSchemaID int64 | ||
if err := job.DecodeArgs(&oldSchemaID); err != nil { | ||
return false, errors.Trace(err) | ||
} | ||
if other.SchemaID == oldSchemaID { | ||
return true, nil | ||
} | ||
} | ||
} | ||
return false, nil | ||
} | ||
|
||
// IsDependentOn returns whether job depends on other. | ||
func (job *Job) IsDependentOn(other *Job) (bool, error) { | ||
isDependent, err := job.hasDependentSchema(other) | ||
if err != nil || isDependent { | ||
return isDependent, errors.Trace(err) | ||
} | ||
isDependent, err = other.hasDependentSchema(job) | ||
if err != nil || isDependent { | ||
return isDependent, errors.Trace(err) | ||
} | ||
|
||
if other.TableID == job.TableID { | ||
return true, nil | ||
} | ||
return false, nil | ||
} | ||
|
||
// IsFinished returns whether job is finished or not. | ||
// If the job state is Done or Cancelled, it is finished. | ||
func (job *Job) IsFinished() bool { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,26 @@ func (t *TxStructure) LLen(key []byte) (int64, error) { | |
return meta.RIndex - meta.LIndex, errors.Trace(err) | ||
} | ||
|
||
// LGetAll gets all elements of this list in order from right to left. | ||
func (t *TxStructure) LGetAll(key []byte) ([][]byte, error) { | ||
metaKey := t.encodeListMetaKey(key) | ||
meta, err := t.loadListMeta(metaKey) | ||
if err != nil || meta.IsEmpty() { | ||
return nil, errors.Trace(err) | ||
} | ||
|
||
length := int(meta.RIndex - meta.LIndex) | ||
elements := make([][]byte, 0, length) | ||
for index := meta.RIndex - 1; index >= meta.LIndex; index-- { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you be sure it's ordered. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use |
||
e, err := t.reader.Get(t.encodeListDataKey(key, index)) | ||
if err != nil { | ||
return nil, errors.Trace(err) | ||
} | ||
elements = append(elements, e) | ||
} | ||
return elements, nil | ||
} | ||
|
||
// LIndex gets an element from a list by its index. | ||
func (t *TxStructure) LIndex(key []byte, index int64) ([]byte, error) { | ||
metaKey := t.encodeListMetaKey(key) | ||
|
There was a problem hiding this comment.
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?