You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2019/08/06 17:51:14 UTC

[couchdb] branch prototype/fdb-layer updated: Remember to remove old doc bodies

This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/prototype/fdb-layer by this push:
     new acfe3fa  Remember to remove old doc bodies
acfe3fa is described below

commit acfe3fac208c3e7b08069bc2ce11edcbcb329708
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Aug 6 12:50:53 2019 -0500

    Remember to remove old doc bodies
---
 src/fabric/src/fabric2_fdb.erl | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index b10c357..3f02e6a 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -509,7 +509,8 @@ write_doc(#{} = Db0, Doc, NewWinner0, OldWinner, ToUpdate, ToRemove) ->
     lists:foreach(fun(RI0) ->
         RI = RI0#{winner := false},
         {K, _, undefined} = revinfo_to_fdb(Tx, DbPrefix, DocId, RI),
-        ok = erlfdb:clear(Tx, K)
+        ok = erlfdb:clear(Tx, K),
+        ok = clear_doc_body(Db, DocId, RI0)
     end, ToRemove),
 
     % _all_docs
@@ -835,6 +836,25 @@ write_doc_body(#{} = Db0, #doc{} = Doc) ->
     end, doc_to_fdb(Db, Doc)).
 
 
+clear_doc_body(_Db, _DocId, not_found) ->
+    % No old body to clear
+    ok;
+
+clear_doc_body(#{} = Db, DocId, #{} = RevInfo) ->
+    #{
+        tx := Tx,
+        db_prefix := DbPrefix
+    } = Db,
+
+    #{
+        rev_id := {RevPos, Rev}
+    } = RevInfo,
+
+    BaseKey = {?DB_DOCS, DocId, RevPos, Rev},
+    {StartKey, EndKey} = erlfdb_tuple:range(BaseKey, DbPrefix),
+    ok = erlfdb:clear_range(Tx, StartKey, EndKey).
+
+
 revinfo_to_fdb(Tx, DbPrefix, DocId, #{winner := true} = RevId) ->
     #{
         deleted := Deleted,
@@ -911,6 +931,9 @@ doc_to_fdb(Db, #doc{} = Doc) ->
     Rows.
 
 
+fdb_to_doc(_Db, _DocId, _Pos, _Path, []) ->
+    {not_found, missing};
+
 fdb_to_doc(Db, DocId, Pos, Path, BinRows) when is_list(BinRows) ->
     Bin = iolist_to_binary(BinRows),
     {Body, DiskAtts, Deleted} = binary_to_term(Bin, [safe]),
@@ -928,10 +951,7 @@ fdb_to_doc(Db, DocId, Pos, Path, BinRows) when is_list(BinRows) ->
     case Db of
         #{after_doc_read := undefined} -> Doc0;
         #{after_doc_read := ADR} -> ADR(Doc0, Db)
-    end;
-
-fdb_to_doc(_Db, _DocId, _Pos, _Path, not_found) ->
-    {not_found, missing}.
+    end.
 
 
 local_doc_to_fdb(Db, #doc{} = Doc) ->