You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2023/10/19 00:52:40 UTC

[couchdb] branch config-delete-reload created (now 4610d12d8)

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

jaydoane pushed a change to branch config-delete-reload
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at 4610d12d8 Reload default config value from disk on delete

This branch includes the following new commits:

     new 1239b7e68 Remove unused include and defines
     new 4132b272f Delete confusing test config delete reason
     new e4ab50254 Ensure these config tests get executed
     new 48bb99ec5 Factor out `config:parse_ini_files/1`
     new 4610d12d8 Reload default config value from disk on delete

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[couchdb] 02/05: Delete confusing test config delete reason

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jaydoane pushed a commit to branch config-delete-reload
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 4132b272f486aee5cd2646ab95bd91bae7823fb7
Author: Jay Doane <ja...@apache.org>
AuthorDate: Wed Oct 18 17:32:29 2023 -0700

    Delete confusing test config delete reason
    
    The third argument to `config:delete/3`, if not a boolean, should be a
    reason for the deletion. This "8080" that looks like a port number was
    presumably a copy-pasta error.
---
 src/config/test/config_tests.erl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/config/test/config_tests.erl b/src/config/test/config_tests.erl
index 77b961872..c10878a7e 100644
--- a/src/config/test/config_tests.erl
+++ b/src/config/test/config_tests.erl
@@ -437,7 +437,7 @@ should_write_changes(_, _) ->
         ?assertEqual("5986", config:get("httpd", "port")),
         ?assertEqual(ok, config:set("httpd", "port", "8080")),
         ?assertEqual("8080", config:get("httpd", "port")),
-        ?assertEqual(ok, config:delete("httpd", "bind_address", "8080")),
+        ?assertEqual(ok, config:delete("httpd", "bind_address")),
         ?assertEqual(undefined, config:get("httpd", "bind_address"))
     end).
 


[couchdb] 05/05: Reload default config value from disk on delete

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jaydoane pushed a commit to branch config-delete-reload
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 4610d12d851829a3e04561a33689eb90b9f5e137
Author: Jay Doane <ja...@apache.org>
AuthorDate: Wed Oct 18 17:48:14 2023 -0700

    Reload default config value from disk on delete
    
    When a key is deleted, reload any default back into memory.
    
    This breaks the existing semantics as demonstrated by how the test
    must change in order to pass now.
---
 src/config/src/config.erl        | 7 +++++++
 src/config/test/config_tests.erl | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/config/src/config.erl b/src/config/src/config.erl
index 3431e9a56..5cb2e6b02 100644
--- a/src/config/src/config.erl
+++ b/src/config/src/config.erl
@@ -326,6 +326,13 @@ handle_call({delete, Sec, Key, Persist, Reason}, _From, Config) ->
         "~p: [~s] ~s deleted for reason ~p",
         [?MODULE, Sec, Key, Reason]
     ),
