summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Doane <jaydoane@apache.org>2020-02-18 02:38:41 -0800
committerJay Doane <jaydoane@apache.org>2020-02-18 02:38:41 -0800
commita9c12c73420870489dbb79efabb5b4338ba96fb9 (patch)
treea3bd3b3743a9ac0d0df97ddf6c12dff9f3b1491c
parent3c35e6b2b79c2b8561e8dc95160d268d9ced8f92 (diff)
downloadcouchdb-fdb_to_rev_info-compatibility.tar.gz
Add fdb_to_revinfo compatibility with 5-tuple Valfdb_to_rev_info-compatibility
Currently, a 5-tuple `Val` parameter crashes fdb_to_revinfo with a function_clause. This adds a compatible function clause, and also a catchall clause to log and throw an informative exception.
-rw-r--r--src/fabric/src/fabric2_fdb.erl24
-rw-r--r--src/fabric/test/fabric2_db_misc_tests.erl38
2 files changed, 61 insertions, 1 deletions
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index cf732447c..48f56a5f9 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,
@@ -1288,6 +1290,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,
@@ -1317,7 +1334,12 @@ 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~nkey=~p val=~p",
+ [?MODULE, Key, 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 c48ee2c73..a81a426d0 100644
--- a/src/fabric/test/fabric2_db_misc_tests.erl
+++ b/src/fabric/test/fabric2_db_misc_tests.erl
@@ -30,6 +30,7 @@ misc_test_() ->
with([
?TDEF(empty_db_info),
?TDEF(accessors),
+ ?TDEF(fdb_to_revinfo),
?TDEF(set_revs_limit),
?TDEF(set_security),
?TDEF(is_system_db),
@@ -325,3 +326,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-a7287d7b0780-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.