diff options
author | Adam Kocoloski <adam@cloudant.com> | 2010-08-09 09:53:16 -0400 |
---|---|---|
committer | Adam Kocoloski <adam@cloudant.com> | 2011-02-25 12:02:24 -0500 |
commit | 21a638afb29c596fbd17349c35065659bfe48a8f (patch) | |
tree | 88d24d19046eb540186c4746a6d435eb73a93241 | |
parent | 3fddaf325d5b46fb35896282a0a6bf03bd34c88d (diff) |
Make couch_view_updater amenable to hot upgrades
-rw-r--r-- | apps/couch/src/couch_view_updater.erl | 29 |
1 files changed, 13 insertions, 16 deletions
diff --git a/apps/couch/src/couch_view_updater.erl b/apps/couch/src/couch_view_updater.erl index 8424862b..b04a80ce 100644 --- a/apps/couch/src/couch_view_updater.erl +++ b/apps/couch/src/couch_view_updater.erl @@ -12,7 +12,7 @@ -module(couch_view_updater). --export([update/2]). +-export([update/2, do_maps/4, do_writes/5, load_docs/3]). -include("couch_db.hrl"). @@ -43,8 +43,8 @@ update(Owner, Group) -> {ok, WriteQueue} = couch_work_queue:new(100000, 500), Self = self(), ViewEmptyKVs = [{View, []} || View <- Group2#group.views], - spawn_link(fun() -> do_maps(Group, MapQueue, WriteQueue, ViewEmptyKVs) end), - spawn_link(fun() -> do_writes(Self, Owner, Group2, WriteQueue, Seq == 0) end), + spawn_link(?MODULE, do_maps, [Group, MapQueue, WriteQueue, ViewEmptyKVs]), + spawn_link(?MODULE, do_writes, [Self, Owner, Group2, WriteQueue, Seq == 0]), % compute on all docs modified since we last computed. TotalChanges = couch_db:count_changes_since(Db, Seq), % update status every half second @@ -58,17 +58,9 @@ update(Owner, Group) -> true -> [conflicts, deleted_conflicts, local_seq]; _ -> [conflicts, deleted_conflicts] end, - {ok, _, _} - = couch_db:enum_docs_since( - Db, - Seq, - fun(DocInfo, _, ChangesProcessed) -> - couch_task_status:update("Processed ~p of ~p changes (~p%)", - [ChangesProcessed, TotalChanges, (ChangesProcessed*100) div TotalChanges]), - load_doc(Db, DocInfo, MapQueue, DocOpts, IncludeDesign), - {ok, ChangesProcessed+1} - end, - 0, []), + EnumFun = fun ?MODULE:load_docs/3, + Acc0 = {0, Db, MapQueue, DocOpts, IncludeDesign, TotalChanges}, + {ok, _, _} = couch_db:enum_docs_since(Db, Seq, EnumFun, Acc0, []), couch_task_status:set_update_frequency(0), couch_task_status:update("Finishing."), couch_work_queue:close(MapQueue), @@ -77,6 +69,11 @@ update(Owner, Group) -> NewGroup#group{current_seq=couch_db:get_update_seq(Db)}}) end. +load_docs(DocInfo, _, {I, Db, MapQueue, DocOpts, IncludeDesign, Total} = Acc) -> + couch_task_status:update("Processed ~p of ~p changes (~p%)", [I, Total, + (I*100) div Total]), + load_doc(Db, DocInfo, MapQueue, DocOpts, IncludeDesign), + {ok, setelement(1, Acc, I+1)}. purge_index(Db, #group{views=Views, id_btree=IdBtree}=Group) -> {ok, PurgedIdsRevs} = couch_db:get_last_purged(Db), @@ -143,7 +140,7 @@ do_maps(Group, MapQueue, WriteQueue, ViewEmptyKVs) -> {ViewKVs, DocIdViewIdKeys} = view_insert_query_results(Docs, Results, ViewEmptyKVs, DelKVs), couch_work_queue:queue(WriteQueue, {LastSeq, ViewKVs, DocIdViewIdKeys}), - do_maps(Group1, MapQueue, WriteQueue, ViewEmptyKVs) + ?MODULE:do_maps(Group1, MapQueue, WriteQueue, ViewEmptyKVs) end. -spec do_writes(pid(), pid() | nil, #group{}, pid(), boolean()) -> any(). @@ -170,7 +167,7 @@ do_writes(Parent, Owner, Group, WriteQueue, InitialBuild) -> nil -> ok; _ -> ok = gen_server:cast(Owner, {partial_update, Parent, Group2}) end, - do_writes(Parent, Owner, Group2, WriteQueue, InitialBuild) + ?MODULE:do_writes(Parent, Owner, Group2, WriteQueue, InitialBuild) end. -spec view_insert_query_results([#doc{}], list(), any(), any()) -> any(). |