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 2019/09/16 21:44:00 UTC

[couchdb] branch make-get-security-consistent created (now 9c9d6b7)

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

vatamane pushed a change to branch make-get-security-consistent
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


      at 9c9d6b7  Make get_security calls consistent

This branch includes the following new commits:

     new 9c9d6b7  Make get_security calls consistent

The 1 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.



[couchdb] 01/01: Make get_security calls consistent

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

vatamane pushed a commit to branch make-get-security-consistent
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 9c9d6b79f4ffa62005fe6329d40f0447b11bc90d
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Mon Sep 16 17:39:32 2019 -0400

    Make get_security calls consistent
    
    There are two fixes:
    
    1) In `fabric2_fdb:get_config/1`, Db was matched before and after
    `ensure_current/1`. Only path was used and didn't normally change so it didn't
    actually blow up. But it's worth fixing it anyway.
    
    2) In `fabric2_db:get_security/2` we used a cached value of the security
    document outside the transaction. Now we force it go through a transaction to
    call `fabric2_fdb:get_config/1` which call `ensure_current/1`. When done also
    update the cached Db handle.
---
 src/fabric/src/fabric2_db.erl  | 17 +++++++++++++++--
 src/fabric/src/fabric2_fdb.erl |  2 +-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl
index 853b502..7118795 100644
--- a/src/fabric/src/fabric2_db.erl
+++ b/src/fabric/src/fabric2_db.erl
@@ -350,8 +350,21 @@ get_revs_limit(#{revs_limit := RevsLimit}) ->
     RevsLimit.
 
 
-get_security(#{security_doc := SecurityDoc}) ->
-    SecurityDoc.
+get_security(#{security_doc := OldSecDoc} = Db) ->
+    KVs = fabric2_fdb:transactional(Db, fun(TxDb) ->
+        fabric2_fdb:get_config(TxDb)
+    end),
+    SecDoc = case lists:keyfind(<<"security_doc">>, 1, KVs) of
+        false ->
+            {[]};
+        {<<"security_doc">>, SecBin} ->
+            ?JSON_DECODE(SecBin)
+    end,
+    case OldSecDoc /= SecDoc of
+        true -> fabric2_server:store(Db#{security_doc := SecDoc});
+        false -> ok
+    end,
+    SecDoc.
 
 
 get_update_seq(#{} = Db) ->
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 391122e..cb00aba 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -338,7 +338,7 @@ get_config(#{} = Db) ->
     #{
         tx := Tx,
         db_prefix := DbPrefix
-    } = Db = ensure_current(Db),
+    } = ensure_current(Db),
 
     {Start, End} = erlfdb_tuple:range({?DB_CONFIG}, DbPrefix),
     Future = erlfdb:get_range(Tx, Start, End),