Skip to content

Commit 843cf73

Browse files
committed
MB-52258: refactor some config_profile calls
Makes the call to cluster_compat_mode internally inside the config_profile.erl module instead of at all call sites where it was previously used. Also made sure to route calls to search/2 through the get/0 function so that it also checks cluster_compat_mode. Added a warning comment to the 'is_serverless' call s/t people don't use it unless it makes sense to do it. Change-Id: I2ce9a543c6548090b7b0af8eb16c061a283c69ff Reviewed-on: https://review.couchbase.org/c/ns_server/+/175773 Tested-by: Bryan McCoid <[email protected]> Reviewed-by: Steve Watanabe <[email protected]>
1 parent 717003b commit 843cf73

File tree

3 files changed

+17
-31
lines changed

3 files changed

+17
-31
lines changed

src/collections.erl

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -149,30 +149,15 @@ manifest_with_system_scope() ->
149149
{collections, Collections}]}]}].
150150

151151
is_system_scope_enabled() ->
152-
case cluster_compat_mode:is_cluster_elixir() of
153-
false ->
154-
false;
155-
true ->
156-
config_profile:get_bool(enable_system_scope)
157-
end.
152+
config_profile:get_bool(enable_system_scope).
158153

159154
max_collections_per_bucket() ->
160-
Default = get_max_supported(num_collections),
161-
case cluster_compat_mode:is_cluster_elixir() of
162-
false ->
163-
Default;
164-
true ->
165-
config_profile:get_value(max_collection_per_bucket, Default)
166-
end.
155+
config_profile:get_value(max_collection_per_bucket,
156+
get_max_supported(num_collections)).
167157

168158
max_scopes_per_bucket() ->
169-
Default = get_max_supported(num_scopes),
170-
case cluster_compat_mode:is_cluster_elixir() of
171-
false ->
172-
Default;
173-
true ->
174-
config_profile:get_value(max_scopes_per_bucket, Default)
175-
end.
159+
config_profile:get_value(max_scopes_per_bucket,
160+
get_max_supported(num_scopes)).
176161

177162
default_kvs(Buckets, Nodes) ->
178163
lists:flatmap(

src/config_profile.erl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ get() ->
5151

5252
-spec(get(list()) -> list()).
5353
get(Default) ->
54-
ns_config:search_node_with_default(?CONFIG_PROFILE, Default).
54+
case cluster_compat_mode:is_cluster_elixir() of
55+
false ->
56+
Default;
57+
true ->
58+
ns_config:search_node_with_default(?CONFIG_PROFILE, Default)
59+
end.
5560

5661
-spec(get_value(term(), term()) -> term()).
5762
get_value(Key, Default) ->
@@ -69,6 +74,9 @@ search(Key) ->
6974
search(Key, Default) ->
7075
search_profile_key(Key, Default).
7176

77+
%% @doc WARNING: Please only use this in certain situations. Instead you should
78+
%% be enabling features by individual flags inside the profile and not a blanket
79+
%% check for if we are using the "serverless" profile. You have been warned.
7280
-spec(is_serverless() -> boolean()).
7381
is_serverless() ->
7482
case name() of
@@ -84,7 +92,7 @@ search_profile_key(Key) ->
8492

8593
-spec(search_profile_key(term(), term()) -> term()).
8694
search_profile_key(Key, Default) ->
87-
ProfileData = ns_config:search_node_with_default(?CONFIG_PROFILE, []),
95+
ProfileData = config_profile:get(),
8896
case lookup_profile_key(ProfileData, Key) of
8997
{value, Value} ->
9098
Value;
@@ -99,6 +107,4 @@ lookup_profile_key(ProfileData, Key) when is_list(ProfileData) ->
99107
{value, Value};
100108
_ ->
101109
false
102-
end;
103-
lookup_profile_key(_, _) ->
104-
false.
110+
end.

src/ns_bucket.erl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,7 @@ get_default_num_vbuckets() ->
816816
end.
817817

818818
allow_variable_num_vbuckets() ->
819-
case cluster_compat_mode:is_cluster_elixir() of
820-
false ->
821-
false;
822-
true ->
823-
config_profile:get_bool(allow_variable_num_vbuckets)
824-
end.
819+
config_profile:get_bool(allow_variable_num_vbuckets).
825820

826821
get_num_vbuckets(BucketConfig) ->
827822
proplists:get_value(num_vbuckets, BucketConfig).

0 commit comments

Comments
 (0)