// Copyright 2024 PingCAP, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace DB::DM { namespace tests { class DMStoreForSegmentReadTaskTest; class DMFileMetaV2Test; } // namespace tests class DMFile; class DMFileWriter; class DMFileV3IncrementWriter; struct DMFileMetaChangeset { std::unordered_map> new_indexes_on_cols; }; class DMFileMeta { public: DMFileMeta( UInt64 file_id_, const String & parent_path_, DMFileStatus status_, KeyspaceID keyspace_id_, DMConfigurationOpt configuration_, DMFileFormat::Version format_version_) : file_id(file_id_) , parent_path(parent_path_) , status(status_) , keyspace_id(keyspace_id_) , configuration(configuration_) , log(Logger::get()) , format_version(format_version_) {} virtual ~DMFileMeta() = default; struct ReadMode { private: static constexpr UInt8 READ_NONE = 0x00; static constexpr UInt8 READ_COLUMN_STAT = 0x01; static constexpr UInt8 READ_PACK_STAT = 0x02; static constexpr UInt8 READ_PACK_PROPERTY = 0x04; UInt8 value; public: explicit ReadMode(UInt8 value_) : value(value_) {} static ReadMode all() { return ReadMode(READ_COLUMN_STAT | READ_PACK_STAT | READ_PACK_PROPERTY); } static ReadMode none() { return ReadMode(READ_NONE); } // after restore with mode, you can call `getBytesOnDisk` to get disk size of this DMFile static ReadMode diskSizeOnly() { return ReadMode(READ_COLUMN_STAT); } // after restore with mode, you can call `getRows`, `getBytes` to get memory size of this DMFile, // and call `getBytesOnDisk` to get disk size of this DMFile static ReadMode memoryAndDiskSize() { return ReadMode(READ_COLUMN_STAT | READ_PACK_STAT); } inline bool needColumnStat() const { return value & READ_COLUMN_STAT; } inline bool needPackStat() const { return value & READ_PACK_STAT; } inline bool needPackProperty() const { return value & READ_PACK_PROPERTY; } inline bool isNone() const { return value == READ_NONE; } inline bool isAll() const { return needColumnStat() && needPackStat() && needPackProperty(); } }; struct PackStat { UInt32 rows; UInt32 not_clean; UInt64 first_version; UInt64 bytes; UInt8 first_tag; String toDebugString() const { return fmt::format( "rows={}, not_clean={}, first_version={}, bytes={}, first_tag={}", rows, not_clean, first_version, bytes, first_tag); } }; static_assert(std::is_standard_layout_v); struct PackProperty { // when gc_safe_point exceed this version, there must be some data obsolete in this pack UInt64 gc_hint_version{}; // effective rows(multiple versions of one row is count as one include delete) UInt64 num_rows{}; // the number of rows in this pack which are deleted UInt64 deleted_rows{}; void toProtobuf(dtpb::PackProperty * p) const { p->set_gc_hint_version(gc_hint_version); p->set_num_rows(num_rows); p->set_deleted_rows(deleted_rows); } void fromProtoBuf(const dtpb::PackProperty & p) { gc_hint_version = p.gc_hint_version(); num_rows = p.num_rows(); deleted_rows = p.deleted_rows(); } explicit PackProperty(const dtpb::PackProperty & p) { fromProtoBuf(p); } }; static_assert(std::is_standard_layout_v); enum class BlockType : UInt64 { PackStat = 0, PackProperty, ColumnStat, // Deprecated, use `ExtendColumnStat` instead MergedSubFilePos, ExtendColumnStat, }; struct BlockHandle { BlockType type; UInt64 offset; UInt64 size; }; static_assert(std::is_standard_layout_v && sizeof(BlockHandle) == sizeof(UInt64) * 3); struct Footer { UInt64 checksum_frame_length = 0; UInt64 checksum_algorithm = 0; }; static_assert(std::is_standard_layout_v