summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@apache.org>2010-08-21 20:23:06 +0000
committerFilipe David Borba Manana <fdmanana@apache.org>2010-08-21 20:23:06 +0000
commit043671429beae470fa9560bfaab0a45324c8f956 (patch)
tree89d26a801b549056bb34343a398d99d0799fdeef /src
parent9b3c2688feba69fe178b4d1e9ecff5c1a36c9475 (diff)
Small refactoring of the work queue module to accomodate for incoming options (multiple workers)
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@987824 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_rep_writer.erl3
-rw-r--r--src/couchdb/couch_view_updater.erl6
-rw-r--r--src/couchdb/couch_work_queue.erl14
3 files changed, 15 insertions, 8 deletions
diff --git a/src/couchdb/couch_rep_writer.erl b/src/couchdb/couch_rep_writer.erl
index dd6396fd..129e279c 100644
--- a/src/couchdb/couch_rep_writer.erl
+++ b/src/couchdb/couch_rep_writer.erl
@@ -147,7 +147,8 @@ streamer_fun(Boundary, JsonBytes, Atts) ->
{start, From} ->
% better use a brand new queue, to ensure there's no garbage from
% a previous (failed) iteration
- {ok, DataQueue} = couch_work_queue:new(1024 * 1024, 1000),
+ {ok, DataQueue} = couch_work_queue:new(
+ [{max_size, 1024 * 1024}, {max_items, 1000}]),
From ! {queue, DataQueue},
couch_doc:doc_to_multi_part_stream(
Boundary,
diff --git a/src/couchdb/couch_view_updater.erl b/src/couchdb/couch_view_updater.erl
index 2a9c960f..70a60950 100644
--- a/src/couchdb/couch_view_updater.erl
+++ b/src/couchdb/couch_view_updater.erl
@@ -38,8 +38,10 @@ update(Owner, Group) ->
couch_task_status:update(<<"Resetting view index due to lost purge entries.">>),
exit(reset)
end,
- {ok, MapQueue} = couch_work_queue:new(100000, 500),
- {ok, WriteQueue} = couch_work_queue:new(100000, 500),
+ {ok, MapQueue} = couch_work_queue:new(
+ [{max_size, 100000}, {max_items, 500}]),
+ {ok, WriteQueue} = couch_work_queue:new(
+ [{max_size, 100000}, {max_items, 500}]),
Self = self(),
ViewEmptyKVs = [{View, []} || View <- Group2#group.views],
spawn_link(fun() -> do_maps(Group, MapQueue, WriteQueue, ViewEmptyKVs) end),
diff --git a/src/couchdb/couch_work_queue.erl b/src/couchdb/couch_work_queue.erl
index decfcad8..44f2816d 100644
--- a/src/couchdb/couch_work_queue.erl
+++ b/src/couchdb/couch_work_queue.erl
@@ -13,7 +13,7 @@
-module(couch_work_queue).
-behaviour(gen_server).
--export([new/2,queue/2,dequeue/1,dequeue/2,close/1]).
+-export([new/1,queue/2,dequeue/1,dequeue/2,close/1]).
-export([init/1, terminate/2, handle_call/3, handle_cast/2, code_change/3, handle_info/2]).
-record(q, {
@@ -27,8 +27,8 @@
close_on_dequeue=false
}).
-new(MaxSize, MaxItems) ->
- gen_server:start_link(couch_work_queue, {MaxSize, MaxItems}, []).
+new(Options) ->
+ gen_server:start_link(couch_work_queue, Options, []).
queue(Wq, Item) ->
gen_server:call(Wq, {queue, Item}, infinity).
@@ -46,8 +46,12 @@ close(Wq) ->
gen_server:cast(Wq, close).
-init({MaxSize,MaxItems}) ->
- {ok, #q{max_size=MaxSize, max_items=MaxItems}}.
+init(Options) ->
+ Q = #q{
+ max_size = couch_util:get_value(max_size, Options),
+ max_items = couch_util:get_value(max_items, Options)
+ },
+ {ok, Q}.
terminate(_Reason, #q{work_waiter=nil}) ->
ok;