diff options
author | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-05-24 11:09:00 -0500 |
---|---|---|
committer | Paul J. Davis <paul.joseph.davis@gmail.com> | 2019-05-24 11:09:00 -0500 |
commit | fb8c51c2c3907de64914e0400346c8811835fecd (patch) | |
tree | aea098fd4ae4e4863dea032478c6c5a58c607ec8 | |
parent | 819c9e6037e064a9e7d53b2f57bc86694374e6ce (diff) | |
download | couchdb-fb8c51c2c3907de64914e0400346c8811835fecd.tar.gz |
Add per-db version checking cache eviction
-rw-r--r-- | src/fabric/src/fabric2.hrl | 5 | ||||
-rw-r--r-- | src/fabric/src/fabric2_fdb.erl | 26 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/fabric/src/fabric2.hrl b/src/fabric/src/fabric2.hrl index 7ea0577f0..2d6778d74 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 666a20b32..9a6f6e9c2 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. |