From c193d8a90743cf437ac2d4b0079b485375b6ca42 Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 23 Oct 2023 21:00:32 +0800 Subject: [PATCH] ddl, parser: fix the DDL job version using issue (#47915) close pingcap/tidb#47910, close pingcap/tidb#47912 --- pkg/ddl/ddl.go | 6 ++---- pkg/ddl/ddl_api.go | 1 + pkg/ddl/reorg.go | 7 ++++--- pkg/parser/model/reorg.go | 9 +++++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pkg/ddl/ddl.go b/pkg/ddl/ddl.go index 659dea6c61abe..2a13eca3304c0 100644 --- a/pkg/ddl/ddl.go +++ b/pkg/ddl/ddl.go @@ -74,9 +74,7 @@ import ( const ( // currentVersion is for all new DDL jobs. - // 1 for the DDL job created <= v7.4.0. - // For fix #46306(whether end key is included or not in the table range) to add version 2. - currentVersion = 2 + currentVersion = 1 // DDLOwnerKey is the ddl owner path that is saved to etcd, and it's exported for testing. DDLOwnerKey = "/tidb/ddl/fg/owner" // addingDDLJobPrefix is the path prefix used to record the newly added DDL job, and it's saved to etcd. @@ -1410,7 +1408,7 @@ func GetDDLInfoWithNewTxn(s sessionctx.Context) (*Info, error) { return info, err } -// GetDDLInfo returns DDL information. +// GetDDLInfo returns DDL information and only uses for testing. func GetDDLInfo(s sessionctx.Context) (*Info, error) { var err error info := &Info{} diff --git a/pkg/ddl/ddl_api.go b/pkg/ddl/ddl_api.go index 22e748535e4a1..98dee5c75221d 100644 --- a/pkg/ddl/ddl_api.go +++ b/pkg/ddl/ddl_api.go @@ -8994,5 +8994,6 @@ func NewDDLReorgMeta(ctx sessionctx.Context) *model.DDLReorgMeta { WarningsCount: make(map[errors.ErrorID]int64), Location: &model.TimeZoneLocation{Name: tzName, Offset: tzOffset}, ResourceGroupName: ctx.GetSessionVars().ResourceGroupName, + Version: model.CurrentReorgMetaVersion, } } diff --git a/pkg/ddl/reorg.go b/pkg/ddl/reorg.go index 92ce02d15e803..65089a81ddc1d 100644 --- a/pkg/ddl/reorg.go +++ b/pkg/ddl/reorg.go @@ -181,6 +181,7 @@ func (w *worker) runReorgJob(reorgInfo *reorgInfo, tblInfo *model.TableInfo, Warnings: make(map[errors.ErrorID]*terror.Error), WarningsCount: make(map[errors.ErrorID]int64), Location: &model.TimeZoneLocation{Name: time.UTC.String(), Offset: 0}, + Version: model.CurrentReorgMetaVersion, } } @@ -893,9 +894,9 @@ 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.Version < currentVersion && err == nil { - logutil.BgLogger().Info("job get table range for old version jobs", zap.String("category", "ddl"), - zap.Int64("jobID", job.ID), zap.Int64("job version", job.Version), zap.Int64("physical table ID", physicalTableID), + 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()))) diff --git a/pkg/parser/model/reorg.go b/pkg/parser/model/reorg.go index 927f842e20f13..68a9f27a0d374 100644 --- a/pkg/parser/model/reorg.go +++ b/pkg/parser/model/reorg.go @@ -31,8 +31,17 @@ type DDLReorgMeta struct { IsDistReorg bool `json:"is_dist_reorg"` UseCloudStorage bool `json:"use_cloud_storage"` ResourceGroupName string `json:"resource_group_name"` + Version int64 `json:"version"` } +const ( + // ReorgMetaVersion0 is the minimum version of DDLReorgMeta. + ReorgMetaVersion0 = int64(0) + // CurrentReorgMetaVersion is the current version of DDLReorgMeta. + // For fix #46306(whether end key is included or not in the table range) to add the version to 1. + CurrentReorgMetaVersion = int64(1) +) + // ReorgType indicates which process is used for the data reorganization. type ReorgType int8