Skip to content

Commit

Permalink
Added a check for existing data on new disk.
Browse files Browse the repository at this point in the history
  • Loading branch information
excitoon committed Jan 9, 2020
1 parent 5e1093f commit 99a5830
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions dbms/src/Storages/MergeTree/MergeTreeData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,24 @@ void MergeTreeData::setStoragePolicy(const String & new_storage_policy_name, boo
throw Exception("New storage policy shall contain disks of old one", ErrorCodes::LOGICAL_ERROR);
}

std::unordered_set<String> all_diff_disk_names;
for (const auto & disk : new_storage_policy->getDisks())
all_diff_disk_names.insert(disk->getName());
for (const auto & disk : old_storage_policy->getDisks())
all_diff_disk_names.erase(disk->getName());

for (const String & disk_name : all_diff_disk_names)
{
const auto & path = getFullPathOnDisk(new_storage_policy->getDiskByName(disk_name));
if (Poco::File(path).exists())
throw Exception("New storage policy contain disks which already contain data of a table with the same name", ErrorCodes::LOGICAL_ERROR);
}

if (!only_check)
{
for (const auto & disk : new_storage_policy->getDisks())
for (const String & disk_name : all_diff_disk_names)
{
const auto & path = getFullPathOnDisk(disk);
const auto & path = getFullPathOnDisk(new_storage_policy->getDiskByName(disk_name));
Poco::File(path).createDirectories();
Poco::File(path + "detached").createDirectory();
}
Expand Down

0 comments on commit 99a5830

Please sign in to comment.