@@ -115,7 +115,8 @@ groups() ->
115115 node_removal_is_not_quorum_critical ,
116116 select_nodes_with_least_replicas ,
117117 select_nodes_with_least_replicas_node_down ,
118- subscribe_from_each
118+ subscribe_from_each ,
119+ get_member_with_highest_index
119120
120121
121122 ]},
@@ -365,6 +366,8 @@ init_per_testcase(Testcase, Config) ->
365366 {skip , " peek_with_wrong_queue_type isn't mixed versions compatible" };
366367 cancel_consumer_gh_3729 when IsMixed andalso RabbitMQ3 ->
367368 {skip , " this test is not compatible with RabbitMQ 3.13.x" };
369+ get_member_with_highest_index when IsMixed ->
370+ {skip , " get_member_with_highest_index isn't mixed versions compatible" };
368371 _ ->
369372 Config1 = rabbit_ct_helpers :testcase_started (Config , Testcase ),
370373 rabbit_ct_broker_helpers :rpc (Config , 0 , ? MODULE , delete_queues , []),
@@ -4576,6 +4579,95 @@ leader_health_check(Config) ->
45764579 amqp_connection :close (Conn1 ),
45774580 amqp_connection :close (Conn2 ).
45784581
4582+ get_member_with_highest_index (Config ) ->
4583+ [Node1 , Node2 , Node3 , Node4 , Node5 ] =
4584+ rabbit_ct_broker_helpers :get_node_configs (Config , nodename ),
4585+
4586+ Q = ? config (queue_name , Config ),
4587+ VHost = <<" /" >>,
4588+
4589+ Statuses =
4590+ % % [{Node, Member, LogIdx, CommitIdx, SnapshotIdx}, ...]
4591+ [{Node1 , leader , 1015 , 1010 , 1010 }, % % highest SnapshotIdx
4592+ {Node2 , follower , 1015 , 1010 , 1010 }, % % highest SnapshotIdx (duplicate)
4593+ {Node3 , follower , 1013 , 1013 , 1009 }, % % highest CommitIdx
4594+ {Node4 , follower , 1016 , 1009 , 1008 }, % % highest LogIdx
4595+ {Node5 , follower , 1013 , 1012 , undefined }],
4596+
4597+ Term = 1 ,
4598+ MachineVersion = 7 ,
4599+
4600+ meck :new (rabbit_quorum_queue , [passthrough , no_link ]),
4601+ meck :expect (
4602+ rabbit_quorum_queue , status ,
4603+ fun (_ , _ ) ->
4604+ [[{<<" Node Name" >>, Node },
4605+ {<<" Raft State" >>, Member },
4606+ {<<" Last Log Index" >>, LogIndex },
4607+ {<<" Last Written" >>, LogIndex },
4608+ {<<" Last Applied" >>, LogIndex },
4609+ {<<" Commit Index" >>, CommitIndex },
4610+ {<<" Snapshot Index" >>, SnapshotIdx },
4611+ {<<" Term" >>, Term },
4612+ {<<" Machine Version" >>, MachineVersion }]
4613+ || {Node , Member , LogIndex , CommitIndex , SnapshotIdx } <- Statuses ]
4614+ end ),
4615+
4616+ ct :pal (" quorum status: ~tp " , [rabbit_quorum_queue :status (VHost , Q )]),
4617+
4618+ ExpectedHighestLogIdx =
4619+ [[{<<" Node Name" >>, Node4 },
4620+ {<<" Raft State" >>, follower },
4621+ {<<" Last Log Index" >>, 1016 },
4622+ {<<" Last Written" >>,1016 },
4623+ {<<" Last Applied" >>,1016 },
4624+ {<<" Commit Index" >>, 1009 },
4625+ {<<" Snapshot Index" >>, 1008 },
4626+ {<<" Term" >>, Term },
4627+ {<<" Machine Version" >>, MachineVersion }]],
4628+
4629+ [? assertEqual (ExpectedHighestLogIdx ,
4630+ rabbit_quorum_queue :get_member_with_highest_index (VHost , Q , I )) || I <- [log , log_index ]],
4631+
4632+ ExpectedHighestCommitIdx =
4633+ [[{<<" Node Name" >>, Node3 },
4634+ {<<" Raft State" >>, follower },
4635+ {<<" Last Log Index" >>, 1013 },
4636+ {<<" Last Written" >>,1013 },
4637+ {<<" Last Applied" >>,1013 },
4638+ {<<" Commit Index" >>, 1013 },
4639+ {<<" Snapshot Index" >>, 1009 },
4640+ {<<" Term" >>, Term },
4641+ {<<" Machine Version" >>, MachineVersion }]],
4642+
4643+ [? assertEqual (ExpectedHighestCommitIdx ,
4644+ rabbit_quorum_queue :get_member_with_highest_index (VHost , Q , I )) || I <- [commit , commit_index ]],
4645+
4646+ ExpectedHighestSnapshotIdx =
4647+ [[{<<" Node Name" >>, Node1 },
4648+ {<<" Raft State" >>, leader },
4649+ {<<" Last Log Index" >>, 1015 },
4650+ {<<" Last Written" >>,1015 },
4651+ {<<" Last Applied" >>,1015 },
4652+ {<<" Commit Index" >>, 1010 },
4653+ {<<" Snapshot Index" >>, 1010 },
4654+ {<<" Term" >>, Term },
4655+ {<<" Machine Version" >>, MachineVersion }]],
4656+ % Duplicate:
4657+ % [{<<"Node Name">>, Node2},
4658+ % {<<"Raft State">>, follower},
4659+ % {<<"Last Log Index">>, 1015},
4660+ % {<<"Last Written">>,1015},
4661+ % {<<"Last Applied">>,1015},
4662+ % {<<"Commit Index">>, 1010},
4663+ % {<<"Snapshot Index">>, 1010},
4664+ % {<<"Term">>, Term},
4665+ % {<<"Machine Version">>, MachineVersion}],
4666+
4667+ [? assertEqual (ExpectedHighestSnapshotIdx ,
4668+ rabbit_quorum_queue :get_member_with_highest_index (VHost , Q , I )) || I <- [snapshot , snapshot_index ]],
4669+
4670+ ok .
45794671
45804672leader_locator_client_local (Config ) ->
45814673 [Server1 | _ ] = Servers = rabbit_ct_broker_helpers :get_node_configs (Config , nodename ),
0 commit comments