#pragma once #include #include #include #include namespace DB { class MergeTreeData; class MergeTreeWriteAheadLog { public: constexpr static auto WAL_FILE_NAME = "wal"; constexpr static auto WAL_FILE_EXTENSION = ".bin"; constexpr static auto DEFAULT_WAL_FILE = "wal.bin"; MergeTreeWriteAheadLog(const MergeTreeData & storage_, const DiskPtr & disk_, const String & name = DEFAULT_WAL_FILE); void write(const Block & block, const String & part_name); std::vector restore(); using MinMaxBlockNumber = std::pair; static std::optional tryParseMinMaxBlockNumber(const String & filename); private: void init(); void rotate(); const MergeTreeData & storage; DiskPtr disk; String name; String path; std::unique_ptr out; std::unique_ptr block_out; Int64 min_block_number = std::numeric_limits::max(); Int64 max_block_number = -1; mutable std::mutex write_mutex; }; }