| 164 | }; |
| 165 | |
| 166 | StorageFileLog::StorageFileLog( |
| 167 | const StorageID & table_id_, |
| 168 | ContextPtr context_, |
| 169 | const ColumnsDescription & columns_, |
| 170 | const String & path_, |
| 171 | const String & metadata_base_path_, |
| 172 | const String & format_name_, |
| 173 | std::unique_ptr<FileLogSettings> settings, |
| 174 | const String & comment, |
| 175 | LoadingStrictnessLevel mode) |
| 176 | : IStorage(table_id_) |
| 177 | , WithContext(context_->getGlobalContext()) |
| 178 | , filelog_context(configureContext(getContext())) |
| 179 | , filelog_settings(std::move(settings)) |
| 180 | , path(path_) |
| 181 | , metadata_base_path(std::filesystem::path(metadata_base_path_) / "metadata") |
| 182 | , format_name(format_name_) |
| 183 | , log(getLogger("StorageFileLog (" + table_id_.getFullTableName() + ")")) |
| 184 | , disk(getContext()->getStoragePolicy("default")->getDisks().at(0)) |
| 185 | , milliseconds_to_wait((*filelog_settings)[FileLogSetting::poll_directory_watch_events_backoff_init].totalMilliseconds()) |
| 186 | { |
| 187 | StorageInMemoryMetadata storage_metadata; |
| 188 | storage_metadata.setColumns(columns_); |
| 189 | storage_metadata.setComment(comment); |
| 190 | storage_metadata.setVirtuals(createVirtuals((*filelog_settings)[FileLogSetting::handle_error_mode])); |
| 191 | setInMemoryMetadata(storage_metadata); |
| 192 | |
| 193 | if (!fileOrSymlinkPathStartsWith(path, getContext()->getUserFilesPath())) |
| 194 | { |
| 195 | if (LoadingStrictnessLevel::SECONDARY_CREATE <= mode) |
| 196 | { |
| 197 | LOG_ERROR(log, "The absolute data path should be inside `user_files_path`({})", getContext()->getUserFilesPath()); |
| 198 | return; |
| 199 | } |
| 200 | throw Exception( |
| 201 | ErrorCodes::BAD_ARGUMENTS, "The absolute data path should be inside `user_files_path`({})", getContext()->getUserFilesPath()); |
| 202 | } |
| 203 | |
| 204 | bool created_metadata_directory = false; |
| 205 | try |
| 206 | { |
| 207 | if (mode < LoadingStrictnessLevel::ATTACH) |
| 208 | { |
| 209 | if (disk->existsDirectory(metadata_base_path)) |
| 210 | { |
| 211 | throw Exception( |
| 212 | ErrorCodes::TABLE_METADATA_ALREADY_EXISTS, |
| 213 | "Metadata files already exist by path: {}, remove them manually if it is intended", |
| 214 | metadata_base_path); |
| 215 | } |
| 216 | disk->createDirectories(metadata_base_path); |
| 217 | created_metadata_directory = true; |
| 218 | } |
| 219 | |
| 220 | loadMetaFiles(LoadingStrictnessLevel::ATTACH <= mode); |
| 221 | loadFiles(); |
| 222 | |
| 223 | chassert(file_infos.file_names.size() == file_infos.meta_by_inode.size()); |
nothing calls this directly
no test coverage detected