couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [couchdb] 01/03: Add get_size_info by partition
Date Thu, 13 Sep 2018 20:10:36 GMT
This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch user-partitioned-dbs-6
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 400632ea943b71da0a7864732e0918f7e9c891fb
Author: Robert Newson <rnewson@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 ->


Mime
View raw message