summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_view.erl
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2008-04-01 20:32:15 +0000
committerDamien F. Katz <damien@apache.org>2008-04-01 20:32:15 +0000
commit042de2f5aeea9fb5be6768df934d61ba26985d5c (patch)
tree9471eb95045593332cf0df9ce5abefb190921781 /src/couchdb/couch_view.erl
parent504c93c4534f07affc2c933bd4d5d7f6075ea013 (diff)
Fix for runaway process in the view code and the so far untested storage compaction code.
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@643556 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_view.erl')
-rw-r--r--src/couchdb/couch_view.erl44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/couchdb/couch_view.erl b/src/couchdb/couch_view.erl
index 612eb5fd..97228530 100644
--- a/src/couchdb/couch_view.erl
+++ b/src/couchdb/couch_view.erl
@@ -20,9 +20,6 @@
-include("couch_db.hrl").
-% arbitrarily chosen amount of memory to use before flushing to disk
--define(FLUSH_MAX_MEM, 10000000).
-
-record(group,
{db,
fd,
@@ -68,12 +65,11 @@ get_updated_group(Pid) ->
receive
{Pid, Response} ->
erlang:demonitor(Mref),
- receive
- {'DOWN', Mref, _, _, _} ->
- Response
- after 0 ->
- Response
- end;
+ receive
+ {'DOWN', Mref, _, _, _} -> ok
+ after 0 -> ok
+ end,
+ Response;
{'DOWN', Mref, _, _, Reason} ->
throw(Reason)
end
@@ -201,7 +197,10 @@ handle_info({'EXIT', FromPid, Reason}, #server{root_dir=RootDir}=Server) ->
[{_, {DbName, GroupId}}] ->
delete_from_ets(FromPid, DbName, GroupId)
end,
- {noreply, Server}.
+ {noreply, Server};
+handle_info(Msg, _Server) ->
+ couch_log:error("Bad message received for view module: ~p", [Msg]),
+ exit({error, Msg}).
add_to_ets(Pid, DbName, GroupId) ->
true = ets:insert(couch_views_by_updater, {Pid, {DbName, GroupId}}),
@@ -216,11 +215,6 @@ delete_from_ets(Pid, DbName, GroupId) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-start_update_loop(RootDir, DbName, GroupId) ->
- % wait for a notify request before doing anything. This way, we can just
- % exit and any exits will be noticed by the callers.
- start_update_loop(RootDir, DbName, GroupId, get_notify_pids(1000)).
-
start_temp_update_loop(DbName, Fd, Lang, Query) ->
NotifyPids = get_notify_pids(1000),
@@ -243,7 +237,12 @@ temp_update_loop(Group, NotifyPids) ->
{ok, Group2} = update_group(Group),
[Pid ! {self(), {ok, Group2}} || Pid <- NotifyPids],
garbage_collect(),
- temp_update_loop(Group2, get_notify_pids(100000)).
+ temp_update_loop(Group2, get_notify_pids(10000)).
+
+start_update_loop(RootDir, DbName, GroupId) ->
+ % wait for a notify request before doing anything. This way, we can just
+ % exit and any exits will be noticed by the callers.
+ start_update_loop(RootDir, DbName, GroupId, get_notify_pids(1000)).
start_update_loop(RootDir, DbName, GroupId, NotifyPids) ->
{Db, DefLang, Defs} =
@@ -284,13 +283,16 @@ update_loop(#group{fd=Fd}=Group, NotifyPids) ->
update_loop(Group2).
update_loop(Group) ->
- update_loop(Group, get_notify_pids()).
+ update_loop(Group, get_notify_pids(100000)).
% wait for the first request to come in.
get_notify_pids(Wait) ->
receive
{Pid, get_updated} ->
- [Pid | get_notify_pids()]
+ [Pid | get_notify_pids()];
+ Else ->
+ couch_log:error("Unexpected message in view updater: ~p", [Else]),
+ exit({error, Else})
after Wait ->
exit(wait_timeout)
end.
@@ -526,15 +528,15 @@ process_doc(Db, DocInfo, {Docs, #group{name=GroupId}=Group, ViewKVs, DocIdViewId
{ok, Doc} = couch_db:open_doc(Db, DocInfo, [conflicts, deleted_conflicts]),
{[Doc | Docs], DocIdViewIdKeys}
end,
- case process_info(self(), memory) of
- {memory, Mem} when Mem > ?FLUSH_MAX_MEM ->
+ case couch_util:should_flush() of
+ true ->
{Group1, Results} = view_compute(Group, Docs2),
{ViewKVs3, DocIdViewIdKeys3} = view_insert_query_results(Docs2, Results, ViewKVs, DocIdViewIdKeys2),
{ok, Group2} = write_changes(Group1, ViewKVs3, DocIdViewIdKeys3, Seq),
garbage_collect(),
ViewEmptyKeyValues = [{View, []} || View <- Group2#group.views],
{ok, {[], Group2, ViewEmptyKeyValues, [], Seq}};
- _Else ->
+ false ->
{ok, {Docs2, Group, ViewKVs, DocIdViewIdKeys2, Seq}}
end
end.