@@ -1346,14 +1346,27 @@ add_member(Q, Node, Membership, Timeout) when ?amqqueue_is_quorum(Q) ->
1346
1346
maps :get (id , Conf )
1347
1347
end ,
1348
1348
case ra :add_member (Members , ServerIdSpec , Timeout ) of
1349
- {ok , _ , Leader } ->
1349
+ {ok , { RaIndex , RaTerm } , Leader } ->
1350
1350
Fun = fun (Q1 ) ->
1351
1351
Q2 = update_type_state (
1352
1352
Q1 , fun (#{nodes := Nodes } = Ts ) ->
1353
1353
Ts #{nodes => [Node | Nodes ]}
1354
1354
end ),
1355
1355
amqqueue :set_pid (Q2 , Leader )
1356
1356
end ,
1357
+ % % The `ra:member_add/3` call above returns before the
1358
+ % % change is committed. This is ok for that addition but
1359
+ % % any follow-up changes to the cluster might be rejected
1360
+ % % with the `cluster_change_not_permitted` error.
1361
+ % %
1362
+ % % Instead of changing other places to wait or retry their
1363
+ % % cluster membership change, we wait for the current add
1364
+ % % to be applied using a conditional leader query before
1365
+ % % proceeding and returning.
1366
+ {ok , _ , _ } = ra :leader_query (
1367
+ Leader ,
1368
+ {erlang , is_list , []},
1369
+ #{condition => {applied , {RaIndex , RaTerm }}}),
1357
1370
_ = rabbit_amqqueue :update (QName , Fun ),
1358
1371
rabbit_log :info (" Added a replica of quorum ~ts on node ~ts " , [rabbit_misc :rs (QName ), Node ]),
1359
1372
ok ;
0 commit comments