summaryrefslogtreecommitdiff
path: root/apps/couch/src/couch_view.erl
diff options
context:
space:
mode:
authorRobert Dionne <bob@cloudant.com>2011-04-19 12:06:37 -0400
committerAdam Kocoloski <adam@cloudant.com>2011-04-19 13:09:18 -0400
commita9410e622d84c4b6c017d16ea600e9b19e306c59 (patch)
tree6d5ff8a1a10fef103594072b50d55990ccc43607 /apps/couch/src/couch_view.erl
parent663d04f907ba0f8e23bab0eb2492c431246974fa (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.erl')
-rw-r--r--apps/couch/src/couch_view.erl11
1 files changed, 9 insertions, 2 deletions
diff --git a/apps/couch/src/couch_view.erl b/apps/couch/src/couch_view.erl
index 8dca17da..65a42c0b 100644
--- a/apps/couch/src/couch_view.erl
+++ b/apps/couch/src/couch_view.erl
@@ -18,7 +18,7 @@
code_change/3,get_reduce_view/4,get_temp_reduce_view/5,get_temp_map_view/4,
get_map_view/4,get_row_count/1,reduce_to_count/1,fold_reduce/4,
extract_map_view/1,get_group_server/2,get_group_info/2,
- cleanup_index_files/1,config_change/2]).
+ cleanup_index_files/1,config_change/2, data_size/2]).
-include("couch_db.hrl").
@@ -102,7 +102,7 @@ list_index_files(Db) ->
get_row_count(#view{btree=Bt}) ->
- {ok, {Count, _Reds}} = couch_btree:full_reduce(Bt),
+ {ok, {Count, _, _}} = couch_btree:full_reduce(Bt),
{ok, Count}.
get_temp_reduce_view(Db, Language, DesignOptions, MapSrc, RedSrc) ->
@@ -150,6 +150,13 @@ expand_dups([{Key, {dups, Vals}} | Rest], Acc) ->
expand_dups([KV | Rest], Acc) ->
expand_dups(Rest, [KV | Acc]).
+data_size(KVList, Reduction) ->
+ lists:foldl(fun([[Key, _], Value], Acc) ->
+ size(term_to_binary(Key)) +
+ size(term_to_binary(Value)) +
+ Acc
+ end,size(term_to_binary(Reduction)),KVList).
+
fold_reduce({temp_reduce, #view{btree=Bt}}, Fun, Acc, Options) ->
WrapperFun = fun({GroupedKey, _}, PartialReds, Acc0) ->
{_, [Red]} = couch_btree:final_reduce(Bt, PartialReds),