Skip to content
Browse files

Add functions for clearing bucket properties.

  • Loading branch information...
1 parent 0d7463d commit a8db9948086a4a998e9a754727004e62a37f93ee @jerith committed
Showing with 49 additions and 1 deletion.
  1. +29 −0 src/riak_core_bucket.erl
  2. +20 −1 src/riak_core_ring.erl
View
29 src/riak_core_bucket.erl
@@ -27,6 +27,7 @@
-export([append_bucket_defaults/1,
set_bucket/2,
+ clear_bucket/1,
get_bucket/1,
get_bucket/2,
get_buckets/1,
@@ -84,6 +85,17 @@ merge_props(Overriding, Other) ->
lists:ukeymerge(1, lists:ukeysort(1, Overriding),
lists:ukeysort(1, Other)).
+
+%% @spec clear_bucket(riak_object:bucket()) -> ok
+%% @doc Clear all properties in Bucket, resetting to defaults.
+clear_bucket(Name) ->
+ F = fun(Ring, _Args) ->
+ {new_ring, riak_core_ring:clear_meta({bucket,Name}, Ring)}
+ end,
+ {ok, _NewRing} = riak_core_ring_manager:ring_trans(F, undefined),
+ ok.
+
+
%% @spec get_bucket(riak_object:bucket()) ->
%% {ok, BucketProps :: riak_core_bucketprops()}
%% @doc Return the complete current list of properties for Bucket.
@@ -157,4 +169,21 @@ simple_set_test() ->
riak_core_ring_manager:stop(),
?assertEqual(value, proplists:get_value(key, Bucket)).
+simple_clear_test() ->
+ application:load(riak_core),
+ %% appending an empty list of defaults makes up for the fact that
+ %% riak_core_app:start/2 is not called during eunit runs
+ %% (that's where the usual defaults are set at startup),
+ %% while also not adding any trash that might affect other tests
+ append_bucket_defaults([]),
+ riak_core_ring_events:start_link(),
+ riak_core_ring_manager:start_link(test),
+ ok = set_bucket(a_bucket,[{key,value}]),
+ BucketSet = get_bucket(a_bucket),
+ ok = clear_bucket(a_bucket),
+ BucketClear = get_bucket(a_bucket),
+ riak_core_ring_manager:stop(),
+ ?assertEqual(value, proplists:get_value(key, BucketSet)),
+ ?assertEqual(undefined, proplists:get_value(key, BucketClear)).
+
-endif.
View
21 src/riak_core_ring.erl
@@ -51,7 +51,8 @@
rename_node/3,
responsible_index/2,
transfer_node/3,
- update_meta/3]).
+ update_meta/3,
+ clear_meta/2]).
-export([cluster_name/1,
legacy_ring/1,
@@ -500,6 +501,24 @@ update_meta(Key, Val, State) ->
State
end.
+% @doc Clear a key in the cluster metadata dict
+-spec clear_meta(Key :: term(), State :: chstate()) -> chstate().
+clear_meta(Key, State) ->
+ Change = case dict:find(Key, State?CHSTATE.meta) of
+ {ok, _} ->
+ true;
+ error ->
+ false
+ end,
+ if Change ->
+ VClock = vclock:increment(State?CHSTATE.nodename,
+ State?CHSTATE.vclock),
+ State?CHSTATE{vclock=VClock,
+ meta=dict:erase(Key, State?CHSTATE.meta)};
+ true ->
+ State
+ end.
+
%% @doc Return the current claimant.
-spec claimant(State :: chstate()) -> node().
claimant(?CHSTATE{claimant=Claimant}) ->

0 comments on commit a8db994

Please sign in to comment.
Something went wrong with that request. Please try again.