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

api,owner(ticdc): return error when api fails #4494

Merged
merged 7 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ kafka_consumer:
install:
go install ./...

unit_test: check_failpoint_ctl
unit_test: check_failpoint_ctl generate_mock
mkdir -p "$(TEST_DIR)"
$(FAILPOINT_ENABLE)
@export log_level=error;\
Expand Down Expand Up @@ -167,7 +167,7 @@ integration_test_mysql:
integration_test_kafka: check_third_party_binary
tests/integration_tests/run.sh kafka "$(CASE)" "$(START_AT)"

fmt: tools/bin/gofumports tools/bin/shfmt
fmt: tools/bin/gofumports tools/bin/shfmt generate_mock
@echo "gofmt (simplify)"
tools/bin/gofumports -l -w $(FILES) 2>&1 | $(FAIL_ON_STDOUT)
@echo "run shfmt"
Expand Down Expand Up @@ -234,6 +234,9 @@ data-flow-diagram: docs/data-flow.dot
swagger-spec: tools/bin/swag
tools/bin/swag init --parseVendor -generalInfo cdc/api/open.go --output docs/swagger

generate_mock: tools/bin/mockgen
tools/bin/mockgen -source cdc/owner/owner.go -destination cdc/owner/mock/owner_mock.go

clean:
go clean -i ./...
rm -rf *.out
Expand Down
57 changes: 41 additions & 16 deletions cdc/api/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,16 @@ func (h *openAPI) PauseChangefeed(c *gin.Context) {
Type: model.AdminStop,
}

_ = h.capture.OperateOwnerUnderLock(func(owner *owner.Owner) error {
owner.EnqueueJob(job)
// Use buffered channel to prevernt blocking owner.
done := make(chan error, 1)
asddongmen marked this conversation as resolved.
Show resolved Hide resolved
_ = h.capture.OperateOwnerUnderLock(func(owner owner.Owner) error {
owner.EnqueueJob(job, done)
return nil
})

if err := waitDone(ctx, done); err != nil {
_ = c.Error(err)
return
}
c.Status(http.StatusAccepted)
}

Expand Down Expand Up @@ -361,11 +366,16 @@ func (h *openAPI) ResumeChangefeed(c *gin.Context) {
Type: model.AdminResume,
}

_ = h.capture.OperateOwnerUnderLock(func(owner *owner.Owner) error {
owner.EnqueueJob(job)
// Use buffered channel to prevernt blocking owner.
asddongmen marked this conversation as resolved.
Show resolved Hide resolved
done := make(chan error, 1)
_ = h.capture.OperateOwnerUnderLock(func(owner owner.Owner) error {
owner.EnqueueJob(job, done)
return nil
})

if err := waitDone(ctx, done); err != nil {
_ = c.Error(err)
return
}
c.Status(http.StatusAccepted)
}

Expand Down Expand Up @@ -465,11 +475,16 @@ func (h *openAPI) RemoveChangefeed(c *gin.Context) {
Type: model.AdminRemove,
}

_ = h.capture.OperateOwnerUnderLock(func(owner *owner.Owner) error {
owner.EnqueueJob(job)
// Use buffered channel to prevernt blocking owner.
done := make(chan error, 1)
_ = h.capture.OperateOwnerUnderLock(func(owner owner.Owner) error {
owner.EnqueueJob(job, done)
return nil
})

if err := waitDone(ctx, done); err != nil {
_ = c.Error(err)
return
}
c.Status(http.StatusAccepted)
}

Expand Down Expand Up @@ -503,11 +518,16 @@ func (h *openAPI) RebalanceTable(c *gin.Context) {
return
}

_ = h.capture.OperateOwnerUnderLock(func(owner *owner.Owner) error {
owner.TriggerRebalance(changefeedID)
// Use buffered channel to prevernt blocking owner.
done := make(chan error, 1)
_ = h.capture.OperateOwnerUnderLock(func(owner owner.Owner) error {
owner.TriggerRebalance(changefeedID, done)
return nil
})

if err := waitDone(ctx, done); err != nil {
_ = c.Error(err)
return
}
c.Status(http.StatusAccepted)
}

Expand Down Expand Up @@ -557,11 +577,16 @@ func (h *openAPI) MoveTable(c *gin.Context) {
return
}

_ = h.capture.OperateOwnerUnderLock(func(owner *owner.Owner) error {
owner.ManualSchedule(changefeedID, data.CaptureID, data.TableID)
// Use buffered channel to prevernt blocking owner.
done := make(chan error, 1)
_ = h.capture.OperateOwnerUnderLock(func(owner owner.Owner) error {
owner.ManualSchedule(changefeedID, data.CaptureID, data.TableID, done)
return nil
})

if err := waitDone(ctx, done); err != nil {
_ = c.Error(err)
return
}
c.Status(http.StatusAccepted)
}

Expand All @@ -580,7 +605,7 @@ func (h *openAPI) ResignOwner(c *gin.Context) {
return
}

_ = h.capture.OperateOwnerUnderLock(func(owner *owner.Owner) error {
_ = h.capture.OperateOwnerUnderLock(func(owner owner.Owner) error {
owner.AsyncStop()
return nil
})
Expand Down
Loading