Fix rename bug

This commit is contained in:
alesapin 2019-09-10 15:23:18 +03:00
parent 193049293a
commit ac4ab3ca2b
2 changed files with 9 additions and 2 deletions

View File

@ -1188,6 +1188,7 @@ void MergeTreeData::rename(
for (const auto & disk : disks)
{
auto new_full_path = disk->getPath() + new_file_db_name + '/' + new_file_table_name + '/';
if (Poco::File{new_full_path}.exists())
throw Exception{"Target path already exists: " + new_full_path, ErrorCodes::DIRECTORY_ALREADY_EXISTS};
}
@ -1195,7 +1196,13 @@ void MergeTreeData::rename(
for (const auto & disk : disks)
{
auto full_path = disk->getPath() + old_file_db_name + '/' + old_file_table_name + '/';
auto new_full_path = disk->getPath() + new_file_db_name + '/' + new_file_table_name + '/';
auto new_db_path = disk->getPath() + new_file_db_name + '/';
Poco::File db_file{new_db_path};
if (!db_file.exists())
db_file.createDirectory();
auto new_full_path = new_db_path + new_file_table_name + '/';
Poco::File{full_path}.renameTo(new_full_path);
}

View File

@ -60,7 +60,7 @@ public:
void swapClonedPart(const std::shared_ptr<const MergeTreeDataPart> & cloned_parts) const;
public:
/// Can stop background moves
/// Can stop background moves and moves from queries
ActionBlocker moves_blocker;
private: