Skip to content

Commit

Permalink
Consider key and term in concert when deciding if an item is in range
Browse files Browse the repository at this point in the history
A bug found by @engelsanchez, where `start_incl` being false
(when using a continuation, for example) led to in range values
being excluded as the key was checked in isolation.
  • Loading branch information
russelldb committed May 23, 2013
1 parent ac1755d commit c2d6d2e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/riak_index.erl
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ index_key_in_range({Bucket, Key, Field, Term}=IK, Bucket,
end_term=EndTerm})
when Term >= StartTerm,
Term =< EndTerm ->
in_range(gt(StartInc, Key, StartKey), true, IK);
in_range(gt(StartInc, {Term, Key}, {StartTerm, StartKey}), true, IK);
index_key_in_range(_, _, _) ->
false.

Expand Down Expand Up @@ -468,6 +468,20 @@ normalize_index_field(V) when is_list(V) ->

-ifdef(TEST).

index_in_range_test() ->
%% In that case that same Key has multiple values for an index
%% make sure that we don't skip in range values
%% when start_inclusive is false
FF = <<"f1">>,
K = <<"k">>,
B = <<"b">>,
IK = {B, K, FF, 1},
IK2 = {B, K, FF, 2},
%% Expect IK to be out of range but IK2 to be in
Q = ?KV_INDEX_Q{filter_field=FF, start_key=K, start_term=1, start_inclusive=false, end_term=3},
?assertEqual({skip, IK}, index_key_in_range(IK, B, Q)),
?assertEqual({true, IK2}, index_key_in_range(IK2, B, Q)).

parse_binary_test() ->
?assertMatch({ok, <<"">>}, parse_binary(<<"">>)),
?assertMatch({ok, <<"A">>}, parse_binary(<<"A">>)),
Expand Down

0 comments on commit c2d6d2e

Please sign in to comment.