|
47 | 47 | #include <Common/ProfileEventsScope.h> |
48 | 48 | #include <Common/escapeForFileName.h> |
49 | 49 | #include "Core/BackgroundSchedulePool.h" |
| 50 | +#include "Storages/MergeTree/MergeTreeDataPartState.h" |
50 | 51 | #include "Storages/ObjectStorage/MergeTree/ExportPartPlainMergeTreeTask.h" |
51 | 52 | #include <Core/Names.h> |
52 | 53 | #include <Storages/ObjectStorage/StorageObjectStorage.h> |
@@ -549,20 +550,12 @@ void StorageMergeTree::exportPartitionToTable(const PartitionCommand & command, |
549 | 550 | } |
550 | 551 |
|
551 | 552 | { |
552 | | - /// Do not put this in a scope because `CurrentlyExportingPartsTagger` instantiated above relies on this already being locked |
553 | | - /// shitty design I came up with huh |
554 | 553 | std::lock_guard lock_background_mutex(currently_processing_in_background_mutex); |
555 | 554 |
|
556 | 555 | if (!already_exported_partition_ids.emplace(partition_id).second) |
557 | 556 | { |
558 | 557 | throw Exception(ErrorCodes::PART_IS_LOCKED, "Partition {} has already been exported", partition_id); |
559 | 558 | } |
560 | | - |
561 | | - for (const auto & part : all_parts) |
562 | | - { |
563 | | - if (!currently_merging_mutating_parts.emplace(part).second) |
564 | | - throw Exception(ErrorCodes::LOGICAL_ERROR, "Tagging already tagged part {}. This is a bug.", part->name); |
565 | | - } |
566 | 559 | } |
567 | 560 |
|
568 | 561 | const auto transaction_id = std::to_string(generateSnowflakeID()); |
@@ -658,26 +651,6 @@ CurrentlyMergingPartsTagger::~CurrentlyMergingPartsTagger() |
658 | 651 | storage.currently_processing_in_background_condition.notify_all(); |
659 | 652 | } |
660 | 653 |
|
661 | | -CurrentlyExportingPartsTagger::CurrentlyExportingPartsTagger(DataPartPtr part_to_export_, StorageMergeTree & storage_) |
662 | | - : part_to_export(std::move(part_to_export_)), storage(storage_) |
663 | | -{ |
664 | | - /// assume it is already locked |
665 | | - if (!storage.currently_merging_mutating_parts.emplace(part_to_export).second) |
666 | | - throw Exception(ErrorCodes::LOGICAL_ERROR, "Tagging already tagged part {}. This is a bug.", part_to_export->name); |
667 | | -} |
668 | | - |
669 | | -CurrentlyExportingPartsTagger::~CurrentlyExportingPartsTagger() |
670 | | -{ |
671 | | - std::lock_guard lock(storage.currently_processing_in_background_mutex); |
672 | | - |
673 | | - if (!storage.currently_merging_mutating_parts.contains(part_to_export)) |
674 | | - std::terminate(); |
675 | | - storage.currently_merging_mutating_parts.erase(part_to_export); |
676 | | - |
677 | | - storage.currently_processing_in_background_condition.notify_all(); |
678 | | -} |
679 | | - |
680 | | - |
681 | 654 | Int64 StorageMergeTree::startMutation(const MutationCommands & commands, ContextPtr query_context) |
682 | 655 | { |
683 | 656 | /// Choose any disk, because when we load mutations we search them at each disk |
@@ -1150,6 +1123,7 @@ void StorageMergeTree::loadMutations() |
1150 | 1123 |
|
1151 | 1124 | void StorageMergeTree::readExportPartitionManifests() |
1152 | 1125 | { |
| 1126 | + static const auto states = {MergeTreeDataPartState::Active, MergeTreeDataPartState::Deleting, MergeTreeDataPartState::Outdated, MergeTreeDataPartState::DeleteOnDestroy}; |
1153 | 1127 | for (const auto & disk : getDisks()) |
1154 | 1128 | { |
1155 | 1129 | for (auto it = disk->iterateDirectory(relative_data_path); it->isValid(); it->next()) |
@@ -1177,6 +1151,28 @@ void StorageMergeTree::readExportPartitionManifests() |
1177 | 1151 | } |
1178 | 1152 | } |
1179 | 1153 |
|
| 1154 | + for (auto & item : manifest->items) |
| 1155 | + { |
| 1156 | + /// if this part has not been pushed yet |
| 1157 | + if (item.remote_path.empty()) |
| 1158 | + { |
| 1159 | + item.part = getPartIfExists(item.part_name, states); |
| 1160 | + |
| 1161 | + if (!item.part) |
| 1162 | + { |
| 1163 | + LOG_ERROR(log, "Part {} is present in the manifest file {}, but not found in the storage {}", |
| 1164 | + item.part_name, |
| 1165 | + manifest->transaction_id, |
| 1166 | + getStorageID().getNameForLogs()); |
| 1167 | + |
| 1168 | + manifest->status = MergeTreeExportManifest::Status::failed; |
| 1169 | + manifest->write(); |
| 1170 | + already_exported_partition_ids.erase(manifest->partition_id); |
| 1171 | + continue; |
| 1172 | + } |
| 1173 | + } |
| 1174 | + } |
| 1175 | + |
1180 | 1176 | export_partition_transaction_id_to_manifest.emplace(manifest->transaction_id, manifest); |
1181 | 1177 |
|
1182 | 1178 | LOG_DEBUG(log, "Loaded export transaction manifest: {} (transaction_id: {})", name, manifest->transaction_id); |
@@ -1670,12 +1666,13 @@ bool StorageMergeTree::scheduleDataMovingJob(BackgroundJobsAssignee & assignee) |
1670 | 1666 | continue; |
1671 | 1667 | } |
1672 | 1668 |
|
| 1669 | + static const auto states = {MergeTreeDataPartState::Active, MergeTreeDataPartState::Deleting, MergeTreeDataPartState::Outdated, MergeTreeDataPartState::DeleteOnDestroy}; |
1673 | 1670 | for (auto & item : manifest->items) |
1674 | 1671 | { |
1675 | 1672 | if (item.in_progress) |
1676 | 1673 | continue; |
1677 | 1674 |
|
1678 | | - auto part = getPartIfExists(item.part_name, {MergeTreeDataPartState::Active}); |
| 1675 | + auto part = getPartIfExists(item.part_name, states); |
1679 | 1676 | if (!part) |
1680 | 1677 | { |
1681 | 1678 | LOG_ERROR(log, "Part {} is present in the manifest file {}, but not found in the storage {}", |
|
0 commit comments