MCPcopy Create free account
hub / github.com/ByConity/ByConity / insertAndRun

Method insertAndRun

src/Server/AsyncQueryManager.cpp:40–85  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40void 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

Callers 2

runImplMethod · 0.80

Calls 10

UUIDToStringFunction · 0.85
generateV4Function · 0.85
setThreadNameFunction · 0.85
funcFunction · 0.85
setAsyncQueryIdMethod · 0.80
totalSecondsMethod · 0.80
setAsyncQueryStatusMethod · 0.45
getCnchCatalogMethod · 0.45
emplaceMethod · 0.45

Tested by

no test coverage detected