Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Inconvenient siblings resolution in reads #78

Closed
ondrejcernos opened this Issue · 5 comments

4 participants

@ondrejcernos

When there are conflicting values, riakc_obj:get_value/1 fails with siblings exception. In my client code, I have a sibling resolution function that performs some automatic analysis, chooses one value and stores the resolved object to the DB. So far so good. The problem is I cannot use the chosen sibling as an object to retrieve value from, as the above mentioned call throws the same sibling exception as for the unresolved version. See the following:

6> Pid = pooler:take_member().
<0.98.0>
8> {ok, Obj} = riakc_pb_socket:get(Pid, <<"user">>, <<"TestVCUser1">>).
{ok,{riakc_obj,<<"user">>,<<"TestVCUser1">>,
<<107,206,97,96,96,96,205,96,202,5,82,28,49,27,174,115,5,
120,44,245,202,96,74,...>>,
[{{dict,3,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],...}}},
<<131,104,25,100,0,4,117,115,101,114,100,0,9,117,110,100,
101,102,105,...>>},
{{dict,3,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],...}}},
<<131,104,25,100,0,4,117,115,101,114,100,0,9,117,110,
100,101,102,...>>}],
undefined,undefined}}
9> riakc_obj:value_count(Obj).
2
10> SelectedSibling = riakc_obj:select_sibling(1, Obj).
{riakc_obj,<<"user">>,<<"TestVCUser1">>,
<<107,206,97,96,96,96,205,96,202,5,82,28,49,27,174,115,5,
120,44,245,202,96,74,100,201,...>>,
[{{dict,3,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],[[...]],[...],...}}},
<<131,104,25,100,0,4,117,115,101,114,100,0,9,117,110,100,
101,102,105,110,101,...>>},
{{dict,3,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],[...],...}}},
<<131,104,25,100,0,4,117,115,101,114,100,0,9,117,110,
100,101,102,105,110,...>>}],
{dict,3,16,16,8,80,48,
{[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],...},
{{[],[],[],[],[],[],[],[],[],[],
[[<<...>>|...]],
[[...]],
[],...}}},
<<131,104,25,100,0,4,117,115,101,114,100,0,9,117,110,100,
101,102,105,110,101,100,...>>}
11> riakc_obj:get_value(SelectedSibling).
** exception throw: siblings
in function riakc_obj:get_value/1 (src/riakc_obj.erl, line 183)
12>

This is unfortunate - my get_value_from_riak_object function doesn't need bucket and object key, so I cannot re-read the value from the DB without changing the function signature and provide these values wherever I need to retrieve value from riak object.

Is this behaviour necessary? Is there a reason the resolved sibling cannot be used for value retrieval? If not, could it be changed so that it doesn't throw the sibling exception?

@metadave

@ondrejcernos I'll try to look into this issue within the next couple days.

@metadave

Won't riakc_obj:get_values/1 solve your issue? It looks like you already have the index of the sibling.

@ondrejcernos

Well, besides the need to repeat myself (select sibling, select value) it does solve the issue. But this issue is not about inability to get to the selected value but about the inconvenience and surprise - I really didn't expect the sibling exception being raised when get_value is called on the selected sibling and imho it breaks the principle of least surprise.

@beerriot

This is a semi-confusing behavior that was brought over from the original, internal riak_object representation: both the original value as-read, and the new, to-be-written value are kept in the object. We call the latter the "update value". What select_sibling/2 is doing is setting the to-be-written "update value". To fetch it, use the get_update_value/1 function instead of just get_value/1. The same goes for get_update_metadata/1.

I agree that this sounds annoying, but there's a bonus: if no update value has been set, get_update_value/1 calls get_value/1 and returns that result instead. So, you should be able to forget get_value/1 all together, and just call get_update_value/1 every time.

@ondrejcernos

Hi, ok, thanks, will do. Please consider documenting the usage in official documentation of the PB client, I am probably not the only one who ran into this.

@seancribbs seancribbs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.