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: fix reorg info end key after resuming from checkpoint (#52447) #52458

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions pkg/ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ func getCheckpointReorgHandle(se *sess.Session, job *model.Job) (startKey, endKe
}
if len(cp.EndKey) > 0 {
endKey = cp.EndKey
endKey = adjustEndKeyAcrossVersion(job, endKey)
}
}
}
Expand Down
25 changes: 17 additions & 8 deletions pkg/ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -897,14 +897,23 @@ func CleanupDDLReorgHandles(job *model.Job, s *sess.Session) {
// GetDDLReorgHandle gets the latest processed DDL reorganize position.
func (r *reorgHandler) GetDDLReorgHandle(job *model.Job) (element *meta.Element, startKey, endKey kv.Key, physicalTableID int64, err error) {
element, startKey, endKey, physicalTableID, err = getDDLReorgHandle(r.s, job)
if job.ReorgMeta != nil && job.ReorgMeta.Version == model.ReorgMetaVersion0 && err == nil {
logutil.BgLogger().Info("job get table range for old version ReorgMetas", zap.String("category", "ddl"),
zap.Int64("jobID", job.ID), zap.Int64("job ReorgMeta version", job.ReorgMeta.Version), zap.Int64("physical table ID", physicalTableID),
zap.String("startKey", hex.EncodeToString(startKey)),
zap.String("current endKey", hex.EncodeToString(endKey)),
zap.String("endKey next", hex.EncodeToString(endKey.Next())))
endKey = endKey.Next()
if err != nil {
return element, startKey, endKey, physicalTableID, err
}
adjustedEndKey := adjustEndKeyAcrossVersion(job, endKey)
return element, startKey, adjustedEndKey, physicalTableID, nil
}

return
// #46306 changes the table range from [start_key, end_key] to [start_key, end_key.next).
// For old version TiDB, the semantic is still [start_key, end_key], we need to adjust it in new version TiDB.
func adjustEndKeyAcrossVersion(job *model.Job, endKey kv.Key) kv.Key {
if job.ReorgMeta != nil && job.ReorgMeta.Version == model.ReorgMetaVersion0 {
logutil.BgLogger().Info("adjust range end key for old version ReorgMetas",
zap.String("category", "ddl"),
zap.Int64("jobID", job.ID),
zap.Int64("reorgMetaVersion", job.ReorgMeta.Version),
zap.String("endKey", hex.EncodeToString(endKey)))
return endKey.Next()
}
return endKey
}