| 342 | |
| 343 | |
| 344 | BlockIO InterpreterSystemQuery::execute() |
| 345 | { |
| 346 | auto & query = query_ptr->as<ASTSystemQuery &>(); |
| 347 | |
| 348 | if (!query.cluster.empty()) |
| 349 | { |
| 350 | DDLQueryOnClusterParams params; |
| 351 | params.access_to_check = getRequiredAccessForDDLOnCluster(); |
| 352 | return executeDDLQueryOnCluster(query_ptr, getContext(), params); |
| 353 | } |
| 354 | |
| 355 | using Type = ASTSystemQuery::Type; |
| 356 | |
| 357 | /// Use global context with fresh system profile settings |
| 358 | auto system_context = Context::createCopy(getContext()->getGlobalContext()); |
| 359 | /// Don't check for constraints when changing profile. It was accepted before (for example it might include |
| 360 | /// some experimental settings) |
| 361 | bool check_constraints = false; |
| 362 | system_context->setCurrentProfile(getContext()->getSystemProfileName(), check_constraints); |
| 363 | |
| 364 | /// Make canonical query for simpler processing |
| 365 | if (query.type == Type::RELOAD_DICTIONARY) |
| 366 | { |
| 367 | if (query.database) |
| 368 | query.setTable(query.getDatabase() + "." + query.getTable()); |
| 369 | } |
| 370 | else if (query.table) |
| 371 | { |
| 372 | StorageID id_in_query(query.getDatabase(), query.getTable()); |
| 373 | /// `IF EXISTS` (currently parsed for `SYSTEM SYNC REPLICA`) must suppress |
| 374 | /// `UNKNOWN_DATABASE` in addition to `UNKNOWN_TABLE`. Plain `resolveStorageID` |
| 375 | /// throws on a missing database before the per-handler `if_exists` check is |
| 376 | /// reached, so use `tryResolveStorageID` here when `if_exists` is set. |
| 377 | /// The handler still validates table existence via the catalog. |
| 378 | if (query.if_exists) |
| 379 | table_id = getContext()->tryResolveStorageID(id_in_query, Context::ResolveOrdinary); |
| 380 | else |
| 381 | table_id = getContext()->resolveStorageID(id_in_query, Context::ResolveOrdinary); |
| 382 | } |
| 383 | |
| 384 | |
| 385 | BlockIO result; |
| 386 | |
| 387 | volume_ptr = {}; |
| 388 | if (!query.storage_policy.empty() && !query.volume.empty()) |
| 389 | volume_ptr = getContext()->getStoragePolicy(query.storage_policy)->getVolumeByName(query.volume); |
| 390 | |
| 391 | switch (query.type) |
| 392 | { |
| 393 | case Type::SHUTDOWN: |
| 394 | { |
| 395 | getContext()->checkAccess(AccessType::SYSTEM_SHUTDOWN); |
| 396 | if (kill(0, SIGTERM)) |
| 397 | throw ErrnoException(ErrorCodes::CANNOT_KILL, "System call kill(0, SIGTERM) failed"); |
| 398 | break; |
| 399 | } |
| 400 | case Type::KILL: |
| 401 | { |
no test coverage detected