Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#11770
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
sdojjy authored and ti-chi-bot committed Nov 20, 2024
1 parent 3ef3c42 commit 3369cb3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cdc/api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ func RegisterOpenAPIV2Routes(router *gin.Engine, api OpenAPIV2) {

// owner apis
ownerGroup := v2.Group("/owner")
<<<<<<< HEAD
unsafeGroup.Use(middleware.ForwardToOwnerMiddleware(api.capture))
=======
ownerGroup.Use(ownerMiddleware)
>>>>>>> 8e3b63acec (fix resign owner api not processed by owner node bug (#11770))
ownerGroup.POST("/resign", api.resignOwner)

// common APIs
Expand Down
30 changes: 29 additions & 1 deletion tests/integration_tests/availability/owner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function test_owner_ha() {
test_owner_retryable_error
test_gap_between_watch_capture
test_delete_owner_key
test_resign_owner
}
# test_kill_owner starts two captures and kill the owner
# we expect the live capture will be elected as the new
Expand Down Expand Up @@ -219,7 +220,7 @@ function test_delete_owner_key() {
run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8301" --logsuffix test_gap_between_watch_capture.server2
ensure $MAX_RETRIES "$CDC_BINARY cli capture list 2>&1 | grep -v \"$owner_id\" | grep id"
capture_pid=$(ps -C $CDC_BINARY -o pid= | awk '{print $1}' | grep -v "$owner_pid")
capture_id=$($CDC_BINARY cli capture list 2>&1 | awk -F '"' '/id/{print $4}' | grep -v "$owner_id")
capture_id=$($CDC_BINARY cli capture list 2>&1 | awk -F '"' '/\"id/{print $4}' | grep -v "$owner_id")
echo "capture_id:" $capture_id

etcdctl del $owner_key
Expand All @@ -242,3 +243,30 @@ function test_delete_owner_key() {
echo "delete_owner_key pass"
cleanup_process $CDC_BINARY
}

# test_resign_owner resign the owner by sending
# the resign owner v2 API
# We expect when the owner is resigned, the new owner will be elected
function test_resign_owner() {
echo "run test case test_resign_owner"
run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8300" --logsuffix test_resign_owner.server1
# ensure the server become the owner
ensure $MAX_RETRIES "$CDC_BINARY cli capture list 2>&1 | grep '\"is-owner\": true'"
owner_pid=$(ps -C $CDC_BINARY -o pid= | awk '{print $1}')
owner_id=$($CDC_BINARY cli capture list 2>&1 | awk -F '"' '/\"id/{print $4}')
echo "owner pid:" $owner_pid
echo "owner id" $owner_id

# run another server
run_cdc_server --workdir $WORK_DIR --binary $CDC_BINARY --addr "127.0.0.1:8301" --logsuffix test_resign_owner.server2
ensure $MAX_RETRIES "$CDC_BINARY cli capture list 2>&1 | grep -v \"$owner_id\" | grep id"
capture_id=$($CDC_BINARY cli capture list 2>&1 | awk -F '"' '/\"id/{print $4}' | grep -v "$owner_id")
echo "capture_id:" $capture_id

# resign the owner
curl -X POST http://127.0.0.1:8301/api/v2/owner/resign
# check that the new owner is elected
ensure $MAX_RETRIES "$CDC_BINARY cli capture list --server 'http://127.0.0.1:8301' 2>&1 |grep $capture_id -A1 | grep '\"is-owner\": true'"
echo "test_resign_owner: pass"
cleanup_process $CDC_BINARY
}

0 comments on commit 3369cb3

Please sign in to comment.