diff options
author | Jay Doane <jaydoane@apache.org> | 2020-02-20 01:41:33 -0800 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2020-03-02 12:26:22 -0600 |
commit | d2a670bb4affe965dc806e6f7dac4adffd0648bf (patch) | |
tree | 30817d2f20a78a957dec320ba2e7a1765c74207f | |
parent | 42062b6b2de1e00f41a9ba528653d2f06fcc62f9 (diff) | |
download | couchdb-d2a670bb4affe965dc806e6f7dac4adffd0648bf.tar.gz |
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`
-rw-r--r-- | src/fabric/src/fabric2_fdb.erl | 32 | ||||
-rw-r--r-- | 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 c18122533..ed4371a55 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 7c88b4ac4..42a63e2f9 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. |