MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / processData

Method processData

src/Interpreters/AsynchronousInsertQueue.cpp:975–1284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

973}
974
975void AsynchronousInsertQueue::processData(
976 InsertQuery key, InsertDataPtr data, ContextPtr global_context, ThreadGroupPtr current_query_thread_group, QueueShardFlushTimeHistory & queue_shard_flush_time_history)
977try
978{
979 if (!data)
980 return;
981
982 SCOPE_EXIT(CurrentMetrics::sub(CurrentMetrics::PendingAsyncInsert, data->entries.size()));
983
984 DB::setThreadName(ThreadName::ASYNC_INSERT_QUEUE);
985
986 const auto log = getLogger("AsynchronousInsertQueue");
987 const auto & insert_query = assert_cast<const ASTInsertQuery &>(*key.query);
988
989 bool internal = true;
990 bool async_insert = true;
991
992 /// Disabled query spans. Could be activated by initializing this to a SpanHolder
993 std::shared_ptr<OpenTelemetry::SpanHolder> query_span{nullptr};
994
995 /// 'resetParser' doesn't work for parallel parsing.
996 key.settings->set("input_format_parallel_parsing", false);
997 /// It maybe insert into distributed table.
998 /// We want the remote part to decide if the insert will be async or not.
999 key.settings->setDefaultValue("async_insert");
1000
1001 auto insert_context = Context::createCopy(global_context);
1002 insert_context->makeQueryContext();
1003
1004 /// Access rights must be checked for the user who executed the initial INSERT query.
1005 if (key.user_id)
1006 {
1007 insert_context->setUser(*key.user_id);
1008 insert_context->setCurrentRoles(key.current_roles);
1009 }
1010
1011 /// Context::setUser only restores the access-control identity, not the ClientInfo user
1012 /// names. Restore them from the originating query so currentUser()/user()/
1013 /// authenticatedUser() and the materialized views triggered by the flush observe the
1014 /// inserting user instead of an empty string.
1015 insert_context->setCurrentUserName(key.current_user);
1016 insert_context->setInitialUserName(key.initial_user);
1017 insert_context->setAuthenticatedUserName(key.authenticated_user);
1018
1019 insert_context->setSettings(*key.settings);
1020
1021 /// Set initial_query_id, because it's used in InterpreterInsertQuery for table lock.
1022 insert_context->setCurrentQueryId(""); // "" means generate a new query id
1023
1024 auto insert_query_id = insert_context->getCurrentQueryId();
1025 auto query_start_time = std::chrono::system_clock::now();
1026
1027 Stopwatch start_watch{CLOCK_MONOTONIC};
1028 insert_context->setQueryKind(ClientInfo::QueryKind::INITIAL_QUERY);
1029 insert_context->setInitialQueryStartTime(query_start_time);
1030 insert_context->setCurrentQueryId(insert_query_id);
1031 insert_context->setInitialQueryId(insert_query_id);
1032

Callers

nothing calls this directly

Calls 15

serializeQueryFunction · 0.85
normalizedQueryHashFunction · 0.85
timeInSecondsFunction · 0.85
logQueryStartFunction · 0.85
logExceptionBeforeStartFunction · 0.85
appendElementsToLogSafeFunction · 0.85
logQueryFinishFunction · 0.85
logQueryExceptionFunction · 0.85
setDefaultValueMethod · 0.80
setCurrentRolesMethod · 0.80
setCurrentUserNameMethod · 0.80

Tested by

no test coverage detected