Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redo(ticdc): support for applying ddl event in applier #8362

Merged
merged 4 commits into from
Mar 6, 2023
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: 6 additions & 0 deletions cdc/model/codec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func postUnmarshal(r *model.RedoLog) {
}
if r.RedoDDL.DDL != nil {
r.RedoDDL.DDL.Type = timodel.ActionType(r.RedoDDL.Type)
r.RedoDDL.DDL.TableInfo = &model.TableInfo{
TableName: r.RedoDDL.TableName,
}
}
}

Expand Down Expand Up @@ -106,6 +109,9 @@ func preMarshal(r *model.RedoLog) {
}
if r.RedoDDL.DDL != nil {
r.RedoDDL.Type = byte(r.RedoDDL.DDL.Type)
if r.RedoDDL.DDL.TableInfo != nil {
r.RedoDDL.TableName = r.RedoDDL.DDL.TableInfo.TableName
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions cdc/model/codec/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,11 @@ func TestDDLRedoConvert(t *testing.T) {
t.Parallel()

ddl := &model.DDLEvent{
StartTs: 1020,
CommitTs: 1030,
Type: timodel.ActionAddColumn,
Query: "ALTER TABLE test.t1 ADD COLUMN a int",
StartTs: 1020,
CommitTs: 1030,
TableInfo: &model.TableInfo{},
Type: timodel.ActionAddColumn,
Query: "ALTER TABLE test.t1 ADD COLUMN a int",
}

redoLog := &model.RedoLog{RedoDDL: model.RedoDDLEvent{DDL: ddl}}
Expand Down
5 changes: 3 additions & 2 deletions cdc/model/sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,9 @@ type RedoRowChangedEvent struct {

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

// ToRedoLog converts row changed event to redo log
Expand Down
39 changes: 34 additions & 5 deletions cdc/model/sink_gen.go

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

10 changes: 5 additions & 5 deletions cdc/redo/reader/blackhole_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ func newBlackHoleReader() *BlackHoleReader {
return &BlackHoleReader{}
}

// ResetReader implements LogReader.ReadLog
func (br *BlackHoleReader) ResetReader(ctx context.Context, startTs, endTs uint64) error {
// Run implements LogReader.Run
func (br *BlackHoleReader) Run(ctx context.Context) error {
return nil
}

// ReadNextLog implements LogReader.ReadNextLog
func (br *BlackHoleReader) ReadNextLog(ctx context.Context, maxNumberOfEvents uint64) ([]*model.RowChangedEvent, error) {
// ReadNextRow implements LogReader.ReadNextRow
func (br *BlackHoleReader) ReadNextRow(ctx context.Context) (*model.RowChangedEvent, error) {
return nil, nil
}

// ReadNextDDL implements LogReader.ReadNextDDL
func (br *BlackHoleReader) ReadNextDDL(ctx context.Context, maxNumberOfEvents uint64) ([]*model.DDLEvent, error) {
func (br *BlackHoleReader) ReadNextDDL(ctx context.Context) (*model.DDLEvent, error) {
return nil, nil
}

Expand Down
5 changes: 5 additions & 0 deletions cdc/redo/reader/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"os"
"path/filepath"
"sync"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/log"
Expand Down Expand Up @@ -85,6 +86,7 @@ func newReader(ctx context.Context, cfg *readerConfig) ([]fileReader, error) {
if cfg.workerNums == 0 {
cfg.workerNums = defaultWorkerNum
}
start := time.Now()

if cfg.useExternalStorage {
extStorage, err := redo.InitExternalStorage(ctx, cfg.uri)
Expand Down Expand Up @@ -114,6 +116,9 @@ func newReader(ctx context.Context, cfg *readerConfig) ([]fileReader, error) {
})
}

log.Info("succeed to download and sort redo logs",
zap.String("type", cfg.fileType),
zap.Duration("duration", time.Since(start)))
return readers, nil
}

Expand Down
Loading