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

vatamane pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit f05b3ad2f1676221d5a469d8c12d2431fb871877
Author: Nick Vatamaniuc <vatam...@apache.org>
AuthorDate: Wed Mar 25 14:31:52 2020 -0400

    Fix db prefix checks in fabric2_fdb
    
    After the recent upgrade to using HCA we forgot to check all the places 
where
    the db prefix was constructed so a few places still used the old pattern of
    {?DBS, DbName}.
    
    In the case of `check_metadata_version` we also have to account for the fact
    that during db creation, there might not be a db_prefix in the `Db` handle 
yet.
---
 src/fabric/src/fabric2_fdb.erl | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 14a649d..2911dbd 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -1115,8 +1115,6 @@ bump_metadata_version(Tx) ->
 check_metadata_version(#{} = Db) ->
     #{
         tx := Tx,
-        layer_prefix := LayerPrefix,
-        name := DbName,
         md_version := Version
     } = Db,
 
@@ -1126,10 +1124,16 @@ check_metadata_version(#{} = Db) ->
             Version ->
                 put(?PDICT_CHECKED_MD_IS_CURRENT, true),
                 % We want to set a read conflict on the db version as we'd want
-                % to to conflict with any writes to this particular db
-                DbPrefix = erlfdb_tuple:pack({?DBS, DbName}, LayerPrefix),
-                DbVersionKey = erlfdb_tuple:pack({?DB_VERSION}, DbPrefix),
-                erlfdb:add_read_conflict_key(Tx, DbVersionKey),
+                % to conflict with any writes to this particular db. However
+                % during db creation db prefix might not exist yet so we don't
+                % add a read-conflict on it then.
+                case maps:get(db_prefix, Db, not_found) of
+                    not_found ->
+                        ok;
+                    <<_/binary>> = DbPrefix ->
+                        DbVerKey = erlfdb_tuple:pack({?DB_VERSION}, DbPrefix),
+                        erlfdb:add_read_conflict_key(Tx, DbVerKey)
+                end,
                 {current, Db};
             NewVersion ->
                 {stale, Db#{md_version := NewVersion}}
@@ -1690,10 +1694,8 @@ check_db_instance(#{} = Db) ->
             #{
                 tx := Tx,
                 uuid := UUID,
-                name := DbName,
-                layer_prefix := LayerPrefix
+                db_prefix := DbPrefix
             } = Db1,
-            DbPrefix = erlfdb_tuple:pack({?DBS, DbName}, LayerPrefix),
             UUIDKey = erlfdb_tuple:pack({?DB_CONFIG, <<"uuid">>}, DbPrefix),
             case erlfdb:wait(erlfdb:get(Tx, UUIDKey)) of
                 UUID -> Db1;

Reply via email to