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

jiangphcn pushed a commit to branch set-DbPrefix-with-hca
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 23487807dea165e878e78c0435acd946ce6293a7
Author: jiangph <[email protected]>
AuthorDate: Mon Mar 23 20:03:43 2020 +0800

    set DbPrefix with value allocated with erlfdb_hca
    
    Previously we are using the DbName to set DbPrefix for clarity. In order
    to support soft-deletion while providing efficient value for DbPrefix
    allocation, we use value allocated with erlfdb_hca for DbPrefix.
---
 src/fabric/include/fabric2.hrl | 2 ++
 src/fabric/src/fabric2_fdb.erl | 9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/fabric/include/fabric2.hrl b/src/fabric/include/fabric2.hrl
index a4f68bd..2d7711f 100644
--- a/src/fabric/include/fabric2.hrl
+++ b/src/fabric/include/fabric2.hrl
@@ -17,6 +17,8 @@
 
 % Prefix Definitions
 
+-define(DEFAULT_DB_PREFIX, <<16#FD>>).
+
 % Layer Level: (LayerPrefix, X, ...)
 
 -define(CLUSTER_CONFIG, 0).
diff --git a/src/fabric/src/fabric2_fdb.erl b/src/fabric/src/fabric2_fdb.erl
index f5f7bec..6326949 100644
--- a/src/fabric/src/fabric2_fdb.erl
+++ b/src/fabric/src/fabric2_fdb.erl
@@ -177,10 +177,13 @@ create(#{} = Db0, Options) ->
         layer_prefix := LayerPrefix
     } = Db = ensure_current(Db0, false),
 
-    % Eventually DbPrefix will be HCA allocated. For now
-    % we're just using the DbName so that debugging is easier.
     DbKey = erlfdb_tuple:pack({?ALL_DBS, DbName}, LayerPrefix),
-    DbPrefix = erlfdb_tuple:pack({?DBS, DbName}, LayerPrefix),
+    DefDbPref = ?DEFAULT_DB_PREFIX,
+    AllDbPrefix = erlfdb_util:get(Options, db_prefix, DefDbPref),
+    DbId = erlfdb_tuple:pack({AllDbPrefix}, AllDbPrefix),
+    DbPrefixAllocator = erlfdb_hca:create(erlfdb_tuple:pack({DbId}, 
<<"hca">>)),
+    AllocPrefix = erlfdb_hca:allocate(DbPrefixAllocator, Tx),
+    DbPrefix = erlfdb_tuple:pack({?DBS, AllocPrefix}, LayerPrefix),
     erlfdb:set(Tx, DbKey, DbPrefix),
 
     % This key is responsible for telling us when something in

Reply via email to