Skip to content

Commit 2a392af

Browse files
author
Luke Bakken
committed
block map-reducing over a bucket or type,bucket
1 parent 7369e45 commit 2a392af

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/riakc_pb_socket.erl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,17 @@ mapred_stream(Pid, {index,Bucket,Name,StartKey,EndKey}, Query, ClientPid, Timeou
752752
BinEndKey = list_to_binary(integer_to_list(EndKey)),
753753
mapred_stream(Pid, {index,Bucket,Name,StartKey,BinEndKey}, Query, ClientPid, Timeout, CallTimeout);
754754
mapred_stream(Pid, Inputs, Query, ClientPid, Timeout, _CallTimeout) ->
755+
AllowListing = riakc_utils:get_allow_listing(),
756+
do_mapred_stream(AllowListing, Pid, Inputs, Query, ClientPid, Timeout).
757+
758+
do_mapred_stream(false, _Pid, Bucket, _Query, _ClientPid, _Timeout) when is_binary(Bucket) ->
759+
{error, <<"Bucket list operations are expensive "
760+
"and should not be used in production.">>};
761+
do_mapred_stream(false, _Pid, {Type, Bucket}, _Query, _ClientPid, _Timeout)
762+
when is_binary(Type), is_binary(Bucket) ->
763+
{error, <<"Bucket list operations are expensive "
764+
"and should not be used in production.">>};
765+
do_mapred_stream(_AllowListing, Pid, Inputs, Query, ClientPid, Timeout) ->
755766
MapRed = [{'inputs', Inputs},
756767
{'query', Query},
757768
{'timeout', Timeout}],

src/riakc_utils.erl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
-export([wait_for_list/1,
2626
characters_to_unicode_binary/1,
27+
get_allow_listing/0,
2728
get_allow_listing/1]).
2829

2930
-spec wait_for_list(non_neg_integer()) -> {ok, list()} | {error, any()}.
@@ -54,6 +55,13 @@ characters_to_unicode_binary(String) ->
5455

5556
%% @doc Return the value of allow_listing, which, if set to 'true`
5657
%% will allow listing keys and buckets.
58+
-spec get_allow_listing() -> boolean().
59+
get_allow_listing() ->
60+
case application:get_env(riakc, allow_listing) of
61+
{ok, true} -> true;
62+
_ -> false
63+
end.
64+
5765
-spec get_allow_listing(proplists:proplist()) -> boolean().
5866
get_allow_listing(Options) ->
5967
case application:get_env(riakc, allow_listing) of

test/riakc_pb_socket_tests.erl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ listing_is_blocked_test() ->
3737
?assertMatch({error, E}, riakc_pb_socket:list_keys(self(), <<"b">>)),
3838
application:set_env(riakc, allow_listing, true).
3939

40+
mapred_over_bucket_is_blocked_test() ->
41+
application:set_env(riakc, allow_listing, false),
42+
Pid = self(),
43+
Input1 = <<"bucket">>,
44+
Input2 = {<<"type">>, <<"bucket">>},
45+
E = <<"Bucket list operations are expensive and should not be used in production.">>,
46+
?assertMatch({error, E}, riakc_pb_socket:mapred(Pid, Input1, [])),
47+
?assertMatch({error, E}, riakc_pb_socket:mapred(Pid, Input2, [])),
48+
application:set_env(riakc, allow_listing, true).
49+
4050
bad_connect_test() ->
4151
%% Start with an unlikely port number
4252
?assertMatch({error, {tcp, econnrefused}}, riakc_pb_socket:start({127,0,0,1}, 65535)).

0 commit comments

Comments
 (0)