Skip to content

Commit

Permalink
Make GeoCouch work again.
Browse files Browse the repository at this point in the history
The couch_tasks module was changed an rendered GeoCouch
unusable. This commit fixes the problem.

Change-Id: I7c0a90e1595ffecf0afd68e4f917fd4fdacae40b
Reviewed-on: http://review.couchbase.org/9780
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Tested-by: Dale Harvey <daleharvey@arandomurl.com>
Reviewed-by: Dale Harvey <daleharvey@arandomurl.com>
  • Loading branch information
Volker Mische authored and Dale Harvey committed Sep 27, 2011
1 parent a5b4c28 commit 2ccd58c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
22 changes: 12 additions & 10 deletions src/geocouch/couch_spatial_compactor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,23 @@ compact_group(Group, EmptyGroup) ->
{ok, DbReduce} = couch_btree:full_reduce(Db#db.fulldocinfo_by_id_btree),
Count = element(1, DbReduce),

<<"_design", ShortName/binary>> = GroupId,
DbName = couch_db:name(Db),
TaskName = <<DbName/binary, ShortName/binary>>,
couch_task_status:add_task(
<<"Spatial Group Compaction">>, TaskName, <<"">>),

% Use "view_compaction" for now, that it shows up in Futons active tasks
% screen. Think about a more generic way for the future.
couch_task_status:add_task([
{type, view_compaction},
{database, DbName},
{design_document, GroupId},
{progress, 0}
]),
% Create a new version of the lookup tree (the ID B-tree)
Fun = fun({DocId, _IndexIdKeys} = KV, {Bt, Acc, TotalCopied, _LastId}) ->
% NOTE vmx (2011-01-18): use the same value as for view compaction,
% though wondering why a value of 10000 is hard-coded
if TotalCopied rem 10000 =:= 0 ->
couch_task_status:update("Copied ~p of ~p Ids (~p%)",
[TotalCopied, Count, (TotalCopied*100) div Count]),
couch_task_status:update([
{progress, (TotalCopied*100) div Count}]),
{ok, Bt2} = couch_btree:add(Bt, lists:reverse([KV|Acc])),
{ok, {Bt2, [], TotalCopied+1, DocId}};
true ->
Expand Down Expand Up @@ -91,10 +95,8 @@ compact_spatial(OldFd, NewFd, Index, EmptyIndex) ->

Fun = fun(Node, {TreePos, TreeHeight, Acc, TotalCopied}) ->
if TotalCopied rem 10000 =:= 0 ->
couch_task_status:update(
"Spatial index #~p: copied ~p of ~p KVs (~p%)",
[Index#spatial.id_num, TotalCopied, Count,
(TotalCopied*100) div Count]),
couch_task_status:update([
{progress, (TotalCopied*100) div Count}]),
{ok, TreePos2, TreeHeight2} = vtree_bulk:bulk_load(
NewFd, TreePos, TreeHeight, [Node|Acc]),
{TreePos2, TreeHeight2, [], TotalCopied + 1};
Expand Down
20 changes: 14 additions & 6 deletions src/geocouch/couch_spatial_updater.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ update(Owner, Group) ->
current_seq = Seq
%purge_seq = PurgeSeq
} = Group,
couch_task_status:add_task(<<"Spatial Group Indexer">>, <<DbName/binary," ",GroupName/binary>>, <<"Starting index update">>),
% XXX vmx: what are purges? when do they happen?
%DbPurgeSeq = couch_db:get_purge_seq(Db),
%Group2 =
Expand All @@ -57,19 +56,28 @@ update(Owner, Group) ->
IndexEmptyKVs = [{Index, []} || Index <- Group#spatial_group.indexes],
% 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:add_task([
{type, indexer},
{database, DbName},
{design_document, GroupName},
{progress, 0},
{changes_done, 0},
{total_changes, TotalChanges}
]),
couch_task_status:set_update_frequency(500),

{ok, _, {_,{UncomputedDocs, Group3, ViewKVsToAdd, DocIdViewIdKeys}}}
= couch_db:enum_docs_since(Db, Seq,
fun(DocInfo, _, {ChangesProcessed, Acc}) ->
couch_task_status:update("Processed ~p of ~p changes (~p%)",
[ChangesProcessed, TotalChanges, (ChangesProcessed*100) div TotalChanges]),
Progress = (ChangesProcessed*100) div TotalChanges,
couch_task_status:update([
{progress, Progress},
{changes_done, ChangesProcessed}
]),
%?LOG_DEBUG("enum_doc_since: ~p", [Acc]),
{ok, {ChangesProcessed+1, process_doc(Db, Owner, DocInfo, Acc)}}
end, {0, {[], Group, IndexEmptyKVs, []}}, []),
%?LOG_DEBUG("enum_doc_since results: ~p~n~p~n~p", [UncomputedDocs, ViewKVsToAdd, DocIdViewIdKeys]),
couch_task_status:set_update_frequency(0),
couch_task_status:update("Finishing."),
{Group4, Results} = spatial_compute(Group3, UncomputedDocs),
% Output is way to huge
%?LOG_DEBUG("spatial_compute results: ~p", [Results]),
Expand Down

0 comments on commit 2ccd58c

Please sign in to comment.