nickva commented on a change in pull request #2707: Set DbPrefix with value 
allocated by erlfdb_hca
URL: https://github.com/apache/couchdb/pull/2707#discussion_r396566069
 
 

 ##########
 File path: 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),
 
 Review comment:
   I wonder we could just keep the HCA counters right under the the 
`LayerPrefix` ?
   
   As in:
   
   ```
   HCA = erlfdb_hca:create(erlfdb_tuple:pack({?DB_HCA}, LayerPrefix)),
   AllocPrefix = erlfdb_hca:allocate(HCA, Tx),
   DbPrefix = erlfdb_tuple:pack({?DBS, AllocPrefix}, LayerPrefix),
   ```
   
   And then define `DB_HCA` to be in fabric2.hrl alongside `ALL_DBS`. 
   
   ```
   ...
   -define(ALL_DBS, 1).
   -define(DB_HCA, 2).
   ```
   
   Then we don't even need the `DEFAULT_DB_PREFIX` since we'd always be 
creating these instances under `LayerPrefix` as well. In other words, they 
won't clash with FDB directory nodes.
   
   Would that work? 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to