You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2020/02/24 23:01:58 UTC

[couchdb] branch prototype/fdb-layer updated (af69ab5 -> 2c12d81)

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

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


    from af69ab5  Do not use the ddoc cache to load _changes filter design documents
     new 89c7983  Add fdb_to_revinfo compatibility with 5-tuple Val
     new ae4abe8  Fix bug in fdb_to_revinfo compatibility clauses
     new 2c12d81  Add fdb_to_revinfo version compatibility unit test

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/fabric/src/fabric2_fdb.erl | 50 ++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 48 insertions(+), 2 deletions(-)


[couchdb] 01/03: Add fdb_to_revinfo compatibility with 5-tuple Val

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 89c7983a2a34514024bf0eb2b5af6e1c7497e58a
Author: Jay Doane <ja...@apache.org>
AuthorDate: Tue Feb 18 21:40:32 2020 -0800

    Add fdb_to_revinfo compatibility with 5-tuple Val
    
    Currently, a 5-tuple `Val` parameter crashes fdb_to_revinfo with a
    function_clause error.
    
    This adds a compatible function clause, and also a catchall clause to
    log an error and throw an informative exception.
---
 src/fabric/src/fabric2_fdb.erl            | 26 +++++++++++++++++++++-
 src/fabric/test/fabric2_db_misc_tests.erl | 37 +++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index e51b8de..c181225 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -38,6 +38,8 @@
     incr_stat/3,
     incr_stat/4,
 
+    fdb_to_revinfo/2,
+
     get_all_revs/2,
     get_winning_revs/3,
     get_winning_revs_future/3,
@@ -1253,6 +1255,21 @@ fdb_to_revinfo(Key, {?CURR_REV_FORMAT, _, _, _, _, _} = Val) ->
         rev_size => RevSize
     };
 
+fdb_to_revinfo(Key, {?CURR_REV_FORMAT, _, _, _, _} = Val) ->
+    {?DB_REVS, _DocId, NotDeleted, RevPos, Rev} = Key,
+    {_RevFormat, Sequence, RevSize, RevPath, AttHash} = Val,
+    #{
+        winner => true,
+        exists => true,
+        deleted => not NotDeleted,
+        rev_id => {RevPos, Rev},
+        rev_path => tuple_to_list(RevPath),
+        sequence => Sequence,
+        branch_count => undefined,
+        att_hash => AttHash,
+        rev_size => RevSize
+    };
+
 fdb_to_revinfo(Key, {?CURR_REV_FORMAT, _, _, _} = Val)  ->
     {?DB_REVS, _DocId, NotDeleted, RevPos, Rev} = Key,
     {_RevFormat, RevPath, AttHash, RevSize} = Val,
@@ -1282,7 +1299,14 @@ fdb_to_revinfo(Key, {1, Seq, BCount, RPath, AttHash}) ->
 
 fdb_to_revinfo(Key, {1, RPath, AttHash}) ->
     Val = {?CURR_REV_FORMAT, RPath, AttHash, 0},
