ClickHouse/programs/keeper-converter/KeeperConverter.cpp

70 lines
3.0 KiB
C++
Raw Normal View History

2021-06-17 16:32:50 +00:00
#include <iostream>
#include <boost/program_options.hpp>
2024-02-14 11:11:45 +00:00
#include <Coordination/CoordinationSettings.h>
2021-06-17 16:32:50 +00:00
#include <Coordination/KeeperSnapshotManager.h>
#include <Coordination/ZooKeeperDataReader.h>
#include <Coordination/KeeperContext.h>
2021-06-17 16:32:50 +00:00
#include <Common/TerminalSize.h>
#include <Poco/ConsoleChannel.h>
#include <Poco/AutoPtr.h>
#include <Poco/Logger.h>
2022-04-27 15:05:45 +00:00
#include <Common/logger_useful.h>
#include <Disks/DiskLocal.h>
2021-06-17 16:32:50 +00:00
int mainEntryClickHouseKeeperConverter(int argc, char ** argv)
{
using namespace DB;
namespace po = boost::program_options;
po::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth());
desc.add_options()
("help,h", "produce help message")
("zookeeper-logs-dir", po::value<std::string>(), "Path to directory with ZooKeeper logs")
("zookeeper-snapshots-dir", po::value<std::string>(), "Path to directory with ZooKeeper snapshots")
("output-dir", po::value<std::string>(), "Directory to place output clickhouse-keeper snapshot")
;
po::variables_map options;
po::store(po::command_line_parser(argc, argv).options(desc).run(), options);
Poco::AutoPtr<Poco::ConsoleChannel> console_channel(new Poco::ConsoleChannel);
2024-01-23 17:04:50 +00:00
LoggerPtr logger = getLogger("KeeperConverter");
2021-06-17 16:32:50 +00:00
logger->setChannel(console_channel);
if (options.count("help"))
{
std::cout << "Usage: " << argv[0] << " --zookeeper-logs-dir /var/lib/zookeeper/data/version-2 --zookeeper-snapshots-dir /var/lib/zookeeper/data/version-2 --output-dir /var/lib/clickhouse/coordination/snapshots" << std::endl;
std::cout << desc << std::endl;
return 0;
}
2024-02-05 14:30:00 +00:00
try
{
2024-02-14 11:11:45 +00:00
auto keeper_context = std::make_shared<KeeperContext>(true, std::make_shared<CoordinationSettings>());
2024-02-05 14:30:00 +00:00
keeper_context->setDigestEnabled(true);
keeper_context->setSnapshotDisk(std::make_shared<DiskLocal>("Keeper-snapshots", options["output-dir"].as<std::string>()));
2022-07-23 14:27:44 +00:00
2024-02-05 14:30:00 +00:00
DB::KeeperStorage storage(/* tick_time_ms */ 500, /* superdigest */ "", keeper_context, /* initialize_system_nodes */ false);
2021-06-17 16:32:50 +00:00
2024-02-05 14:30:00 +00:00
DB::deserializeKeeperStorageFromSnapshotsDir(storage, options["zookeeper-snapshots-dir"].as<std::string>(), logger);
storage.initializeSystemNodes();
2022-07-21 09:31:06 +00:00
2024-02-05 14:30:00 +00:00
DB::deserializeLogsAndApplyToStorage(storage, options["zookeeper-logs-dir"].as<std::string>(), logger);
DB::SnapshotMetadataPtr snapshot_meta = std::make_shared<DB::SnapshotMetadata>(storage.getZXID(), 1, std::make_shared<nuraft::cluster_config>());
DB::KeeperStorageSnapshot snapshot(&storage, snapshot_meta);
2021-06-17 16:32:50 +00:00
2024-02-05 14:30:00 +00:00
DB::KeeperSnapshotManager manager(1, keeper_context);
auto snp = manager.serializeSnapshotToBuffer(snapshot);
auto file_info = manager.serializeSnapshotBufferToDisk(*snp, storage.getZXID());
std::cout << "Snapshot serialized to path:" << fs::path(file_info.disk->getPath()) / file_info.path << std::endl;
}
catch (...)
{
std::cerr << getCurrentExceptionMessage(true) << '\n';
return getCurrentExceptionCode();
}
2021-06-17 16:32:50 +00:00
return 0;
}