summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Vatamaniuc <vatamane@apache.org>2020-03-25 14:31:52 -0400
committerNick Vatamaniuc <nickva@users.noreply.github.com>2020-03-25 15:10:47 -0400
commitf05b3ad2f1676221d5a469d8c12d2431fb871877 (patch)
tree445087747a7027bdddbcf398499bcc56dd0f640d
parente06c5f360ad3b217591267eb2b05e305899b8887 (diff)
downloadcouchdb-f05b3ad2f1676221d5a469d8c12d2431fb871877.tar.gz
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.
-rw-r--r--src/fabric/src/fabric2_fdb.erl20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 14a649d50..2911dbdf5 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;