Skip to content

Commit

Permalink
owner,scheduler(cdc): fix nil pointer panic in owner scheduler (pingc…
Browse files Browse the repository at this point in the history
  • Loading branch information
asddongmen committed Dec 21, 2021
1 parent 9ef831f commit 951b343
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cdc/owner/scheduler_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ func (s *oldScheduler) handleJobs(jobs []*schedulerJob) {
func (s *oldScheduler) 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.")
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_v1_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 @@ -83,8 +84,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

0 comments on commit 951b343

Please sign in to comment.