File: main.cpp

package info (click to toggle)
clickhouse 18.16.1%2Bds-7.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 40,292 kB
  • sloc: cpp: 223,075; sql: 21,608; python: 6,596; sh: 4,299; ansic: 3,889; xml: 3,312; perl: 155; makefile: 57; asm: 34
file content (66 lines) | stat: -rw-r--r-- 1,878 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <list>
#include <Common/ZooKeeper/ZooKeeper.h>
#include <IO/ReadHelpers.h>
#include <IO/ReadBufferFromFileDescriptor.h>
#include <boost/program_options.hpp>


int main(int argc, char ** argv)
try
{
    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")
        ;

    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 << "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;
    }

    zkutil::ZooKeeper zookeeper(options.at("address").as<std::string>());

    DB::ReadBufferFromFileDescriptor in(STDIN_FILENO);
    std::list<std::future<Coordination::RemoveResponse>> futures;

    std::cerr << "Requested: ";
    while (!in.eof())
    {
        std::string path;
        DB::readEscapedString(path, in);
        DB::assertString("\n", in);
        futures.emplace_back(zookeeper.asyncRemove(path));
        std::cerr << ".";
    }
    std::cerr << "\n";

    std::cerr << "Done: ";
    for (auto & future : futures)
    {
        try
        {
            future.get();
        }
        catch (...)
        {
            std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
        }
        std::cerr << ".";
    }
    std::cerr << "\n";

    return 0;
}
catch (const Poco::Exception & e)
{
    std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
    throw;
}