Skip to content

Commit

Permalink
http_api (ticdc): fix http api 'get processor' panic. (#4117) (#4123)
Browse files Browse the repository at this point in the history
close #3840
  • Loading branch information
ti-chi-bot authored Jan 12, 2022
1 parent 2d745de commit cabee2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cdc/capture/http_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var httpBadRequestError = []*errors.Error{
cerror.ErrAPIInvalidParam, cerror.ErrSinkURIInvalid, cerror.ErrStartTsBeforeGC,
cerror.ErrChangeFeedNotExists, cerror.ErrTargetTsBeforeStartTs, cerror.ErrTableIneligible,
cerror.ErrFilterRuleInvalid, cerror.ErrChangefeedUpdateRefused, cerror.ErrMySQLConnectionError,
cerror.ErrMySQLInvalidConfig,
cerror.ErrMySQLInvalidConfig, cerror.ErrCaptureNotExist,
}

// IsHTTPBadRequestError check if a error is a http bad request error
Expand Down
2 changes: 2 additions & 0 deletions cdc/capture/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ func (h *HTTPHandler) GetProcessor(c *gin.Context) {
status, exist := statuses[captureID]
if !exist {
_ = c.Error(cerror.ErrCaptureNotExist.GenWithStackByArgs(captureID))
return
}

positions, err := statusProvider.GetTaskPositions(ctx, changefeedID)
Expand All @@ -586,6 +587,7 @@ func (h *HTTPHandler) GetProcessor(c *gin.Context) {
position, exist := positions[captureID]
if !exist {
_ = c.Error(cerror.ErrCaptureNotExist.GenWithStackByArgs(captureID))
return
}

processorDetail := &model.ProcessorDetail{CheckPointTs: position.CheckPointTs, ResolvedTs: position.ResolvedTs, Error: position.Error}
Expand Down
11 changes: 8 additions & 3 deletions tests/integration_tests/http_api/util/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,19 @@ def list_processor():

# must at least one table is sync will the test success
def get_processor():
url = BASE_URL0 + "/processors"
resp = rq.get(url, cert=CERT, verify=VERIFY)
base_url = BASE_URL0 + "/processors"
resp = rq.get(base_url, cert=CERT, verify=VERIFY)
assert resp.status_code == rq.codes.ok
data = resp.json()[0]
url = url + "/" + data["changefeed_id"] + "/" + data["capture_id"]
url = base_url + "/" + data["changefeed_id"] + "/" + data["capture_id"]
resp = rq.get(url, cert=CERT, verify=VERIFY)
assert resp.status_code == rq.codes.ok

# test capture_id error and cdc server no panic
url = base_url + "/" + data["changefeed_id"] + "/" + "non-exist-capture-id"
resp = rq.get(url, cert=CERT, verify=VERIFY)
assert resp.status_code == rq.codes.bad_request

print("pass test: get processors")


Expand Down

0 comments on commit cabee2c

Please sign in to comment.