Ejemplo n.º 1
0
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")
	("path,p", boost::program_options::value<std::string>()->required(), "path of replica queue to insert node (without trailing slash)")
	("name,n", boost::program_options::value<std::string>()->required(), "name of part to download")
	;

	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 << "Insert log entry to replication queue to download part from any replica." << std::endl;
		std::cout << "Usage: " << argv[0] << " [options]" << std::endl;
		std::cout << desc << std::endl;
		return 1;
	}

	std::string path = options.at("path").as<std::string>();
	std::string name = options.at("name").as<std::string>();

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

	DB::ReplicatedMergeTreeLogEntry entry;
	entry.type = DB::ReplicatedMergeTreeLogEntry::MERGE_PARTS;
	entry.parts_to_merge = {name};
	entry.new_part_name = name;

	zookeeper.create(path + "/queue-", entry.toString(), zkutil::CreateMode::PersistentSequential);
	return 0;
}
catch (const Poco::Exception & e)
{
	std::cerr << DB::getCurrentExceptionMessage(true) << '\n';
	throw;
}
Ejemplo n.º 2
0
int main()
try
{
    ZooKeeperImpl::ZooKeeper zookeeper({Poco::Net::SocketAddress{"localhost:2181"}}, "", "", "", {30, 0}, {0, 50000}, {0, 50000});

    zookeeper.create("/test", "hello", false, false, {}, [](const ZooKeeperImpl::ZooKeeper::CreateResponse & response)
    {
        if (response.error)
            std::cerr << "Error " << response.error << ": " << ZooKeeperImpl::ZooKeeper::errorMessage(response.error) << "\n";
        else
            std::cerr << "Path created: " << response.path_created << "\n";
    });

    sleep(100);

    return 0;
}
catch (...)
{
    DB::tryLogCurrentException(__PRETTY_FUNCTION__);
    return 1;
}