2018-03-25 04:20:31 +00:00
|
|
|
#include <list>
|
2015-09-23 01:21:47 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <boost/program_options.hpp>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Common/Exception.h>
|
2018-03-25 04:20:31 +00:00
|
|
|
#include <Common/ZooKeeper/ZooKeeper.h>
|
2018-04-03 17:35:48 +00:00
|
|
|
#include <Common/ZooKeeper/KeeperException.h>
|
2015-09-23 01:21:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
try
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
boost::program_options::options_description desc("Allowed options");
|
|
|
|
desc.add_options()
|
|
|
|
("help,h", "produce help message")
|
|
|
|
("address,a", boost::program_options::value<std::string>()->required(),
|
|
|
|
"addresses of ZooKeeper instances, comma separated. Example: example01e.yandex.ru:2181")
|
|
|
|
("path,p", boost::program_options::value<std::string>()->default_value("/"),
|
|
|
|
"where to start")
|
|
|
|
;
|
|
|
|
|
|
|
|
boost::program_options::variables_map options;
|
|
|
|
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
|
|
|
|
|
|
|
|
if (options.count("help"))
|
|
|
|
{
|
|
|
|
std::cout << "Dump paths of all nodes in ZooKeeper." << std::endl;
|
|
|
|
std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
|
|
|
|
std::cout << desc << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-03-25 04:20:31 +00:00
|
|
|
zkutil::ZooKeeper zookeeper(options.at("address").as<std::string>());
|
|
|
|
|
|
|
|
std::string initial_path = options.at("path").as<std::string>();
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-08-25 01:58:14 +00:00
|
|
|
std::list<std::pair<std::string, std::future<Coordination::ListResponse>>> list_futures;
|
2018-03-25 04:20:31 +00:00
|
|
|
list_futures.emplace_back(initial_path, zookeeper.asyncGetChildren(initial_path));
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-03-25 04:20:31 +00:00
|
|
|
for (auto it = list_futures.begin(); it != list_futures.end(); ++it)
|
|
|
|
{
|
2018-08-25 01:58:14 +00:00
|
|
|
Coordination::ListResponse response;
|
2018-03-25 04:20:31 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
response = it->second.get();
|
|
|
|
}
|
2018-08-25 01:58:14 +00:00
|
|
|
catch (const Coordination::Exception & e)
|
2018-03-25 04:20:31 +00:00
|
|
|
{
|
2020-06-12 15:09:12 +00:00
|
|
|
if (e.code == Coordination::Error::ZNONODE)
|
2018-03-25 04:20:31 +00:00
|
|
|
continue;
|
|
|
|
throw;
|
|
|
|
}
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-03-25 04:20:31 +00:00
|
|
|
std::cout << it->first << '\t' << response.stat.numChildren << '\t' << response.stat.dataLength << '\n';
|
2017-04-01 07:20:54 +00:00
|
|
|
|
2018-03-25 04:20:31 +00:00
|
|
|
for (const auto & name : response.names)
|
|
|
|
{
|
|
|
|
std::string child_path = it->first == "/" ? it->first + name : it->first + '/' + name;
|
|
|
|
list_futures.emplace_back(child_path, zookeeper.asyncGetChildren(child_path));
|
|
|
|
}
|
|
|
|
}
|
2015-09-23 01:21:47 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
|
|
|
|
throw;
|
2015-09-23 01:21:47 +00:00
|
|
|
}
|