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/09 20:18:34 UTC

[couchdb] 01/02: WIP: more db_version stuff

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 8a3402c27de76c3a66895554dee6e061558d544d
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Jun 9 11:20:04 2020 -0500

    WIP: more db_version stuff
---
 src/fabric/src/fabric2_fdb.erl | 29 +++++++++++++++++++++--------
 1 file changed, 21 insertions(+), 8 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index fc777b0..f501b80 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -202,9 +202,13 @@ create(#{} = Db0, Options) ->
     % On creation we're setting this to the current MDVersion
     % because it is a valid versionstamp on the current cluster
     % and also so that we don't have to use two transactions
-    % when creating a database.
+    % when creating a database. The addition of the 51 prefix
+    % and two trailing zeros changes the metadataVersion from
+    % a raw 80 bit versionstamp into a tuple encoded 96 bit
+    % versionstamp
     DbVersionKey = erlfdb_tuple:pack({?DB_VERSION}, DbPrefix),
-    erlfdb:set(Tx, DbVersionKey, MDVersion),
+    DbVersion = <<51, MDVersion/binary, 0, 0>>,
+    erlfdb:set(Tx, DbVersionKey, DbVersion),
 
     UUID = fabric2_util:uuid(),
 
@@ -310,15 +314,14 @@ open(#{} = Db0, Options) ->
 refresh(#{tx := undefined, name := DbName} = Db) ->
     #{
         uuid := UUID,
-        md_version := OldVer
+        db_version := OldVer
     } = Db,
 
     case fabric2_server:fetch(DbName, UUID) of
-        % Relying on these assumptions about the `md_version` value:
-        %  - It is bumped every time `db_version` is bumped
+        % Relying on these assumptions about the `db_version` value:
         %  - Is a versionstamp, so we can check which one is newer
         %  - If it is `not_found`, it would sort less than a binary value
-        #{md_version := Ver} = Db1 when Ver > OldVer ->
+        #{db_version := Ver} = Db1 when Ver > OldVer ->
             Db1#{
                 user_ctx := maps:get(user_ctx, Db),
                 security_fun := maps:get(security_fun, Db)
@@ -340,7 +343,11 @@ reopen(#{} = OldDb) ->
         uuid := UUID,
         db_options := Options,
         user_ctx := UserCtx,
-        security_fun := SecurityFun
+        security_fun := SecurityFun,
+
+        validate_doc_update_funs := VDUs,
+        before_doc_update := BDU,
+        after_doc_read := ADR
     } = OldDb,
     Options1 = lists:keystore(user_ctx, 1, Options, {user_ctx, UserCtx}),
     NewDb = open(init_db(Tx, DbName, Options1), Options1),
@@ -351,7 +358,13 @@ reopen(#{} = OldDb) ->
         _OtherUUID -> error(database_does_not_exist)
     end,
 
-    NewDb#{security_fun := SecurityFun}.
+    NewDb#{
+        security_fun := SecurityFun,
+
+        validate_doc_update_funs := VDUs,
+        before_doc_update := BDU,
+        after_doc_read := ADR
+    }.
 
 
 delete(#{} = Db) ->