Skip to content

Commit

Permalink
MB-48767 Keep autocompaction settings when not specified
Browse files Browse the repository at this point in the history
Prior to this change if the databaseFragmentationThreshold
percentage/size or viewFragmentationThreshold percentage/size were not
specified in the /controller/setAutoCompaction arguments the existing
values were over-written with undefined. With this change the existing
values will be maintained.

Change-Id: I54e54ce468bab62d52d3e70bd8ff809ad46cc9b4
Reviewed-on: https://review.couchbase.org/c/ns_server/+/166257
Well-Formed: Build Bot <build@couchbase.com>
Tested-by: Steve Watanabe <steve.watanabe@couchbase.com>
Reviewed-by: Abhijeeth Nuthan <abhijeeth.nuthan@couchbase.com>
  • Loading branch information
stevewatanabe committed Nov 30, 2021
1 parent e346f89 commit 9f21c6a
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 21 deletions.
89 changes: 68 additions & 21 deletions src/menelaus_web_autocompaction.erl
Expand Up @@ -343,25 +343,49 @@ do_parse_validate_settings(Params, _ExpectIndex, magma) ->
end;
%% Non-magma bucket or global settings
do_parse_validate_settings(Params, ExpectIndex, not_magma) ->
PercResults = lists:flatmap(mk_number_field_validator(2, 100, Params),
[{"databaseFragmentationThreshold[percentage]",
db_fragmentation_percentage,
"database fragmentation"},
{"viewFragmentationThreshold[percentage]",
view_fragmentation_percentage,
"view fragmentation"}]),
SizeResults = lists:flatmap(mk_number_field_validator(1, infinity, Params),
[{"databaseFragmentationThreshold[size]",
db_fragmentation_size,
"database fragmentation size"},
{"viewFragmentationThreshold[size]",
view_fragmentation_size,
"view fragmentation size"}]),
GlobalSettings =
compaction_daemon:get_autocompaction_settings(ns_config:latest()),
{GDBFragPct, GDBFragSz} =
proplists:get_value(database_fragmentation_threshold, GlobalSettings),
{GViewFragPct, GViewFragSz} =
proplists:get_value(view_fragmentation_threshold, GlobalSettings),

PercValidator = mk_number_field_validator(2, 100, Params),
SizeValidator = mk_number_field_validator(1, infinity, Params),

ValidatorFun =
fun (Validator, {_, Key, _} = ValidatorParams, Default) ->
case Validator(ValidatorParams) of
[] ->
[{ok, Key, Default}];
ValueOrError ->
ValueOrError
end
end,

DBFragPct = ValidatorFun(PercValidator,
{"databaseFragmentationThreshold[percentage]",
db_fragmentation_percentage,
"database fragmentation"}, GDBFragPct),
ViewFragPct = ValidatorFun(PercValidator,
{"viewFragmentationThreshold[percentage]",
view_fragmentation_percentage,
"view fragmentation"}, GViewFragPct),
PercResults = DBFragPct ++ ViewFragPct,

DbFragSz = ValidatorFun(SizeValidator,
{"databaseFragmentationThreshold[size]",
db_fragmentation_size,
"database fragmentation size"}, GDBFragSz),
ViewFragSz = ValidatorFun(SizeValidator,
{"viewFragmentationThreshold[size]",
view_fragmentation_size,
"view fragmentation size"}, GViewFragSz),
SizeResults = DbFragSz ++ ViewFragSz,

IndexResults =
case ExpectIndex of
true ->
PercValidator = mk_number_field_validator(2, 100, Params),
RV0 = PercValidator({"indexFragmentationThreshold[percentage]",
index_fragmentation_percentage,
"index fragmentation"}),
Expand Down Expand Up @@ -431,10 +455,35 @@ do_parse_validate_settings(Params, ExpectIndex, not_magma) ->


-ifdef(TEST).
basic_parse_validate_settings_test() ->
setup_meck() ->
meck:new(cluster_compat_mode, [passthrough]),
meck:expect(cluster_compat_mode, is_cluster_NEO,
fun () -> true end),
meck:new(ns_config, [passthrough]),
meck:expect(ns_config, search,
fun (_, _) -> {value,
[{database_fragmentation_threshold,
{30, undefined}},
{view_fragmentation_threshold,
{30, undefined}}]}
end),
meck:new(chronicle_kv, [passthrough]),
meck:expect(chronicle_kv, get,
fun (_, _) ->
{ok,
{[{database_fragmentation_threshold, {30, undefined}},
{view_fragmentation_threshold, {30, undefined}},
{magma_fragmentation_percentage, 50}],
{<<"f663189bff34bd2523ee5ff25480d845">>, 4}}}
end).

teardown_meck() ->
meck:unload(cluster_compat_mode),
meck:unload(ns_config),
meck:unload(chronicle_kv).

basic_parse_validate_settings_test() ->
setup_meck(),
Settings = [{"databaseFragmentationThreshold[percentage]", "10"},
{"viewFragmentationThreshold[percentage]", "20"},
{"indexFragmentationThreshold[size]", "42"},
Expand Down Expand Up @@ -476,13 +525,11 @@ basic_parse_validate_settings_test() ->
{ok, Stuff3, []} = parse_validate_settings(Settings3, false),
?assertEqual(lists:sort(Expected3), lists:sort(Stuff3)),

meck:unload(cluster_compat_mode),
teardown_meck(),
ok.

extra_field_parse_validate_settings_test() ->
meck:new(cluster_compat_mode, [passthrough]),
meck:expect(cluster_compat_mode, is_cluster_NEO,
fun () -> true end),
setup_meck(),
{errors, Stuff0} =
parse_validate_settings([{"databaseFragmentationThreshold", "10"},
{"viewFragmentationThreshold", "20"},
Expand Down Expand Up @@ -510,6 +557,6 @@ extra_field_parse_validate_settings_test() ->
false),
?assertEqual([{<<"_">>, <<"Got unsupported fields: databaseFragmentationThreshold">>}],
Stuff1),
meck:unload(cluster_compat_mode),
teardown_meck(),
ok.
-endif.
14 changes: 14 additions & 0 deletions src/menelaus_web_buckets.erl
Expand Up @@ -2267,6 +2267,18 @@ basic_parse_validate_bucket_auto_compaction_settings_test() ->
meck:new(cluster_compat_mode, [passthrough]),
meck:expect(cluster_compat_mode, is_cluster_NEO,
fun () -> true end),
meck:new(ns_config, [passthrough]),
meck:expect(ns_config, get,
fun () -> [] end),
meck:new(chronicle_kv, [passthrough]),
meck:expect(chronicle_kv, get,
fun (_, _) ->
{ok,
{[{database_fragmentation_threshold, {30, undefined}},
{view_fragmentation_threshold, {30, undefined}},
{magma_fragmentation_percentage, 50}],
{<<"f663189bff34bd2523ee5ff25480d845">>, 4}}}
end),
Value0 = parse_validate_bucket_auto_compaction_settings([{"not_autoCompactionDefined", "false"},
{"databaseFragmentationThreshold[percentage]", "10"},
{"viewFragmentationThreshold[percentage]", "20"},
Expand Down Expand Up @@ -2307,6 +2319,8 @@ basic_parse_validate_bucket_auto_compaction_settings_test() ->
{view_fragmentation_threshold, {20, undefined}}],
Stuff1),
meck:unload(cluster_compat_mode),
meck:unload(ns_config),
meck:unload(chronicle_kv),
ok.

parse_validate_pitr_max_history_age_test() ->
Expand Down

0 comments on commit 9f21c6a

Please sign in to comment.