@@ -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
0 commit comments