Add cluster support for new size calculations
This adds the cluster aggregation of database and view size information.
Now that we have three values they're nested under a single "sizes" key.
COUCHDB-2001
diff --git a/src/fabric_db_info.erl b/src/fabric_db_info.erl
index 58139e8..24fc44d 100644
--- a/src/fabric_db_info.erl
+++ b/src/fabric_db_info.erl
@@ -84,6 +84,8 @@
[{disk_size, lists:sum(X)} | Acc];
(other, X, Acc) ->
[{other, {merge_other_results(X)}} | Acc];
+ (sizes, X, Acc) ->
+ [{sizes, {fabric_util:merge_size_objects(X)}} | Acc];
(disk_format_version, X, Acc) ->
[{disk_format_version, lists:max(X)} | Acc];
(_, _, Acc) ->
diff --git a/src/fabric_group_info.erl b/src/fabric_group_info.erl
index 135090f..5da94fd 100644
--- a/src/fabric_group_info.erl
+++ b/src/fabric_group_info.erl
@@ -81,6 +81,8 @@
[{disk_size, lists:sum(X)} | Acc];
(data_size, X, Acc) ->
[{data_size, lists:sum(X)} | Acc];
+ (sizes, X, Acc) ->
+ [{sizes, {fabric_util:merge_size_objects(X)}} | Acc];
(compact_running, X, Acc) ->
[{compact_running, lists:member(true, X)} | Acc];
(updater_running, X, Acc) ->
diff --git a/src/fabric_util.erl b/src/fabric_util.erl
index a6982f3..e58a321 100644
--- a/src/fabric_util.erl
+++ b/src/fabric_util.erl
@@ -16,6 +16,7 @@
update_counter/3, remove_ancestors/2, create_monitors/1, kv/2,
remove_down_workers/2]).
-export([request_timeout/0]).
+-export([merge_size_objects/1]).
-include_lib("fabric/include/fabric.hrl").
-include_lib("mem3/include/mem3.hrl").
@@ -141,6 +142,28 @@
MonRefs = lists:usort([{rexi_server, N} || #shard{node=N} <- Shards]),
rexi_monitor:start(MonRefs).
+% This is used to merge the new size objects found in database
+% and view info blobs for clustered calls.
+merge_size_objects(SizeObjects) ->
+ Dict = lists:foldl(fun({Props}, D) ->
+ lists:foldl(fun({K, V}, D0) ->
+ orddict:append(K, V, D0)
+ end, D, Props)
+ end, orddict:new(), SizeObjects),
+ orddict:fold(fun
+ (file, X, Acc) ->
+ [{file, lists:sum(X)} | Acc];
+ (active, X, Acc) ->
+ case lists:member(null, X) of
+ true ->
+ [{active, null} | Acc];
+ false ->
+ [{active, lists:sum(X)} | Acc]
+ end;
+ (external, X, Acc) ->
+ [{external, lists:sum(X)} | Acc]
+ end, [], Dict).
+
%% verify only id and rev are used in key.
update_counter_test() ->
Reply = {ok, #doc{id = <<"id">>, revs = <<"rev">>,