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:33 UTC

[couchdb] branch prototype/fdb-layer-db-version-as-vstamps updated (f424cd1 -> 3bb3071)

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

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


    from f424cd1  WIP: Set versionstamp db_veresion on creation
     new 8a3402c  WIP: more db_version stuff
     new 3bb3071  Account for missing metadataVersion

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


Summary of changes:
 src/fabric/src/fabric2_fdb.erl | 41 ++++++++++++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 11 deletions(-)


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

Posted by da...@apache.org.
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) ->


[couchdb] 02/02: Account for missing metadataVersion

Posted by da...@apache.org.
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 3bb30710dc12e5f667306f01e2ee0b923ea01f63
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Tue Jun 9 15:18:08 2020 -0500

    Account for missing metadataVersion
---
 src/fabric/src/fabric2_fdb.erl | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index f501b80..37e235a 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -1200,18 +1200,24 @@ debug_cluster(Start, End) ->
 
 init_db(Tx, DbName, Options) ->
     Prefix = get_dir(Tx),
-    Version = erlfdb:wait(erlfdb:get(Tx, ?METADATA_VERSION_KEY)),
     #{
         name => DbName,
         tx => Tx,
         layer_prefix => Prefix,
-        md_version => Version,
+        md_version => get_md_version(Tx),
 
         security_fun => undefined,
         db_options => Options
     }.
 
 
+get_md_version(Tx) ->
+    case erlfdb:wait(erlfdb:get(Tx, ?METADATA_VERSION_KEY)) of
+        not_found -> <<0:80>>;
+        Version -> Version
+    end.
+
+
 load_validate_doc_funs(#{} = Db) ->
     FoldFun = fun
         ({row, Row}, Acc) ->
@@ -1318,7 +1324,7 @@ check_metadata_version(#{} = Db) ->
 
     AlreadyChecked = get(?PDICT_CHECKED_MD_IS_CURRENT),
     if AlreadyChecked == true -> ok; true ->
-        CurrVersion = erlfdb:wait(erlfdb:get_ss(Tx, ?METADATA_VERSION_KEY)),
+        CurrVersion = get_md_version(Tx),
         if CurrVersion == Version -> ok; true ->
             fabric2_server:maybe_remove(Db),
             throw({?MODULE, reopen})