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

Method run

src/Server/MySQLHandler.cpp:228–379  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226}
227
228void MySQLHandler::run()
229{
230 setThreadName("MySQLHandler");
231 ThreadStatus thread_status;
232 connection_context->makeSessionContext();
233 connection_context->getClientInfo().interface = ClientInfo::Interface::MYSQL;
234 connection_context->setDefaultFormat("MySQLWire");
235 connection_context->getClientInfo().connection_id = connection_id;
236
237 in = std::make_shared<ReadBufferFromPocoSocket>(socket());
238 out = std::make_shared<WriteBufferFromPocoSocket>(socket());
239 packet_endpoint = std::make_shared<MySQLProtocol::PacketEndpoint>(*in, *out, sequence_id);
240
241 try
242 {
243 Handshake handshake(server_capabilities, connection_id, "5.1.0",
244 auth_plugin->getName(), auth_plugin->getAuthPluginData(), CharacterSet::utf8_general_ci);
245 packet_endpoint->sendPacket<Handshake>(handshake, true);
246
247 LOG_TRACE(log, "Sent handshake");
248
249 HandshakeResponse handshake_response;
250 finishHandshake(handshake_response);
251 client_capabilities = handshake_response.capability_flags;
252 max_packet_size = handshake_response.max_packet_size ? handshake_response.max_packet_size : MAX_PACKET_LENGTH;
253
254 LOG_TRACE(log,
255 "Capabilities: {}, max_packet_size: {}, character_set: {}, user: {}, auth_response length: {}, database: {}, auth_plugin_name: {}",
256 handshake_response.capability_flags,
257 handshake_response.max_packet_size,
258 static_cast<int>(handshake_response.character_set),
259 handshake_response.username,
260 handshake_response.auth_response.length(),
261 handshake_response.database,
262 handshake_response.auth_plugin_name);
263
264 if (!(client_capabilities & CLIENT_PROTOCOL_41))
265 throw Exception("Required capability: CLIENT_PROTOCOL_41.", ErrorCodes::MYSQL_CLIENT_INSUFFICIENT_CAPABILITIES);
266
267 try
268 {
269 auto &default_database = handshake_response.database;
270 if (!default_database.empty())
271 {
272 //CNCH multi-tenant default database pattern from gateway client: {tenant_id}`{default_database}
273 if (auto pos = default_database.find('`'); pos != String::npos)
274 {
275 connection_context->setSetting("tenant_id", String(default_database.c_str(), pos)); /// {tenant_id}`*
276 connection_context->setTenantId(String(default_database.c_str(), pos));
277 if (pos + 1 != default_database.size()) ///multi-tenant default database storage pattern: {tenant_id}.{default_database}
278 default_database[pos] = '.';
279 else /// {tenant_id}`
280 default_database.clear();
281 }
282 else if (!default_database.empty() && !connection_context->getTenantId().empty())
283 {
284 default_database = connection_context->getTenantId() + '.' + default_database;
285 }

Callers

nothing calls this directly

Calls 15

setThreadNameFunction · 0.85
ERRPacketClass · 0.85
authenticateFunction · 0.85
tryLogCurrentExceptionFunction · 0.85
getCurrentExceptionCodeFunction · 0.85
makeSessionContextMethod · 0.80
setDefaultFormatMethod · 0.80
lengthMethod · 0.80
setTenantIdMethod · 0.80
getTenantIdMethod · 0.80
setCurrentDatabaseMethod · 0.80

Tested by

no test coverage detected