Skip to content

Commit

Permalink
Fix jubagraph cannot start with ZK: fixes #179
Browse files Browse the repository at this point in the history
Before refactoring mixed bug which cause not to prepare ZK.
Fix to call server_helper_impl::prepare_for_start before *_serv constructor.
  • Loading branch information
suma committed Nov 22, 2012
1 parent b269fc9 commit 205d3fc
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 37 deletions.
4 changes: 1 addition & 3 deletions src/framework/server_helper.cpp
Expand Up @@ -49,7 +49,7 @@ server_helper_impl::server_helper_impl(const server_argv& a) {
#endif
}

bool server_helper_impl::prepare_for_start(const server_argv& a, bool use_cht) {
void server_helper_impl::prepare_for_start(const server_argv& a, bool use_cht) {
#ifdef HAVE_ZOOKEEPER_H
if (!a.is_standalone()) {
ls = zk_;
Expand All @@ -67,10 +67,8 @@ bool server_helper_impl::prepare_for_start(const server_argv& a, bool use_cht) {
}

register_actor(*zk_, a.type, a.name, a.eth, a.port);
return true;
}
#endif
return false;
}

}
Expand Down
18 changes: 9 additions & 9 deletions src/framework/server_helper.hpp
Expand Up @@ -35,7 +35,7 @@ namespace framework {
class server_helper_impl {
public:
explicit server_helper_impl(const server_argv& a);
bool prepare_for_start(const server_argv& a, bool use_cht);
void prepare_for_start(const server_argv& a, bool use_cht);

common::cshared_ptr<jubatus::common::lock_service> zk() const {
return zk_;
Expand All @@ -50,8 +50,10 @@ class server_helper {
public:
typedef typename Server::status_t status_t;

explicit server_helper(const server_argv& a)
: impl_(a), use_cht_(false) {
explicit server_helper(const server_argv& a, bool use_cht = false)
: impl_(a), use_cht_(use_cht) {

impl_.prepare_for_start(a, use_cht);
server_.reset(new Server(a, impl_.zk()));
}

Expand Down Expand Up @@ -100,13 +102,10 @@ class server_helper {
return status;
}

void use_cht() {
use_cht_ = true;
}

int start(pfi::network::mprpc::rpc_server& serv) {
const server_argv& a = server_->argv();
if (impl_.prepare_for_start(a, use_cht_)) {

if (!a.is_standalone()) {
server_->get_mixer()->start();
}

Expand All @@ -127,9 +126,10 @@ class server_helper {
}

private:

common::cshared_ptr<Server> server_;
server_helper_impl impl_;
bool use_cht_;
const bool use_cht_;
};

}
Expand Down
4 changes: 2 additions & 2 deletions src/server/graph_impl.cpp
Expand Up @@ -19,8 +19,8 @@ class graph_impl_ : public graph<graph_impl_>
public:
graph_impl_(const server_argv& a):
graph<graph_impl_>(a.timeout),
p_(new server_helper<graph_serv>(a))
{ p_->use_cht();}
p_(new server_helper<graph_serv>(a, true))
{}

std::string create_node(std::string name) //nolock random
{ NOLOCK__(p_); RETURN_OR_THROW(get_p()->create_node()); }
Expand Down
4 changes: 2 additions & 2 deletions src/server/recommender_impl.cpp
Expand Up @@ -19,8 +19,8 @@ class recommender_impl_ : public recommender<recommender_impl_>
public:
recommender_impl_(const server_argv& a):
recommender<recommender_impl_>(a.timeout),
p_(new server_helper<recommender_serv>(a))
{ p_->use_cht();}
p_(new server_helper<recommender_serv>(a, true))
{}

bool set_config(std::string name, config_data c) //update broadcast
{ JWLOCK__(p_); RETURN_OR_THROW(get_p()->set_config(c)); }
Expand Down
4 changes: 2 additions & 2 deletions src/server/stat_impl.cpp
Expand Up @@ -19,8 +19,8 @@ class stat_impl_ : public stat<stat_impl_>
public:
stat_impl_(const server_argv& a):
stat<stat_impl_>(a.timeout),
p_(new server_helper<stat_serv>(a))
{ p_->use_cht();}
p_(new server_helper<stat_serv>(a, true))
{}

bool set_config(std::string name, config_data c) //update broadcast
{ JWLOCK__(p_); RETURN_OR_THROW(get_p()->set_config(c)); }
Expand Down
38 changes: 19 additions & 19 deletions tools/generator/impl_generator.ml
Expand Up @@ -84,33 +84,33 @@ let generate s output strees =

output <<< "namespace jubatus { namespace server {";
(* output <<< "using "^s#basename^"::server::"^s#basename^";"; no way!! *)
output <<< ("class "^s#basename^"_impl_ : public "^s#basename^"<"^s#basename^"_impl_>");
output <<< "{";
output <<< "public:";
output <<< (" "^s#basename^"_impl_(const server_argv& a):");
output <<< (" "^s#basename^"<"^s#basename^"_impl_>(a.timeout),");
output <<< (" p_(new server_helper<"^s#basename^"_serv>(a))");



let use_cht =
let include_cht_api = function
| Service(_, methods) ->
let has_cht (Method(_,_,_,decs)) =
let rec has_cht_ = function
| [] -> false;
| Routing(Cht(_))::_ -> true;
| _::tl -> has_cht_ tl
in
has_cht_ decs
in
List.exists has_cht methods;
let has_cht (Method(_,_,_,decs)) =
let rec has_cht_ = function
| [] -> false;
| Routing(Cht(_))::_ -> true;
| _::tl -> has_cht_ tl
in
has_cht_ decs
in
List.exists has_cht methods;
| _ -> false
in
if List.exists include_cht_api strees then " p_->use_cht();"
if List.exists include_cht_api strees then ", true"
else ""
in
output <<< (" {" ^ use_cht ^ "}");
output <<< ("class "^s#basename^"_impl_ : public "^s#basename^"<"^s#basename^"_impl_>");
output <<< "{";
output <<< "public:";
output <<< (" "^s#basename^"_impl_(const server_argv& a):");
output <<< (" "^s#basename^"<"^s#basename^"_impl_>(a.timeout),");
output <<< (" p_(new server_helper<"^s#basename^"_serv>(a" ^ use_cht ^ "))");
output <<< (" {}");



List.iter (fun l -> output <<< l)
(List.flatten (List.map to_impl_strings
Expand Down

0 comments on commit 205d3fc

Please sign in to comment.