diff options
author | Nick Vatamaniuc <vatamane@gmail.com> | 2022-11-12 22:29:49 -0500 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2022-11-13 09:13:19 +0100 |
commit | eddb6365bc871ba072951361422d98ef69320f52 (patch) | |
tree | 1e9360449d548988ecd21d07abb6744e6146fc32 | |
parent | c5fb0948065ab9eb484152cd0a04e1e031154ffc (diff) | |
download | couchdb-eddb6365bc871ba072951361422d98ef69320f52.tar.gz |
Update active db size calculation to use only leaf nodes
Previously it used both leaf and intermediate nodes.
With this PR active db size should decrease when users delete documents. This,
in turn, should make smoosh enqueue those dbs for compaction to recover the
disk space used by the now deleted document bodies. Previously, it was possible
for users to delete gigabytes worth of document bodies and smoosh never
noticing and never triggering the compaction.
Original idea and patch provided by Robert Newson in CouchDB dev Slack
discussion channel.
Co-authored-by: Robert Newson <rnewson@apache.org>
Fixes: https://github.com/apache/couchdb/issues/4263
-rw-r--r-- | src/couch/src/couch_db_updater.erl | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl index 0248c21ec..fac5aee10 100644 --- a/src/couch/src/couch_db_updater.erl +++ b/src/couch/src/couch_db_updater.erl @@ -440,7 +440,7 @@ check_doc_atts(Db, Doc) -> end end. -add_sizes(Type, #leaf{sizes = Sizes, atts = AttSizes}, Acc) -> +add_sizes(leaf, #leaf{sizes = Sizes, atts = AttSizes}, Acc) -> % Maybe upgrade from disk_size only #size_info{ active = ActiveSize, @@ -448,14 +448,13 @@ add_sizes(Type, #leaf{sizes = Sizes, atts = AttSizes}, Acc) -> } = upgrade_sizes(Sizes), {ASAcc, ESAcc, AttsAcc} = Acc, NewASAcc = ActiveSize + ASAcc, - NewESAcc = - ESAcc + - if - Type == leaf -> ExternalSize; - true -> 0 - end, + NewESAcc = ExternalSize + ESAcc, NewAttsAcc = lists:umerge(AttSizes, AttsAcc), - {NewASAcc, NewESAcc, NewAttsAcc}. + {NewASAcc, NewESAcc, NewAttsAcc}; +add_sizes(_, #leaf{atts = AttSizes}, Acc) -> + % For intermediate nodes external and active contribution is 0 + {ASAcc, ESAcc, AttsAcc} = Acc, + {ASAcc, ESAcc, lists:umerge(AttSizes, AttsAcc)}. upgrade_sizes(#size_info{} = SI) -> SI; |