1#include <IO/ReadHelpers.h>
2#include <IO/WriteHelpers.h>
3#include <Common/Config/ConfigProcessor.h>
4#include <Common/ZooKeeper/ZooKeeper.h>
5#include <Common/Exception.h>
6#include <Common/Stopwatch.h>
7#include <Storages/MergeTree/EphemeralLockInZooKeeper.h>
8
9#include <ext/scope_guard.h>
10#include <pcg_random.hpp>
11
12#include <iostream>
13
14
15using namespace DB;
16
17/// This test is useful for assessing the performance of acquiring block numbers in all partitions (and there
18/// can be ~1000 of them). This is needed when creating a mutation entry for a ReplicatedMergeTree table.
19int main(int argc, char ** argv)
20try
21{
22 if (argc != 3)
23 {
24 std::cerr << "usage: " << argv[0] << " <zookeeper_config> <path_to_table>" << std::endl;
25 return 3;
26 }
27
28 ConfigProcessor processor(argv[1], false, true);
29 auto config = processor.loadConfig().configuration;
30 String root_path = argv[2];
31
32 zkutil::ZooKeeper zk(*config, "zookeeper");
33
34 String temp_path = root_path + "/temp";
35 String blocks_path = root_path + "/block_numbers";
36
37 Stopwatch total_timer;
38 Stopwatch timer;
39
40 EphemeralLocksInAllPartitions locks(blocks_path, "test_lock-", temp_path, zk);
41
42 std::cerr << "Locked, elapsed: " << timer.elapsedSeconds() << std::endl;
43 for (const auto & lock : locks.getLocks())
44 std::cout << lock.partition_id << " " << lock.number << std::endl;
45 timer.restart();
46
47 locks.unlock();
48 std::cerr << "Abandoned, elapsed: " << timer.elapsedSeconds() << std::endl;
49
50 std::cerr << "Total elapsed: " << total_timer.elapsedSeconds() << std::endl;
51
52 return 0;
53}
54catch (const Exception & e)
55{
56 std::cerr << e.what() << ", " << e.displayText() << ": " << std::endl
57 << e.getStackTrace().toString() << std::endl;
58 throw;
59}
60catch (Poco::Exception & e)
61{
62 std::cerr << "Exception: " << e.displayText() << std::endl;
63 throw;
64}
65catch (std::exception & e)
66{
67 std::cerr << "std::exception: " << e.what() << std::endl;
68 throw;
69}
70catch (...)
71{
72 std::cerr << "Some exception" << std::endl;
73 throw;
74}
75