1 | #include <iostream> |
2 | #include <Common/ZooKeeper/ZooKeeper.h> |
3 | #include <Common/ZooKeeper/KeeperException.h> |
4 | #include <Poco/ConsoleChannel.h> |
5 | #include <Common/Exception.h> |
6 | |
7 | |
8 | /// Проверяет, какие ошибки выдает ZooKeeper при попытке сделать какую-нибудь операцию через разное время после истечения сессии. |
9 | /// Спойлер: multi иногда падает с segfault, а до этого фейлится с marshalling error. |
10 | /// create всегда фейлится с invalid zhandle state. |
11 | |
12 | int main(int argc, char ** argv) |
13 | { |
14 | try |
15 | { |
16 | if (argc != 2) |
17 | { |
18 | std::cerr << "usage: " << argv[0] << " hosts" << std::endl; |
19 | return 2; |
20 | } |
21 | |
22 | Poco::AutoPtr<Poco::ConsoleChannel> channel = new Poco::ConsoleChannel(std::cerr); |
23 | Logger::root().setChannel(channel); |
24 | Logger::root().setLevel("trace" ); |
25 | |
26 | zkutil::ZooKeeper zk(argv[1]); |
27 | std::string unused; |
28 | zk.tryCreate("/test" , "" , zkutil::CreateMode::Persistent, unused); |
29 | |
30 | std::cerr << "Please run `./nozk.sh && sleep 40s && ./yeszk.sh`" << std::endl; |
31 | |
32 | time_t time0 = time(nullptr); |
33 | |
34 | while (true) |
35 | { |
36 | { |
37 | Coordination::Requests ops; |
38 | ops.emplace_back(zkutil::makeCreateRequest("/test/zk_expiration_test" , "hello" , zkutil::CreateMode::Persistent)); |
39 | ops.emplace_back(zkutil::makeRemoveRequest("/test/zk_expiration_test" , -1)); |
40 | |
41 | Coordination::Responses responses; |
42 | int32_t code = zk.tryMultiNoThrow(ops, responses); |
43 | |
44 | std::cout << time(nullptr) - time0 << "s: " << zkutil::ZooKeeper::error2string(code) << std::endl; |
45 | try |
46 | { |
47 | if (code) |
48 | std::cout << "Path: " << zkutil::KeeperMultiException(code, ops, responses).getPathForFirstFailedOp() << std::endl; |
49 | } |
50 | catch (...) |
51 | { |
52 | std::cout << DB::getCurrentExceptionMessage(false) << std::endl; |
53 | } |
54 | |
55 | } |
56 | |
57 | sleep(1); |
58 | } |
59 | } |
60 | catch (Coordination::Exception &) |
61 | { |
62 | std::cerr << "KeeperException: " << DB::getCurrentExceptionMessage(true) << std::endl; |
63 | return 1; |
64 | } |
65 | catch (...) |
66 | { |
67 | std::cerr << "Some exception: " << DB::getCurrentExceptionMessage(true) << std::endl; |
68 | return 2; |
69 | } |
70 | } |
71 | |