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 2020/02/10 22:39:35 UTC

[couchdb] 01/02: fixup: add size tracking

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

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

commit b728bceacf5c46df1fe294f6d54fb8752154db1b
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Mon Feb 10 16:41:33 2020 -0600

    fixup: add size tracking
---
 src/fabric/src/fabric2_fdb.erl  | 17 +++--------------
 src/fabric/src/fabric2_util.erl | 33 ++++++++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 15 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 8d8616d..d5be6d7 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -1317,24 +1317,13 @@ local_doc_to_fdb(Db, #doc{} = Doc) ->
         {{K, Chunk}, ChunkId + 1}
     end, 0, chunkify_binary(BVal)),
 
-    % Calculate size
-    TotalSize = case Doc#doc.deleted of
-        true ->
-            0;
-        false ->
-            lists:sum([
-                size(Id),
-                size(StoreRev),
-                couch_ejson_size:encoded_size(Body)
-            ])
-    end,
-
-    RawValue = erlfdb_tuple:pack({?CURR_LDOC_FORMAT, StoreRev, TotalSize}),
+    NewSize = fabric2_util:ldoc_size(Doc),
+    RawValue = erlfdb_tuple:pack({?CURR_LDOC_FORMAT, StoreRev, NewSize}),
 
     % Prefix our tuple encoding to make upgrades easier
     Value = <<255, RawValue/binary>>,
 
-    {Key, Value, TotalSize, Rows}.
+    {Key, Value, NewSize, Rows}.
 
 
 fdb_to_local_doc(_Db, _DocId, not_found, []) ->
diff --git a/src/fabric/src/fabric2_util.erl b/src/fabric/src/fabric2_util.erl
index 0f75390..766441c 100644
--- a/src/fabric/src/fabric2_util.erl
+++ b/src/fabric/src/fabric2_util.erl
@@ -18,6 +18,7 @@
     revinfo_to_path/1,
     sort_revinfos/1,
     rev_size/1,
+    ldoc_size/1,
 
     seq_zero_vs/0,
     seq_max_vs/0,
@@ -82,11 +83,16 @@ rev_sort_key(#{} = RevInfo) ->
 rev_size(#doc{} = Doc) ->
     #doc{
         id = Id,
-        revs = {Start, [Rev | _]},
+        revs = Revs,
         body = Body,
         atts = Atts
     } = Doc,
 
+    {Start, Rev} = case Revs of
+        {0, []} -> {0, <<>>};
+        {N, [RevId | _]} -> {N, RevId}
+    end,
+
     lists:sum([
         size(Id),
         size(erlfdb_tuple:pack({Start})),
@@ -99,6 +105,31 @@ rev_size(#doc{} = Doc) ->
     ]).
 
 
+ldoc_size(#doc{id = <<"_local/">>} = Doc) ->
+    #doc{
+        id = Id,
+        revs = {0, [Rev]},
+        deleted = Deleted,
+        body = Body
+    } = Doc,
+
+    StoreRev = case Rev of
+        _ when is_integer(Rev) -> integer_to_binary(Rev);
+        _ when is_binary(Rev) -> Rev
+    end,
+
+    case Deleted of
+        true ->
+            0;
+        false ->
+            lists:sum([
+                size(Id),
+                size(StoreRev),
+                couch_ejson_size:encoded_size(Body)
+            ])
+    end.
+
+
 seq_zero_vs() ->
     {versionstamp, 0, 0, 0}.