22% % License, v. 2.0. If a copy of the MPL was not distributed with this
33% % file, You can obtain one at https://mozilla.org/MPL/2.0/.
44% %
5- % % Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
5+ % % Copyright (c) 2019-2024 Broadcom. All Rights Reserved. The term “Broadcom”
6+ % % refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
67% %
78
89% % @author The RabbitMQ team
9- % % @copyright 2007-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
10+ % % @copyright 2019-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc.
11+ % % and/or its subsidiaries. All rights reserved.
1012% %
1113% % @doc
1214% % The feature flag controller is responsible for synchronization and managing
@@ -823,12 +825,29 @@ refresh_after_app_load_task() ->
823825 Ret :: ok | {error , Reason },
824826 Reason :: term ().
825827
826- enable_many (#{states_per_node := _ } = Inventory , [FeatureName | Rest ]) ->
828+ enable_many (#{states_per_node := _ } = Inventory , FeatureNames ) ->
829+ % % We acquire a lock before making any change to the registry. This is not
830+ % % used by the controller (because it is already using a globally
831+ % % registered name to prevent concurrent runs). But this is used in
832+ % % `rabbit_feature_flags:is_enabled()' to block while the state is
833+ % % `state_changing'.
834+ rabbit_ff_registry_factory :acquire_state_change_lock (),
835+ Ret = enable_many_locked (Inventory , FeatureNames ),
836+ rabbit_ff_registry_factory :release_state_change_lock (),
837+ Ret .
838+
839+ - spec enable_many_locked (Inventory , FeatureNames ) -> Ret when
840+ Inventory :: rabbit_feature_flags :cluster_inventory (),
841+ FeatureNames :: [rabbit_feature_flags :feature_name ()],
842+ Ret :: ok | {error , Reason },
843+ Reason :: term ().
844+
845+ enable_many_locked (#{states_per_node := _ } = Inventory , [FeatureName | Rest ]) ->
827846 case enable_if_supported (Inventory , FeatureName ) of
828- {ok , Inventory1 } -> enable_many (Inventory1 , Rest );
847+ {ok , Inventory1 } -> enable_many_locked (Inventory1 , Rest );
829848 Error -> Error
830849 end ;
831- enable_many (_Inventory , []) ->
850+ enable_many_locked (_Inventory , []) ->
832851 ok .
833852
834853- spec enable_if_supported (Inventory , FeatureName ) -> Ret when
@@ -845,7 +864,7 @@ enable_if_supported(#{states_per_node := _} = Inventory, FeatureName) ->
845864 " Feature flags: `~ts `: supported; continuing" ,
846865 [FeatureName ],
847866 #{domain => ? RMQLOG_DOMAIN_FEAT_FLAGS }),
848- lock_registry_and_enable (Inventory , FeatureName );
867+ enable_with_registry_locked (Inventory , FeatureName );
849868 false ->
850869 ? LOG_DEBUG (
851870 " Feature flags: `~ts `: unsupported; aborting" ,
@@ -854,23 +873,6 @@ enable_if_supported(#{states_per_node := _} = Inventory, FeatureName) ->
854873 {error , unsupported }
855874 end .
856875
857- - spec lock_registry_and_enable (Inventory , FeatureName ) -> Ret when
858- Inventory :: rabbit_feature_flags :cluster_inventory (),
859- FeatureName :: rabbit_feature_flags :feature_name (),
860- Ret :: {ok , Inventory } | {error , Reason },
861- Reason :: term ().
862-
863- lock_registry_and_enable (#{states_per_node := _ } = Inventory , FeatureName ) ->
864- % % We acquire a lock before making any change to the registry. This is not
865- % % used by the controller (because it is already using a globally
866- % % registered name to prevent concurrent runs). But this is used in
867- % % `rabbit_feature_flags:is_enabled()' to block while the state is
868- % % `state_changing'.
869- rabbit_ff_registry_factory :acquire_state_change_lock (),
870- Ret = enable_with_registry_locked (Inventory , FeatureName ),
871- rabbit_ff_registry_factory :release_state_change_lock (),
872- Ret .
873-
874876- spec enable_with_registry_locked (Inventory , FeatureName ) -> Ret when
875877 Inventory :: rabbit_feature_flags :cluster_inventory (),
876878 FeatureName :: rabbit_feature_flags :feature_name (),
0 commit comments