-    fdb_to_revinfo(Key, Val).
+    fdb_to_revinfo(Key, Val);
+
+fdb_to_revinfo(Key, Val) ->
+    couch_log:error(
+        "~p:fdb_to_revinfo unsupported val format "
+        "rev_format=~p key_size=~p val_size=~p",
+        [?MODULE, element(1, Val), tuple_size(Key), tuple_size(Val)]),
+    throw({unsupported_data_format, fdb_to_revinfo_val}).
 
 
 doc_to_fdb(Db, #doc{} = Doc) ->
diff --git a/src/fabric/test/fabric2_db_misc_tests.erl b/src/fabric/test/fabric2_db_misc_tests.erl
index 42a63e2..7c88b4a 100644
--- a/src/fabric/test/fabric2_db_misc_tests.erl
+++ b/src/fabric/test/fabric2_db_misc_tests.erl
@@ -333,3 +333,40 @@ db_version_bump({DbName, _, _}) ->
 
     % Check that db handle in the cache got the new metadata version
     ?assertMatch(#{db_version := NewDbVersion}, Db2).
+
+
+fdb_to_revinfo_test_() ->
+    {
+        "Test fdb_to_revinfo compatibility",
+        {
+            setup,
+            fun() -> ok end,
+            fun(_) -> ok end,
+            with([
+                ?TDEF(fdb_to_revinfo)
+            ])
+        }
+    }.
+
+
+fdb_to_revinfo(_) ->
+    Sequence = {versionstamp, 10873034897377, 0, 0},
+    Rev = <<60,84,174,140,210,120,192,18,100,148,9,181,129,165,248,92>>,
+    Key = {20, <<"d491280e-feab-42ce-909e-a7287d7b078-bluemix">>, true, 1, Rev},
+    FiveTupleVal = {2, Sequence, 1, {}, <<>>},
+    Expect = #{
+        att_hash => <<>>,
+        branch_count => undefined,
+        deleted => false,
+        exists => true,
+        rev_id =>
+            {1, <<60,84,174,140,210,120,192,18,100,148,9,181,129,165,248,92>>},
+        rev_path => [],
+        rev_size => 1,
+        sequence => Sequence,
+        winner => true
+    },
+    ?assertEqual(Expect, fabric2_fdb:fdb_to_revinfo(Key, FiveTupleVal)),
+    ?assertThrow({unsupported_data_format, fdb_to_revinfo_val},
+        fabric2_fdb:fdb_to_revinfo({bad}, {input})),
+    ok.


[couchdb] 03/03: Add fdb_to_revinfo version compatibility unit test

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2c12d81427a6a3369e40ac3d3e9c05439b65f2bd
Author: Jay Doane <ja...@apache.org>
AuthorDate: Thu Feb 20 15:09:49 2020 -0800

    Add fdb_to_revinfo version compatibility unit test
    
    This test adds coverage for the 4 fdb_to_revinfo compatibility clauses,
    and will help ensure any additional future clauses will not break
    backwards compatibility.
    
    Module coverage without this test:
    fabric2_fdb                    :  92%
    
    Module coverage with this test:
    fabric2_fdb                    :  94%
---
 src/fabric/src/fabric2_fdb.erl | 44 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index ed4371a..c34b33c 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -1746,3 +1746,47 @@ with_span(Operation, ExtraTags, Fun) ->
         false ->
             Fun()
     end.
+
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+fdb_to_revinfo_version_compatibility_test() ->
+    DocId = <<"doc_id">>,
+    FirstRevFormat = 0,
+    RevPos = 1,
+    Rev = <<60,84,174,140,210,120,192,18,100,148,9,181,129,165,248,92>>,
+    RevPath = {},
+    NotDeleted = true,
+    Sequence = {versionstamp, 10873034897377, 0, 0},
+    BranchCount = 1,
+
+    KeyWinner = {?DB_REVS, DocId, NotDeleted, RevPos, Rev},
+    ValWinner = {FirstRevFormat, Sequence, BranchCount, RevPath},
+    ExpectedWinner = expected(
+        true, BranchCount, NotDeleted, RevPos, Rev, RevPath, Sequence),
+    ?assertEqual(ExpectedWinner, fdb_to_revinfo(KeyWinner, ValWinner)),
+
+    KeyLoser = {?DB_REVS, DocId, NotDeleted, RevPos, Rev},
+    ValLoser = {FirstRevFormat, RevPath},
+    ExpectedLoser = expected(
+        false, undefined, NotDeleted, RevPos, Rev, RevPath, undefined),
+    ?assertEqual(ExpectedLoser, fdb_to_revinfo(KeyLoser, ValLoser)),
+    ok.
+
+
+expected(Winner, BranchCount, NotDeleted, RevPos, Rev, RevPath, Sequence) ->
+    #{
+        att_hash => <<>>,
+        branch_count => BranchCount,
+        deleted => not NotDeleted,
+        exists => true,
+        rev_id => {RevPos, Rev},
+        rev_path => tuple_to_list(RevPath),
+        rev_size => 0,
+        sequence => Sequence,
+        winner => Winner
+    }.
+
+
+-endif.


[couchdb] 02/03: Fix bug in fdb_to_revinfo compatibility clauses

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ae4abe8f2b6dd23771ca1412caf2e53b1763990c
Author: Jay Doane <ja...@apache.org>
AuthorDate: Thu Feb 20 01:41:33 2020 -0800

    Fix bug in fdb_to_revinfo compatibility clauses
    
    A bug was introduced in https://github.com/apache/couchdb/commit/eb1a09e114dafc55fa9511d477b9ada4350134eb#diff-32274bcb4785f432811085d2e08c3580L1227
    when `CURR_REV_FORMAT` was bumped from `1->2`, but `?CURR_REV_FORMAT` in
    compatibility clauses going from format version `0->1` were left
    unchanged, when those values of `?CURR_REV_FORMAT` should have changed
    to `1`.
    
    This fixes the compatibility clauses for rev format versions from `0->1`
---
 src/fabric/src/fabric2_fdb.erl            | 32 +++++---------------------
 src/fabric/test/fabric2_db_misc_tests.erl | 37 -------------------------------
 2 files changed, 5 insertions(+), 64 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index c181225..ed4371a 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -38,8 +38,6 @@
     incr_stat/3,
     incr_stat/4,
 
-    fdb_to_revinfo/2,
-
     get_all_revs/2,
     get_winning_revs/3,
     get_winning_revs_future/3,
