1#include <list>
2#include <Common/ZooKeeper/ZooKeeper.h>
3#include <IO/ReadHelpers.h>
4#include <IO/ReadBufferFromFileDescriptor.h>
5#include <boost/program_options.hpp>
6
7
8int main(int argc, char ** argv)
9try
10{
11 boost::program_options::options_description desc("Allowed options");
12 desc.add_options()
13 ("help,h", "produce help message")
14 ("address,a", boost::program_options::value<std::string>()->required(),
15 "addresses of ZooKeeper instances, comma separated. Example: example01e.yandex.ru:2181")
16 ;
17
18 boost::program_options::variables_map options;
19 boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
20
21 if (options.count("help"))
22 {
23 std::cout << "Remove nodes in ZooKeeper by list passed in stdin." << std::endl;
24 std::cout << "Usage: " << argv[0] << " [options] < list_of_nodes_on_each_line" << std::endl;
25 std::cout << desc << std::endl;
26 return 1;
27 }
28
29 zkutil::ZooKeeper zookeeper(options.at("address").as<std::string>());
30
31 DB::ReadBufferFromFileDescriptor in(STDIN_FILENO);
32 std::list<std::future<Coordination::RemoveResponse>> futures;
33
34 std::cerr << "Requested: ";
35 while (!in.eof())
36 {
37 std::string path;
38 DB::readEscapedString(path, in);
39 DB::assertString("\n", in);
40 futures.emplace_back(zookeeper.asyncRemove(path));
41 std::cerr << ".";
42 }
43 std::cerr << "\n";
44
45 std::cerr << "Done: ";
46 for (auto & future : futures)
47 {
48 try
49 {
50 future.get();
51 }
52 catch (...)
53 {
54 std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
55 }
56 std::cerr << ".";
57 }
58 std::cerr << "\n";
59
60 return 0;
61}
62catch (const Poco::Exception & e)
63{
64 std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
65 throw;
66}
67