Skip to content

Commit

Permalink
Merge pull request #210 from basho/AZ727-detect-siblings-in-2i-hook
Browse files Browse the repository at this point in the history
AZ727 - Detect Siblings in 2I Hook
  • Loading branch information
rustyio committed Sep 20, 2011
2 parents 19c6ca4 + 1705a54 commit 5c273bf
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/riak_index.erl
Expand Up @@ -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()}]}
Expand Down

0 comments on commit 5c273bf

Please sign in to comment.