diff options
author | Robert Dionne <bob@cloudant.com> | 2011-04-19 12:06:37 -0400 |
---|---|---|
committer | Adam Kocoloski <adam@cloudant.com> | 2011-04-19 13:09:18 -0400 |
commit | a9410e622d84c4b6c017d16ea600e9b19e306c59 (patch) | |
tree | 6d5ff8a1a10fef103594072b50d55990ccc43607 /apps/couch/src/couch_view_group.erl | |
parent | 663d04f907ba0f8e23bab0eb2492c431246974fa (diff) |
Track and report size of live data in DBs and views
The #full_doc_info record is extended to include the summed size of
leaf revision document bodies and their attachments. Document sizes
are computed on update; accurate sizes of existing databases and
view groups are only available after compaction.
The document size is defined to be the size of the binary
representation of #doc.body. The att_len field is used for
attachments; attachments that are shared by multiple revisions of a
document are only counted once. The size of a view index is defined as
the size of all keys, values, and reductions accessible from the current
root of the tree.
BugzID: 9995
Diffstat (limited to 'apps/couch/src/couch_view_group.erl')
-rw-r--r-- | apps/couch/src/couch_view_group.erl | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/apps/couch/src/couch_view_group.erl b/apps/couch/src/couch_view_group.erl index b0e67db5..de64ef51 100644 --- a/apps/couch/src/couch_view_group.erl +++ b/apps/couch/src/couch_view_group.erl @@ -466,6 +466,7 @@ get_group_info(State) -> fd = Fd, sig = GroupSig, def_lang = Lang, + views = Views, current_seq=CurrentSeq, purge_seq=PurgeSeq } = Group, @@ -474,6 +475,7 @@ get_group_info(State) -> {signature, ?l2b(hex_sig(GroupSig))}, {language, Lang}, {disk_size, Size}, + {data_size, compute_data_size(Views)}, {updater_running, UpdaterPid /= nil}, {compact_running, CompactorPid /= nil}, {waiting_commit, WaitingCommit}, @@ -482,6 +484,13 @@ get_group_info(State) -> {purge_seq, PurgeSeq} ]. +compute_data_size(ViewList) -> + lists:foldl(fun(#view{btree=Btree}, Acc) -> + {ok, {_, _, Size}} = couch_btree:full_reduce(Btree), + Size + Acc + end, 0, ViewList). + + % maybe move to another module design_doc_to_view_group(#doc{id=Id,body={Fields}}) -> Language = couch_util:get_value(<<"language">>, Fields, <<"javascript">>), @@ -563,13 +572,14 @@ init_group(Fd, #group{def_lang=Lang,views=Views}=Group, IndexHeader) -> KVs3 = couch_view:detuple_kvs(KVs2,[]), {ok, Reduced} = couch_query_servers:reduce(Lang, FunSrcs, KVs3), - {length(KVs3), Reduced}; + {length(KVs3), Reduced, couch_view:data_size(KVs3, Reduced)}; (rereduce, Reds) -> - Count = lists:sum([Count0 || {Count0, _} <- Reds]), - UserReds = [UserRedsList || {_, UserRedsList} <- Reds], + Count = lists:sum(extract(Reds, counts)), + DataSize = lists:sum(extract(Reds, data_size)), + UserReds = extract(Reds, user_reds), {ok, Reduced} = couch_query_servers:rereduce(Lang, FunSrcs, UserReds), - {Count, Reduced} + {Count, Reduced, DataSize} end, case couch_util:get_value(<<"collation">>, Options, <<"default">>) of @@ -585,3 +595,10 @@ init_group(Fd, #group{def_lang=Lang,views=Views}=Group, IndexHeader) -> ViewStates, Views), Group#group{fd=Fd, current_seq=Seq, purge_seq=PurgeSeq, id_btree=IdBtree, views=Views2}. + +extract(Reds, counts) -> + [element(1, R) || R <- Reds]; +extract(Reds, user_reds) -> + [element(2, R) || R <- Reds]; +extract(Reds, data_size) -> + lists:map(fun({_, _}) -> 0; ({_, _, Size}) -> Size end, Reds). |