MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / copyFileFromDisk

Method copyFileFromDisk

src/Backups/BackupIO_S3.cpp:382–423  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380}
381
382void BackupWriterS3::copyFileFromDisk(
383 const String & path_in_backup, DiskPtr src_disk, const String & src_path, bool copy_encrypted, UInt64 start_pos, UInt64 length)
384{
385 /// Use the native copy as a more optimal way to copy a file from S3 to S3 if it's possible.
386 /// We don't check for `has_throttling` here because the native copy almost doesn't use network.
387 auto source_data_source_description = src_disk->getDataSourceDescription();
388 if (source_data_source_description.sameKind(data_source_description) && (source_data_source_description.is_encrypted == copy_encrypted))
389 {
390 /// getBlobPath() can return more than 2 elements if the file is stored as multiple objects in S3 bucket.
391 /// In this case we can't use the native copy.
392 if (auto blob_path = src_disk->getBlobPath(src_path); blob_path.size() == 2)
393 {
394 LOG_TRACE(log, "Copying file {} from disk {} to S3", src_path, src_disk->getName());
395 copyS3File(
396 /* src_s3_client */ disk_client_factory.getOrCreate(src_disk),
397 /* src_bucket */ blob_path[1],
398 /* src_key */ blob_path[0],
399 start_pos,
400 length,
401 /* dest_s3_client */ client,
402 /* dest_bucket */ s3_uri.bucket,
403 /* dest_key */ fs::path(s3_uri.key) / path_in_backup,
404 s3_settings.request_settings,
405 read_settings,
406 blob_storage_log,
407 threadPoolCallbackRunnerUnsafe<void>(getBackupsIOThreadPool().get(), ThreadName::S3_BACKUP_WRITER),
408 [&, this]
409 {
410 LOG_TRACE(log, "Falling back to copy file {} from disk {} to S3 through buffers", src_path, src_disk->getName());
411
412 if (copy_encrypted)
413 return src_disk->readEncryptedFile(src_path, read_settings);
414
415 return src_disk->readFile(src_path, read_settings);
416 });
417 return; /// copied!
418 }
419 }
420
421 /// Fallback to copy through buffers.
422 BackupWriterDefault::copyFileFromDisk(path_in_backup, src_disk, src_path, copy_encrypted, start_pos, length);
423}
424
425void BackupWriterS3::copyFile(const String & destination, const String & source, size_t size)
426{

Callers 1

writeFileMethod · 0.45

Calls 10

copyS3FileFunction · 0.85
sameKindMethod · 0.80
getBlobPathMethod · 0.45
sizeMethod · 0.45
getNameMethod · 0.45
getOrCreateMethod · 0.45
getMethod · 0.45
readEncryptedFileMethod · 0.45
readFileMethod · 0.45

Tested by

no test coverage detected