| 215 | |
| 216 | |
| 217 | IMergeTreeDataPart::Checksums checkDataPart( |
| 218 | MergeTreeData::DataPartPtr data_part, |
| 219 | const DiskPtr & disk, |
| 220 | const String & full_relative_path, |
| 221 | const NamesAndTypesList & columns_list, |
| 222 | const MergeTreeDataPartType & part_type, |
| 223 | const NameSet & files_without_checksums, |
| 224 | bool require_checksums, |
| 225 | std::function<bool()> is_cancelled) |
| 226 | { |
| 227 | /** Responsibility: |
| 228 | * - read list of columns from columns.txt; |
| 229 | * - read checksums if exist; |
| 230 | * - validate list of columns and checksums |
| 231 | */ |
| 232 | |
| 233 | CurrentMetrics::Increment metric_increment{CurrentMetrics::ReplicatedChecks}; |
| 234 | |
| 235 | String path = full_relative_path; |
| 236 | if (!path.empty() && path.back() != '/') |
| 237 | path += "/"; |
| 238 | |
| 239 | NamesAndTypesList columns_txt; |
| 240 | |
| 241 | { |
| 242 | auto buf = disk->readFile(fs::path(path) / "columns.txt"); |
| 243 | columns_txt.readText(*buf); |
| 244 | assertEOF(*buf); |
| 245 | } |
| 246 | |
| 247 | if (columns_txt != columns_list) |
| 248 | throw Exception("Columns doesn't match in part " + path |
| 249 | + ". Expected: " + columns_list.toString() |
| 250 | + ". Found: " + columns_txt.toString(), ErrorCodes::CORRUPTED_DATA); |
| 251 | |
| 252 | /// Real checksums based on contents of data. Must correspond to checksums.txt. If not - it means the data is broken. |
| 253 | IMergeTreeDataPart::Checksums checksums_data; |
| 254 | |
| 255 | /// This function calculates checksum for both compressed and decompressed contents of compressed file. |
| 256 | auto checksum_compressed_file = [](const DiskPtr & disk_, const String & file_path) |
| 257 | { |
| 258 | auto file_buf = disk_->readFile(file_path); |
| 259 | HashingReadBuffer compressed_hashing_buf(*file_buf); |
| 260 | CompressedReadBuffer uncompressing_buf(compressed_hashing_buf); |
| 261 | HashingReadBuffer uncompressed_hashing_buf(uncompressing_buf); |
| 262 | |
| 263 | uncompressed_hashing_buf.ignoreAll(); |
| 264 | return IMergeTreeDataPart::Checksums::Checksum |
| 265 | { |
| 266 | compressed_hashing_buf.count(), compressed_hashing_buf.getHash(), |
| 267 | uncompressed_hashing_buf.count(), uncompressed_hashing_buf.getHash() |
| 268 | }; |
| 269 | }; |
| 270 | |
| 271 | /// This function calculates only checksum of file content (compressed or uncompressed). |
| 272 | /// It also calculates checksum of projections. |
| 273 | auto checksum_file = [&](const String & file_path, const String & file_name) |
| 274 | { |
no test coverage detected