| 2484 | } |
| 2485 | |
| 2486 | void InterpreterCreateQuery::prepareOnClusterQuery(ASTCreateQuery & create, ContextPtr local_context, const String & cluster_name) |
| 2487 | { |
| 2488 | if (create.attach) |
| 2489 | return; |
| 2490 | |
| 2491 | /// For CREATE query generate UUID on initiator, so it will be the same on all hosts. |
| 2492 | /// It will be ignored if database does not support UUIDs. |
| 2493 | create.generateRandomUUIDs(); |
| 2494 | |
| 2495 | /// For cross-replication cluster we cannot use UUID in replica path. |
| 2496 | String cluster_name_expanded = local_context->getMacros()->expand(cluster_name); |
| 2497 | ClusterPtr cluster = local_context->getCluster(cluster_name_expanded); |
| 2498 | |
| 2499 | if (cluster->maybeCrossReplication()) |
| 2500 | { |
| 2501 | auto on_cluster_version = local_context->getSettingsRef()[Setting::distributed_ddl_entry_format_version].value; |
| 2502 | if (DDLLogEntry::NORMALIZE_CREATE_ON_INITIATOR_VERSION <= on_cluster_version) |
| 2503 | throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Value {} of setting distributed_ddl_entry_format_version " |
| 2504 | "is incompatible with cross-replication", on_cluster_version); |
| 2505 | |
| 2506 | /// Check that {uuid} macro is not used in zookeeper_path for ReplicatedMergeTree. |
| 2507 | /// Otherwise replicas will generate different paths. |
| 2508 | if (!create.storage) |
| 2509 | return; |
| 2510 | if (!create.storage->engine) |
| 2511 | return; |
| 2512 | if (!startsWith(create.storage->engine->name, "Replicated")) |
| 2513 | return; |
| 2514 | |
| 2515 | bool has_explicit_zk_path_arg = create.storage->engine->arguments && |
| 2516 | create.storage->engine->arguments->children.size() >= 2 && |
| 2517 | create.storage->engine->arguments->children[0]->as<ASTLiteral>() && |
| 2518 | create.storage->engine->arguments->children[0]->as<ASTLiteral>()->value.getType() == Field::Types::String; |
| 2519 | |
| 2520 | if (has_explicit_zk_path_arg) |
| 2521 | { |
| 2522 | String zk_path = create.storage->engine->arguments->children[0]->as<ASTLiteral>()->value.safeGet<String>(); |
| 2523 | Macros::MacroExpansionInfo info; |
| 2524 | info.table_id.uuid = create.uuid; |
| 2525 | info.ignore_unknown = true; |
| 2526 | local_context->getMacros()->expand(zk_path, info); |
| 2527 | if (!info.expanded_uuid) |
| 2528 | return; |
| 2529 | } |
| 2530 | |
| 2531 | throw Exception(ErrorCodes::INCORRECT_QUERY, |
| 2532 | "Seems like cluster is configured for cross-replication, " |
| 2533 | "but zookeeper_path for ReplicatedMergeTree is not specified or contains {{uuid}} macro. " |
| 2534 | "It's not supported for cross replication, because tables must have different UUIDs. " |
| 2535 | "Please specify unique zookeeper_path explicitly."); |
| 2536 | } |
| 2537 | } |
| 2538 | |
| 2539 | BlockIO InterpreterCreateQuery::executeQueryOnCluster(ASTCreateQuery & create) |
| 2540 | { |
nothing calls this directly
no test coverage detected