Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Validate that n_val is sane when set on a bucket

Sane means an integer less than ring_size
  • Loading branch information...
commit 8a42f26866bed304aae5d50d3a1df9a1b9ec6b7f 1 parent dcf8e52
@russelldb russelldb authored
Showing with 32 additions and 2 deletions.
  1. +2 −1  src/riak_core_app.erl
  2. +30 −1 src/riak_core_bucket.erl
View
3  src/riak_core_app.erl
@@ -75,7 +75,8 @@ start(_StartType, _StartArgs) ->
%% Spin up the supervisor; prune ring files as necessary
case riak_core_sup:start_link() of
{ok, Pid} ->
- riak_core:register(riak_core, [{stat_mod, riak_core_stat}]),
+ riak_core:register(riak_core, [{stat_mod, riak_core_stat},
+ {bucket_validator, riak_core_bucket}]),
ok = riak_core_ring_events:add_guarded_handler(riak_core_ring_handler, []),
%% Register capabilities
View
31 src/riak_core_bucket.erl
@@ -33,7 +33,8 @@
get_buckets/1,
merge_props/2,
name/1,
- n_val/1]).
+ n_val/1,
+ validate/1]).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
@@ -148,6 +149,34 @@ name(BProps) ->
n_val(BProps) ->
proplists:get_value(n_val, BProps).
+%% Bucket validators API
+validate(BucketProps) when is_list(BucketProps) ->
+ case proplists:is_defined(n_val, BucketProps) of
+ true ->
+ validate_nval(BucketProps);
+ false -> {BucketProps, []}
+ end.
+
+validate_nval(BucketProps) ->
+ %% n_val must be an integer smaller than ring size
+ case proplists:get_value(n_val, BucketProps) of
+ N when is_integer(N) ->
+ %%validate
+ RingSize = get_ring_size(),
+ case N =< RingSize of
+ true ->
+ {BucketProps, []};
+ false ->
+ {lists:keydelete(n_val, 1, BucketProps), [{n_val, greater_than_ringsize}]}
+ end;
+ _Other ->
+ {lists:keydelete(n_val, 1, BucketProps), [{n_val, not_an_integer}]}
+ end.
+
+get_ring_size() ->
+ {ok, MyRing} = riak_core_ring_manager:get_raw_ring(),
+ riak_core_ring:num_partitions(MyRing).
+
%% ===================================================================
%% EUnit tests
%% ===================================================================
Please sign in to comment.
Something went wrong with that request. Please try again.