diff options
author | Robert Newson <rnewson@apache.org> | 2018-09-12 19:10:34 +0100 |
---|---|---|
committer | Robert Newson <rnewson@apache.org> | 2018-10-08 09:51:20 +0100 |
commit | 1f35605d98d416d52225e994e43c02e8a91eca03 (patch) | |
tree | 29cbbb541be6b2137c24f81ca2f48c73f8b39554 | |
parent | eae0d06c21f7a72205fef4f35722ef06aa1c4bcd (diff) | |
download | couchdb-1f35605d98d416d52225e994e43c02e8a91eca03.tar.gz |
Add get_partition_info/2
-rw-r--r-- | src/couch/src/couch_bt_engine.erl | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl index abeaeaaa7..f9f8b7b72 100644 --- a/src/couch/src/couch_bt_engine.erl +++ b/src/couch/src/couch_bt_engine.erl @@ -44,6 +44,7 @@ get_prop/2, get_prop/3, get_size_info/1, + get_partition_info/2, get_update_seq/1, get_uuid/1, @@ -279,6 +280,52 @@ get_size_info(#st{} = St) -> ]. +partition_size_cb(traverse, Key, {DC, DDC, Sizes}, {Partition, DCAcc, DDCAcc, SizesAcc}) -> + case in_partition(Key, Partition) of + true -> + {skip, {Partition, DC + DCAcc, DDC + DDCAcc, reduce_sizes(Sizes, SizesAcc)}}; + false -> + {ok, {Partition, DCAcc, DDCAcc, SizesAcc}} + end; + + +partition_size_cb(visit, FDI, _PrevReds, {Partition, DCAcc, DDCAcc, Acc}) -> + InPartition = in_partition(FDI#full_doc_info.id, Partition), + Deleted = FDI#full_doc_info.deleted, + case {InPartition, Deleted} of + {true, true} -> + {ok, {Partition, DCAcc, DDCAcc + 1, + reduce_sizes(FDI#full_doc_info.sizes, Acc)}}; + {true, false} -> + {ok, {Partition, DCAcc + 1, DDCAcc, + reduce_sizes(FDI#full_doc_info.sizes, Acc)}}; + {false, _} -> + {ok, {Partition, DCAcc, DDCAcc, Acc}} + end. + + +get_partition_info(#st{} = St, Partition) -> + StartKey = <<Partition/binary, ":">>, + EndKey = <<Partition/binary, ";">>, + Fun = fun partition_size_cb/4, + InitAcc = {Partition, 0, 0, #size_info{}}, + Options = [{start_key, StartKey}, {end_key, EndKey}], + {ok, _, OutAcc} = couch_btree:fold(St#st.id_tree, Fun, InitAcc, Options), + {Partition, DocCount, DocDelCount, SizeInfo} = OutAcc, + [ + {partition, Partition}, + {doc_count, DocCount}, + {doc_del_count, DocDelCount}, + {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 -> |