Skip to content

Commit c9e46d5

Browse files
committed
add method
1 parent a79cf5d commit c9e46d5

File tree

6 files changed

+40
-10
lines changed

6 files changed

+40
-10
lines changed

src/Disks/IDisk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ class IDisk : public Space
442442

443443
virtual bool isReadOnly() const { return false; }
444444

445+
virtual bool isPlain() const { return false; }
446+
445447
virtual bool isWriteOnce() const { return false; }
446448

447449
virtual bool supportsHardLinks() const { return true; }

src/Disks/IStoragePolicy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class IStoragePolicy
5959
VolumePtr getVolumeByName(const String & volume_name) const;
6060
/// Checks if storage policy can be replaced by another one.
6161
virtual void checkCompatibleWith(const StoragePolicyPtr & new_storage_policy) const = 0;
62+
///
63+
virtual bool isCompatibleForPartitionOps(const StoragePolicyPtr & other) const = 0;
6264
/// Finds a volume index, which contains disk
6365
virtual std::optional<size_t> tryGetVolumeIndexByDiskName(const String & disk_name) const = 0;
6466
size_t getVolumeIndexByDiskName(const String & disk_name) const;

src/Disks/ObjectStorages/DiskObjectStorage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ friend class DiskObjectStorageRemoteMetadataRestoreHelper;
205205
/// with static files, so only read-only operations are allowed for this storage.
206206
bool isReadOnly() const override;
207207

208-
bool isPlain() const;
208+
bool isPlain() const override;
209209

210210
/// Is object write-once?
211211
/// For example: S3PlainObjectStorage is write once, this means that it

src/Disks/StoragePolicy.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <Disks/VolumeJBOD.h>
1313

1414
#include <algorithm>
15+
#include <ranges>
1516
#include <set>
1617

1718

@@ -392,6 +393,22 @@ void StoragePolicy::checkCompatibleWith(const StoragePolicyPtr & new_storage_pol
392393
}
393394
}
394395

396+
bool StoragePolicy::isCompatibleForPartitionOps(const StoragePolicyPtr & other) const
397+
{
398+
if (getName() == other->getName())
399+
return true;
400+
401+
constexpr auto is_compatible = [](const auto & disk) -> bool
402+
{
403+
if (disk->isPlain())
404+
return true;
405+
if (auto delegate = disk->getDelegateDiskIfExists())
406+
return delegate->isPlain();
407+
return false;
408+
};
409+
410+
return std::ranges::all_of(getDisks(), is_compatible) && std::ranges::all_of(other->getDisks(), is_compatible);
411+
}
395412

396413
std::optional<size_t> StoragePolicy::tryGetVolumeIndexByDiskName(const String & disk_name) const
397414
{

src/Disks/StoragePolicy.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ class StoragePolicy : public IStoragePolicy
8282
/// Checks if storage policy can be replaced by another one.
8383
void checkCompatibleWith(const StoragePolicyPtr & new_storage_policy) const override;
8484

85+
///
86+
bool isCompatibleForPartitionOps(const StoragePolicyPtr & other) const override;
87+
8588
/// Check if we have any volume with stopped merges
8689
bool hasAnyVolumeWithDisabledMerges() const override;
8790

src/Storages/StorageMergeTree.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,7 @@ void StorageMergeTree::replacePartitionFrom(const StoragePtr & source_table, con
22682268

22692269
static const String TMP_PREFIX = "tmp_replace_from_";
22702270

2271+
bool are_policies_partition_compatible = getStoragePolicy()->isCompatibleForPartitionOps(source_table->getStoragePolicy());
22712272
for (const DataPartPtr & src_part : src_parts)
22722273
{
22732274
if (is_all)
@@ -2294,7 +2295,7 @@ void StorageMergeTree::replacePartitionFrom(const StoragePtr & source_table, con
22942295
clone_params,
22952296
local_context->getReadSettings(),
22962297
local_context->getWriteSettings(),
2297-
true/*must_on_same_disk*/);
2298+
!are_policies_partition_compatible /*must_on_same_disk*/);
22982299
dst_parts.emplace_back(std::move(dst_part));
22992300
dst_parts_locks.emplace_back(std::move(part_lock));
23002301
}
@@ -2371,13 +2372,18 @@ void StorageMergeTree::movePartitionToTable(const StoragePtr & dest_table, const
23712372
throw Exception(ErrorCodes::NOT_IMPLEMENTED,
23722373
"Table {} supports movePartitionToTable only for MergeTree family of table engines. Got {}",
23732374
getStorageID().getNameForLogs(), dest_table->getName());
2374-
if (dest_table_storage->getStoragePolicy() != this->getStoragePolicy())
2375-
throw Exception(ErrorCodes::UNKNOWN_POLICY,
2376-
"Destination table {} should have the same storage policy of source table {}. {}: {}, {}: {}",
2377-
dest_table_storage->getStorageID().getNameForLogs(),
2378-
getStorageID().getNameForLogs(), getStorageID().getNameForLogs(),
2379-
this->getStoragePolicy()->getName(), dest_table_storage->getStorageID().getNameForLogs(),
2380-
dest_table_storage->getStoragePolicy()->getName());
2375+
bool are_policies_partition_compatible = getStoragePolicy()->isCompatibleForPartitionOps(dest_table_storage->getStoragePolicy());
2376+
2377+
if (!are_policies_partition_compatible)
2378+
throw Exception(
2379+
ErrorCodes::UNKNOWN_POLICY,
2380+
"Destination table {} should have the same or partition compatible storage policy of source table {}. {}: {}, {}: {}",
2381+
dest_table_storage->getStorageID().getNameForLogs(),
2382+
getStorageID().getNameForLogs(),
2383+
getStorageID().getNameForLogs(),
2384+
this->getStoragePolicy()->getName(),
2385+
dest_table_storage->getStorageID().getNameForLogs(),
2386+
dest_table_storage->getStoragePolicy()->getName());
23812387

23822388
// Use the same back-pressure (delay/throw) logic as for INSERTs to be consistent and avoid possibility of exceeding part limits using MOVE PARTITION queries
23832389
dest_table_storage->delayInsertOrThrowIfNeeded(nullptr, local_context, true);
@@ -2437,7 +2443,7 @@ void StorageMergeTree::movePartitionToTable(const StoragePtr & dest_table, const
24372443
clone_params,
24382444
local_context->getReadSettings(),
24392445
local_context->getWriteSettings(),
2440-
true/*must_on_same_disk*/
2446+
!are_policies_partition_compatible /*must_on_same_disk*/
24412447
);
24422448

24432449
dst_parts.emplace_back(std::move(dst_part));

0 commit comments

Comments
 (0)