You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/03/29 16:15:33 UTC

[GitHub] [couchdb] ksnavely commented on a change in pull request #3468: Improve search for FDB cluster files

ksnavely commented on a change in pull request #3468:
URL: https://github.com/apache/couchdb/pull/3468#discussion_r603429201



##########
File path: src/fabric/src/fabric2_server.erl
##########
@@ -212,14 +213,47 @@ get_db_and_cluster(EunitDbOpts) ->
         {ok, true} ->
             {<<"eunit_test">>, erlfdb_util:get_test_db(EunitDbOpts)};
         undefined ->
-            ClusterFileStr = config:get("erlfdb", "cluster_file", ?CLUSTER_FILE),
+            ClusterFileStr = get_cluster_file_string(),
             {ok, ConnectionStr} = file:read_file(ClusterFileStr),
             DbHandle = erlfdb:open(iolist_to_binary(ClusterFileStr)),
             {string:trim(ConnectionStr), DbHandle}
     end,
     apply_tx_options(Db, config:get(?TX_OPTIONS_SECTION)),
     {Cluster, Db}.
 
+get_cluster_file_string() ->
+    Locations = [
+        {custom, config:get("erlfdb", "cluster_file", false)},
+        {custom, os:getenv("FDB_CLUSTER_FILE")},
+        {default, ?CLUSTER_FILE_MACOS},
+        {default, ?CLUSTER_FILE_LINUX}
+    ],
+    case find_cluster_file(Locations) of
+        {ok, Location} ->
+            Location;
+        {error, Reason} ->
+            erlang:error(Reason)
+    end.
+
+find_cluster_file([]) ->
+    {error, cluster_file_missing};
+find_cluster_file([{custom, false} | Rest]) ->
+    find_cluster_file(Rest);
+find_cluster_file([{Type, Location} | Rest]) ->
+    case file:read_file_info(Location, [posix]) of
+        {ok, #file_info{access = read_write}} ->
+            couch_log:info("Using ~s FDB cluster file: ~s", [Type, Location]),
+            {ok, Location};
+        {ok, _} ->
+            couch_log:error("CouchDB needs read/write access to FDB cluster file: ~s", [Location]),

Review comment:
       This might seem alarming, maybe add a comment that the FDB C client is the thing that may need to change the contents of the cluster-file.




-- 
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:
users@infra.apache.org