| 38 | } |
| 39 | |
| 40 | void AsyncQueryManager::insertAndRun( |
| 41 | String & query, |
| 42 | ASTPtr ast, |
| 43 | ContextMutablePtr ctx, |
| 44 | ReadBuffer * istr, |
| 45 | SendAsyncQueryIdCallback send_async_query_id, |
| 46 | AsyncQueryHandlerFunc && func) |
| 47 | { |
| 48 | if (pool) |
| 49 | { |
| 50 | String id = UUIDHelpers::UUIDToString(UUIDHelpers::generateV4()); |
| 51 | ctx->setAsyncQueryId(id); |
| 52 | AsyncQueryStatus status; |
| 53 | status.set_id(id); |
| 54 | status.set_query_id(ctx->getClientInfo().current_query_id); |
| 55 | status.set_status(AsyncQueryStatus::NotStarted); |
| 56 | auto c_time = time(nullptr); |
| 57 | status.set_start_time(c_time); |
| 58 | status.set_update_time(c_time); |
| 59 | status.set_max_execution_time(ctx->getSettingsRef().max_execution_time.totalSeconds()); |
| 60 | ctx->getCnchCatalog()->setAsyncQueryStatus(id, status); |
| 61 | |
| 62 | send_async_query_id(id); |
| 63 | |
| 64 | pool->scheduleOrThrowOnError(make_copyable_function<void()>([query = std::move(query), |
| 65 | ast = std::move(ast), |
| 66 | context = std::move(ctx), |
| 67 | istr, |
| 68 | func = std::move(func), |
| 69 | id = std::move(id), |
| 70 | status = std::move(status)]() mutable { |
| 71 | setThreadName("async_query"); |
| 72 | status.set_status(AsyncQueryStatus::Running); |
| 73 | status.set_update_time(time(nullptr)); |
| 74 | context->getCnchCatalog()->setAsyncQueryStatus(id, status); |
| 75 | |
| 76 | std::optional<CurrentThread::QueryScope> query_scope; |
| 77 | query_scope.emplace(context); |
| 78 | func(query, ast, context, istr); |
| 79 | })); |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | func(query, ast, ctx, istr); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | } // namespace DB |
no test coverage detected