@@ -1255,21 +1253,6 @@ fdb_to_revinfo(Key, {?CURR_REV_FORMAT, _, _, _, _, _} = Val) ->
         rev_size => RevSize
     };
 
-fdb_to_revinfo(Key, {?CURR_REV_FORMAT, _, _, _, _} = Val) ->
-    {?DB_REVS, _DocId, NotDeleted, RevPos, Rev} = Key,
-    {_RevFormat, Sequence, RevSize, RevPath, AttHash} = Val,
-    #{
-        winner => true,
-        exists => true,
-        deleted => not NotDeleted,
-        rev_id => {RevPos, Rev},
-        rev_path => tuple_to_list(RevPath),
-        sequence => Sequence,
-        branch_count => undefined,
-        att_hash => AttHash,
-        rev_size => RevSize
-    };
-
 fdb_to_revinfo(Key, {?CURR_REV_FORMAT, _, _, _} = Val)  ->
     {?DB_REVS, _DocId, NotDeleted, RevPos, Rev} = Key,
     {_RevFormat, RevPath, AttHash, RevSize} = Val,
@@ -1286,27 +1269,22 @@ fdb_to_revinfo(Key, {?CURR_REV_FORMAT, _, _, _} = Val)  ->
     };
 
 fdb_to_revinfo(Key, {0, Seq, BCount, RPath}) ->
-    Val = {?CURR_REV_FORMAT, Seq, BCount, RPath, <<>>},
+    Val = {1, Seq, BCount, RPath, <<>>},
     fdb_to_revinfo(Key, Val);
 
 fdb_to_revinfo(Key, {0, RPath}) ->
-    Val = {?CURR_REV_FORMAT, RPath, <<>>},
+    Val = {1, RPath, <<>>},
     fdb_to_revinfo(Key, Val);
 
 fdb_to_revinfo(Key, {1, Seq, BCount, RPath, AttHash}) ->
+    % Don't forget to change ?CURR_REV_FORMAT to 2 here when it increments
     Val = {?CURR_REV_FORMAT, Seq, BCount, RPath, AttHash, 0},
     fdb_to_revinfo(Key, Val);
 
 fdb_to_revinfo(Key, {1, RPath, AttHash}) ->
+    % Don't forget to change ?CURR_REV_FORMAT to 2 here when it increments
     Val = {?CURR_REV_FORMAT, RPath, AttHash, 0},
-    fdb_to_revinfo(Key, Val);
-
-fdb_to_revinfo(Key, Val) ->
-    couch_log:error(
-        "~p:fdb_to_revinfo unsupported val format "
-        "rev_format=~p key_size=~p val_size=~p",
-        [?MODULE, element(1, Val), tuple_size(Key), tuple_size(Val)]),
-    throw({unsupported_data_format, fdb_to_revinfo_val}).
+    fdb_to_revinfo(Key, Val).
 
 
 doc_to_fdb(Db, #doc{} = Doc) ->
diff --git a/src/fabric/test/fabric2_db_misc_tests.erl b/src/fabric/test/fabric2_db_misc_tests.erl
index 7c88b4a..42a63e2 100644
--- a/src/fabric/test/fabric2_db_misc_tests.erl
+++ b/src/fabric/test/fabric2_db_misc_tests.erl
@@ -333,40 +333,3 @@ db_version_bump({DbName, _, _}) ->
 
     % Check that db handle in the cache got the new metadata version
     ?assertMatch(#{db_version := NewDbVersion}, Db2).
-
-
-fdb_to_revinfo_test_() ->
-    {
-        "Test fdb_to_revinfo compatibility",
-        {
-            setup,
-            fun() -> ok end,
-            fun(_) -> ok end,
-            with([
-                ?TDEF(fdb_to_revinfo)
-            ])
-        }
-    }.
-
-
-fdb_to_revinfo(_) ->
-    Sequence = {versionstamp, 10873034897377, 0, 0},
-    Rev = <<60,84,174,140,210,120,192,18,100,148,9,181,129,165,248,92>>,
-    Key = {20, <<"d491280e-feab-42ce-909e-a7287d7b078-bluemix">>, true, 1, Rev},
-    FiveTupleVal = {2, Sequence, 1, {}, <<>>},
-    Expect = #{
-        att_hash => <<>>,
-        branch_count => undefined,
-        deleted => false,
-        exists => true,
-        rev_id =>
-            {1, <<60,84,174,140,210,120,192,18,100,148,9,181,129,165,248,92>>},
-        rev_path => [],
-        rev_size => 1,
-        sequence => Sequence,
-        winner => true
-    },
-    ?assertEqual(Expect, fabric2_fdb:fdb_to_revinfo(Key, FiveTupleVal)),
-    ?assertThrow({unsupported_data_format, fdb_to_revinfo_val},
-        fabric2_fdb:fdb_to_revinfo({bad}, {input})),
-    ok.