| 476 | } |
| 477 | |
| 478 | void ClickHouseDumper::loadAndDumpPart(StorageCloudMergeTree & cloud, MergeTreeCNCHDataDumper & dumper, const String & part_name) |
| 479 | { |
| 480 | DiskPtr local_disk = global_context->getStoragePolicy("default")->getAnyDisk(); |
| 481 | DiskPtr remote_disk = global_context->getStoragePolicy("cnch_default_hdfs")->getAnyDisk(); |
| 482 | if (remote_disk->getType() == DiskType::Type::ByteS3) |
| 483 | throw Exception("Currently dump to " + DiskType::toString(remote_disk->getType()) + " doesn't supported.", ErrorCodes::UNKNOWN_TABLE); |
| 484 | |
| 485 | auto volume = std::make_shared<SingleDiskVolume>("volume_single", local_disk, 0); |
| 486 | const String to_path = '/' + cloud.getDatabaseName() + '/' + cloud.getTableName() + '/'; |
| 487 | const String relative_path = config().getString("path") + "/data/" + cloud.getDatabaseName() + "/" + cloud.getTableName() + "/" + part_name; |
| 488 | const String from_path = cloud.getRelativeDataPath(IStorage::StorageLocation::MAIN) + '/' + part_name; |
| 489 | bool overwrite = config().has("overwrite"); |
| 490 | |
| 491 | LOG_TRACE(log, "loadAndDumpPart local disk path = {}, remote disk path = {}, relative_path = {}", local_disk->getPath(), remote_disk->getPath(), relative_path); |
| 492 | const String full_path = remote_disk->getPath() + to_path + part_name; |
| 493 | if(!overwrite && remote_disk->exists(full_path)) |
| 494 | { |
| 495 | LOG_WARNING(log, "Part " + part_name + " already exists. Ignore it."); |
| 496 | return; |
| 497 | } |
| 498 | |
| 499 | auto part_info = MergeTreePartInfo::fromPartName(part_name, cloud.format_version); |
| 500 | auto local_part = std::make_shared<MergeTreeDataPartWide>( |
| 501 | cloud, |
| 502 | part_name, |
| 503 | part_info, |
| 504 | volume, |
| 505 | relative_path, |
| 506 | nullptr, |
| 507 | IStorage::StorageLocation::AUXILITY); |
| 508 | |
| 509 | bool skip_corrupt_parts = config().has("skip_corrupt_parts"); |
| 510 | try |
| 511 | { |
| 512 | LOG_TRACE(log, "Loading {}", part_name); |
| 513 | |
| 514 | local_part->loadColumnsChecksumsIndexes(true, true); |
| 515 | |
| 516 | LOG_TRACE(log, "Dumping {} remote_disk path {}", local_part->name, remote_disk->getPath()); |
| 517 | |
| 518 | auto dumped_part = dumper.dumpTempPart(local_part, remote_disk, true); |
| 519 | dumped_part->is_temp = false; |
| 520 | dumped_part->renameTo(local_part->name, true); |
| 521 | |
| 522 | if (remote_disk->exists(full_path)) |
| 523 | remote_disk->removeRecursive(full_path); |
| 524 | |
| 525 | /// remote disk from uuid path move to {database}/{table} |
| 526 | remote_disk->moveDirectory(from_path, remote_disk->getPath() + to_path); |
| 527 | } |
| 528 | catch (const DB::Exception & e) |
| 529 | { |
| 530 | if (!skip_corrupt_parts) |
| 531 | throw; |
| 532 | LOG_ERROR(log, "Failed to load or dump the part: {}, exception: {}", part_name, e.what()); |
| 533 | } |
| 534 | } |
| 535 |
nothing calls this directly
no test coverage detected