Browse files

implemented basic (suboptimal) batchsize for queries

  • Loading branch information...
1 parent c3dc452 commit ed6fa178486ce4079dbc20d879aff54c2f0493fd @pavlobaron committed Apr 15, 2012
Showing with 21 additions and 5 deletions.
  1. +20 −4 src/riak_mongo_riak.erl
  2. +1 −1 src/riak_mongo_server.erl
View
24 src/riak_mongo_riak.erl
@@ -66,17 +66,33 @@ is_true(0.0) -> false;
is_true(_) -> true.
-find(#mongo_query{dbcoll=Collection, selector=Selector, projector=Projection }) ->
+find(#mongo_query{dbcoll=Bucket, selector=Selector, projector=Projection, batchsize=BatchSize }) ->
Project = compute_projection_fun(Projection),
CompiledQuery = riak_mongo_query:compile(Selector),
+ error_logger:info_msg("Find executed ~p, ~p, ~p~n", [Projection, CompiledQuery, Project]),
+
{ok, Documents}
- = riak_kv_mrc_pipe:mapred(Collection,
+ = riak_kv_mrc_pipe:mapred(Bucket,
[{map, {qfun, fun map_query/3}, {CompiledQuery, Project}, true}]),
+
+ % dig deeper here to find out if it's possible to limit the
+ % number of returned docs during mapred, not afterwards
+ case BatchSize /= 0 of
+ true ->
+ error_logger:info_msg("Limiting result set to ~p docs~n", [BatchSize]),
+
+ limit_docs(Documents, abs(BatchSize), 0);
+ false -> Documents
+ end.
- Documents.
-
+limit_docs(_, BatchSize, N) when N =:= BatchSize ->
+ [];
+limit_docs(_, [], _) ->
+ [];
+limit_docs([Document|T], BatchSize, N) ->
+ [Document|limit_docs(T, BatchSize, N + 1)].
map_query(Object, _KeyData, {CompiledQuery, Project}) ->
Acc = [],
View
2 src/riak_mongo_server.erl
@@ -45,7 +45,7 @@ new_connection(Sock, State) ->
sock_opts() -> ?SOCK_OPTS.
handle_info(?CONTROLLING_PROCESS_MSG(Sock, NewOwner), State) ->
- error_logger:info_msg("Handing over control from to ~p on sock ~p~n", [NewOwner, Sock]),
+ error_logger:info_msg("Handing over control to ~p on sock ~p~n", [NewOwner, Sock]),
gen_tcp:controlling_process(Sock, NewOwner),
NewOwner ! ?CONTROL_MSG,

0 comments on commit ed6fa17

Please sign in to comment.