Skip to content

Commit

Permalink
ddl, parser: fix the DDL job version using issue (#47915)
Browse files Browse the repository at this point in the history
close #47910, close #47912
  • Loading branch information
zimulala authored Oct 23, 2023
1 parent 0901886 commit c193d8a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 2 additions & 4 deletions pkg/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{}
Expand Down
1 change: 1 addition & 0 deletions pkg/ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
7 changes: 4 additions & 3 deletions pkg/ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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())))
Expand Down
9 changes: 9 additions & 0 deletions pkg/parser/model/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c193d8a

Please sign in to comment.