Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions cdc/model/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ func MarshalRedoLog(r *model.RedoLog, b []byte) (o []byte, err error) {

// MarshalDDLAsRedoLog converts a DDLEvent into RedoLog, and then marshals it.
func MarshalDDLAsRedoLog(d *model.DDLEvent, b []byte) (o []byte, err error) {
log := &model.RedoLog{
RedoDDL: model.RedoDDLEvent{DDL: d},
Type: model.RedoLogTypeDDL,
}
return MarshalRedoLog(log, b)
return MarshalRedoLog(d.ToRedoLog(), b)
}

func decodeVersion(bts []byte) (uint16, []byte) {
Expand Down
4 changes: 2 additions & 2 deletions cdc/model/codec/v1/codec_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cdc/model/codec/v1/codec_gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cdc/model/kv_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cdc/model/kv_gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 25 additions & 4 deletions cdc/model/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,18 @@ type RedoRowChangedEvent struct {

// RedoDDLEvent represents DDL event used in redo log persistent
type RedoDDLEvent struct {
DDL *DDLEvent `msg:"ddl"`
Type byte `msg:"type"`
TableName TableName `msg:"table-name"`
DDL *DDLEvent `msg:"ddl"`
Type byte `msg:"type"`
TableName TableName `msg:"table-name"`
Columns []*ColumnInfo `msg:"columns"`
}

// ColumnInfo is for column meta in DDL event
type ColumnInfo struct {
Name string `msg:"name"`
OriginDefaultValue any `msg:"origin_default"`
Type byte `msg:"type"`
Version uint64 `msg:"version"`
}
Comment on lines +296 to 301
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ColumnInfo struct is missing the column ID. Since timodel.ColumnInfo requires a unique ID for various internal operations and schema tracking, it is recommended to persist the original ID from the upstream table info to ensure accurate reconstruction during redo log playback.

Suggested change
type ColumnInfo struct {
Name string `msg:"name"`
OriginDefaultValue any `msg:"origin_default"`
Type byte `msg:"type"`
Version uint64 `msg:"version"`
}
// ColumnInfo is for column meta in DDL event
type ColumnInfo struct {
ID int64 `msg:"id"`
Name string `msg:"name"`
OriginDefaultValue any `msg:"origin_default"`
Type byte `msg:"type"`
Version uint64 `msg:"version"`
}


// ToRedoLog converts row changed event to redo log
Expand All @@ -314,8 +323,20 @@ func (r *RowChangedEvent) ToRedoLog() *RedoLog {

// ToRedoLog converts ddl event to redo log
func (d *DDLEvent) ToRedoLog() *RedoLog {
var columns []*ColumnInfo
if d.TableInfo != nil && d.TableInfo.TableInfo != nil {
columns = make([]*ColumnInfo, 0, len(d.TableInfo.Columns))
for _, col := range d.TableInfo.Columns {
columns = append(columns, &ColumnInfo{
Name: col.Name.String(),
OriginDefaultValue: col.GetOriginDefaultValue(),
Type: col.GetType(),
Version: col.Version,
})
Comment on lines +330 to +335
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Populate the ID field from the original column info to allow for accurate reconstruction of the table schema from redo logs.

			columns = append(columns, &ColumnInfo{
				ID:                 col.ID,
				Name:               col.Name.String(),
				OriginDefaultValue: col.GetOriginDefaultValue(),
				Type:               col.GetType(),
				Version:            col.Version,
			})

}
}
return &RedoLog{
RedoDDL: RedoDDLEvent{DDL: d},
RedoDDL: RedoDDLEvent{DDL: d, Columns: columns},
Type: RedoLogTypeDDL,
}
}
Expand Down
Loading