2018-03-25 04:20:31 +00:00
|
|
|
#include <list>
|
2017-06-19 20:06:35 +00:00
|
|
|
#include <Common/ZooKeeper/ZooKeeper.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/ReadHelpers.h>
|
|
|
|
#include <IO/ReadBufferFromFileDescriptor.h>
|
2015-09-23 20:49:49 +00:00
|
|
|
#include <boost/program_options.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
;
|
2015-09-23 20:49:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
boost::program_options::variables_map options;
|
|
|
|
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
|
2015-09-23 20:49:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (options.count("help"))
|
|
|
|
{
|
|
|
|
std::cout << "Remove nodes in ZooKeeper by list passed in stdin." << std::endl;
|
|
|
|
std::cout << "Usage: " << argv[0] << " [options] < list_of_nodes_on_each_line" << std::endl;
|
|
|
|
std::cout << desc << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2015-09-23 20:49:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
zkutil::ZooKeeper zookeeper(options.at("address").as<std::string>());
|
2015-09-23 20:49:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
DB::ReadBufferFromFileDescriptor in(STDIN_FILENO);
|
2018-08-25 01:58:14 +00:00
|
|
|
std::list<std::future<Coordination::RemoveResponse>> futures;
|
2015-09-23 20:49:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << "Requested: ";
|
|
|
|
while (!in.eof())
|
|
|
|
{
|
|
|
|
std::string path;
|
|
|
|
DB::readEscapedString(path, in);
|
|
|
|
DB::assertString("\n", in);
|
2018-03-25 04:20:31 +00:00
|
|
|
futures.emplace_back(zookeeper.asyncRemove(path));
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << ".";
|
|
|
|
}
|
|
|
|
std::cerr << "\n";
|
2015-09-23 20:49:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << "Done: ";
|
|
|
|
for (auto & future : futures)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
future.get();
|
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
|
|
|
|
}
|
|
|
|
std::cerr << ".";
|
|
|
|
}
|
|
|
|
std::cerr << "\n";
|
2015-09-23 20:49:49 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return 0;
|
2015-09-23 20:49:49 +00:00
|
|
|
}
|
2020-05-09 22:59:34 +00:00
|
|
|
catch (...)
|
2015-09-23 20:49:49 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
|
|
|
|
throw;
|
2015-09-23 20:49:49 +00:00
|
|
|
}
|