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

Method run

src/Server/MySQLHandler.cpp:240–371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

238MySQLHandler::~MySQLHandler() = default;
239
240void MySQLHandler::run()
241{
242 DB::setThreadName(ThreadName::MYSQL_HANDLER);
243
244 session = std::make_unique<Session>(server.context(), ClientInfo::Interface::MYSQL);
245 SCOPE_EXIT({ session.reset(); });
246
247 session->setClientConnectionId(connection_id);
248
249 const Settings & settings = server.context()->getSettingsRef();
250 socket().setReceiveTimeout(settings[Setting::receive_timeout]);
251 socket().setSendTimeout(settings[Setting::send_timeout]);
252
253 in = std::make_shared<ReadBufferFromPocoSocket>(socket(), read_event);
254 out = std::make_shared<AutoCanceledWriteBuffer<WriteBufferFromPocoSocket>>(socket(), write_event);
255 packet_endpoint = std::make_shared<MySQLProtocol::PacketEndpoint>(*in, *out, sequence_id);
256
257 try
258 {
259 Handshake handshake(server_capabilities, connection_id, VERSION_STRING + String("-") + VERSION_NAME,
260 auth_plugin->getName(), auth_plugin->getAuthPluginData(), CharacterSet::utf8_general_ci);
261 packet_endpoint->sendPacket<Handshake>(handshake);
262
263 LOG_TRACE(log, "Sent handshake");
264
265 HandshakeResponse handshake_response;
266 finishHandshake(handshake_response);
267 client_capabilities = handshake_response.capability_flags;
268 max_packet_size = handshake_response.max_packet_size ? handshake_response.max_packet_size : MAX_PACKET_LENGTH;
269
270 LOG_TRACE(log,
271 "Capabilities: {}, max_packet_size: {}, character_set: {}, user: {}, auth_response length: {}, database: {}, auth_plugin_name: {}",
272 handshake_response.capability_flags,
273 handshake_response.max_packet_size,
274 static_cast<int>(handshake_response.character_set),
275 handshake_response.username,
276 handshake_response.auth_response.length(),
277 handshake_response.database,
278 handshake_response.auth_plugin_name);
279
280 if (!(client_capabilities & CLIENT_PROTOCOL_41))
281 throw Exception(ErrorCodes::MYSQL_CLIENT_INSUFFICIENT_CAPABILITIES, "Required capability: CLIENT_PROTOCOL_41.");
282
283 if (secure_required && !(client_capabilities & CLIENT_SSL))
284 throw Exception(ErrorCodes::OPENSSL_ERROR, "SSL connection required.");
285
286 authenticate(handshake_response.username, handshake_response.auth_plugin_name, handshake_response.auth_response);
287
288 try
289 {
290 session->makeSessionContext();
291 session->sessionContext()->setDefaultFormat("MySQLWire");
292 if (!handshake_response.database.empty())
293 session->sessionContext()->setCurrentDatabase(handshake_response.database);
294 }
295 catch (const Exception & exc)
296 {
297 log->log(exc);

Callers

nothing calls this directly

Calls 15

ERRPacketClass · 0.85
getCurrentExceptionCodeFunction · 0.85
setDefaultFormatMethod · 0.80
sessionContextMethod · 0.80
sendPacketMethod · 0.80
resetSequenceIdMethod · 0.80
getPayloadMethod · 0.80
setThreadNameFunction · 0.50
StringClass · 0.50
ExceptionClass · 0.50
tryLogCurrentExceptionFunction · 0.50

Tested by

no test coverage detected