Skip to content

Commit

Permalink
fix resign owner api not processed by owner node bug (#11770) (#11782)
Browse files Browse the repository at this point in the history
close #11769
  • Loading branch information
ti-chi-bot authored Nov 27, 2024
1 parent efe4d97 commit be9e14a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cdc/api/v2/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func RegisterOpenAPIV2Routes(router *gin.Engine, api OpenAPIV2) {

// owner apis
ownerGroup := v2.Group("/owner")
unsafeGroup.Use(middleware.ForwardToOwnerMiddleware(api.capture))
ownerGroup.Use(middleware.ForwardToOwnerMiddleware(api.capture))
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 be9e14a

Please sign in to comment.