Skip to content

Commit 9cae5a4

Browse files
committed
MB-68072: Allow presetting new bucket settings
There are customers who use diag/eval or extra_config_string or cbebctl to specify buckets setting because there is no REST support. In the morpheus release some of these settings are now supported via the standard API (/pools/default/buckets). This change allows the user, while running pre-morpheus, to specify bucket setting values which normally get set on upgrade. The specified value will be used after upgrade rather than the default value. For example: access_scanner_enabled is added to the bucket config on upgrade and has the default value of true. But a user running pre-morpheus can specify access_scanner_enabled to be false using NON-ns_server methods (/diag/eval, etc.) On the upgrade, the user wants to preserve access_scanner_enabled being set to false (even though the upgrade defaults it to true). With this change we'll keep the preset value. Change-Id: I4074ea7a7b26f3af254179667fd2561a62701314 Reviewed-on: https://review.couchbase.org/c/ns_server/+/232236 Tested-by: Steve Watanabe <[email protected]> Well-Formed: Build Bot <[email protected]> Reviewed-by: Ben Huddleston <[email protected]>
1 parent 00b5151 commit 9cae5a4

File tree

1 file changed

+118
-50
lines changed

1 file changed

+118
-50
lines changed

apps/ns_server/src/ns_bucket.erl

Lines changed: 118 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2879,6 +2879,54 @@ chronicle_add_uuid2bucket_mapping_upgrade_to_79(BucketName, Txn) ->
28792879
NewKey = uuid2bucket_key(UUID),
28802880
chronicle_upgrade:set_key(NewKey, BucketName, Txn).
28812881

2882+
%% Return a list of properties to add to the specified bucket config.
2883+
props_to_add_for_79(BucketConfig) ->
2884+
case bucket_type(BucketConfig) of
2885+
memcached ->
2886+
[];
2887+
membase ->
2888+
[{expiry_pager_sleep_time,
2889+
attribute_default(expiry_pager_sleep_time)},
2890+
{memory_low_watermark,
2891+
attribute_default(memory_low_watermark)},
2892+
{memory_high_watermark,
2893+
attribute_default(memory_high_watermark)},
2894+
{warmup_behavior,
2895+
attribute_default(warmup_behavior)},
2896+
{durability_impossible_fallback,
2897+
attribute_default(durability_impossible_fallback)},
2898+
%% The default value isn't used for existing buckets as it
2899+
%% may lead to XDCR setups stopping.
2900+
{invalid_hlc_strategy, ignore},
2901+
{hlc_max_future_threshold,
2902+
attribute_default(hlc_max_future_threshold)},
2903+
{dcp_connections_between_nodes,
2904+
attribute_default(dcp_connections_between_nodes)},
2905+
{dcp_backfill_idle_protection_enabled,
2906+
get_dcp_backfill_idle_protection_default(BucketConfig)},
2907+
{dcp_backfill_idle_limit_seconds,
2908+
get_dcp_backfill_idle_limit_seconds(BucketConfig)},
2909+
{dcp_backfill_idle_disk_threshold,
2910+
get_dcp_backfill_idle_disk_threshold(BucketConfig)}] ++
2911+
case is_persistent(BucketConfig) of
2912+
true ->
2913+
[{access_scanner_enabled, true}];
2914+
false ->
2915+
[]
2916+
end ++
2917+
case ns_bucket:is_magma(BucketConfig) of
2918+
true ->
2919+
[{continuous_backup_enabled,
2920+
attribute_default(continuous_backup_enabled)},
2921+
{continuous_backup_interval,
2922+
attribute_default(continuous_backup_interval)},
2923+
{continuous_backup_location,
2924+
attribute_default(continuous_backup_location)}];
2925+
false ->
2926+
[]
2927+
end
2928+
end.
2929+
28822930
chronicle_upgrade_bucket_props_to_79(BucketName, ChronicleTxn) ->
28832931
PropsKey = sub_key(BucketName, props),
28842932
{ok, BucketConfig0} = chronicle_upgrade:get_key(PropsKey, ChronicleTxn),
@@ -2887,62 +2935,36 @@ chronicle_upgrade_bucket_props_to_79(BucketName, ChronicleTxn) ->
28872935
fun ({Key, _Value}) ->
28882936
not lists:member(Key, removed_bucket_settings())
28892937
end, BucketConfig0),
2890-
AddProps =
2891-
case bucket_type(BucketConfig) of
2892-
memcached ->
2893-
[];
2894-
membase ->
2895-
[{expiry_pager_sleep_time,
2896-
attribute_default(expiry_pager_sleep_time)},
2897-
{memory_low_watermark,
2898-
attribute_default(memory_low_watermark)},
2899-
{memory_high_watermark,
2900-
attribute_default(memory_high_watermark)},
2901-
{warmup_behavior,
2902-
attribute_default(warmup_behavior)},
2903-
{durability_impossible_fallback,
2904-
attribute_default(durability_impossible_fallback)},
2905-
%% The default value isn't used for existing buckets as it
2906-
%% may lead to XDCR setups stopping.
2907-
{invalid_hlc_strategy, ignore},
2908-
{hlc_max_future_threshold,
2909-
attribute_default(hlc_max_future_threshold)},
2910-
{dcp_connections_between_nodes,
2911-
attribute_default(dcp_connections_between_nodes)},
2912-
{dcp_backfill_idle_protection_enabled,
2913-
get_dcp_backfill_idle_protection_default(BucketConfig)},
2914-
{dcp_backfill_idle_limit_seconds,
2915-
get_dcp_backfill_idle_limit_seconds(BucketConfig)},
2916-
{dcp_backfill_idle_disk_threshold,
2917-
get_dcp_backfill_idle_disk_threshold(BucketConfig)}] ++
2918-
case is_persistent(BucketConfig) of
2919-
true ->
2920-
[{access_scanner_enabled, true}];
2921-
false ->
2922-
[]
2923-
end ++
2924-
case ns_bucket:is_magma(BucketConfig) of
2925-
true ->
2926-
[{continuous_backup_enabled,
2927-
attribute_default(continuous_backup_enabled)},
2928-
{continuous_backup_interval,
2929-
attribute_default(continuous_backup_interval)},
2930-
{continuous_backup_location,
2931-
attribute_default(continuous_backup_location)}];
2932-
false ->
2933-
[]
2934-
end
2935-
end,
2936-
case AddProps of
2938+
case props_to_add_for_79(BucketConfig) of
29372939
[] ->
29382940
ChronicleTxn;
2939-
_ ->
2940-
NewBucketConfig = misc:merge_proplists(fun(_, L, _) -> L end,
2941-
AddProps, BucketConfig),
2941+
AddProps ->
2942+
NewBucketConfig = check_for_preset_bucket_settings(AddProps,
2943+
BucketConfig),
29422944
chronicle_upgrade:set_key(PropsKey, NewBucketConfig,
29432945
ChronicleTxn)
29442946
end.
29452947

