| 226 | } |
| 227 | |
| 228 | void 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 | } |
nothing calls this directly
no test coverage detected