You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2013/06/29 17:18:22 UTC
[41/50] [abbrv] git commit: updated refs/heads/1843-feature-bigcouch
to cba2e81
Rewrite restartServer() for robustness
This uses an instance wide token set in the application environment to
detect when the server has restarted.
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/0cbf6a9c
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/0cbf6a9c
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/0cbf6a9c
Branch: refs/heads/1843-feature-bigcouch
Commit: 0cbf6a9cea01eea599524bcdb77dedb322c7ade4
Parents: 0c273b1
Author: Paul J. Davis <pa...@gmail.com>
Authored: Wed Mar 13 14:08:43 2013 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Wed Mar 20 06:02:56 2013 -0500
----------------------------------------------------------------------
share/www/script/couch_test_runner.js | 55 +++++++++++-------------
src/couch/src/couch_httpd_misc_handlers.erl | 11 +++++
2 files changed, 36 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0cbf6a9c/share/www/script/couch_test_runner.js
----------------------------------------------------------------------
diff --git a/share/www/script/couch_test_runner.js b/share/www/script/couch_test_runner.js
index c04e6b1..cf5e57b 100644
--- a/share/www/script/couch_test_runner.js
+++ b/share/www/script/couch_test_runner.js
@@ -417,40 +417,35 @@ function waitForSuccess(fun, tag) {
}
}
-function waitForRestart() {
- var waiting = true;
- // Wait for the server to go down but don't
- // wait too long because we might miss the
- // the unavailable period.
- var count = 25;
- while (waiting && count > 0) {
- count--;
- try {
- CouchDB.request("GET", "/");
- } catch(e) {
- waiting = false;
- }
- }
- // Wait for it to come back up
- waiting = true;
- while (waiting) {
- try {
- CouchDB.request("GET", "/");
- waiting = false;
- } catch(e) {
- // the request will fail until restart completes
- }
- }
+function getCurrentToken() {
+ var xhr = CouchDB.request("GET", "/_restart/token");
+ return JSON.parse(xhr.responseText).token;
};
+
function restartServer() {
- var xhr;
- try {
- CouchDB.request("POST", "/_restart");
- } catch(e) {
- // this request may sometimes fail
+ var token = getCurrentToken();
+ var token_changed = false;
+ var tDelta = 5000;
+ var t0 = new Date();
+ var t1;
+
+ CouchDB.request("POST", "/_restart");
+
+ do {
+ try {
+ if(token != getCurrentToken()) {
+ token_changed = true;
+ }
+ } catch (e) {
+ // Ignore errors while the server restarts
+ }
+ t1 = new Date();
+ } while(((t1 - t0) <= tDelta) && !token_changed);
+
+ if(!token_changed) {
+ throw("Server restart failed");
}
- waitForRestart();
}
// legacy functions for CouchDB < 1.2.0
http://git-wip-us.apache.org/repos/asf/couchdb/blob/0cbf6a9c/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 d57ceeb..3b2bbeb 100644
--- a/src/couch/src/couch_httpd_misc_handlers.erl
+++ b/src/couch/src/couch_httpd_misc_handlers.erl
@@ -94,6 +94,17 @@ handle_task_status_req(Req) ->
send_method_not_allowed(Req, "GET,HEAD").
+handle_restart_req(#httpd{method='GET', path_parts=[_, <<"token">>]}=Req) ->
+ ok = couch_httpd:verify_is_server_admin(Req),
+ Token = case application:get_env(couch, instance_token) of
+ {ok, Tok} ->
+ Tok;
+ _ ->
+ Tok = erlang:phash2(make_ref()),
+ application:set_env(couch, instance_token, Tok),
+ Tok
+ end,
+ send_json(Req, 200, {[{token, Token}]});
handle_restart_req(#httpd{method='POST'}=Req) ->
couch_httpd:validate_ctype(Req, "application/json"),
ok = couch_httpd:verify_is_server_admin(Req),