diff --git a/include/Request.h b/include/Request.h index f11933eedd..938ecfdd08 100644 --- a/include/Request.h +++ b/include/Request.h @@ -177,6 +177,8 @@ protected: bool log_method_call; //Write method call and result to the log + bool leader_only; //Method can be only execute by leaders or solo servers + /* ---------------------------------------------------------------------- */ /* Class Constructors */ /* ---------------------------------------------------------------------- */ @@ -189,6 +191,8 @@ protected: hidden_params.clear(); log_method_call = true; + + leader_only = true; }; virtual ~Request(){}; diff --git a/include/RequestManagerInfo.h b/include/RequestManagerInfo.h index b2c91a8ade..68d67ed9d1 100644 --- a/include/RequestManagerInfo.h +++ b/include/RequestManagerInfo.h @@ -34,6 +34,8 @@ protected: :Request(method_name, "A:si", help) { auth_op = AuthRequest::USE; + + leader_only = false; }; ~RequestManagerInfo(){}; diff --git a/include/RequestManagerPoolInfoFilter.h b/include/RequestManagerPoolInfoFilter.h index 19ee399967..ee5e26eb34 100644 --- a/include/RequestManagerPoolInfoFilter.h +++ b/include/RequestManagerPoolInfoFilter.h @@ -63,7 +63,9 @@ protected: const string& help, const string& signature) :Request(method_name,signature,help) - {}; + { + leader_only = false; + }; ~RequestManagerPoolInfoFilter(){}; diff --git a/include/RequestManagerZone.h b/include/RequestManagerZone.h index 14c8d0b462..df8b8b27f2 100644 --- a/include/RequestManagerZone.h +++ b/include/RequestManagerZone.h @@ -92,6 +92,7 @@ public: "A:siiiiiiis") { log_method_call = false; + leader_only = false; }; ~ZoneReplicateLog(){}; @@ -106,9 +107,11 @@ public: class ZoneVoteRequest : public RequestManagerZone { public: - ZoneVoteRequest(): - RequestManagerZone("one.zone.voterequest", - "Request vote from a candidate", "A:siiii"){}; + ZoneVoteRequest(): RequestManagerZone("one.zone.voterequest", + "Request vote from a candidate", "A:siiii") + { + leader_only = false; + }; ~ZoneVoteRequest(){}; @@ -122,9 +125,11 @@ public: class ZoneRaftStatus : public RequestManagerZone { public: - ZoneRaftStatus(): - RequestManagerZone("one.zone.raftstatus", "Returns Raft status", - "A:s"){}; + ZoneRaftStatus(): RequestManagerZone("one.zone.raftstatus", + "Returns Raft status", "A:s") + { + leader_only = false; + }; ~ZoneRaftStatus(){}; diff --git a/src/rm/Request.cc b/src/rm/Request.cc index f95da92527..b18ade4453 100644 --- a/src/rm/Request.cc +++ b/src/rm/Request.cc @@ -273,29 +273,39 @@ void Request::execute( att.req_id = (reinterpret_cast(this) * rand()) % 10000; Nebula& nd = Nebula::instance(); - UserPool* upool = nd.get_upool(); - bool authenticated = upool->authenticate(att.session, - att.password, - att.uid, - att.gid, - att.uname, - att.gname, - att.group_ids, - att.umask); + UserPool* upool = nd.get_upool(); + RaftManager * raftm = nd.get_raftm(); + if ( log_method_call ) { log_method_invoked(att, _paramList, format_str, method_name, hidden_params); } - if ( authenticated == false ) + if ( raftm->is_follower() && leader_only) { - failure_response(AUTHENTICATION, att); + att.resp_msg = "Cannot process request, server is a follower"; + failure_response(INTERNAL, att); } - else + else if ( raftm->is_candidate() && leader_only) { - request_execute(_paramList, att); + att.resp_msg = "Cannot process request, oned cluster in election mode"; + failure_response(INTERNAL, att); + } + else //leader or solo or !leader_only + { + bool authenticated = upool->authenticate(att.session, att.password, + att.uid, att.gid, att.uname, att.gname, att.group_ids, att.umask); + + if ( authenticated == false ) + { + failure_response(AUTHENTICATION, att); + } + else + { + request_execute(_paramList, att); + } } if ( log_method_call )