mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-29 05:00:47 +00:00
Small improvements for IStorage::rename
This commit is contained in:
parent
0597ad3150
commit
7fb4dfea2c
@ -866,7 +866,7 @@ void StorageDistributed::flushClusterNodesAllData()
|
||||
|
||||
void StorageDistributed::rename(const String & new_path_to_table_data, const StorageID & new_table_id)
|
||||
{
|
||||
if (!relative_data_path.empty())
|
||||
if (!relative_data_path.empty() && relative_data_path != new_path_to_table_data)
|
||||
renameOnDisk(new_path_to_table_data);
|
||||
renameInMemory(new_table_id);
|
||||
}
|
||||
@ -878,7 +878,7 @@ void StorageDistributed::renameOnDisk(const String & new_path_to_table_data)
|
||||
{
|
||||
const String path(disk->getPath());
|
||||
auto new_path = path + new_path_to_table_data;
|
||||
Poco::File(path + relative_data_path).renameTo(new_path);
|
||||
disk->moveDirectory(path + relative_data_path, new_path);
|
||||
|
||||
LOG_DEBUG(log, "Updating path to {}", new_path);
|
||||
|
||||
|
@ -525,9 +525,12 @@ void StorageFile::rename(const String & new_path_to_table_data, const StorageID
|
||||
if (paths.size() != 1)
|
||||
throw Exception("Can't rename table " + getStorageID().getNameForLogs() + " in readonly mode", ErrorCodes::DATABASE_ACCESS_DENIED);
|
||||
|
||||
std::string path_new = getTablePath(base_path + new_path_to_table_data, format_name);
|
||||
if (path_new == paths[0])
|
||||
return;
|
||||
|
||||
std::unique_lock<std::shared_mutex> lock(rwlock);
|
||||
|
||||
std::string path_new = getTablePath(base_path + new_path_to_table_data, format_name);
|
||||
Poco::File(Poco::Path(path_new).parent()).createDirectories();
|
||||
Poco::File(paths[0]).renameTo(path_new);
|
||||
|
||||
|
@ -547,6 +547,8 @@ void StorageLog::loadMarks()
|
||||
|
||||
|
||||
void StorageLog::rename(const String & new_path_to_table_data, const StorageID & new_table_id)
|
||||
{
|
||||
if (table_path != new_path_to_table_data)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(rwlock);
|
||||
|
||||
@ -559,6 +561,7 @@ void StorageLog::rename(const String & new_path_to_table_data, const StorageID &
|
||||
file.second.data_file_path = table_path + fileName(file.second.data_file_path);
|
||||
|
||||
marks_file_path = table_path + DBMS_STORAGE_LOG_MARKS_FILE_NAME;
|
||||
}
|
||||
renameInMemory(new_table_id);
|
||||
}
|
||||
|
||||
|
@ -281,6 +281,8 @@ StorageStripeLog::StorageStripeLog(
|
||||
|
||||
|
||||
void StorageStripeLog::rename(const String & new_path_to_table_data, const StorageID & new_table_id)
|
||||
{
|
||||
if (table_path != new_path_to_table_data)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(rwlock);
|
||||
|
||||
@ -288,6 +290,7 @@ void StorageStripeLog::rename(const String & new_path_to_table_data, const Stora
|
||||
|
||||
table_path = new_path_to_table_data;
|
||||
file_checker.setPath(table_path + "sizes.json");
|
||||
}
|
||||
renameInMemory(new_table_id);
|
||||
}
|
||||
|
||||
|
@ -406,6 +406,8 @@ void StorageTinyLog::addFiles(const String & column_name, const IDataType & type
|
||||
|
||||
|
||||
void StorageTinyLog::rename(const String & new_path_to_table_data, const StorageID & new_table_id)
|
||||
{
|
||||
if (table_path != new_path_to_table_data)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(rwlock);
|
||||
|
||||
@ -416,6 +418,7 @@ void StorageTinyLog::rename(const String & new_path_to_table_data, const Storage
|
||||
|
||||
for (auto & file : files)
|
||||
file.second.data_file_path = table_path + fileName(file.second.data_file_path);
|
||||
}
|
||||
renameInMemory(new_table_id);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user