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

binlog: allow multiple ddl targets #30904

Merged
merged 9 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ddl/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,21 +798,22 @@ func onRenameTables(d *ddlCtx, t *meta.Meta, job *model.Job) (ver int64, _ error
return ver, errors.Trace(err)
}

tblInfo := &model.TableInfo{}
var tblInfos = make([]*model.TableInfo, 0, len(tableNames))
var err error
for i, oldSchemaID := range oldSchemaIDs {
job.TableID = tableIDs[i]
ver, tblInfo, err = checkAndRenameTables(t, job, oldSchemaID, newSchemaIDs[i], oldSchemaNames[i], tableNames[i])
ver, tblInfo, err := checkAndRenameTables(t, job, oldSchemaID, newSchemaIDs[i], oldSchemaNames[i], tableNames[i])
if err != nil {
return ver, errors.Trace(err)
}
tblInfos = append(tblInfos, tblInfo)
}

ver, err = updateSchemaVersion(t, job)
if err != nil {
return ver, errors.Trace(err)
}
job.FinishTableJob(model.JobStateDone, model.StatePublic, ver, tblInfo)
job.FinishMultipleTableJob(model.JobStateDone, model.StatePublic, ver, tblInfos)
hicqu marked this conversation as resolved.
Show resolved Hide resolved
return ver, nil
}

Expand Down
23 changes: 23 additions & 0 deletions parser/model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ type HistoryInfo struct {
DBInfo *DBInfo
TableInfo *TableInfo
FinishedTS uint64

// MultipleDBInfo is like DBInfo but only for operations updating multiple DBs.
MultipleDBInfo []*DBInfo
hicqu marked this conversation as resolved.
Show resolved Hide resolved
// MultipleTableInfo is like TableInfo but only for operations updating multiple DBs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// MultipleTableInfo is like TableInfo but only for operations updating multiple DBs.
// MultipleTableInfo is like TableInfo but only for operations updating multiple tables.

MultipleTableInfo []*TableInfo
Copy link
Contributor

Choose a reason for hiding this comment

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

s/MultipleTableInfo/MultipleTableInfos?

}

// AddDBInfo adds schema version and schema information that are used for binlog.
Expand Down Expand Up @@ -279,6 +284,15 @@ func (job *Job) FinishTableJob(jobState JobState, schemaState SchemaState, ver i
job.BinlogInfo.AddTableInfo(ver, tblInfo)
}

// FinishMultipleTableJob is called when a job is finished.
// It updates the job's state information and adds tblInfos to the binlog.
func (job *Job) FinishMultipleTableJob(jobState JobState, schemaState SchemaState, ver int64, tblInfos []*TableInfo) {
job.State = jobState
job.SchemaState = schemaState
job.BinlogInfo.SchemaVersion = ver
job.BinlogInfo.MultipleTableInfo = tblInfos
}

// FinishDBJob is called when a job is finished.
// It updates the job's state information and adds dbInfo the binlog.
func (job *Job) FinishDBJob(jobState JobState, schemaState SchemaState, ver int64, dbInfo *DBInfo) {
Expand All @@ -287,6 +301,15 @@ func (job *Job) FinishDBJob(jobState JobState, schemaState SchemaState, ver int6
job.BinlogInfo.AddDBInfo(ver, dbInfo)
}

// FinishDBJob is called when a job is finished.
// It updates the job's state information and adds dbInfos the binlog.
func (job *Job) FinishMultipleDBJob(jobState JobState, schemaState SchemaState, ver int64, dbInfos []*DBInfo) {
hicqu marked this conversation as resolved.
Show resolved Hide resolved
job.State = jobState
job.SchemaState = schemaState
job.BinlogInfo.SchemaVersion = ver
job.BinlogInfo.MultipleDBInfo = dbInfos
}

// TSConvert2Time converts timestamp to time.
func TSConvert2Time(ts uint64) time.Time {
t := int64(ts >> 18) // 18 is for the logical time.
Expand Down