You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2018/09/18 08:27:39 UTC
[couchdb] 21/22: Add get_size_info by partition
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch user-partitioned-dbs-7
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit f5d4eaf44efa78dca505578162ad98cc4034de41
Author: Robert Newson <rn...@apache.org>
AuthorDate: Wed Sep 12 19:10:34 2018 +0100
Add get_size_info by partition
---
src/couch/src/couch_bt_engine.erl | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl
index 6748e98..bc2d2c1 100644
--- a/src/couch/src/couch_bt_engine.erl
+++ b/src/couch/src/couch_bt_engine.erl
@@ -43,6 +43,7 @@
get_prop/2,
get_prop/3,
get_size_info/1,
+ get_size_info/2,
get_update_seq/1,
get_uuid/1,
@@ -262,6 +263,43 @@ get_size_info(#st{} = St) ->
].
+partition_size_cb(traverse, Key, {_, _, Sizes}, {Partition, Acc}) ->
+ case in_partition(Key, Partition) of
+ true ->
+ {skip, {Partition, reduce_sizes(Sizes, Acc)}};
+ false ->
+ {ok, {Partition, Acc}}
+ end;
+
+
+partition_size_cb(visit, FDI, _PrevReds, {Partition, Acc}) ->
+ case in_partition(FDI#full_doc_info.id, Partition) of
+ true ->
+ {ok, {Partition, reduce_sizes(FDI#full_doc_info.sizes, Acc)}};
+ false ->
+ {ok, {Partition, Acc}}
+ end.
+
+
+get_size_info(#st{} = St, Partition) ->
+ StartKey = <<Partition/binary, ":">>,
+ EndKey = <<Partition/binary, ";">>,
+ Fun = fun partition_size_cb/4,
+ InitAcc = {Partition, #size_info{}},
+ Options = [{start_key, StartKey}, {end_key, EndKey}],
+ {ok, _, OutAcc} = couch_btree:fold(St#st.id_tree, Fun, InitAcc, Options),
+ {_, SizeInfo} = OutAcc,
+ [
+ {active, SizeInfo#size_info.active},
+ {external, SizeInfo#size_info.external}
+ ].
+
+
+in_partition(DocId, Partition0) ->
+ [Partition1, _Id] = binary:split(DocId, <<":">>),
+ Partition0 == Partition1.
+
+
get_security(#st{header = Header} = St) ->
case couch_bt_engine_header:get(Header, security_ptr) of
undefined ->