Repository: mesos Updated Branches: refs/heads/master fb93d93cd -> a8414b507
Fixed master to drop scheduler HTTP calls during recovery. Review: https://reviews.apache.org/r/37588 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a8414b50 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a8414b50 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a8414b50 Branch: refs/heads/master Commit: a8414b507dedfea50ec80a1591c73005a971a60e Parents: fb93d93 Author: Vinod Kone <[email protected]> Authored: Tue Aug 18 10:28:53 2015 -0700 Committer: Vinod Kone <[email protected]> Committed: Tue Aug 18 12:11:28 2015 -0700 ---------------------------------------------------------------------- src/master/http.cpp | 17 +++++++++++++++++ src/scheduler/scheduler.cpp | 28 ++++++++++++++++++---------- 2 files changed, 35 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/a8414b50/src/master/http.cpp ---------------------------------------------------------------------- diff --git a/src/master/http.cpp b/src/master/http.cpp index d016b3c..37d76ee 100644 --- a/src/master/http.cpp +++ b/src/master/http.cpp @@ -76,6 +76,7 @@ using process::http::NotImplemented; using process::http::NotAcceptable; using process::http::OK; using process::http::Pipe; +using process::http::ServiceUnavailable; using process::http::TemporaryRedirect; using process::http::Unauthorized; using process::http::UnsupportedMediaType; @@ -341,6 +342,22 @@ const string Master::Http::SCHEDULER_HELP = HELP( Future<Response> Master::Http::scheduler(const Request& request) const { + // TODO(vinod): Add metrics for rejected requests. + + // TODO(vinod): Add support for rate limiting. + + if (!master->elected()) { + // Note that this could happen if the scheduler realizes this is the + // leading master before master itself realizes it (e.g., ZK watch delay). + return ServiceUnavailable("Not the leading master"); + } + + CHECK_SOME(master->recovered); + + if (!master->recovered.get().isReady()) { + return ServiceUnavailable("Master has not finished recovery"); + } + if (master->flags.authenticate_frameworks) { return Unauthorized( "Mesos master", http://git-wip-us.apache.org/repos/asf/mesos/blob/a8414b50/src/scheduler/scheduler.cpp ---------------------------------------------------------------------- diff --git a/src/scheduler/scheduler.cpp b/src/scheduler/scheduler.cpp index 37f41de..ee146eb 100644 --- a/src/scheduler/scheduler.cpp +++ b/src/scheduler/scheduler.cpp @@ -348,8 +348,9 @@ protected: return; } - if (call.type() == Call::SUBSCRIBE && - response.get().status == process::http::statuses[200] ) { + if (response.get().status == process::http::statuses[200]) { + // Only SUBSCRIBE call should get a "200 OK" response. + CHECK_EQ(Call::SUBSCRIBE, call.type()); CHECK_EQ(response.get().type, http::Response::PIPE); CHECK_SOME(response.get().reader); @@ -364,21 +365,28 @@ protected: connection = Connection {reader, decoder}; read(); + + return; + } + + if (response.get().status == process::http::statuses[202]) { + // Only non SUBSCRIBE calls should get a "202 Accepted" response. + CHECK_NE(Call::SUBSCRIBE, call.type()); return; } - if (call.type() != Call::SUBSCRIBE && - response.get().status == process::http::statuses[202] ) { + if (response.get().status == process::http::statuses[503]) { + // This could happen if the master hasn't realized it is the leader yet + // or is still in the process of recovery. + LOG(WARNING) << "Received '" << response.get().status << "' (" + << response.get().body << ") for " << call.type(); return; } // We should be able to get here only for AuthN errors which is not - // yet supported for HTTP frameworks. The other possible scenario - // can be that the master was not able to de-serialize the Call - // message. Since we validate the Call messages before sending, this - // can only happen when a packet corruption happens. - error("Received unexpected '" + response.get().status + "' for " + - stringify(call.type()) + " call: " + response.get().body); + // yet supported for HTTP frameworks. + error("Received unexpected '" + response.get().status + "' (" + + response.get().body + ") for " + stringify(call.type())); } void ___send()
