Skip to content

Commit

Permalink
parser, ddl: update the DDL job's Location structure (#31199)
Browse files Browse the repository at this point in the history
close #31212
  • Loading branch information
zimulala authored Jan 3, 2022
1 parent 69e179e commit e50e03c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
4 changes: 0 additions & 4 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4390,7 +4390,6 @@ func (d *ddl) getModifiableColumnJob(ctx context.Context, sctx sessionctx.Contex
SQLMode: sctx.GetSessionVars().SQLMode,
Warnings: make(map[errors.ErrorID]*terror.Error),
WarningsCount: make(map[errors.ErrorID]int64),
Location: sctx.GetSessionVars().Location(),
},
Args: []interface{}{&newCol, originalColName, spec.Position, modifyColumnTp, newAutoRandBits},
}
Expand Down Expand Up @@ -4630,7 +4629,6 @@ func (d *ddl) RenameColumn(ctx sessionctx.Context, ident ast.Ident, spec *ast.Al
SQLMode: ctx.GetSessionVars().SQLMode,
Warnings: make(map[errors.ErrorID]*terror.Error),
WarningsCount: make(map[errors.ErrorID]int64),
Location: ctx.GetSessionVars().Location(),
},
Args: []interface{}{&newCol, oldColName, spec.Position, 0},
}
Expand Down Expand Up @@ -5442,7 +5440,6 @@ func (d *ddl) CreatePrimaryKey(ctx sessionctx.Context, ti ast.Ident, indexName m
SQLMode: ctx.GetSessionVars().SQLMode,
Warnings: make(map[errors.ErrorID]*terror.Error),
WarningsCount: make(map[errors.ErrorID]int64),
Location: ctx.GetSessionVars().Location(),
},
Args: []interface{}{unique, indexName, indexPartSpecifications, indexOption, sqlMode, nil, global},
Priority: ctx.GetSessionVars().DDLReorgPriority,
Expand Down Expand Up @@ -5630,7 +5627,6 @@ func (d *ddl) CreateIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast.Inde
SQLMode: ctx.GetSessionVars().SQLMode,
Warnings: make(map[errors.ErrorID]*terror.Error),
WarningsCount: make(map[errors.ErrorID]int64),
Location: ctx.GetSessionVars().Location(),
},
Args: []interface{}{unique, indexName, indexPartSpecifications, indexOption, hiddenCols, global},
Priority: ctx.GetSessionVars().DDLReorgPriority,
Expand Down
1 change: 0 additions & 1 deletion ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ func (w *worker) runReorgJob(t *meta.Meta, reorgInfo *reorgInfo, tblInfo *model.
SQLMode: mysql.ModeNone,
Warnings: make(map[errors.ErrorID]*terror.Error),
WarningsCount: make(map[errors.ErrorID]int64),
Location: time.Local,
}
}
if w.reorgCtx.doneCh == nil {
Expand Down
8 changes: 7 additions & 1 deletion parser/model/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,13 @@ type DDLReorgMeta struct {
SQLMode mysql.SQLMode `json:"sql_mode"`
Warnings map[errors.ErrorID]*terror.Error `json:"warnings"`
WarningsCount map[errors.ErrorID]int64 `json:"warnings_count"`
Location *time.Location `json:"time_location"`
Location *TimeZone `json:"time_zone"`
}

// TimeZone represents a single time zone.
type TimeZone struct {
Name string
Offset int // seconds east of UTC
}

// NewDDLReorgMeta new a DDLReorgMeta.
Expand Down
6 changes: 6 additions & 0 deletions parser/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,16 @@ func TestJobCodec(t *testing.T) {
type A struct {
Name string
}
tzName, tzOffset := time.Now().In(time.UTC).Zone()
job := &Job{
ID: 1,
TableID: 2,
SchemaID: 1,
BinlogInfo: &HistoryInfo{},
Args: []interface{}{NewCIStr("a"), A{Name: "abc"}},
ReorgMeta: &DDLReorgMeta{
Location: &TimeZone{Name: tzName, Offset: tzOffset},
},
}
job.BinlogInfo.AddDBInfo(123, &DBInfo{ID: 1, Name: NewCIStr("test_history_db")})
job.BinlogInfo.AddTableInfo(123, &TableInfo{ID: 1, Name: NewCIStr("test_history_tbl")})
Expand Down Expand Up @@ -204,6 +208,8 @@ func TestJobCodec(t *testing.T) {
require.Equal(t, NewCIStr(""), name)
require.Equal(t, A{Name: ""}, a)
require.Greater(t, len(newJob.String()), 0)
require.Equal(t, newJob.ReorgMeta.Location.Name, tzName)
require.Equal(t, newJob.ReorgMeta.Location.Offset, tzOffset)

job.BinlogInfo.Clean()
b1, err := job.Encode(true)
Expand Down

0 comments on commit e50e03c

Please sign in to comment.