mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 19:02:04 +00:00
Fix some more tests.
This commit is contained in:
parent
fc3645a483
commit
b3d38301c9
@ -25,7 +25,7 @@ namespace ErrorCodes
|
||||
|
||||
DataPartStorageOnDisk::DataPartStorageOnDisk(VolumePtr volume_, std::string root_path_, std::string part_dir_)
|
||||
: volume(std::move(volume_)), root_path(std::move(root_path_)), part_dir(std::move(part_dir_))
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
void DataPartStorageOnDisk::setRelativePath(const std::string & path)
|
||||
@ -143,7 +143,7 @@ DataPartStorageIteratorPtr DataPartStorageOnDisk::iterateDirectory(const String
|
||||
void DataPartStorageOnDisk::remove(
|
||||
bool can_remove_shared_data,
|
||||
const NameSet & names_not_to_remove,
|
||||
const MergeTreeDataPartChecksums & checksums,
|
||||
const MergeTreeDataPartChecksums & checksums,
|
||||
std::list<ProjectionChecksums> projections,
|
||||
Poco::Logger * log) const
|
||||
{
|
||||
@ -189,6 +189,10 @@ void DataPartStorageOnDisk::remove(
|
||||
{
|
||||
std::string proj_dir_name = projection.name + ".proj";
|
||||
projection_directories.emplace(proj_dir_name);
|
||||
|
||||
clearDirectory(
|
||||
fs::path(to) / proj_dir_name,
|
||||
can_remove_shared_data, names_not_to_remove, projection.checksums, {}, log, true);
|
||||
}
|
||||
|
||||
clearDirectory(to, can_remove_shared_data, names_not_to_remove, checksums, projection_directories, log, false);
|
||||
@ -198,8 +202,8 @@ void DataPartStorageOnDisk::clearDirectory(
|
||||
const std::string & dir,
|
||||
bool can_remove_shared_data,
|
||||
const NameSet & names_not_to_remove,
|
||||
const MergeTreeDataPartChecksums & checksums,
|
||||
const std::unordered_set<String> & skip_directories,
|
||||
const MergeTreeDataPartChecksums & checksums,
|
||||
const std::unordered_set<String> & skip_directories,
|
||||
Poco::Logger * log,
|
||||
bool is_projection) const
|
||||
{
|
||||
@ -552,6 +556,13 @@ void DataPartStorageOnDisk::rename(const String & new_relative_path, Poco::Logge
|
||||
"Part directory {} doesn't exist. Most likely it is a logical error.",
|
||||
std::string(fs::path(volume->getDisk()->getPath()) / root_path / part_dir));
|
||||
|
||||
auto new_path = fs::path(root_path) / new_relative_path;
|
||||
if (!new_path.has_filename())
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||
"Cannot rename from {} to {}. Destination should not contain trailing slash",
|
||||
getFullRelativePath(),
|
||||
new_relative_path);
|
||||
|
||||
/// Why "" ?
|
||||
String to = fs::path(root_path) / new_relative_path / "";
|
||||
|
||||
@ -562,8 +573,8 @@ void DataPartStorageOnDisk::rename(const String & new_relative_path, Poco::Logge
|
||||
Names files;
|
||||
volume->getDisk()->listFiles(to, files);
|
||||
|
||||
LOG_WARNING(log,
|
||||
"Part directory {} already exists and contains {} files. Removing it.",
|
||||
LOG_WARNING(log,
|
||||
"Part directory {} already exists and contains {} files. Removing it.",
|
||||
fullPath(volume->getDisk(), to), files.size());
|
||||
|
||||
volume->getDisk()->removeRecursive(to);
|
||||
@ -571,8 +582,8 @@ void DataPartStorageOnDisk::rename(const String & new_relative_path, Poco::Logge
|
||||
else
|
||||
{
|
||||
throw Exception(
|
||||
ErrorCodes::DIRECTORY_ALREADY_EXISTS,
|
||||
"Part directory {} already exists",
|
||||
ErrorCodes::DIRECTORY_ALREADY_EXISTS,
|
||||
"Part directory {} already exists",
|
||||
fullPath(volume->getDisk(), to));
|
||||
}
|
||||
}
|
||||
@ -585,7 +596,8 @@ void DataPartStorageOnDisk::rename(const String & new_relative_path, Poco::Logge
|
||||
/// Why?
|
||||
volume->getDisk()->setLastModified(from, Poco::Timestamp::fromEpochTime(time(nullptr)));
|
||||
volume->getDisk()->moveDirectory(from, to);
|
||||
part_dir = new_relative_path;
|
||||
part_dir = new_path.filename();
|
||||
root_path = new_path.remove_filename();
|
||||
// metadata_manager->updateAll(true);
|
||||
|
||||
SyncGuardPtr sync_guard;
|
||||
@ -593,6 +605,32 @@ void DataPartStorageOnDisk::rename(const String & new_relative_path, Poco::Logge
|
||||
sync_guard = volume->getDisk()->getDirectorySyncGuard(getFullRelativePath());
|
||||
}
|
||||
|
||||
void DataPartStorageOnDisk::changeRootPath(const std::string & from_root, const std::string & to_root)
|
||||
{
|
||||
/// This is a very dumb implementation, here for root path like
|
||||
/// "some/current/path/to/part" and change like
|
||||
/// "some/current" -> "other/different", we just replace prefix to make new root like
|
||||
/// "other/different/path/to/part".
|
||||
/// Here we expect that actual move was done by somebody else.
|
||||
|
||||
size_t prefix_size = from_root.size();
|
||||
if (prefix_size > 0 && from_root.back() == '/')
|
||||
--prefix_size;
|
||||
|
||||
if (prefix_size > root_path.size()
|
||||
|| std::string_view(from_root).substr(0, prefix_size) != std::string_view(root_path).substr(0, prefix_size))
|
||||
throw Exception(
|
||||
ErrorCodes::LOGICAL_ERROR,
|
||||
"Cannot change part root to {} because it is not a prefix of current root {}",
|
||||
from_root, root_path);
|
||||
|
||||
size_t dst_size = to_root.size();
|
||||
if (dst_size > 0 && to_root.back() == '/')
|
||||
--dst_size;
|
||||
|
||||
root_path = to_root.substr(0, dst_size) + root_path.substr(prefix_size);
|
||||
}
|
||||
|
||||
bool DataPartStorageOnDisk::shallParticipateInMerges(const IStoragePolicy & storage_policy) const
|
||||
{
|
||||
/// `IMergeTreeDataPart::volume` describes space where current part belongs, and holds
|
||||
@ -666,7 +704,7 @@ void DataPartStorageOnDisk::backup(
|
||||
|
||||
|
||||
DataPartStoragePtr DataPartStorageOnDisk::freeze(
|
||||
const std::string & to,
|
||||
const std::string & to,
|
||||
const std::string & dir_path,
|
||||
bool make_source_readonly,
|
||||
std::function<void(const DiskPtr &)> save_metadata_callback,
|
||||
@ -711,7 +749,7 @@ DataPartStoragePtr DataPartStorageOnDisk::freeze(
|
||||
|
||||
DataPartStorageBuilderOnDisk::DataPartStorageBuilderOnDisk(VolumePtr volume_, std::string root_path_, std::string part_dir_)
|
||||
: volume(std::move(volume_)), root_path(std::move(root_path_)), part_dir(std::move(part_dir_))
|
||||
{
|
||||
{
|
||||
}
|
||||
|
||||
std::unique_ptr<ReadBufferFromFileBase> DataPartStorageBuilderOnDisk::readFile(
|
||||
@ -756,12 +794,12 @@ void DataPartStorageBuilderOnDisk::createHardLinkFrom(const IDataPartStorage & s
|
||||
const auto * source_on_disk = typeid_cast<const DataPartStorageOnDisk *>(&source);
|
||||
if (!source_on_disk)
|
||||
throw Exception(
|
||||
ErrorCodes::LOGICAL_ERROR,
|
||||
ErrorCodes::LOGICAL_ERROR,
|
||||
"Cannot create hardlink from different storage. Expected DataPartStorageOnDisk, got {}",
|
||||
typeid(source).name());
|
||||
|
||||
volume->getDisk()->createHardLink(
|
||||
fs::path(source_on_disk->getFullRelativePath()) / from,
|
||||
fs::path(source_on_disk->getFullRelativePath()) / from,
|
||||
fs::path(root_path) / part_dir / to);
|
||||
}
|
||||
|
||||
|
@ -99,6 +99,8 @@ public:
|
||||
|
||||
void rename(const String & new_relative_path, Poco::Logger * log, bool remove_new_dir_if_exists, bool fsync_part_dir) override;
|
||||
|
||||
void changeRootPath(const std::string & from_root, const std::string & to_root) override;
|
||||
|
||||
std::string getName() const override;
|
||||
std::string getDiskType() const override;
|
||||
|
||||
|
@ -165,7 +165,11 @@ public:
|
||||
const std::string & dir_path,
|
||||
Poco::Logger * log) const = 0;
|
||||
|
||||
virtual void rename(const String & new_relative_path, Poco::Logger * log, bool remove_new_dir_if_exists, bool fsync_part_dir) = 0;
|
||||
virtual void rename(const std::string & new_relative_path, Poco::Logger * log, bool remove_new_dir_if_exists, bool fsync_part_dir) = 0;
|
||||
|
||||
/// Change part's root. From should be a prefix path of current root path.
|
||||
/// Right now, this is needed for rename table query.
|
||||
virtual void changeRootPath(const std::string & from_root, const std::string & to_root) = 0;
|
||||
|
||||
/// Disk name
|
||||
virtual std::string getName() const = 0;
|
||||
|
@ -1376,16 +1376,19 @@ try
|
||||
{
|
||||
assertOnDisk();
|
||||
|
||||
std::string relative_path = storage.relative_data_path;
|
||||
bool fsync_dir = storage.getSettings()->fsync_part_directory;
|
||||
|
||||
if (parent_part)
|
||||
throw Exception(
|
||||
ErrorCodes::LOGICAL_ERROR,
|
||||
"Move is not supported for projection parts: moving form {} to {}",
|
||||
data_part_storage->getFullPath(), new_relative_path);
|
||||
{
|
||||
/// For projections, move is only possible inside parent part dir.
|
||||
relative_path = parent_part->data_part_storage->getFullRelativePath();
|
||||
}
|
||||
|
||||
String from = data_part_storage->getFullRelativePath();
|
||||
String to = fs::path(storage.relative_data_path) / new_relative_path / "";
|
||||
String to = fs::path(relative_path) / new_relative_path / "";
|
||||
|
||||
data_part_storage->rename(new_relative_path, storage.log, remove_new_dir_if_exists, storage.getSettings()->fsync_part_directory);
|
||||
data_part_storage->rename(new_relative_path, storage.log, remove_new_dir_if_exists, fsync_dir);
|
||||
metadata_manager->move(from, to);
|
||||
|
||||
for (const auto & [p_name, part] : projection_parts)
|
||||
|
@ -1893,6 +1893,9 @@ void MergeTreeData::rename(const String & new_table_path, const StorageID & new_
|
||||
if (!getStorageID().hasUUID())
|
||||
getContext()->dropCaches();
|
||||
|
||||
for (const auto & part : data_parts_by_info)
|
||||
part->data_part_storage->changeRootPath(relative_data_path, new_table_path);
|
||||
|
||||
relative_data_path = new_table_path;
|
||||
renameInMemory(new_table_id);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user