Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rabbit_feature_flags: Lock registry once and enable many feature flags #12441

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_depr_ff_extra.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2023 Broadcom. All Rights Reserved. The term “Broadcom”
%% Copyright (c) 2023-2024 Broadcom. All Rights Reserved. The term “Broadcom”
%% refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%
%% @doc
Expand Down
6 changes: 4 additions & 2 deletions deps/rabbit/src/rabbit_deprecated_features.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% Copyright (c) 2023-2024 Broadcom. All Rights Reserved. The term “Broadcom”
%% refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%

%% @author The RabbitMQ team
%% @copyright 2007-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% @copyright 2023-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc.
%% and/or its subsidiaries. All rights reserved.
%%
%% @doc
%% This module provides an API to manage deprecated features in RabbitMQ. It
Expand Down
6 changes: 4 additions & 2 deletions deps/rabbit/src/rabbit_feature_flags.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% Copyright (c) 2019-2024 Broadcom. All Rights Reserved. The term “Broadcom”
%% refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%

%% @author The RabbitMQ team
%% @copyright 2007-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% @copyright 2019-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc.
%% and/or its subsidiaries. All rights reserved.
%%
%% @doc
%% This module offers a framework to declare capabilities a RabbitMQ node
Expand Down
48 changes: 25 additions & 23 deletions deps/rabbit/src/rabbit_ff_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% Copyright (c) 2019-2024 Broadcom. All Rights Reserved. The term “Broadcom”
%% refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%

%% @author The RabbitMQ team
%% @copyright 2007-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% @copyright 2019-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc.
%% and/or its subsidiaries. All rights reserved.
%%
%% @doc
%% The feature flag controller is responsible for synchronization and managing
Expand Down Expand Up @@ -823,12 +825,29 @@ refresh_after_app_load_task() ->
Ret :: ok | {error, Reason},
Reason :: term().

enable_many(#{states_per_node := _} = Inventory, [FeatureName | Rest]) ->
enable_many(#{states_per_node := _} = Inventory, FeatureNames) ->
%% We acquire a lock before making any change to the registry. This is not
%% used by the controller (because it is already using a globally
%% registered name to prevent concurrent runs). But this is used in
%% `rabbit_feature_flags:is_enabled()' to block while the state is
%% `state_changing'.
rabbit_ff_registry_factory:acquire_state_change_lock(),
Ret = enable_many_locked(Inventory, FeatureNames),
rabbit_ff_registry_factory:release_state_change_lock(),
Ret.

-spec enable_many_locked(Inventory, FeatureNames) -> Ret when
Inventory :: rabbit_feature_flags:cluster_inventory(),
FeatureNames :: [rabbit_feature_flags:feature_name()],
Ret :: ok | {error, Reason},
Reason :: term().

enable_many_locked(#{states_per_node := _} = Inventory, [FeatureName | Rest]) ->
case enable_if_supported(Inventory, FeatureName) of
{ok, Inventory1} -> enable_many(Inventory1, Rest);
{ok, Inventory1} -> enable_many_locked(Inventory1, Rest);
Error -> Error
end;
enable_many(_Inventory, []) ->
enable_many_locked(_Inventory, []) ->
ok.

-spec enable_if_supported(Inventory, FeatureName) -> Ret when
Expand All @@ -845,7 +864,7 @@ enable_if_supported(#{states_per_node := _} = Inventory, FeatureName) ->
"Feature flags: `~ts`: supported; continuing",
[FeatureName],
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
lock_registry_and_enable(Inventory, FeatureName);
enable_with_registry_locked(Inventory, FeatureName);
false ->
?LOG_DEBUG(
"Feature flags: `~ts`: unsupported; aborting",
Expand All @@ -854,23 +873,6 @@ enable_if_supported(#{states_per_node := _} = Inventory, FeatureName) ->
{error, unsupported}
end.

-spec lock_registry_and_enable(Inventory, FeatureName) -> Ret when
Inventory :: rabbit_feature_flags:cluster_inventory(),
FeatureName :: rabbit_feature_flags:feature_name(),
Ret :: {ok, Inventory} | {error, Reason},
Reason :: term().

lock_registry_and_enable(#{states_per_node := _} = Inventory, FeatureName) ->
%% We acquire a lock before making any change to the registry. This is not
%% used by the controller (because it is already using a globally
%% registered name to prevent concurrent runs). But this is used in
%% `rabbit_feature_flags:is_enabled()' to block while the state is
%% `state_changing'.
rabbit_ff_registry_factory:acquire_state_change_lock(),
Ret = enable_with_registry_locked(Inventory, FeatureName),
rabbit_ff_registry_factory:release_state_change_lock(),
Ret.

-spec enable_with_registry_locked(Inventory, FeatureName) -> Ret when
Inventory :: rabbit_feature_flags:cluster_inventory(),
FeatureName :: rabbit_feature_flags:feature_name(),
Expand Down
3 changes: 2 additions & 1 deletion deps/rabbit/src/rabbit_ff_extra.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% @copyright 2007-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% @copyright 2019-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc.
%% and/or its subsidiaries. All rights reserved.
%%
%% @doc
%% This module provides extra functions unused by the feature flags
Expand Down
6 changes: 4 additions & 2 deletions deps/rabbit/src/rabbit_ff_registry.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% Copyright (c) 2019-2024 Broadcom. All Rights Reserved. The term “Broadcom”
%% refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%

%% @author The RabbitMQ team
%% @copyright 2007-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% @copyright 2019-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc.
%% and/or its subsidiaries. All rights reserved.
%%
%% @doc
%% This module exposes the API of the {@link rabbit_feature_flags}
Expand Down
3 changes: 2 additions & 1 deletion deps/rabbit/src/rabbit_ff_registry_factory.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% Copyright (c) 2019-2024 Broadcom. All Rights Reserved. The term “Broadcom”
%% refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%

-module(rabbit_ff_registry_factory).
Expand Down
6 changes: 4 additions & 2 deletions deps/rabbit/src/rabbit_ff_registry_wrapper.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% Copyright (c) 2019-2024 Broadcom. All Rights Reserved. The term “Broadcom”
%% refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%%

%% @author The RabbitMQ team
%% @copyright 2007-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
%% @copyright 2019-2024 Broadcom. The term “Broadcom” refers to Broadcom Inc.
%% and/or its subsidiaries. All rights reserved.
%%
%% @doc
%% This module sits in front of {@link rabbit_ff_registry}.
Expand Down
Loading