Skip to content

Commit ea326c3

Browse files
Merge pull request #11445 from rabbitmq/mergify/bp/v3.13.x/pr-11439
etcd peer discovery fixes (backport #11439)
2 parents 28181bb + 6a5c922 commit ea326c3

File tree

11 files changed

+56
-24
lines changed

11 files changed

+56
-24
lines changed

.github/workflows/templates/test-mixed-versions.template.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ jobs:
144144
with:
145145
otp-version: 26
146146
elixir-version: 1.15
147+
hexpm-mirrors: |
148+
https://builds.hex.pm
149+
https://cdn.jsdelivr.net/hex
147150
- name: ENSURE WORKFLOWS ARE UP TO DATE
148151
run: |
149152
mkdir local-bin/

.github/workflows/templates/test.template.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ jobs:
5858
with:
5959
otp-version: 26
6060
elixir-version: 1.15
61+
hexpm-mirrors: |
62+
https://builds.hex.pm
63+
https://cdn.jsdelivr.net/hex
6164
- name: ENSURE WORKFLOWS ARE UP TO DATE
6265
run: |
6366
mkdir local-bin/

.github/workflows/test-mixed-versions.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ jobs:
121121
with:
122122
otp-version: 26
123123
elixir-version: 1.15
124+
hexpm-mirrors: |
125+
https://builds.hex.pm
126+
https://cdn.jsdelivr.net/hex
124127
- name: ENSURE WORKFLOWS ARE UP TO DATE
125128
run: |
126129
mkdir local-bin/

.github/workflows/test-plugin-mixed.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ jobs:
4747
with:
4848
otp-version: ${{ matrix.erlang_version }}
4949
elixir-version: ${{ matrix.elixir_version }}
50+
hexpm-mirrors: |
51+
https://builds.hex.pm
52+
https://cdn.jsdelivr.net/hex
5053
- name: AUTHENTICATE TO GOOGLE CLOUD
5154
uses: google-github-actions/[email protected]
5255
with:

.github/workflows/test-plugin.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ jobs:
4747
with:
4848
otp-version: ${{ matrix.erlang_version }}
4949
elixir-version: ${{ matrix.elixir_version }}
50+
hexpm-mirrors: |
51+
https://builds.hex.pm
52+
https://cdn.jsdelivr.net/hex
5053
- name: AUTHENTICATE TO GOOGLE CLOUD
5154
uses: google-github-actions/[email protected]
5255
with:

.github/workflows/test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ jobs:
3838
with:
3939
otp-version: 26
4040
elixir-version: 1.15
41+
hexpm-mirrors: |
42+
https://builds.hex.pm
43+
https://cdn.jsdelivr.net/hex
4144
- name: ENSURE WORKFLOWS ARE UP TO DATE
4245
run: |
4346
mkdir local-bin/

deps/rabbit/test/unit_quorum_queue_SUITE.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
-module(unit_quorum_queue_SUITE).
22

3+
-compile(nowarn_export_all).
34
-compile(export_all).
45

56
all() ->

deps/rabbitmq_peer_discovery_etcd/src/rabbit_peer_discovery_etcd.erl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,13 @@ list_nodes() ->
6060
{ok, {[], disc}}
6161
end,
6262
Fun2 = fun(_Proplist) ->
63-
%% error logging will be done by the client
64-
Nodes = rabbitmq_peer_discovery_etcd_v3_client:list_nodes(),
65-
{ok, {Nodes, disc}}
63+
%% nodes are returned sorted with the create_revision as
64+
%% the first element in the tuple.
65+
%% The node with the lowest create_revision is thus selected
66+
%% based on the assumption that the create_revision remains
67+
%% consistent throughout the lifetime of the etcd key.
68+
[{_, Node} | _] = rabbitmq_peer_discovery_etcd_v3_client:list_nodes(),
69+
{ok, {Node, disc}}
6670
end,
6771
rabbit_peer_discovery_util:maybe_backend_configured(?BACKEND_CONFIG_KEY, Fun0, Fun1, Fun2).
6872

deps/rabbitmq_peer_discovery_etcd/src/rabbitmq_peer_discovery_etcd_v3_client.erl

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,13 @@ connected({call, From}, list_keys, Data = #statem_data{connection_name = Conn})
230230
rabbit_log:debug("etcd peer discovery: will use prefix ~ts to query for node keys", [Prefix]),
231231
{ok, #{kvs := Result}} = eetcd_kv:get(C2),
232232
rabbit_log:debug("etcd peer discovery returned keys: ~tp", [Result]),
233-
Values = [maps:get(value, M) || M <- Result],
234-
rabbit_log:debug("etcd peer discovery: listing node keys returned ~b results", [length(Values)]),
235-
ParsedNodes = lists:map(fun extract_node/1, Values),
236-
{Successes, Failures} = lists:partition(fun filter_node/1, ParsedNodes),
237-
JoinedString = lists:join(",", [rabbit_data_coercion:to_list(Node) || Node <- lists:usort(Successes)]),
238-
rabbit_log:error("etcd peer discovery: successfully extracted nodes: ~ts", [JoinedString]),
239-
lists:foreach(fun(Val) ->
240-
rabbit_log:error("etcd peer discovery: failed to extract node name from etcd value ~tp", [Val])
241-
end, Failures),
242-
gen_statem:reply(From, lists:usort(Successes)),
233+
Values = [{maps:get(create_revision, M), maps:get(value, M)} || M <- Result],
234+
rabbit_log:debug("etcd peer discovery: listing node keys returned ~b results",
235+
[length(Values)]),
236+
ParsedNodes = lists:filtermap(fun extract_node/1, Values),
237+
rabbit_log:info("etcd peer discovery: successfully extracted nodes: ~0tp",
238+
[ParsedNodes]),
239+
gen_statem:reply(From, lists:usort(ParsedNodes)),
243240
keep_state_and_data.
244241

245242

@@ -298,15 +295,18 @@ registration_value(#statem_data{node_key_lease_id = LeaseID, node_key_ttl_in_sec
298295
<<"ttl">> => TTL
299296
})).
300297

301-
-spec extract_node(binary()) -> atom() | {error, any()}.
302-
303-
extract_node(Payload) ->
298+
extract_node({CreatedRev, Payload}) ->
304299
case rabbit_json:try_decode(Payload) of
305-
{error, Error} -> {error, Error};
300+
{error, _Error} ->
301+
rabbit_log:error("etcd peer discovery: failed to extract node name from etcd value ~tp",
302+
[Payload]),
303+
false;
306304
{ok, Map} ->
307305
case maps:get(<<"node">>, Map, undefined) of
308-
undefined -> undefined;
309-
Node -> rabbit_data_coercion:to_atom(Node)
306+
undefined ->
307+
false;
308+
Node ->
309+
{true, {CreatedRev, rabbit_data_coercion:to_atom(Node)}}
310310
end
311311
end.
312312

deps/rabbitmq_peer_discovery_etcd/test/system_SUITE.erl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ registration_with_locking_test(Config) ->
120120
?assertEqual(ok, rabbitmq_peer_discovery_etcd_v3_client:unlock(Pid, LockOwnerKey)),
121121

122122
Condition2 = fun() ->
123-
[node()] =:= rabbitmq_peer_discovery_etcd_v3_client:list_nodes(Pid)
123+
case rabbitmq_peer_discovery_etcd_v3_client:list_nodes(Pid) of
124+
[{_, N}] when N =:= node() ->
125+
true;
126+
_ ->
127+
false
128+
end
124129
end,
125130
try
126131
rabbit_ct_helpers:await_condition(Condition2, 45000)

deps/rabbitmq_peer_discovery_etcd/test/unit_SUITE.erl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ registration_value_test(_Config) ->
5555
extract_nodes_case1_test(_Config) ->
5656
Input = registration_value_of(8488283859587364900, 61),
5757
Expected = node(),
58-
59-
?assertEqual(Expected, rabbitmq_peer_discovery_etcd_v3_client:extract_node(Input)),
60-
61-
?assertEqual(undefined, rabbitmq_peer_discovery_etcd_v3_client:extract_node(<<"{}">>)).
58+
CreatedRev = ?LINE,
59+
?assertEqual({true, {CreatedRev, Expected}},
60+
rabbitmq_peer_discovery_etcd_v3_client:extract_node(
61+
{CreatedRev, Input})),
62+
63+
?assertEqual(false,
64+
rabbitmq_peer_discovery_etcd_v3_client:extract_node(
65+
{CreatedRev, <<"{}">>})).
6266

6367
filter_nodes_test(_Config) ->
6468
Input = [node(), undefined, undefined, {error, reason1}, {error, {another, reason}}],

0 commit comments

Comments
 (0)