Пример #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;
}