This commit is contained in:
flynn 2023-02-11 13:58:19 +00:00
parent d3255fa420
commit 50dace9571
2 changed files with 25 additions and 9 deletions

View File

@ -6,23 +6,37 @@
namespace DB
{
namespace ErrorCodes
{
extern const int INVALID_SETTING_VALUE;
}
String getDiskName(ASTStorage & storage_def, ContextPtr context)
{
if (storage_def.settings)
{
SettingsChanges changes = storage_def.settings->changes;
for (const auto & change : changes)
const auto disk_change
= std::find_if(changes.begin(), changes.end(), [&](const SettingChange & change) { return change.name == "disk"; });
const auto storage_policy_change
= std::find_if(changes.begin(), changes.end(), [&](const SettingChange & change) { return change.name == "storage_policy"; });
if (disk_change != changes.end() && storage_policy_change != changes.end())
throw Exception(
ErrorCodes::INVALID_SETTING_VALUE, "Could not specify `disk` and `storage_policy` at the same time for storage Log Family");
if (disk_change != changes.end())
return disk_change->value.safeGet<String>();
if (storage_policy_change != changes.end())
{
/// How about both disk and storage_policy are specified?
if (change.name == "disk")
return change.value.safeGet<String>();
if (change.name == "storage_policy")
{
auto policy = context->getStoragePolicy(change.value.safeGet<String>());
return policy->getAnyDisk()->getName();
}
auto policy = context->getStoragePolicy(storage_policy_change->value.safeGet<String>());
return policy->getDisks()[0]->getName();
}
}
return "default";
}

View File

@ -21,3 +21,5 @@ INSERT INTO test_2554_stripelog SELECT 1;
SELECT * FROM test_2554_stripelog;
DROP TABLE test_2554_stripelog;
CREATE TABLE test_2554_error (n UInt32) ENGINE = Log SETTINGS disk = 'default', storage_policy = 'default'; -- { serverError 471 }