C0 code coverage information

Generated on 2009-08-09 21:22:54 with etap 0.3.4.

Name Total lines Lines of code Total coverage Code coverage
couch_view_compactor ?? ?? ??
0% 
....1 % Licensed under the Apache License, Version 2.0 (the "License"); you may not
....2 % use this file except in compliance with the License. You may obtain a copy of
....3 % the License at
....4 %
....5 %   http://www.apache.org/licenses/LICENSE-2.0
....6 %
....7 % Unless required by applicable law or agreed to in writing, software
....8 % distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
....9 % WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
...10 % License for the specific language governing permissions and limitations under
...11 % the License.
...12 
...13 -module(couch_view_compactor).
...14 
...15 -include ("couch_db.hrl").
...16 
...17 -export([start_compact/2]).
...18 
...19 %% @spec start_compact(DbName::binary(), GroupId:binary()) -> ok
...20 %% @doc Compacts the views.  GroupId must not include the _design/ prefix
...21 start_compact(DbName, GroupId) ->
...22     Pid = couch_view:get_group_server(DbName, <<"_design/",GroupId/binary>>),
...23     gen_server:cast(Pid, {start_compact, fun compact_group/2}).
...24 
...25 %%=============================================================================
...26 %% internal functions
...27 %%=============================================================================
...28 
...29 %% @spec compact_group(Group, NewGroup) -> ok
...30 compact_group(Group, EmptyGroup) ->
...31     #group{
...32         current_seq = Seq,
...33         id_btree = IdBtree,
...34         name = GroupId,
...35         views = Views
...36     } = Group,
...37 
...38     #group{
...39         db = Db,
...40         id_btree = EmptyIdBtree,
...41         views = EmptyViews
...42     } = EmptyGroup,
...43 
...44     {ok, {Count, _}} = couch_btree:full_reduce(Db#db.fulldocinfo_by_id_btree),
...45 
...46     <<"_design", ShortName/binary>> = GroupId,
...47     DbName = couch_db:name(Db),
...48     TaskName = <>,
...49     couch_task_status:add_task(<<"View Group Compaction">>, TaskName, <<"">>),
...50 
...51     Fun = fun(KV, {Bt, Acc, TotalCopied}) ->
...52         if TotalCopied rem 10000 == 0 ->
...53             couch_task_status:update("Copied ~p of ~p Ids (~p%)",
...54                 [TotalCopied, Count, (TotalCopied*100) div Count]),
...55             {ok, Bt2} = couch_btree:add(Bt, lists:reverse([KV|Acc])),
...56             {ok, {Bt2, [], TotalCopied+1}};
...57         true ->
...58             {ok, {Bt, [KV|Acc], TotalCopied+1}}
...59         end
...60     end,
...61     {ok, {Bt3, Uncopied, _Total}} = couch_btree:foldl(IdBtree, Fun,
...62         {EmptyIdBtree, [], 0}),
...63     {ok, NewIdBtree} = couch_btree:add(Bt3, lists:reverse(Uncopied)),
...64 
...65     NewViews = lists:map(fun({View, EmptyView}) ->
...66         compact_view(View, EmptyView)
...67     end, lists:zip(Views, EmptyViews)),
...68 
...69     NewGroup = EmptyGroup#group{
...70         id_btree=NewIdBtree,
...71         views=NewViews,
...72         current_seq=Seq
...73     },
...74 
...75     Pid = couch_view:get_group_server(DbName, GroupId),
...76     gen_server:cast(Pid, {compact_done, NewGroup}).
...77 
...78 %% @spec compact_view(View, EmptyView, Retry) -> CompactView
...79 compact_view(View, EmptyView) ->
...80     {ok, Count} = couch_view:get_row_count(View),
...81 
...82     %% Key is {Key,DocId}
...83     Fun = fun(KV, {Bt, Acc, TotalCopied}) ->
...84         if TotalCopied rem 10000 == 0 ->
...85             couch_task_status:update("View #~p: copied ~p of ~p KVs (~p%)",
...86                 [View#view.id_num, TotalCopied, Count, (TotalCopied*100) div Count]),
...87             {ok, Bt2} = couch_btree:add(Bt, lists:reverse([KV|Acc])),
...88             {ok, {Bt2, [], TotalCopied + 1}};
...89         true ->
...90             {ok, {Bt, [KV|Acc], TotalCopied + 1}}
...91         end
...92     end,
...93 
...94     {ok, {Bt3, Uncopied, _Total}} = couch_btree:foldl(View#view.btree, Fun,
...95         {EmptyView#view.btree, [], 0}),
...96     {ok, NewBt} = couch_btree:add(Bt3, lists:reverse(Uncopied)),
...97     EmptyView#view{btree = NewBt}.
...98 

Generated using etap 0.3.4.