Skip to content

Commit

Permalink
Merge pull request basho#498 from basho/bugfix/jrw/btypes-mixed-cluster
Browse files Browse the repository at this point in the history
Fix a Couple Mixed Cluster Issues w/ Bucket Types
  • Loading branch information
jrwest committed Jan 8, 2014
2 parents 1ccc935 + 13b42e5 commit c887065
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/riak_core_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ start(_StartType, _StartArgs) ->
riak_core_capability:register({riak_core, security},
[true, false],
false),
riak_core_capability:register({riak_core, bucket_types},
[true, false],
false),

{ok, Pid};
{error, Reason} ->
{error, Reason}
Expand Down
16 changes: 11 additions & 5 deletions src/riak_core_bucket_type.erl
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
-type bucket_type() :: binary().
-type bucket_type_props() :: [{term(), term()}].

-define(IF_CAPABLE(X, E), case riak_core_capability:get({riak_core, bucket_types}) of
true -> X;
false -> E
end).


%% @doc The hardcoded defaults for all bucket types.
-spec defaults() -> bucket_type_props().
Expand Down Expand Up @@ -141,23 +146,24 @@ defaults() ->
create(?DEFAULT_TYPE, _Props) ->
{error, default_type};
create(BucketType, Props) when is_binary(BucketType) ->
riak_core_claimant:create_bucket_type(BucketType,
riak_core_bucket_props:merge(Props, defaults())).
?IF_CAPABLE(riak_core_claimant:create_bucket_type(BucketType,
riak_core_bucket_props:merge(Props, defaults())),
{error, not_capable}).

%% @doc Returns the state the type is in.
-spec status(bucket_type()) -> undefined | created | ready | active.
status(?DEFAULT_TYPE) ->
active;
status(BucketType) when is_binary(BucketType) ->
riak_core_claimant:bucket_type_status(BucketType).
?IF_CAPABLE(riak_core_claimant:bucket_type_status(BucketType), undefined).

%% @doc Activate the type. This will succeed only if the type is in the `ready' state. Otherwise,
%% an error is returned.
-spec activate(bucket_type()) -> ok | {error, undefined | not_ready}.
activate(?DEFAULT_TYPE) ->
ok;
activate(BucketType) when is_binary(BucketType) ->
riak_core_claimant:activate_bucket_type(BucketType).
?IF_CAPABLE(riak_core_claimant:activate_bucket_type(BucketType), {error, undefined}).

%% @doc Update an existing bucket type. Updates may only be performed
%% on active types. Properties not provided will keep their existing
Expand All @@ -166,7 +172,7 @@ activate(BucketType) when is_binary(BucketType) ->
update(?DEFAULT_TYPE, _Props) ->
{error, no_default_update}; %% default props are in the app.config
update(BucketType, Props) when is_binary(BucketType)->
riak_core_claimant:update_bucket_type(BucketType, Props).
?IF_CAPABLE(riak_core_claimant:update_bucket_type(BucketType, Props), {error, not_capable}).

%% @doc Return the properties associated with the given bucket type.
-spec get(bucket_type()) -> undefined | bucket_type_props().
Expand Down
3 changes: 2 additions & 1 deletion src/riak_core_claimant.erl
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,8 @@ get_remote_type_status(BucketType, Props) ->
riak_core_metadata,
get, [?BUCKET_TYPE_PREFIX, BucketType, [{default, []}]]),
SortedProps = lists:ukeysort(1, Props),
DiffProps = [P || P <- AllProps, lists:ukeysort(1, P) =/= SortedProps],
%% P may be a {badrpc, ...} in addition to a list of properties when there are older nodes involved
DiffProps = [P || P <- AllProps, (not is_list(P) orelse lists:ukeysort(1, P) =/= SortedProps)],
case {DiffProps, BadNodes} of
{[], []} -> ready;
%% unreachable nodes may or may not have correct value, so we assume they dont
Expand Down

0 comments on commit c887065

Please sign in to comment.