From 2fdacb1a55b0dc814e4a6aee75e22cf7d6975956 Mon Sep 17 00:00:00 2001 From: jiangjianyuan Date: Mon, 18 Nov 2024 15:13:56 +0800 Subject: [PATCH 1/6] fix resign owner api not processed by owner node bug --- cdc/api/v2/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdc/api/v2/api.go b/cdc/api/v2/api.go index 9d70f3ca37f..033fe177bd5 100644 --- a/cdc/api/v2/api.go +++ b/cdc/api/v2/api.go @@ -86,7 +86,7 @@ func RegisterOpenAPIV2Routes(router *gin.Engine, api OpenAPIV2) { // owner apis ownerGroup := v2.Group("/owner") - unsafeGroup.Use(ownerMiddleware) + ownerGroup.Use(ownerMiddleware) ownerGroup.POST("/resign", api.resignOwner) // common APIs From fa86456c6de2ddda986ad37f3d57e3f6f1500034 Mon Sep 17 00:00:00 2001 From: jiangjianyuan Date: Tue, 19 Nov 2024 09:43:41 +0800 Subject: [PATCH 2/6] add test --- tests/integration_tests/availability/owner.sh | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/integration_tests/availability/owner.sh b/tests/integration_tests/availability/owner.sh index b78c0ecd78e..9146aaef086 100755 --- a/tests/integration_tests/availability/owner.sh +++ b/tests/integration_tests/availability/owner.sh @@ -242,3 +242,31 @@ 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:8301" --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_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") + 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 +} From 93753d7b5492df3d04f58d6af5ed08dd109a8a70 Mon Sep 17 00:00:00 2001 From: jiangjianyuan Date: Tue, 19 Nov 2024 10:14:39 +0800 Subject: [PATCH 3/6] add test --- tests/integration_tests/availability/owner.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration_tests/availability/owner.sh b/tests/integration_tests/availability/owner.sh index 9146aaef086..3e74db78e74 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 From d6a71de8f31153848b9d4b1c5044f76c8147eb9d Mon Sep 17 00:00:00 2001 From: jiangjianyuan Date: Tue, 19 Nov 2024 10:21:44 +0800 Subject: [PATCH 4/6] add test --- tests/integration_tests/availability/owner.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration_tests/availability/owner.sh b/tests/integration_tests/availability/owner.sh index 3e74db78e74..331bcc8cc77 100755 --- a/tests/integration_tests/availability/owner.sh +++ b/tests/integration_tests/availability/owner.sh @@ -249,7 +249,7 @@ function test_delete_owner_key() { # 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:8301" --logsuffix test_resign_owner.server1 + 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}') From 467cc91d86c646147166e27c92ab283dbb04a624 Mon Sep 17 00:00:00 2001 From: jiangjianyuan Date: Tue, 19 Nov 2024 10:28:11 +0800 Subject: [PATCH 5/6] add test --- tests/integration_tests/availability/owner.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration_tests/availability/owner.sh b/tests/integration_tests/availability/owner.sh index 331bcc8cc77..6459a98bdd9 100755 --- a/tests/integration_tests/availability/owner.sh +++ b/tests/integration_tests/availability/owner.sh @@ -261,7 +261,6 @@ function test_resign_owner() { 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_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") echo "capture_id:" $capture_id # resign the owner From c9541c7f6a307a908e987a52c6b67f88c7404b23 Mon Sep 17 00:00:00 2001 From: jiangjianyuan Date: Tue, 19 Nov 2024 10:44:20 +0800 Subject: [PATCH 6/6] add test --- tests/integration_tests/availability/owner.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration_tests/availability/owner.sh b/tests/integration_tests/availability/owner.sh index 6459a98bdd9..82eb2ad69c2 100755 --- a/tests/integration_tests/availability/owner.sh +++ b/tests/integration_tests/availability/owner.sh @@ -220,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 @@ -258,10 +258,10 @@ function test_resign_owner() { 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_pid=$(ps -C $CDC_BINARY -o pid= | awk '{print $1}' | grep -v "$owner_pid") - echo "capture_id:" $capture_id + 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