2948+
%% To enable the case where the user, under the guidance from Couchbase
2949+
%% support, has preset "new" settings in the bucket config with values
2950+
%% that normally would be added on upgrade. We want to keep the preset
2951+
%% values rather than default values for the new settings.
2952+
check_for_preset_bucket_settings(AddProps, BucketConfig) ->
2953+
NewKeys = proplists:get_keys(AddProps),
2954+
ExistingKeys = proplists:get_keys(BucketConfig),
2955+
IntersectingKeys = [Key || Key <- NewKeys, lists:member(Key, ExistingKeys)],
2956+
case IntersectingKeys of
2957+
[] ->
2958+
ok;
2959+
_ ->
2960+
?log_debug("Using preset bucket keys: ~p", [IntersectingKeys])
2961+
end,
2962+
2963+
%% Any key already in the bucket config take precedence over newly
2964+
%% added keys. This preserves the preset settings.
2965+
misc:merge_proplists(fun(_, _, R) -> R end,
2966+
AddProps, BucketConfig).
2967+
29462968
chronicle_upgrade_to_79(ChronicleTxn) ->
29472969
{ok, BucketNames} = chronicle_upgrade:get_key(root(), ChronicleTxn),
29482970
chronicle_upgrade_bucket(
@@ -3813,4 +3835,50 @@ uuid2bucket_key_test() ->
38133835
fake_chronicle_kv:teardown()
38143836
end.
38153837

3838+
upgrade_to_79_test() ->
3839+
meck:new(cluster_compat_mode, [passthrough]),
3840+
meck:expect(cluster_compat_mode, is_cluster_79, fun () -> true end),
3841+
meck:expect(cluster_compat_mode, is_enterprise, fun () -> true end),
3842+
3843+
%% Normal upgrade
3844+
BC1 = [{type, membase},
3845+
{num_vbuckets, 16},
3846+
{servers, [node1, node2]},
3847+
{ram_quota, 100 * ?MIB},
3848+
{storage_mode, magma}],
3849+
AddProps1 = props_to_add_for_79(BC1),
3850+
NewBC1 = check_for_preset_bucket_settings(AddProps1, BC1),
3851+
?assertEqual(attribute_default(expiry_pager_sleep_time),
3852+
proplists:get_value(expiry_pager_sleep_time, NewBC1)),
3853+
?assertEqual(attribute_default(memory_low_watermark),
3854+
proplists:get_value(memory_low_watermark, NewBC1)),
3855+
?assertEqual(attribute_default(memory_high_watermark),
3856+
proplists:get_value(memory_high_watermark, NewBC1)),
3857+
?assertEqual(attribute_default(access_scanner_enabled),
3858+
proplists:get_value(access_scanner_enabled, NewBC1)),
3859+
?assertEqual(attribute_default(warmup_behavior),
3860+
proplists:get_value(warmup_behavior, NewBC1)),
3861+
3862+
%% Bucket with preset values.
3863+
BC2 = [{type, membase},
3864+
{num_vbuckets, 16},
3865+
{servers, [node1, node2]},
3866+
{ram_quota, 100 * ?MIB},
3867+
{storage_mode, magma},
3868+
%% Preset values
3869+
{access_scanner_enabled, false},
3870+
{expiry_pager_sleep_time, 300},
3871+
{memory_high_watermark, 90},
3872+
{memory_low_watermark, 89},
3873+
{warmup_behavior, blocking}],
3874+
AddProps2 = props_to_add_for_79(BC2),
3875+
NewBC2 = check_for_preset_bucket_settings(AddProps2, BC2),
3876+
?assertEqual(300, proplists:get_value(expiry_pager_sleep_time, NewBC2)),
3877+
?assertEqual(89, proplists:get_value(memory_low_watermark, NewBC2)),
3878+
?assertEqual(90, proplists:get_value(memory_high_watermark, NewBC2)),
3879+
?assertEqual(false, proplists:get_value(access_scanner_enabled, NewBC2)),
3880+
?assertEqual(blocking, proplists:get_value(warmup_behavior, NewBC2)),
3881+
3882+
meck:unload().
3883+
38163884
-endif.

0 commit comments

Comments
 (0)