couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [39/50] [abbrv] git commit: updated refs/heads/1843-feature-bigcouch to cba2e81
Date Sat, 29 Jun 2013 15:18:20 GMT
Add a config:reload/0 and HTTP trigger

Theoretically this should prevent all of those annoying test suite
failures when a test fails in with a temporary config set and fails to
undo its changes.

This works by storing the list of INI files in the config server and on
command will clear its ets table and re-read data from disk thus
clearing its cache of non-persisted values. Obviously this isn't
something that should be relied on in production settings.


Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/6e53c8a7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/6e53c8a7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/6e53c8a7

Branch: refs/heads/1843-feature-bigcouch
Commit: 6e53c8a7ee5a7f70a7492baf23c1aa383f7c5843
Parents: 19bab5c
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Wed Mar 13 01:47:34 2013 -0500
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Wed Mar 20 06:02:55 2013 -0500

----------------------------------------------------------------------
 share/www/script/couch.js                   |  6 +++++
 src/config/src/config.erl                   | 31 ++++++++++++++++++++++--
 src/couch/src/couch_httpd_misc_handlers.erl |  7 +++++-
 test/javascript/cli_runner.js               |  1 +
 4 files changed, 42 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/6e53c8a7/share/www/script/couch.js
----------------------------------------------------------------------
diff --git a/share/www/script/couch.js b/share/www/script/couch.js
index 3deb441..58ad7a7 100644
--- a/share/www/script/couch.js
+++ b/share/www/script/couch.js
@@ -356,6 +356,12 @@ CouchDB.getVersion = function() {
   return JSON.parse(CouchDB.last_req.responseText).version;
 };
 
+CouchDB.reloadConfig = function() {
+  CouchDB.last_req = CouchDB.request("POST", "/_config/_reload");
+  CouchDB.maybeThrowError(CouchDB.last_req);
+  return JSON.parse(CouchDB.last_req.responseText);
+};
+
 CouchDB.replicate = function(source, target, rep_options) {
   rep_options = rep_options || {};
   var headers = rep_options.headers || {};

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6e53c8a7/src/config/src/config.erl
----------------------------------------------------------------------
diff --git a/src/config/src/config.erl b/src/config/src/config.erl
index 8a94f2c..f47639a 100644
--- a/src/config/src/config.erl
+++ b/src/config/src/config.erl
@@ -19,7 +19,7 @@
 -module(config).
 -behaviour(gen_server).
 
--export([start_link/1, stop/0]).
+-export([start_link/1, stop/0, reload/0]).
 -export([all/0, get/1, get/2, get/3, set/3, set/4, delete/2, delete/3]).
 -export([listen_for_changes/2]).
 -export([parse_ini_file/1]).
@@ -29,6 +29,7 @@
 
 -record(config, {
     notify_funs=[],
+    ini_files=undefined,
     write_filename=undefined
 }).
 
@@ -40,6 +41,9 @@ stop() ->
     gen_server:cast(?MODULE, stop).
 
 
+reload() ->
+    gen_server:call(?MODULE, reload).
+
 all() ->
     lists:sort(gen_server:call(?MODULE, all, infinity)).
 
@@ -94,7 +98,7 @@ init(IniFiles) ->
         _ -> undefined
     end,
     debug_config(),
-    {ok, #config{write_filename=WriteFile}}.
+    {ok, #config{ini_files=IniFiles, write_filename=WriteFile}}.
 
 
 terminate(_Reason, _State) ->
@@ -131,6 +135,29 @@ handle_call({delete, Sec, Key, Persist}, _From, Config) ->
     end,
     Event = {config_change, Sec, Key, deleted, Persist},
     gen_event:sync_notify(config_event, Event),
+    {reply, ok, Config};
+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),
+    % Update ets with anything we just read
+    % from disk
+    dict:fold(fun(K, V, _) ->
+        ets:insert(?MODULE, {K, V})
+    end, nil, DiskKVs),
+    % And remove anything in ets that wasn't
+    % on disk.
+    ets:foldl(fun({K, _}, _) ->
+        case dict:is_key(K, DiskKVs) of
+            true ->
+                ok;
+            false ->
+                ets:delete(?MODULE, K)
+        end
+    end, nil, ?MODULE),
     {reply, ok, Config}.
 
 

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6e53c8a7/src/couch/src/couch_httpd_misc_handlers.erl
----------------------------------------------------------------------
diff --git a/src/couch/src/couch_httpd_misc_handlers.erl b/src/couch/src/couch_httpd_misc_handlers.erl
index b8f59cd..d57ceeb 100644
--- a/src/couch/src/couch_httpd_misc_handlers.erl
+++ b/src/couch/src/couch_httpd_misc_handlers.erl
@@ -157,6 +157,11 @@ handle_config_req(#httpd{method='GET', path_parts=[_, Section, Key]}=Req)
->
     Value ->
         send_json(Req, 200, list_to_binary(Value))
     end;
+% POST /_config/_reload - Flushes unpersisted config values from RAM
+handle_config_req(#httpd{method='POST', path_parts=[_, <<"_reload">>]}=Req) ->
+    ok = couch_httpd:verify_is_server_admin(Req),
+    ok = config:reload(),
+    send_json(Req, 200, {[{ok, true}]});
 % PUT or DELETE /_config/Section/Key
 handle_config_req(#httpd{method=Method, path_parts=[_, Section, Key]}=Req)
       when (Method == 'PUT') or (Method == 'DELETE') ->
@@ -215,7 +220,7 @@ handle_config_req(#httpd{method=Method, path_parts=[_, Section, Key]}=Req)
             end
     end;
 handle_config_req(Req) ->
-    send_method_not_allowed(Req, "GET,PUT,DELETE").
+    send_method_not_allowed(Req, "GET,PUT,POST,DELETE").
 
 % PUT /_config/Section/Key
 % "value"

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6e53c8a7/test/javascript/cli_runner.js
----------------------------------------------------------------------
diff --git a/test/javascript/cli_runner.js b/test/javascript/cli_runner.js
index fcb4633..5d82a51 100644
--- a/test/javascript/cli_runner.js
+++ b/test/javascript/cli_runner.js
@@ -48,6 +48,7 @@ function T(arg1, arg2) {
 }
 
 function runTestConsole(num, name, func) {
+  CouchDB.reloadConfig();
   var passed = false;
   try {
     func();


Mime
View raw message