ClickHouse/utils/keeper-data-dumper/main.cpp

88 lines
2.9 KiB
C++
Raw Normal View History

2021-03-16 11:44:43 +00:00
#include <Poco/ConsoleChannel.h>
#include <Poco/Logger.h>
2021-03-29 09:16:58 +00:00
#include <Coordination/KeeperStateMachine.h>
2021-03-16 11:44:43 +00:00
#include <Common/ZooKeeper/ZooKeeperCommon.h>
#include <Common/ZooKeeper/ZooKeeperIO.h>
#include <Common/Exception.h>
#include <libnuraft/nuraft.hxx> // Y_IGNORE
2021-03-29 09:16:58 +00:00
#include <Coordination/KeeperLogStore.h>
2021-03-16 11:44:43 +00:00
#include <Coordination/Changelog.h>
2021-10-02 07:13:14 +00:00
#include <base/logger_useful.h>
2021-03-16 11:44:43 +00:00
using namespace Coordination;
using namespace DB;
2021-03-29 09:16:58 +00:00
void dumpMachine(std::shared_ptr<KeeperStateMachine> machine)
2021-03-16 11:44:43 +00:00
{
auto & storage = machine->getStorage();
std::queue<std::string> keys;
keys.push("/");
while (!keys.empty())
{
auto key = keys.front();
keys.pop();
std::cout << key << "\n";
2021-03-16 12:37:46 +00:00
auto value = storage.container.getValue(key);
2021-03-16 11:44:43 +00:00
std::cout << "\tStat: {version: " << value.stat.version <<
", mtime: " << value.stat.mtime <<
", emphemeralOwner: " << value.stat.ephemeralOwner <<
", czxid: " << value.stat.czxid <<
", mzxid: " << value.stat.mzxid <<
", numChildren: " << value.stat.numChildren <<
", dataLength: " << value.stat.dataLength <<
"}" << std::endl;
std::cout << "\tData: " << storage.container.getValue(key).data << std::endl;
for (const auto & child : value.children)
{
if (key == "/")
keys.push(key + child);
else
keys.push(key + "/" + child);
}
}
std::cout << std::flush;
}
int main(int argc, char *argv[])
{
if (argc != 3)
{
std::cerr << "usage: " << argv[0] << " snapshotpath logpath" << std::endl;
return 3;
}
else
{
Poco::AutoPtr<Poco::ConsoleChannel> channel(new Poco::ConsoleChannel(std::cerr));
Poco::Logger::root().setChannel(channel);
Poco::Logger::root().setLevel("trace");
}
2021-03-30 07:45:51 +00:00
auto * logger = &Poco::Logger::get("keeper-dumper");
2021-03-16 11:44:43 +00:00
ResponsesQueue queue;
SnapshotsQueue snapshots_queue{1};
CoordinationSettingsPtr settings = std::make_shared<CoordinationSettings>();
2021-03-29 09:16:58 +00:00
auto state_machine = std::make_shared<KeeperStateMachine>(queue, snapshots_queue, argv[1], settings);
2021-03-16 11:44:43 +00:00
state_machine->init();
size_t last_commited_index = state_machine->last_commit_index();
2021-03-23 07:28:14 +00:00
LOG_INFO(logger, "Last committed index: {}", last_commited_index);
2021-03-16 11:44:43 +00:00
2021-09-25 15:20:16 +00:00
DB::KeeperLogStore changelog(argv[2], 10000000, true, settings->compress_logs);
2021-03-16 11:44:43 +00:00
changelog.init(last_commited_index, 10000000000UL); /// collect all logs
if (changelog.size() == 0)
LOG_INFO(logger, "Changelog empty");
else
LOG_INFO(logger, "Last changelog entry {}", changelog.next_slot() - 1);
for (size_t i = last_commited_index + 1; i < changelog.next_slot(); ++i)
{
if (changelog.entry_at(i)->get_val_type() == nuraft::log_val_type::app_log)
state_machine->commit(i, changelog.entry_at(i)->get_buf());
}
dumpMachine(state_machine);
return 0;
}