+    DiskKVs = parse_ini_files(Config#config.ini_files),
+    case dict:find({Sec, Key}, DiskKVs) of
+        {ok, DiskVal} ->
+            true = ets:insert(?MODULE, {{Sec, Key}, DiskVal});
+        error ->
+            ok
+    end,
     ConfigDeleteReturn =
         case {Persist, Config#config.write_filename} of
             {true, undefined} ->
diff --git a/src/config/test/config_tests.erl b/src/config/test/config_tests.erl
index dc83d2c72..ff7fcc546 100644
--- a/src/config/test/config_tests.erl
+++ b/src/config/test/config_tests.erl
@@ -438,7 +438,7 @@ should_write_changes(_, _) ->
         ?assertEqual(ok, config:set("httpd", "port", "8080")),
         ?assertEqual("8080", config:get("httpd", "port")),
         ?assertEqual(ok, config:delete("httpd", "bind_address")),
-        ?assertEqual(undefined, config:get("httpd", "bind_address"))
+        ?assertEqual("127.0.0.1", config:get("httpd", "bind_address"))
     end).
 
 should_ensure_default_wasnt_modified(_, _) ->


[couchdb] 03/05: Ensure these config tests get executed

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jaydoane pushed a commit to branch config-delete-reload
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e4ab50254adf80f7856ef663a5251e1655113edb
Author: Jay Doane <ja...@apache.org>
AuthorDate: Wed Oct 18 17:10:14 2023 -0700

    Ensure these config tests get executed
    
    Unwrap tests from unnecessary `?_test(begin ... end)` so that they
    actually execute their assertions.
---
 src/config/test/config_tests.erl | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/config/test/config_tests.erl b/src/config/test/config_tests.erl
index c10878a7e..dc83d2c72 100644
--- a/src/config/test/config_tests.erl
+++ b/src/config/test/config_tests.erl
@@ -457,16 +457,12 @@ should_ensure_that_no_ini_files_loaded() ->
     ?assertEqual(0, length(config:all())).
 
 should_create_non_persistent_option() ->
-    ?_test(begin
-        ?assertEqual(ok, config:set("httpd", "port", "80", false)),
-        ?assertEqual("80", config:get("httpd", "port"))
-    end).
+    ?assertEqual(ok, config:set("httpd", "port", "80", false)),
+    ?assertEqual("80", config:get("httpd", "port")).
 
 should_create_persistent_option() ->
-    ?_test(begin
-        ?assertEqual(ok, config:set("httpd", "bind_address", "127.0.0.1")),
-        ?assertEqual("127.0.0.1", config:get("httpd", "bind_address"))
-    end).
+    ?assertEqual(ok, config:set("httpd", "bind_address", "127.0.0.1")),
+    ?assertEqual("127.0.0.1", config:get("httpd", "bind_address")).
 
 should_handle_value_change({_Apps, Pid}) ->
     ?_test(begin


[couchdb] 04/05: Factor out `config:parse_ini_files/1`

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jaydoane pushed a commit to branch config-delete-reload
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 48bb99ec509917db8ca8b45226525e7da431a71d
Author: Jay Doane <ja...@apache.org>
AuthorDate: Mon Oct 16 13:11:51 2023 -0700

    Factor out `config:parse_ini_files/1`
---
 src/config/src/config.erl | 31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/src/config/src/config.erl b/src/config/src/config.erl
index cf8c44835..3431e9a56 100644
--- a/src/config/src/config.erl
+++ b/src/config/src/config.erl
@@ -344,20 +344,7 @@ handle_call({delete, Sec, Key, Persist, Reason}, _From, Config) ->
             {reply, Else, Config}
     end;
 handle_call(reload, _From, Config) ->
-    DiskKVs = lists:foldl(
-        fun(IniFile, DiskKVs0) ->
-            {ok, ParsedIniValues} = parse_ini_file(IniFile),
-            lists:foldl(
-                fun({K, V}, DiskKVs1) ->
-                    dict:store(K, V, DiskKVs1)
-                end,
-                DiskKVs0,
-                ParsedIniValues
-            )
-        end,
-        dict:new(),
-        Config#config.ini_files
-    ),
+    DiskKVs = parse_ini_files(Config#config.ini_files),
     % Update ets with anything we just read
     % from disk
     dict:fold(
@@ -426,6 +413,22 @@ is_sensitive(Section, Key) ->
         _ -> false
     end.
 
+parse_ini_files(IniFiles) ->
+    lists:foldl(
+        fun(IniFile, DiskKVs0) ->
+            {ok, ParsedIniValues} = parse_ini_file(IniFile),
+            lists:foldl(
+                fun({K, V}, DiskKVs1) ->
+                    dict:store(K, V, DiskKVs1)
+                end,
+                DiskKVs0,
+                ParsedIniValues
+            )
+        end,
+        dict:new(),
+        IniFiles
+    ).
+
 parse_ini_file(IniFile) ->
     IniBin = read_ini_file(IniFile),
     ParsedIniValues = parse_ini(IniBin),


[couchdb] 01/05: Remove unused include and defines

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jaydoane pushed a commit to branch config-delete-reload
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 1239b7e68ba357d260aa635ab137e797c9782313
Author: Jay Doane <ja...@apache.org>
AuthorDate: Mon Oct 16 13:12:45 2023 -0700

    Remove unused include and defines
---
 src/config/test/config_tests.erl | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/src/config/test/config_tests.erl b/src/config/test/config_tests.erl
index 90d430a87..77b961872 100644
--- a/src/config/test/config_tests.erl
+++ b/src/config/test/config_tests.erl
@@ -19,7 +19,6 @@
 ]).
 
 -include_lib("couch/include/couch_eunit.hrl").
--include_lib("couch/include/couch_db.hrl").
 
 -define(TIMEOUT, 4000).
 -define(RESTART_TIMEOUT_IN_MILLISEC, 3000).
@@ -56,9 +55,6 @@
     FileName
 end).
 
--define(T(F), {erlang:fun_to_list(F), F}).
--define(FEXT(F), fun(_, _) -> F() end).
-
 setup() ->
     setup(?CONFIG_CHAIN).