Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: etcd cluster single node failure APISIX startup failure #5158

Merged
merged 16 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions apisix/cli/etcd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local str_format = string.format
local str_sub = string.sub
local table_concat = table.concat
local table_insert = table.insert
local io_stderr = io.stderr

local _M = {}

Expand Down Expand Up @@ -218,24 +219,22 @@ function _M.init(env, args)

local cluster_version = body["etcdcluster"]
if compare_semantic_version(cluster_version, env.min_etcd_version) then
util.die("etcd cluster version ", cluster_version,
" is less than the required version ",
env.min_etcd_version,
", please upgrade your etcd cluster\n")
util.die("etcd cluster version ", cluster_version, " is less than the required version ",
env.min_etcd_version, ", please upgrade your etcd cluster\n")
end

table_insert(etcd_healthy_hosts, host)
else
print(str_format("request etcd endpoint \'%s\' error, %s\n", version_url, err))
io_stderr:write(str_format("request etcd endpoint \'%s\' error, %s\n", version_url, err))
end
end

if #etcd_healthy_hosts <= 0 then
util.die("all etcd nodes are unavailable\n")
end

if host_count >= 2 and #etcd_healthy_hosts < 2 then
util.die("etcd cluster must have two or more healthy nodes\n")
if host_count >= 2 and (#etcd_healthy_hosts / host_count * 100) < 50 then
util.die("the etcd cluster needs at least 50% and above healthy nodes\n")
end

local etcd_ok = false
Expand Down
2 changes: 1 addition & 1 deletion rockspec/apisix-master-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies = {
"lua-resty-ctxdump = 0.1-0",
"lua-resty-dns-client = 5.2.0",
"lua-resty-template = 2.0",
"lua-resty-etcd = 1.5.5",
"lua-resty-etcd = 1.6.0",
"api7-lua-resty-http = 0.2.0",
"lua-resty-balancer = 0.02rc5",
"lua-resty-ngxvar = 0.5.2",
Expand Down
4 changes: 2 additions & 2 deletions t/cli/test_etcd_ha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ etcd:

docker-compose -f ./t/cli/docker-compose-etcd-cluster.yaml up -d

# case 1: stop one etcd nodes (result: start successful)
# case 1: stop one etcd node (result: start successful)
docker stop ${ETCD_NAME_0}

out=$(make init 2>&1)
Expand All @@ -49,7 +49,7 @@ out=$(make init 2>&1)
if echo "$out" | grep "23791" | grep "connection refused"; then
echo "passed: APISIX failed to start, etcd cluster must have two or more healthy nodes"
else
echo "failed: etcd has stopped two nodes, APISIX should fail to start"
echo "failed: two etcd nodes have been stopped, APISIX should fail to start"
exit 1
fi

Expand Down