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 2017/09/12 20:09:05 UTC

[couchdb] 22/28: Fix compatibility with master local document revisions

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

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 013344a4f2fe5e77ec1aa19257bccb41f07d2bbb
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Wed May 31 18:17:17 2017 -0400

    Fix compatibility with master local document revisions
    
    Previously local doc revisions were integers. Keep them that way to allow
    downgrading back to previous CouchDB version.
---
 src/couch/src/couch_bt_engine.erl  | 15 +++++++--------
 src/couch/src/couch_db_updater.erl |  8 ++++----
 src/couch/src/test_engine_util.erl |  6 +++---
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/couch/src/couch_bt_engine.erl b/src/couch/src/couch_bt_engine.erl
index 798543e..b069067 100644
--- a/src/couch/src/couch_bt_engine.erl
+++ b/src/couch/src/couch_bt_engine.erl
@@ -600,26 +600,25 @@ seq_tree_reduce(rereduce, Reds) ->
     lists:sum(Reds).
 
 
-local_tree_split(#doc{} = Doc) ->
+local_tree_split(#doc{revs = {0, [Rev]}} = Doc) when is_binary(Rev) ->
     #doc{
         id = Id,
-        revs = {0, [Rev]},
         body = BodyData
     } = Doc,
-    {Id, {Rev, BodyData}}.
-
+    {Id, {binary_to_integer(Rev), BodyData}};
 
-local_tree_join(Id, {Rev, BodyData}) when is_binary(Rev) ->
+local_tree_split(#doc{revs = {0, [Rev]}} = Doc) when is_integer(Rev) ->
     #doc{
         id = Id,
-        revs = {0, [Rev]},
         body = BodyData
-    };
+    } = Doc,
+    {Id, {Rev, BodyData}}.
+
 
 local_tree_join(Id, {Rev, BodyData}) when is_integer(Rev) ->
     #doc{
         id = Id,
-        revs = {0, [list_to_binary(integer_to_list(Rev))]},
+        revs = {0, [integer_to_binary(Rev)]},
         body = BodyData
     }.
 
diff --git a/src/couch/src/couch_db_updater.erl b/src/couch/src/couch_db_updater.erl
index 4a8158f..904167c 100644
--- a/src/couch/src/couch_db_updater.erl
+++ b/src/couch/src/couch_db_updater.erl
@@ -674,17 +674,17 @@ update_local_doc_revs(Docs) ->
         } = NewDoc,
         case PrevRevs of
             [RevStr | _] ->
-                PrevRev = list_to_integer(?b2l(RevStr));
+                PrevRev = binary_to_integer(RevStr);
             [] ->
                 PrevRev = 0
         end,
         NewRev = case Delete of
             false ->
-                ?l2b(integer_to_list(PrevRev + 1));
+                PrevRev + 1;
             true  ->
-                <<"0">>
+                0
         end,
-        send_result(Client, NewDoc, {ok, {0, NewRev}}),
+        send_result(Client, NewDoc, {ok, {0, integer_to_binary(NewRev)}}),
         NewDoc#doc{
             revs = {0, [NewRev]}
         }
diff --git a/src/couch/src/test_engine_util.erl b/src/couch/src/test_engine_util.erl
index d19b7f1..c81acd0 100644
--- a/src/couch/src/test_engine_util.erl
+++ b/src/couch/src/test_engine_util.erl
@@ -161,13 +161,13 @@ gen_local_write(Engine, St, {Action, {DocId, Body}}) ->
         [#doc{revs = {0, []}}] ->
             0;
         [#doc{revs = {0, [RevStr | _]}}] ->
-            list_to_integer(binary_to_list(RevStr))
+            binary_to_integer(RevStr)
     end,
     {RevId, Deleted} = case Action of
         Action when Action == create; Action == update ->
-            {list_to_binary(integer_to_list(PrevRev + 1)), false};
+            {PrevRev + 1, false};
         delete ->
-            {<<"0">>, true}
+            {0, true}
     end,
     #doc{
         id = DocId,

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.