Permalink
Browse files

Merge pull request #210 from basho/AZ727-detect-siblings-in-2i-hook

AZ727 - Detect Siblings in 2I Hook
  • Loading branch information...
2 parents 19c6ca4 + 1705a54 commit 5c273bfe100328e41250dcc5397af75ff53f7772 @rustyio rustyio committed Sep 20, 2011
Showing with 21 additions and 7 deletions.
  1. +21 −7 src/riak_index.erl
View
@@ -74,13 +74,27 @@ mapred_index(_Pipe, [Bucket, Query], Timeout) ->
%% is either `{unknown_field_type, Field}` or
%% `{field_parsing_failed, {Field, Value}}.`
parse_object_hook(RObj) ->
- case parse_object(RObj) of
- {ok, ParsedFields} ->
- MD1 = riak_object:get_metadata(RObj),
- MD2 = dict:store(?MD_INDEX, ParsedFields, MD1),
- riak_object:update_metadata(RObj, MD2);
- {error, Reasons} ->
- {fail, Reasons}
+ %% Ensure that the object only has a single metadata, or fail
+ %% loudly.
+ case riak_object:value_count(RObj) == 1 of
+ true ->
+ %% Parse the object and update the metadata...
+ case parse_object(RObj) of
+ {ok, ParsedFields} ->
+ MD1 = riak_object:get_metadata(RObj),
+ MD2 = dict:store(?MD_INDEX, ParsedFields, MD1),
+ riak_object:update_metadata(RObj, MD2);
+ {error, Reasons} ->
+ {fail, Reasons}
+ end;
+ false ->
+ %% The object has siblings. This can only happen when a
+ %% put is initated through the riak_client:put/N function.
+ %% Any operation that occurs through the HTTP or PB
+ %% interface is forced to resolve siblings and send back a
+ %% single update.
+ lager:error("Siblings not allowed: ~p", [RObj]),
+ {fail, {siblings_not_allowed, RObj}}
end.
%% @spec parse_object(riak_object:riak_object()) -> {ok, [{Field::binary(), Val :: term()}]}

0 comments on commit 5c273bf

Please sign in to comment.