Example #1
0
void remove_config_fromzk(lock_service& z,
                          const string& type, const string& name)
{
  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);

  if(!z.exists(path))
    throw JUBATUS_EXCEPTION(jubatus::exception::runtime_error("config is not exists: " + path));

  if (!z.remove(path))
    throw JUBATUS_EXCEPTION(jubatus::exception::runtime_error("failed to remove config from zookeeper:" + path)
        << jubatus::exception::error_api_func("lock_service::remove"));

  LOG(INFO) << "remove config from zookeeper: " << path;
}
Example #2
0
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;
}
Example #3
0
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;
}