Skip to content

Commit

Permalink
scheduler(ticdc): preven table agent from receiving expired messages (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesCheung96 authored Nov 30, 2023
1 parent 8fb72da commit 197057b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
20 changes: 20 additions & 0 deletions cdc/scheduler/internal/v3/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ func newAgent(
return result, nil
}

var ownerCaptureInfo *model.CaptureInfo
_, captures, err := etcdClient.GetCaptures(ctx)
for _, captureInfo := range captures {
if captureInfo.ID == ownerCaptureID {
ownerCaptureInfo = captureInfo
break
}
}
if ownerCaptureInfo == nil {
log.Info("schedulerv3: no owner found. We will wait for an owner to contact us.",
zap.String("namespace", changeFeedID.Namespace),
zap.String("changefeed", changeFeedID.ID),
zap.Error(err))
return result, nil
}

result.compat.UpdateCaptureInfo(map[model.CaptureID]*model.CaptureInfo{
ownerCaptureID: ownerCaptureInfo,
})

log.Info("schedulerv3: agent owner found",
zap.String("ownerCaptureID", ownerCaptureID),
zap.String("captureID", captureID),
Expand Down
8 changes: 7 additions & 1 deletion cdc/scheduler/internal/v3/agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func TestNewAgent(t *testing.T) {
tableExector := newMockTableExecutor()

// owner and revision found successfully
me.EXPECT().GetOwnerID(gomock.Any()).Return("owneID", nil).Times(1)
me.EXPECT().GetOwnerID(gomock.Any()).Return("ownerID", nil).Times(1)
me.EXPECT().GetCaptures(
gomock.Any()).Return(int64(0), []*model.CaptureInfo{{ID: "ownerID"}}, nil).Times(1)
me.EXPECT().GetOwnerRevision(gomock.Any(), gomock.Any()).Return(int64(2333), nil).Times(1)
a, err := newAgent(
context.Background(), "capture-test", &liveness, changefeed, me, tableExector, 0)
Expand All @@ -110,6 +112,8 @@ func TestNewAgent(t *testing.T) {

// owner found, get revision failed.
me.EXPECT().GetOwnerID(gomock.Any()).Return("ownerID", nil).Times(1)
me.EXPECT().GetCaptures(
gomock.Any()).Return(int64(0), []*model.CaptureInfo{{ID: "ownerID"}}, nil).Times(1)
me.EXPECT().GetOwnerRevision(gomock.Any(), gomock.Any()).
Return(int64(0), cerror.ErrPDEtcdAPIError).Times(1)
a, err = newAgent(
Expand All @@ -118,6 +122,8 @@ func TestNewAgent(t *testing.T) {
require.Nil(t, a)

me.EXPECT().GetOwnerID(gomock.Any()).Return("ownerID", nil).Times(1)
me.EXPECT().GetCaptures(
gomock.Any()).Return(int64(0), []*model.CaptureInfo{{ID: "ownerID"}}, nil).Times(1)
me.EXPECT().GetOwnerRevision(gomock.Any(), gomock.Any()).
Return(int64(0), cerror.ErrOwnerNotFound).Times(1)
a, err = newAgent(
Expand Down

0 comments on commit 197057b

Please sign in to comment.