| 104 | |
| 105 | |
| 106 | BackupFileInfo buildFileInfoForBackupEntry( |
| 107 | const String & file_name, |
| 108 | const BackupEntryPtr & backup_entry, |
| 109 | const BackupPtr & base_backup, |
| 110 | const ReadSettings & read_settings, |
| 111 | LoggerPtr log) |
| 112 | { |
| 113 | auto adjusted_path = removeLeadingSlash(file_name); |
| 114 | |
| 115 | BackupFileInfo info; |
| 116 | info.file_name = adjusted_path; |
| 117 | |
| 118 | /// If it's a "reference" just set the target to a concrete file |
| 119 | if (backup_entry->isReference()) |
| 120 | { |
| 121 | info.reference_target = removeLeadingSlash(backup_entry->getReferenceTarget()); |
| 122 | return info; |
| 123 | } |
| 124 | |
| 125 | info.size = backup_entry->getSize(); |
| 126 | info.encrypted_by_disk = backup_entry->isEncryptedByDisk(); |
| 127 | |
| 128 | if (backup_entry->isFromRemoteFile()) |
| 129 | { |
| 130 | info.object_key = backup_entry->getRemotePath(); |
| 131 | return info; |
| 132 | } |
| 133 | |
| 134 | /// We don't set `info.data_file_name` and `info.data_file_index` in this function because they're set during backup coordination |
| 135 | /// (see the class BackupCoordinationFileInfos). |
| 136 | |
| 137 | if (!info.size) |
| 138 | { |
| 139 | /// Empty file. |
| 140 | return info; |
| 141 | } |
| 142 | |
| 143 | if (!log) |
| 144 | log = getLogger("FileInfoFromBackupEntry"); |
| 145 | |
| 146 | std::optional<SizeAndChecksum> base_backup_file_info = getInfoAboutFileFromBaseBackupIfExists(base_backup, adjusted_path); |
| 147 | |
| 148 | /// We have info about this file in base backup |
| 149 | /// If file has no checksum -- calculate and fill it. |
| 150 | if (base_backup_file_info) |
| 151 | { |
| 152 | LOG_TRACE(log, "File {} found in base backup, checking for equality", adjusted_path); |
| 153 | CheckBackupResult check_base = checkBaseBackupForFile(*base_backup_file_info, info); |
| 154 | |
| 155 | /// File with the same name but smaller size exist in previous backup |
| 156 | if (check_base == CheckBackupResult::HasPrefix) |
| 157 | { |
| 158 | auto checksums = calculateNewEntryChecksumsIfNeeded(backup_entry, base_backup_file_info->first, read_settings); |
| 159 | info.checksum = checksums.full_checksum; |
| 160 | |
| 161 | /// We have prefix of this file in backup with the same checksum. |
| 162 | /// In ClickHouse this can happen for StorageLog for example, |
| 163 | /// or for .sql files that store DDL if only last part of the query was changed. |
no test coverage detected