Skip to content

Commit

Permalink
ddl: fix reorg info end key after resuming from checkpoint (#52447) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Apr 10, 2024
1 parent 428670a commit 2ecc47d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
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
}

0 comments on commit 2ecc47d

Please sign in to comment.