Permalink
Browse files

Always write main_group, even when only updating leaf

This ensures that if another process did a split on the 
relevant leaf, then subsequent reads will see a conflict
in the master group; and then do a read repair on that.
  • Loading branch information...
1 parent 2d4ed9b commit 8d8d1b3833e80d3ded6699ae78e0faf321134ea0 @krestenkrab committed Apr 27, 2011
Showing with 6 additions and 4 deletions.
  1. +4 −2 src/riak_column.erl
  2. +2 −2 test/riak_column_tests.erl
View
@@ -142,11 +142,13 @@ update(RowKey, {VC,Values}) when is_list(Values) ->
ok = update_main_group(RObj, #main_group{ entries=NewEntries })
end,
{ok, Merged};
- {ok, #main_group{entries=[],grouppointers=Groups}, RObj} ->
+ {ok, #main_group{entries=[],grouppointers=Groups}=TheMainGroup, RObj} ->
{ok, GroupP} = listfind( bit_prefix_match(RowKey), Groups),
?edbg("storing ~p into ~p", [RowKey, group_name(GroupP)]),
case update_group(GroupP, RowKey, {VC,Values}) of
{ok, [], Merged} ->
+ %% must re-update main group to force later read repair if different
+ update_main_group(RObj, TheMainGroup),
{ok, Merged};
{ok, [GP1,GP2]=SplitGroupPs, Merged} when is_bitstring(GP1), is_bitstring(GP2) ->
NewMainGroup = #main_group{ grouppointers= lists:sort( SplitGroupPs ++ [R || R <- Groups, R =/= GroupP] ) },
@@ -318,7 +320,7 @@ get_main_group() ->
merge_main_groups(#main_group{entries=Elms1, grouppointers=Groups1},
#main_group{entries=Elms2, grouppointers=Groups2}) ->
#main_group{ entries=merge_entries(Elms1, Elms2),
- grouppointers=merge_grouppointers(Groups1, Groups2) }.
+ grouppointers=merge_grouppointers(Groups1, Groups2) }.
merge_grouppointers(Groups1,Groups2) ->
R = lists:umerge(Groups1,Groups2),
@@ -20,8 +20,8 @@ simple_test() ->
Column:add(<<"peter9">>, 9),
{ok, {_,[3]}} = Column:lookup(<<"peter3">>),
- {ok, {VC, [6,5]}} = Column:lookup(<<"peter5">>),
- ok = Column:put(<<"peter5">>, {VC, [5]}),
+ {ok, {VClock, [6,5]}} = Column:lookup(<<"peter5">>),
+ ok = Column:put(<<"peter5">>, {VClock, [5]}),
{ok, {_, [5]}} = Column:lookup(<<"peter5">>),
Values = Column:fold(fun({_Key,{_VC,[V]}}, Acc) -> [V|Acc] end, []),

0 comments on commit 8d8d1b3

Please sign in to comment.