2828
2929-export ([create_index_route_table /0 ]).
3030
31+ % % For testing
32+ -export ([clear /0 ]).
33+
3134% % -------------------------------------------------------------------
3235% % exists().
3336% % -------------------------------------------------------------------
@@ -60,8 +63,7 @@ exists_in_mnesia(Binding) ->
6063 Binding :: rabbit_types :binding (),
6164 Src :: rabbit_types :r ('exchange' ),
6265 Dst :: rabbit_types :r ('exchange' ) | rabbit_types :r ('queue' ),
63- BindingType :: durable | semi_durable | transient ,
64- ChecksFun :: fun ((Src , Dst ) -> {ok , BindingType } | {error , Reason :: any ()}),
66+ ChecksFun :: fun ((Src , Dst ) -> ok | {error , Reason :: any ()}),
6567 Ret :: ok | {error , Reason :: any ()}.
6668% % @doc Writes a binding if it doesn't exist already and passes the validation in
6769% % `ChecksFun` i.e. exclusive access
@@ -83,8 +85,7 @@ create(Binding, ChecksFun) ->
8385 Binding :: rabbit_types :binding (),
8486 Src :: rabbit_types :r ('exchange' ),
8587 Dst :: rabbit_types :r ('exchange' ) | rabbit_types :r ('queue' ),
86- BindingType :: durable | semi_durable | transient ,
87- ChecksFun :: fun ((Src , Dst ) -> {ok , BindingType } | {error , Reason :: any ()}),
88+ ChecksFun :: fun ((Src , Dst ) -> ok | {error , Reason :: any ()}),
8889 Ret :: ok | {error , Reason :: any ()}.
8990% % @doc Deletes a binding record from the database if it passes the validation in
9091% % `ChecksFun`. It also triggers the deletion of auto-delete exchanges if needed.
@@ -557,7 +558,7 @@ recover_semi_durable_route(#route{binding = B} = Route, X) ->
557558serial_in_mnesia (false , _ ) ->
558559 none ;
559560serial_in_mnesia (true , X ) ->
560- rabbit_db_exchange :next_serial_in_mnesia_tx (X ).
561+ rabbit_db_exchange :next_serial_in_mnesia_tx (X # exchange . name ).
561562
562563sync_route (Route , durable , ShouldIndexTable , Fun ) ->
563564 ok = Fun (rabbit_durable_route , Route , write ),
@@ -621,6 +622,25 @@ continue('$end_of_table') -> false;
621622continue ({[_ |_ ], _ }) -> true ;
622623continue ({[], Continuation }) -> continue (mnesia :select (Continuation )).
623624
625+ % % -------------------------------------------------------------------
626+ % % clear().
627+ % % -------------------------------------------------------------------
628+
629+ -spec clear () -> ok .
630+ % % @doc Deletes all bindings.
631+ % %
632+ % % @private
633+
634+ clear () ->
635+ rabbit_db :run (
636+ #{mnesia => fun () -> clear_in_mnesia () end }).
637+
638+ clear_in_mnesia () ->
639+ mnesia :clear_table (rabbit_route ),
640+ mnesia :clear_table (rabbit_durable_route ),
641+ mnesia :clear_table (rabbit_reverse_route ),
642+ mnesia :clear_table (rabbit_index_route ).
643+
624644% % Routing. Hot code path
625645% % -------------------------------------------------------------------------
626646route_in_mnesia_v1 (SrcName , [RoutingKey ]) ->
0 commit comments