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

Function deserializeChangelog

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

Source from the content-addressed store, hash-verified

708}
709
710int deserializeChangelog(
711 const std::string & changelog_path,
712 const std::string & output_file,
713 const std::string & output_format,
714 bool parallel_output,
715 bool with_requests,
716 uint64_t start_index,
717 uint64_t end_index)
718{
719 try
720 {
721 auto desc = Changelog::getChangelogFileDescription(changelog_path);
722 desc->disk = std::make_shared<DB::DiskLocal>("LogDisk", fs::path(changelog_path).parent_path().string());
723
724 CoordinationSettingsPtr settings = std::make_shared<CoordinationSettings>();
725 LogEntryStorage entry_storage{LogFileSettings{}, std::make_shared<KeeperContext>(true, settings)};
726 Changelog::readChangelog(desc, entry_storage);
727
728 if (start_index == 0)
729 start_index = desc->from_log_index;
730 else if (start_index < desc->from_log_index || start_index > desc->to_log_index)
731 {
732 throw DB::Exception(
733 DB::ErrorCodes::BAD_ARGUMENTS,
734 "start_index {} is out of range for changelog {} which has range [{}, {}]",
735 start_index,
736 changelog_path,
737 desc->from_log_index,
738 desc->to_log_index);
739 }
740
741 if (end_index == std::numeric_limits<uint64_t>::max())
742 end_index = desc->from_log_index + entry_storage.size();
743 else if (end_index < desc->from_log_index || end_index > desc->from_log_index + entry_storage.size())
744 {
745 throw DB::Exception(
746 DB::ErrorCodes::BAD_ARGUMENTS,
747 "end_index {} is out of range for changelog {} which has range [{}, {}]",
748 end_index,
749 changelog_path,
750 desc->from_log_index,
751 desc->from_log_index + entry_storage.size());
752 }
753
754 SnapshotsQueue snapshots_queue{1};
755 KeeperContextPtr keeper_context = std::make_shared<DB::KeeperContext>(true, settings);
756 keeper_context->setLogDisk(std::make_shared<DB::DiskLocal>("LogDisk", fs::temp_directory_path() / "keeper-utils-log"));
757 keeper_context->setSnapshotDisk(std::make_shared<DB::DiskLocal>("SnapshotDisk", fs::temp_directory_path() / "keeper-utils-snapshot"));
758 auto state_machine = std::make_shared<KeeperStateMachine<DB::KeeperMemoryStorage>>(nullptr, snapshots_queue, keeper_context, nullptr);
759
760 if (!output_file.empty())
761 {
762 LOG_INFO(getLogger("keeper-utils"), "Writing changelog entries to {}", output_file);
763
764 SharedContextHolder shared_context;
765 ContextMutablePtr global_context;
766 shared_context = DB::Context::createShared();
767 global_context = DB::Context::createGlobal(shared_context.get());

Callers 1

Calls 15

registerFormatsFunction · 0.85
formatBlockFunction · 0.85
parent_pathMethod · 0.80
setLogDiskMethod · 0.80
setSnapshotDiskMethod · 0.80
makeGlobalContextMethod · 0.80
parseRequestMethod · 0.80
ExceptionClass · 0.50
maxFunction · 0.50
getLoggerFunction · 0.50
toStringFunction · 0.50
formatFunction · 0.50

Tested by

no test coverage detected