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

owner,scheduler(cdc): fix nil pointer panic in owner scheduler (#2980) (#4007) #4015

Merged
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
5 changes: 5 additions & 0 deletions cdc/owner/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ func (s *scheduler) handleJobs(jobs []*schedulerJob) {
func (s *scheduler) cleanUpFinishedOperations() {
for captureID := range s.state.TaskStatuses {
s.state.PatchTaskStatus(captureID, func(status *model.TaskStatus) (*model.TaskStatus, bool, error) {
if status == nil {
log.Warn("task status of the capture is not found, may be the key in etcd was deleted", zap.String("captureID", captureID), zap.String("changeFeedID", s.state.ID))
return status, false, nil
}

changed := false
for tableID, operation := range status.Operation {
if operation.Status == model.OperFinished {
Expand Down
19 changes: 18 additions & 1 deletion cdc/owner/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/pingcap/check"
"github.com/pingcap/tiflow/cdc/model"
"github.com/pingcap/tiflow/pkg/etcd"
"github.com/pingcap/tiflow/pkg/orchestrator"
"github.com/pingcap/tiflow/pkg/util/testleak"
)
Expand Down Expand Up @@ -84,8 +85,24 @@ func (s *schedulerSuite) finishTableOperation(captureID model.CaptureID, tableID

func (s *schedulerSuite) TestScheduleOneCapture(c *check.C) {
defer testleak.AfterTest(c)()

s.reset(c)
captureID := "test-capture-0"
s.addCapture(captureID)

_, _ = s.scheduler.Tick(s.state, []model.TableID{}, s.captures)

// Manually simulate the scenario where the corresponding key was deleted in the etcd
key := &etcd.CDCKey{
Tp: etcd.CDCKeyTypeTaskStatus,
CaptureID: captureID,
ChangefeedID: s.state.ID,
}
s.tester.MustUpdate(key.String(), nil)
s.tester.MustApplyPatches()

s.reset(c)
captureID := "test-capture-1"
captureID = "test-capture-1"
s.addCapture(captureID)

// add three tables
Expand Down