bool register_keeper(lock_service& z, const std::string& ip, int port){ std::string path = JUBAKEEPER_BASE_PATH; z.create(path, ""); { std::string path1; build_existence_path(path, ip, port, path1); z.create(path1, "", true); } // set exit zlistener here pfi::lang::function <void()> f = &force_exit; z.push_cleanup(f); return true; }
void config_tozk(lock_service& z, const string& type, const string& name, string& config) { string lock_path; build_config_lock_path(lock_path, type, name); if(!z.exists(lock_path)) throw JUBATUS_EXCEPTION(jubatus::exception::runtime_error("node is not exists: " + lock_path)); common::lock_service_mutex zk_config_lock(z, lock_path); int retry = 3; while(!zk_config_lock.try_lock()){ if (retry == 0) throw JUBATUS_EXCEPTION(jubatus::exception::runtime_error("any user is using config?")); retry--; sleep(1); } if (!is_no_workers(z, type, name)) throw JUBATUS_EXCEPTION(jubatus::exception::runtime_error("any server is running: " + type + ", " + name)); string path; build_config_path(path, type, name); bool success = true; success = z.create(path) && success; success = z.set(path, config) && success; if (!success) throw JUBATUS_EXCEPTION(jubatus::exception::runtime_error("failed to set config to zookeeper:" + path) << jubatus::exception::error_api_func("lock_service::set")); LOG(INFO) << "set config to zookeeper: " << path; }
// zk -> name -> ip -> port -> bool bool register_actor(lock_service& z, const std::string& name, const std::string& ip, int port){ std::string path = ACTOR_BASE_PATH + "/" + name; z.create(path, ""); z.create(path + "/master_lock", ""); path += "/nodes"; z.create(path , ""); { std::string path1; build_existence_path(path, ip, port, path1); z.create(path1, "", true); } // set exit zlistener here pfi::lang::function <void()> f = &force_exit; z.push_cleanup(f); return true; }
void cht::setup_cht_dir( lock_service& ls, const std::string& type, const std::string& name) { bool success = true; std::string path; build_actor_path(path, type, name); success = ls.create(path) && success; path += "/cht"; success = ls.create(path) && success; if (!success) { throw JUBATUS_EXCEPTION( core::common::exception::runtime_error("Failed to create cht directory") << core::common::exception::error_api_func("lock_service::create") << core::common::exception::error_message("cht path: " + path)); } }
void prepare_jubatus(lock_service& ls){ ls.create(JUBATUS_BASE_PATH); ls.create(JUBAVISOR_BASE_PATH); ls.create(JUBAKEEPER_BASE_PATH); ls.create(ACTOR_BASE_PATH); }
void cht::setup_cht_dir(lock_service& ls, const std::string& name){ std::string path = ACTOR_BASE_PATH + "/" + name; ls.create(path, ""); path += "/cht"; ls.create(path, ""); }
void config_tozk( lock_service& z, const string& type, const string& name, string& config, const string& config_src) { if (config == "") { throw JUBATUS_EXCEPTION( jubatus::core::common::exception::runtime_error("config is empty")); } try { jubatus::util::lang::lexical_cast<jubatus::util::text::json::json>(config); } catch (jubatus::util::lang::parse_error& e) { std::string msg = std::string("syntax error in configuration: ") + config_src + ":" + jubatus::util::lang::lexical_cast<std::string>(e.lineno()) + ":" + jubatus::util::lang::lexical_cast<std::string>(e.pos()) + " " + e.msg(); throw JUBATUS_EXCEPTION(core::common::exception::runtime_error(msg)); } string lock_path; build_config_lock_path(lock_path, type, name); if (!z.exists(lock_path)) { throw JUBATUS_EXCEPTION( core::common::exception::runtime_error( "node is not exists: " + lock_path)); } common::lock_service_mutex zk_config_lock(z, lock_path); int retry = 3; while (!zk_config_lock.try_lock()) { if (retry == 0) { throw JUBATUS_EXCEPTION( core::common::exception::runtime_error("any user is using config?")); } retry--; sleep(1); } if (!is_no_workers(z, type, name)) { throw JUBATUS_EXCEPTION(jubatus::core::common::exception::runtime_error( "any server is running: " + type + ", " + name)); } string path; build_config_path(path, type, name); bool success = true; success = z.create(path) && success; success = z.set(path, config) && success; if (!success) { throw JUBATUS_EXCEPTION(jubatus::core::common::exception::runtime_error( "failed to set config to zookeeper:" + path) << core::common::exception::error_api_func("lock_service::set")); } LOG(INFO) << "set config to zookeeper: " << path; }