-
Notifications
You must be signed in to change notification settings - Fork 41
redo: improve redo writer #4353
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
Open
wk989898
wants to merge
8
commits into
pingcap:master
Choose a base branch
from
wk989898:redo-0304
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
486f86a
init
wk989898 31592de
update
wk989898 e29004d
update
wk989898 71216c4
chore
wk989898 e43775b
chore
wk989898 1d40b99
fix
wk989898 8571a24
update test
wk989898 a634bcd
Merge branch 'master' into redo-0304
wk989898 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,9 @@ import ( | |
| commonEvent "github.com/pingcap/ticdc/pkg/common/event" | ||
| "github.com/pingcap/ticdc/pkg/config" | ||
| "github.com/pingcap/ticdc/pkg/redo" | ||
| "github.com/pingcap/ticdc/pkg/redo/writer" | ||
| "github.com/pingcap/ticdc/pkg/util" | ||
| "github.com/pingcap/ticdc/utils/chann" | ||
| "github.com/stretchr/testify/require" | ||
| "golang.org/x/sync/errgroup" | ||
| ) | ||
|
|
@@ -329,3 +331,62 @@ func runBenchTest(b *testing.B, storage string, useFileBackend bool) { | |
|
|
||
| require.ErrorIs(b, eg.Wait(), context.Canceled) | ||
| } | ||
|
|
||
| type mockBatchWriter struct { | ||
|
||
| mu sync.Mutex | ||
| batchLens []int | ||
| } | ||
|
|
||
| func (m *mockBatchWriter) WriteEvents(_ context.Context, events ...writer.RedoEvent) error { | ||
| m.mu.Lock() | ||
| defer m.mu.Unlock() | ||
| m.batchLens = append(m.batchLens, len(events)) | ||
| for _, event := range events { | ||
| event.PostFlush() | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (m *mockBatchWriter) Run(ctx context.Context) error { | ||
| <-ctx.Done() | ||
| return ctx.Err() | ||
| } | ||
|
|
||
| func (m *mockBatchWriter) Close() error { | ||
| return nil | ||
| } | ||
|
|
||
| func (m *mockBatchWriter) SetTableSchemaStore(_ *commonEvent.TableSchemaStore) {} | ||
|
|
||
| func TestRedoSinkSendMessagesInBatch(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| ctx, cancel := context.WithCancel(context.Background()) | ||
| defer cancel() | ||
|
|
||
| mockWriter := &mockBatchWriter{} | ||
| s := &Sink{ | ||
| dmlWriter: mockWriter, | ||
| logBuffer: chann.NewUnlimitedChannelDefault[writer.RedoEvent](), | ||
| } | ||
|
|
||
| doneCh := make(chan error, 1) | ||
| go func() { | ||
| doneCh <- s.sendMessages(ctx) | ||
| }() | ||
|
|
||
| totalEvents := redo.DefaultFlushBatchSize*2 + 17 | ||
| events := make([]writer.RedoEvent, 0, totalEvents) | ||
| for i := 0; i < totalEvents; i++ { | ||
| events = append(events, &commonEvent.RedoRowEvent{}) | ||
| } | ||
| s.logBuffer.Push(events...) | ||
| s.logBuffer.Close() | ||
|
|
||
| err := <-doneCh | ||
| require.NoError(t, err) | ||
|
|
||
| mockWriter.mu.Lock() | ||
| defer mockWriter.mu.Unlock() | ||
| require.Equal(t, []int{redo.DefaultFlushBatchSize, redo.DefaultFlushBatchSize, 17}, mockWriter.batchLens) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: pingcap/ticdc
Length of output: 88
🏁 Script executed:
Repository: pingcap/ticdc
Length of output: 210
🏁 Script executed:
sed -n '230,240p' downstreamadapter/sink/kafka/sink.goRepository: pingcap/ticdc
Length of output: 292
Fix compilation error:
make()requiresinttype for capacity, butevent.Len()returnsint32.Line 234 assigns
rowsCount := event.Len(), makingrowsCounttypeint32. Line 236 then usesrowsCountas the capacity argument tomake([]*commonEvent.MQRowEvent, 0, rowsCount), which requiresint. Add an explicit conversion:🤖 Prompt for AI Agents