MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / dumpStateMachine

Function dumpStateMachine

programs/keeper-utils/KeeperUtils.cpp:630–708  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

628}
629
630int dumpStateMachine(
631 const std::string & snapshot_path,
632 const std::string & log_path,
633 bool debug_mode,
634 const std::string & output_file,
635 const std::string & output_format,
636 bool parallel_output,
637 bool with_acl,
638 uint64_t end_index = std::numeric_limits<uint64_t>::max(),
639 bool dump_sessions = false)
640{
641 Poco::AutoPtr<Poco::ConsoleChannel> channel(new Poco::ConsoleChannel(std::cerr));
642 Poco::Logger::root().setChannel(channel);
643 Poco::Logger::root().setLevel("trace");
644
645 auto logger = getLogger("keeper-utils");
646 SnapshotsQueue snapshots_queue{1};
647
648 CoordinationSettingsPtr settings = std::make_shared<CoordinationSettings>();
649 KeeperContextPtr keeper_context = std::make_shared<DB::KeeperContext>(true, settings);
650 keeper_context->setLogDisk(std::make_shared<DB::DiskLocal>("LogDisk", log_path));
651 keeper_context->setSnapshotDisk(std::make_shared<DB::DiskLocal>("SnapshotDisk", snapshot_path));
652
653 auto state_machine = std::make_shared<KeeperStateMachine<DB::KeeperMemoryStorage>>(nullptr, snapshots_queue, keeper_context, nullptr);
654 state_machine->init();
655 size_t last_committed_index = state_machine->last_commit_index();
656
657 LOG_INFO(logger, "Last committed index: {}", last_committed_index);
658
659 DB::KeeperLogStore changelog(
660 LogFileSettings{
661 .force_sync = true, .compress_logs = (*settings)[DB::CoordinationSetting::compress_logs], .rotate_interval = 10000000},
662 FlushSettings(),
663 keeper_context);
664
665 changelog.init(last_committed_index, 10000000000UL); // collect all logs
666
667 if (changelog.size() == 0)
668 LOG_INFO(logger, "Changelog empty");
669 else
670 LOG_INFO(logger, "Last changelog entry {}", changelog.next_slot() - 1);
671
672 // Apply log entries to the state machine up to end_index
673 size_t last_index_to_apply = std::min(changelog.next_slot() - 1, end_index);
674 if (last_committed_index + 1 < last_index_to_apply)
675 {
676 LOG_INFO(logger, "Applying changelog entries from {} to {}", last_committed_index + 1, last_index_to_apply - 1);
677 for (size_t i = last_committed_index + 1; i < last_index_to_apply; ++i)
678 {
679 auto & entry = *changelog.entry_at(i);
680 if (entry.get_val_type() == nuraft::log_val_type::app_log)
681 {
682 if (debug_mode)
683 {
684 LOG_INFO(logger, "Current digest of state machine: {}", state_machine->getNodesDigest().value);
685 auto req = state_machine->parseRequest(entry.get_buf(), true);
686 LOG_INFO(
687 logger,

Callers 1

Calls 15

FlushSettingsClass · 0.85
dumpSessionsFunction · 0.85
dumpNodesFunction · 0.85
setLogDiskMethod · 0.80
setSnapshotDiskMethod · 0.80
parseRequestMethod · 0.80
maxFunction · 0.50
getLoggerFunction · 0.50
minFunction · 0.50
setChannelMethod · 0.45
setLevelMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected