Skip to content

Commit ee99ba9

Browse files
committed
MB-46881: Enforce ns_server scope limits
Change-Id: Iaad2bd0accdadc633284bed468f6c0a3d8f1decc Reviewed-on: http://review.couchbase.org/c/ns_server/+/159834 Tested-by: Abhijeeth Nuthan <[email protected]> Well-Formed: Build Bot <[email protected]> Reviewed-by: Artem Stemkovski <[email protected]>
1 parent a6fa7c1 commit ee99ba9

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/collections.erl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,9 +577,17 @@ verify_oper({create_collection, ScopeName, Name, _}, Manifest) ->
577577
with_scope(
578578
fun (Scope) ->
579579
Collections = get_collections(Scope),
580+
Limit = get_limit(clusterManager, num_collections, Scope),
580581
case find_collection(Name, Collections) of
581582
undefined ->
582-
ok;
583+
case cluster_compat_mode:should_enforce_limits() andalso
584+
Limit =/= infinity andalso
585+
length(Collections) > Limit of
586+
false ->
587+
ok;
588+
true ->
589+
{max_number_exceeded, num_collections}
590+
end;
583591
_ ->
584592
{collection_already_exists, ScopeName, Name}
585593
end
@@ -714,6 +722,13 @@ on_scopes(Fun, Manifest) ->
714722
get_limits(Scope) ->
715723
proplists:get_value(limits, Scope, []).
716724

725+
get_limit(Service, Limit, Scope) ->
726+
functools:chain(
727+
Scope,
728+
[proplists:get_value(limits, _, []),
729+
proplists:get_value(Service, _, []),
730+
proplists:get_value(Limit, _, infinity)]).
731+
717732
get_collections(Scope) ->
718733
proplists:get_value(collections, Scope, []).
719734

0 commit comments

Comments
 (0)