nickva commented on a change in pull request #3366:
URL: https://github.com/apache/couchdb/pull/3366#discussion_r574053457



##########
File path: src/couch/src/couch_server.erl
##########
@@ -860,19 +865,55 @@ get_engine_path(DbName, Engine) when is_binary(DbName), 
is_atom(Engine) ->
     end.
 
 lock(DbName, Reason) when is_binary(DbName), is_binary(Reason) ->
-    case ets:lookup(couch_dbs, DbName) of
+    case ets:lookup(couch_dbs(DbName), DbName) of
         [] ->
-            true = ets:insert(couch_dbs_locks, {DbName, Reason}),
+            true = ets:insert(couch_dbs_locks(DbName), {DbName, Reason}),
             ok;
         [#entry{}] ->
             {error, already_opened}
     end.
 
 unlock(DbName) when is_binary(DbName) ->
-    true = ets:delete(couch_dbs_locks, DbName),
+    true = ets:delete(couch_dbs_locks(DbName), DbName),
     ok.
 
 
+db_updated(Db) ->
+    DbName = couch_db:name(Db),
+    gen_server:call(couch_server(DbName), {db_updated, Db}, infinity).
+
+
+couch_server(Arg) ->
+    name("couch_server", Arg).
+
+
+couch_dbs(Arg) ->
+    name("couch_dbs", Arg).
+
+
+couch_dbs_pid_to_name(Arg) ->
+    name("couch_dbs_pid_to_name", Arg).
+
+
+couch_dbs_locks(Arg) ->
+    name("couch_dbs_locks", Arg).
+
+
+name(BaseName, DbName) when is_binary(DbName) ->
+    N = 1 + (erlang:crc32(DbName) rem num_servers()),

Review comment:
       May even be a tiny bit faster...
   
   ```
   > DbName = crypto:strong_rand_bytes(100).
   <<23,241,236,53,92,151,12,217,246,88,65,153,224,214,236,
     240,126,243,188,248,53,187,206,165,235,96,24,5,38,...>>
   
   > f(USec), {USec, ok} = timer:tc(fun() -> [erlang:crc32(DbName) rem 10 || I 
<- lists:seq(1, 1000000)], ok end), USec/1.0e6.
   1.499477
   
   > f(USec), {USec, ok} = timer:tc(fun() -> [erlang:phash2(DbName, 10) || I <- 
lists:seq(1, 1000000)], ok end), USec/1.0e6.
   1.331179
   ```




----------------------------------------------------------------
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


Reply via email to