Skip to content

Commit

Permalink
ddl, parser: fix the DDL job version using issue (#47915) (#47936)
Browse files Browse the repository at this point in the history
close #46306, close #47912
  • Loading branch information
ti-chi-bot authored Oct 25, 2023
1 parent f738b86 commit c914b34
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,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 @@ -8993,5 +8993,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,
}
}
13 changes: 12 additions & 1 deletion 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 @@ -892,5 +893,15 @@ 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) {
return getDDLReorgHandle(r.s, job)
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()
}

return
}
9 changes: 9 additions & 0 deletions pkg/parser/model/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ type DDLReorgMeta struct {
ReorgTp ReorgType `json:"reorg_tp"`
IsDistReorg bool `json:"is_dist_reorg"`
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 c914b34

Please sign in to comment.