From 256beffee8068fa5ea4e6df2319a54a54441b61d Mon Sep 17 00:00:00 2001 From: Jianyuan Jiang Date: Tue, 19 Nov 2024 16:26:53 +0800 Subject: [PATCH] This is an automated cherry-pick of #11770 Signed-off-by: ti-chi-bot --- cdc/api/v2/api.go | 5 ++++ tests/integration_tests/availability/owner.sh | 30 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cdc/api/v2/api.go b/cdc/api/v2/api.go index a6b8b48c4ba..92dda1a8813 100644 --- a/cdc/api/v2/api.go +++ b/cdc/api/v2/api.go @@ -88,8 +88,13 @@ func RegisterOpenAPIV2Routes(router *gin.Engine, api OpenAPIV2) { // owner apis ownerGroup := v2.Group("/owner") +<<<<<<< HEAD unsafeGroup.Use(controllerMiddleware) ownerGroup.POST("/resign", api.resignController) +======= + ownerGroup.Use(ownerMiddleware) + ownerGroup.POST("/resign", api.resignOwner) +>>>>>>> 8e3b63acec (fix resign owner api not processed by owner node bug (#11770)) // common APIs v2.POST("/tso", api.QueryTso) diff --git a/tests/integration_tests/availability/owner.sh b/tests/integration_tests/availability/owner.sh index b78c0ecd78e..82eb2ad69c2 100755 --- a/tests/integration_tests/availability/owner.sh +++ b/tests/integration_tests/availability/owner.sh @@ -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 @@ -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 @@ -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 +}