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/06/17 15:48:25 UTC

[couchdb] 01/06: Rearrange function ordering for clarity

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

davisp pushed a commit to branch prototype/fdb-layer-db-version-as-vstamps
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 42d9106b889b3a13570059435940fad4cb186f13
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Jun 16 11:19:18 2020 -0500

    Rearrange function ordering for clarity
    
    This moves ensure_current/1 to match its order in the export list, and
    ensure_current/2 is moved near the check_metadata_version and
    check_db_version functions to group related logic.
---
 src/fabric/src/fabric2_fdb.erl | 71 +++++++++++++++++++++---------------------
 1 file changed, 36 insertions(+), 35 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index f721ca4..c6f9b5e 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -18,9 +18,10 @@
     transactional/3,
     transactional/2,
 
+    ensure_current/1,
+
     create/2,
     open/2,
-    ensure_current/1,
     delete/1,
     undelete/3,
     remove_deleted_db/2,
@@ -180,6 +181,10 @@ do_transaction(Fun, LayerPrefix) when is_function(Fun, 1) ->
     end.
 
 
+ensure_current(Db) ->
+    ensure_current(Db, true).
+
+
 create(#{} = Db0, Options) ->
     #{
         name := DbName,
@@ -1255,6 +1260,36 @@ load_validate_doc_funs(#{} = Db) ->
     }.
 
 
+ensure_current(#{} = Db0, CheckDbVersion) ->
+    require_transaction(Db0),
+    Db3 = case check_metadata_version(Db0) of
+        {current, Db1} ->
+            Db1;
+        {stale, Db1} ->
+            case check_db_version(Db1, CheckDbVersion) of
+                current ->
+                    % If db version is current, update cache with the latest
+                    % metadata so other requests can immediately see the
+                    % refreshed db handle.
+                    Now = erlang:monotonic_time(millisecond),
+                    Db2 = Db1#{check_current_ts := Now},
+                    fabric2_server:maybe_update(Db2),
+                    Db2;
+                stale ->
+                    fabric2_server:maybe_remove(Db1),
+                    throw({?MODULE, reopen})
+            end
+    end,
+    case maps:get(security_fun, Db3) of
+        SecurityFun when is_function(SecurityFun, 2) ->
+            #{security_doc := SecDoc} = Db3,
+            ok = SecurityFun(Db3, SecDoc),
+            Db3#{security_fun := undefined};
+        undefined ->
+            Db3
+    end.
+
+
 bump_metadata_version(Tx) ->
     % The 14 zero bytes is pulled from the PR for adding the
     % metadata version key. Not sure why 14 bytes when version
@@ -1858,40 +1893,6 @@ require_transaction(#{} = _Db) ->
     erlang:error(transaction_required).
 
 
-ensure_current(Db) ->
-    ensure_current(Db, true).
-
-
-ensure_current(#{} = Db0, CheckDbVersion) ->
-    require_transaction(Db0),
-    Db3 = case check_metadata_version(Db0) of
-        {current, Db1} ->
-            Db1;
-        {stale, Db1} ->
-            case check_db_version(Db1, CheckDbVersion) of
-                current ->
-                    % If db version is current, update cache with the latest
-                    % metadata so other requests can immediately see the
-                    % refreshed db handle.
-                    Now = erlang:monotonic_time(millisecond),
-                    Db2 = Db1#{check_current_ts := Now},
-                    fabric2_server:maybe_update(Db2),
-                    Db2;
-                stale ->
-                    fabric2_server:maybe_remove(Db1),
-                    throw({?MODULE, reopen})
-            end
-    end,
-    case maps:get(security_fun, Db3) of
-        SecurityFun when is_function(SecurityFun, 2) ->
-            #{security_doc := SecDoc} = Db3,
-            ok = SecurityFun(Db3, SecDoc),
-            Db3#{security_fun := undefined};
-        undefined ->
-            Db3
-    end.
-
-
 check_db_instance(undefined) ->
     undefined;