3737-export ([update /2 , store_queue /1 , update_decorators /2 , policy_changed /2 ]).
3838-export ([emit_unresponsive /6 , emit_unresponsive_local /5 , is_unresponsive /2 ]).
3939-export ([is_match /2 , is_in_virtual_host /2 ]).
40- -export ([is_replicated /1 , is_exclusive /1 , is_not_exclusive /1 , is_dead_exclusive /1 ]).
40+ -export ([is_replicable /1 , is_exclusive /1 , is_not_exclusive /1 , is_dead_exclusive /1 ]).
4141-export ([list_local_quorum_queues /0 , list_local_quorum_queue_names /0 ,
4242 list_local_stream_queues /0 , list_stream_queues_on /1 ,
4343 list_local_leaders /0 , list_local_followers /0 , get_quorum_nodes /1 ,
@@ -150,11 +150,7 @@ filter_pid_per_type(QPids) ->
150150
151151- spec stop (rabbit_types :vhost ()) -> 'ok' .
152152stop (VHost ) ->
153- % % Classic queues
154- ok = rabbit_amqqueue_sup_sup :stop_for_vhost (VHost ),
155- {ok , BQ } = application :get_env (rabbit , backing_queue_module ),
156- ok = BQ :stop (VHost ),
157- rabbit_quorum_queue :stop (VHost ).
153+ rabbit_queue_type :stop (VHost ).
158154
159155- spec start ([amqqueue :amqqueue ()]) -> 'ok' .
160156
@@ -424,14 +420,16 @@ rebalance(Type, VhostSpec, QueueSpec) ->
424420 % % We have not yet acquired the rebalance_queues global lock.
425421 maybe_rebalance (get_rebalance_lock (self ()), Type , VhostSpec , QueueSpec ).
426422
423+ % % TODO: classic queues do not support rebalancing, it looks like they are simply
424+ % % filtered out with is_replicable(Q). Maybe error instead?
427425maybe_rebalance ({true , Id }, Type , VhostSpec , QueueSpec ) ->
428426 rabbit_log :info (" Starting queue rebalance operation: '~ts ' for vhosts matching '~ts ' and queues matching '~ts '" ,
429427 [Type , VhostSpec , QueueSpec ]),
430428 Running = rabbit_maintenance :filter_out_drained_nodes_consistent_read (rabbit_nodes :list_running ()),
431429 NumRunning = length (Running ),
432430 ToRebalance = [Q || Q <- list (),
433431 filter_per_type (Type , Q ),
434- is_replicated (Q ),
432+ is_replicable (Q ),
435433 is_match (amqqueue :get_vhost (Q ), VhostSpec ) andalso
436434 is_match (get_resource_name (amqqueue :get_name (Q )), QueueSpec )],
437435 NumToRebalance = length (ToRebalance ),
@@ -459,10 +457,20 @@ filter_per_type(stream, Q) ->
459457filter_per_type (classic , Q ) ->
460458 ? amqqueue_is_classic (Q ).
461459
462- rebalance_module (Q ) when ? amqqueue_is_quorum (Q ) ->
463- rabbit_quorum_queue ;
464- rebalance_module (Q ) when ? amqqueue_is_stream (Q ) ->
465- rabbit_stream_queue .
460+ % % TODO: note that it can return {error, not_supported}.
461+ % % this will result in a badmatch. However that's fine
462+ % % for now because the original function will fail with
463+ % % bad clause if called with classical queue.
464+ % % The assumption is all non-replicated queues
465+ % % are filtered before calling this with is_replicable/0
466+ rebalance_module (Q ) ->
467+ case rabbit_queue_type :rebalance_module (Q ) of
468+ undefined ->
469+ rabbit_log :error (" Undefined rebalance module for queue type: ~s " , [amqqueue :get_type (Q )]),
470+ {error , not_supported };
471+ RBModule ->
472+ RBModule
473+ end .
466474
467475get_resource_name (# resource {name = Name }) ->
468476 Name .
@@ -487,13 +495,19 @@ iterative_rebalance(ByNode, MaxQueuesDesired) ->
487495maybe_migrate (ByNode , MaxQueuesDesired ) ->
488496 maybe_migrate (ByNode , MaxQueuesDesired , maps :keys (ByNode )).
489497
498+ % % TODO: unfortunate part - UI bits mixed deep inside logic.
499+ % % I will not be moving this inside queue type. Instead
500+ % % an attempt to generate something more readable than
501+ % % Other made.
490502column_name (rabbit_classic_queue ) -> <<" Number of replicated classic queues" >>;
491503column_name (rabbit_quorum_queue ) -> <<" Number of quorum queues" >>;
492504column_name (rabbit_stream_queue ) -> <<" Number of streams" >>;
493- column_name (Other ) -> Other .
505+ column_name (TypeModule ) ->
506+ Alias = rabbit_queue_type :short_alias_of (TypeModule ),
507+ <<" Number of \" " , Alias /binary , " \" queues" >>.
494508
495509maybe_migrate (ByNode , _ , []) ->
496- ByNodeAndType = maps :map (fun (_Node , Queues ) -> maps :groups_from_list (fun ({_ , Q , _ }) -> column_name (? amqqueue_v2_field_type (Q )) end , Queues ) end , ByNode ),
510+ ByNodeAndType = maps :map (fun (_Node , Queues ) -> maps :groups_from_list (fun ({_ , Q , _ }) -> column_name (amqqueue : get_type (Q )) end , Queues ) end , ByNode ),
497511 CountByNodeAndType = maps :map (fun (_Node , Type ) -> maps :map (fun (_ , Qs )-> length (Qs ) end , Type ) end , ByNodeAndType ),
498512 {ok , maps :values (maps :map (fun (Node ,Counts ) -> [{<<" Node name" >>, Node } | maps :to_list (Counts )] end , CountByNodeAndType ))};
499513maybe_migrate (ByNode , MaxQueuesDesired , [N | Nodes ]) ->
@@ -1281,14 +1295,12 @@ list_durable() ->
12811295
12821296- spec list_by_type (atom ()) -> [amqqueue :amqqueue ()].
12831297
1284- list_by_type (classic ) -> list_by_type (rabbit_classic_queue );
1285- list_by_type (quorum ) -> list_by_type (rabbit_quorum_queue );
1286- list_by_type (stream ) -> list_by_type (rabbit_stream_queue );
1287- list_by_type (Type ) ->
1288- rabbit_db_queue :get_all_durable_by_type (Type ).
1298+ list_by_type (TypeDescriptor ) ->
1299+ TypeModule = rabbit_queue_type :discover (TypeDescriptor ),
1300+ rabbit_db_queue :get_all_durable_by_type (TypeModule ).
12891301
1302+ % % TODO: looks unused
12901303- spec list_local_quorum_queue_names () -> [name ()].
1291-
12921304list_local_quorum_queue_names () ->
12931305 [ amqqueue :get_name (Q ) || Q <- list_by_type (quorum ),
12941306 amqqueue :get_state (Q ) =/= crashed ,
@@ -1313,18 +1325,19 @@ list_stream_queues_on(Node) when is_atom(Node) ->
13131325list_local_leaders () ->
13141326 [ Q || Q <- list (),
13151327 amqqueue :is_quorum (Q ),
1316- amqqueue :get_state (Q ) =/= crashed , amqqueue :get_leader (Q ) =:= node ()].
1328+ amqqueue :get_state (Q ) =/= crashed , amqqueue :get_leader_node (Q ) =:= node ()].
13171329
13181330- spec list_local_followers () -> [amqqueue :amqqueue ()].
13191331list_local_followers () ->
13201332 [Q
13211333 || Q <- list (),
13221334 amqqueue :is_quorum (Q ),
1323- amqqueue :get_leader (Q ) =/= node (),
1335+ amqqueue :get_leader_node (Q ) =/= node (),
13241336 lists :member (node (), get_quorum_nodes (Q )),
13251337 rabbit_quorum_queue :is_recoverable (Q )
13261338 ].
13271339
1340+ % % TODO: looks unused
13281341- spec list_local_quorum_queues_with_name_matching (binary ()) -> [amqqueue :amqqueue ()].
13291342list_local_quorum_queues_with_name_matching (Pattern ) ->
13301343 [ Q || Q <- list_by_type (quorum ),
@@ -1909,13 +1922,10 @@ forget_node_for_queue(Q) ->
19091922run_backing_queue (QPid , Mod , Fun ) ->
19101923 gen_server2 :cast (QPid , {run_backing_queue , Mod , Fun }).
19111924
1912- - spec is_replicated (amqqueue :amqqueue ()) -> boolean ().
1925+ - spec is_replicable (amqqueue :amqqueue ()) -> boolean ().
19131926
1914- is_replicated (Q ) when ? amqqueue_is_classic (Q ) ->
1915- false ;
1916- is_replicated (_Q ) ->
1917- % % streams and quorum queues are all replicated
1918- true .
1927+ is_replicable (Q ) ->
1928+ rabbit_queue_type :is_replicable (Q ).
19191929
19201930is_exclusive (Q ) when ? amqqueue_exclusive_owner_is (Q , none ) ->
19211931 false ;
@@ -1985,7 +1995,7 @@ filter_transient_queues_to_delete(Node) ->
19851995 amqqueue :qnode (Q ) == Node andalso
19861996 not rabbit_process :is_process_alive (amqqueue :get_pid (Q ))
19871997 andalso (not amqqueue :is_classic (Q ) orelse not amqqueue :is_durable (Q ))
1988- andalso (not is_replicated (Q )
1998+ andalso (not is_replicable (Q )
19891999 orelse is_dead_exclusive (Q ))
19902000 andalso amqqueue :get_type (Q ) =/= rabbit_mqtt_qos0_queue
19912001 end .
0 commit comments