summaryrefslogtreecommitdiff
path: root/apps/couch/src/couch_view_updater.erl
diff options
context:
space:
mode:
authorRobert Newson <robert.newson@cloudant.com>2012-11-14 19:32:23 +0000
committerRobert Newson <robert.newson@cloudant.com>2012-11-15 11:23:46 +0000
commit19017b3612b4567ced3b8ac9cfe816e6cf80e0f8 (patch)
treea0ffdab1271fb3ffd0c95b22340c7f10c5e98e53 /apps/couch/src/couch_view_updater.erl
parentbf4d46be7037ddea375bdaf2bab067e29f2c423f (diff)
Backport new /_active_tasks API
Improved _active_tasks API Tasks are now free to set any properties they wish (as an Erlang proplist). Different tasks can have different properties and the status string doesn't exist anymore - instead client applications can build it using more granular properties from _active_tasks. Some of these properties are: 1) "progress" (an integer percentage, for all tasks) 2) "database" (for compactions and indexer tasks) 3) "design_document" (for indexer and view compaction tasks) 4) "source" and "target" (for replications) 5) "docs_read", "docs_written", "doc_write_failures", "missing_revs_found", "missing_revs_checked", "source_seq", "checkpointed_source_seq" and "continuous" for replications BugzID: 14269 Conflicts: apps/couch/src/couch_db_updater.erl apps/couch/src/couch_rep.erl apps/couch/src/couch_task_status.erl apps/couch/src/couch_view_compactor.erl apps/couch/src/couch_view_updater.erl
Diffstat (limited to 'apps/couch/src/couch_view_updater.erl')
-rw-r--r--apps/couch/src/couch_view_updater.erl23
1 files changed, 12 insertions, 11 deletions
diff --git a/apps/couch/src/couch_view_updater.erl b/apps/couch/src/couch_view_updater.erl
index 8238e3e5..ca144149 100644
--- a/apps/couch/src/couch_view_updater.erl
+++ b/apps/couch/src/couch_view_updater.erl
@@ -32,17 +32,25 @@ update(Owner, Group, #db{name = DbName} = Db) ->
current_seq = Seq,
purge_seq = PurgeSeq
} = Group,
- couch_task_status:add_task(<<"View Group Indexer">>, <<DbName/binary," ",GroupName/binary>>, <<"Starting index update">>),
+ % compute on all docs modified since we last computed.
+ TotalChanges = couch_db:count_changes_since(Db, Seq),
+ couch_task_status:add_task([
+ {type, indexer},
+ {database, DbName},
+ {design_document, GroupName},
+ {progress, 0},
+ {changes_done, 0},
+ {total_changes, TotalChanges}
+ ]),
+ couch_task_status:set_update_frequency(500),
DbPurgeSeq = couch_db:get_purge_seq(Db),
Group2 =
if DbPurgeSeq == PurgeSeq ->
Group;
DbPurgeSeq == PurgeSeq + 1 ->
- couch_task_status:update(<<"Removing purged entries from view index.">>),
purge_index(Group, Db);
true ->
- couch_task_status:update(<<"Resetting view index due to lost purge entries.">>),
exit(reset)
end,
{ok, MapQueue} = couch_work_queue:new(
@@ -53,10 +61,6 @@ update(Owner, Group, #db{name = DbName} = Db) ->
ViewEmptyKVs = [{View, []} || View <- Group2#group.views],
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
- couch_task_status:set_update_frequency(500),
#group{ design_options = DesignOptions } = Group,
IncludeDesign = couch_util:get_value(<<"include_design">>,
DesignOptions, false),
@@ -69,8 +73,6 @@ update(Owner, Group, #db{name = DbName} = Db) ->
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),
receive {new_group, NewGroup} ->
exit({new_group,
@@ -78,8 +80,7 @@ update(Owner, Group, #db{name = DbName} = 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]),
+ couch_task_status:update([{changes_done, I}, {progress, (I * 100) div Total}]),
load_doc(Db, DocInfo, MapQueue, DocOpts, IncludeDesign),
{ok, setelement(1, Acc, I+1)}.