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): return internal error in redo writer #11011

Merged
merged 2 commits into from
May 14, 2024
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
31 changes: 16 additions & 15 deletions cdc/redo/writer/memory/encoding_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
workerNum int
nextWorker atomic.Uint64

closed chan struct{}
closed chan error
}

func newEncodingWorkerGroup(cfg *writer.LogWriterConfig) *encodingWorkerGroup {
Expand All @@ -121,19 +121,20 @@
inputChs: inputChs,
outputCh: make(chan *polymorphicRedoEvent, redo.DefaultEncodingOutputChanSize),
workerNum: workerNum,
closed: make(chan struct{}),
closed: make(chan error, 1),
}
}

func (e *encodingWorkerGroup) Run(ctx context.Context) (err error) {
defer func() {
close(e.closed)
log.Warn("redo encoding workers closed",
zap.String("namespace", e.changefeed.Namespace),
zap.String("changefeed", e.changefeed.ID),
zap.Error(err))
if err != nil && errors.Cause(err) != context.Canceled {
log.Warn("redo fileWorkerGroup closed with error",
zap.String("namespace", e.changefeed.Namespace),
zap.String("changefeed", e.changefeed.ID),
zap.Error(err))
e.closed <- err

Check warning on line 135 in cdc/redo/writer/memory/encoding_worker.go

View check run for this annotation

Codecov / codecov/patch

cdc/redo/writer/memory/encoding_worker.go#L135

Added line #L135 was not covered by tests
}
close(e.closed)
}()
eg, egCtx := errgroup.WithContext(ctx)
for i := 0; i < e.workerNum; i++ {
Expand Down Expand Up @@ -183,8 +184,8 @@
select {
case <-ctx.Done():
return ctx.Err()
case <-e.closed:
return errors.ErrRedoWriterStopped.GenWithStack("encoding worker is closed")
case err := <-e.closed:
return errors.WrapError(errors.ErrRedoWriterStopped, err, "encoding worker is closed")
case e.inputChs[idx] <- event:
return nil
}
Expand All @@ -196,8 +197,8 @@
select {
case <-ctx.Done():
return ctx.Err()
case <-e.closed:
return errors.ErrRedoWriterStopped.GenWithStack("encoding worker is closed")
case err := <-e.closed:
return errors.WrapError(errors.ErrRedoWriterStopped, err, "encoding worker is closed")

Check warning on line 201 in cdc/redo/writer/memory/encoding_worker.go

View check run for this annotation

Codecov / codecov/patch

cdc/redo/writer/memory/encoding_worker.go#L200-L201

Added lines #L200 - L201 were not covered by tests
case e.outputCh <- event:
return nil
}
Expand All @@ -221,8 +222,8 @@
select {
case <-ctx.Done():
return ctx.Err()
case <-e.closed:
return errors.ErrRedoWriterStopped.GenWithStack("encoding worker is closed")
case err := <-e.closed:
return errors.WrapError(errors.ErrRedoWriterStopped, err, "encoding worker is closed")
case <-flushCh:
}
return nil
Expand All @@ -245,8 +246,8 @@
select {
case <-ctx.Done():
return ctx.Err()
case <-e.closed:
return errors.ErrRedoWriterStopped.GenWithStack("encoding worker is closed")
case err := <-e.closed:
return errors.WrapError(errors.ErrRedoWriterStopped, err, "encoding worker is closed")
case <-ch:
}
}
Expand Down
10 changes: 4 additions & 6 deletions cdc/redo/writer/memory/file_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@ func (f *fileWorkerGroup) Run(
) (err error) {
defer func() {
f.close()
if err != nil && errors.Cause(err) != context.Canceled {
log.Warn("redo file workers closed with error",
zap.String("namespace", f.cfg.ChangeFeedID.Namespace),
zap.String("changefeed", f.cfg.ChangeFeedID.ID),
zap.Error(err))
}
log.Warn("redo file workers closed",
zap.String("namespace", f.cfg.ChangeFeedID.Namespace),
zap.String("changefeed", f.cfg.ChangeFeedID.ID),
zap.Error(err))
}()

eg, egCtx := errgroup.WithContext(ctx)
Expand Down
11 changes: 4 additions & 7 deletions cdc/redo/writer/memory/mem_log_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/pingcap/log"
"github.com/pingcap/tiflow/cdc/model"
"github.com/pingcap/tiflow/cdc/redo/writer"
cerror "github.com/pingcap/tiflow/pkg/errors"
"github.com/pingcap/tiflow/pkg/redo"
"github.com/pingcap/tiflow/pkg/util"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -101,11 +100,9 @@ func testWriteEvents(t *testing.T, events []writer.RedoEvent) {
require.NoError(t, err)

require.ErrorIs(t, lw.Close(), context.Canceled)
require.Eventually(t, func() bool {
err = lw.WriteEvents(ctx, events...)
return err != nil
}, 2*time.Second, 10*time.Millisecond)
require.ErrorIs(t, err, cerror.ErrRedoWriterStopped)

err = lw.WriteEvents(ctx, events...)
require.NoError(t, err)
err = lw.FlushLog(ctx)
require.ErrorIs(t, err, cerror.ErrRedoWriterStopped)
require.NoError(t, err)
}
Loading