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 2019/05/24 16:09:28 UTC

[couchdb] branch prototype/rfc-001-revision-metadata-model updated: Add per-db version checking cache eviction

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

davisp pushed a commit to branch prototype/rfc-001-revision-metadata-model
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/prototype/rfc-001-revision-metadata-model by this push:
     new fb8c51c  Add per-db version checking cache eviction
fb8c51c is described below

commit fb8c51c2c3907de64914e0400346c8811835fecd
Author: Paul J. Davis <pa...@gmail.com>
AuthorDate: Fri May 24 11:09:00 2019 -0500

    Add per-db version checking cache eviction
---
 src/fabric/src/fabric2.hrl     |  5 +++++
 src/fabric/src/fabric2_fdb.erl | 26 +++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/fabric/src/fabric2.hrl b/src/fabric/src/fabric2.hrl
index 7ea0577..2d6778d 100644
--- a/src/fabric/src/fabric2.hrl
+++ b/src/fabric/src/fabric2.hrl
@@ -28,11 +28,16 @@
 
 % Prefix Definitions
 
+% Layer Level: (LayerPrefix, X, ...)
+
 -define(CLUSTER_CONFIG, 0).
 -define(ALL_DBS, 1).
 -define(DBS, 15).
 -define(TX_IDS, 255).
 
+% Database Level: (LayerPrefix, ?DBS, DbPrefix, X, ...)
+
+-define(DB_VERSION, 0).
 -define(DB_CONFIG, 16).
 -define(DB_STATS, 17).
 -define(DB_ALL_DOCS, 18).
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index 666a20b..9a6f6e9 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -118,6 +118,16 @@ create(#{} = Db0, Options) ->
     DbPrefix = erlfdb_tuple:pack({?DBS, DbName}, LayerPrefix),
     erlfdb:set(Tx, DbKey, DbPrefix),
 
+    % This key is responsible for telling us when something in
+    % the database cache (i.e., fabric2_server's ets table) has
+    % changed and requires re-loading. This currently includes
+    % revs_limit and validate_doc_update functions. There's
+    % no order to versioning here. Its just a value that changes
+    % that is used in the ensure_current check.
+    DbVersionKey = erlfdb_tuple:pack({?DB_VERSION}, DbPrefix),
+    DbVersion = fabric2_util:uuid(),
+    erlfdb:set(Tx, DbVersionKey, DbVersion),
+
     UUID = fabric2_util:uuid(),
 
     Defaults = [
@@ -140,6 +150,7 @@ create(#{} = Db0, Options) ->
     Db#{
         uuid => UUID,
         db_prefix => DbPrefix,
+        db_version => DbVersion,
 
         revs_limit => 1000,
         security_doc => {[]},
@@ -167,10 +178,14 @@ open(#{} = Db0, Options) ->
         not_found -> erlang:error(database_does_not_exist)
     end,
 
+    DbVersionKey = erlfdb_tuple:pack({?DB_VERSION}, DbPrefix),
+    DbVersion = erlfdb:wait(erlfdb:get(Tx, DbVersionKey)),
+
     UserCtx = fabric2_util:get_value(user_ctx, Options, #user_ctx{}),
 
     Db2 = Db1#{
         db_prefix => DbPrefix,
+        db_version => DbVersion,
 
         revs_limit => 1000,
         security_doc => {[]},
@@ -989,12 +1004,21 @@ ensure_current(#{} = Db) ->
 
     #{
         tx := Tx,
-        md_version := MetaDataVersion
+        md_version := MetaDataVersion,
+        db_prefix := DbPrefix,
+        db_version := DbVersion
     } = Db,
 
     case erlfdb:wait(erlfdb:get(Tx, ?METADATA_VERSION_KEY)) of
         MetaDataVersion -> Db;
         _NewVersion -> reopen(Db)
+    end,
+
+    DbVersionKey = erlfdb:tuple_pack({?DB_VERSION}, DbPrefix),
+
+    case erlfdb:wait(erlfdb:get(Tx, DbVersionKey)) of
+        DbVersion -> Db;
+        _NewDBVersion -> reopen(Db)
     end.