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



##########
File path: src/couch/src/couch_server.erl
##########
@@ -301,22 +306,22 @@ terminate(Reason, Srv) ->
         if Db == undefined -> ok; true ->
             couch_util:shutdown_sync(couch_db:get_pid(Db))
         end
-    end, nil, couch_dbs),
+    end, nil, couch_dbs(Srv)),
     ok.
 
 handle_config_change("couchdb", "database_dir", _, _, _) ->
     exit(whereis(couch_server), config_change),
     remove_handler;
-handle_config_change("couchdb", "update_lru_on_read", "true", _, _) ->
-    {ok, gen_server:call(couch_server,{set_update_lru_on_read,true})};
-handle_config_change("couchdb", "update_lru_on_read", _, _, _) ->
-    {ok, gen_server:call(couch_server,{set_update_lru_on_read,false})};
-handle_config_change("couchdb", "max_dbs_open", Max, _, _) when is_list(Max) ->
-    {ok, 
gen_server:call(couch_server,{set_max_dbs_open,list_to_integer(Max)})};
-handle_config_change("couchdb", "max_dbs_open", _, _, _) ->
-    {ok, gen_server:call(couch_server,{set_max_dbs_open,?MAX_DBS_OPEN})};
-handle_config_change("couchdb_engines", _, _, _, _) ->
-    {ok, gen_server:call(couch_server, reload_engines)};
+handle_config_change("couchdb", "update_lru_on_read", "true", _, N) ->
+    {ok, gen_server:call(couch_server(N),{set_update_lru_on_read,true})};
+handle_config_change("couchdb", "update_lru_on_read", _, _, N) ->
+    {ok, gen_server:call(couch_server(N),{set_update_lru_on_read,false})};
+handle_config_change("couchdb", "max_dbs_open", Max, _, N) when is_list(Max) ->
+    {ok, 
gen_server:call(couch_server(N),{set_max_dbs_open,list_to_integer(Max)})};
+handle_config_change("couchdb", "max_dbs_open", _, _, N) ->
+    {ok, gen_server:call(couch_server(N),{set_max_dbs_open,?MAX_DBS_OPEN})};
+handle_config_change("couchdb_engines", _, _, _, N) ->
+    {ok, gen_server:call(couch_server(N), reload_engines)};

Review comment:
       Hmmm... do we want to trigger the config change callbacks `N` times now? 
The current approach keeps the code simpler, and I'm being a bit pedantic here, 
but it might be worth making a dedicated config listener pid that loops over 
the couch_server pids to trigger updates.

##########
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()),
+    name(BaseName, N);
+
+name(BaseName, #server{} = Srv) ->
+    name(BaseName, Srv#server.n);

Review comment:
       If we're caching N, should we also just cache the relevant atoms so 
we're not doing `list_to_atom` on concatenated strings every time? Probably 
won't have a major impact given this approach will have parallelize 
couch_server pids, but it's certainly more work to do for them to do.




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