MySQL adds a Connection source code

Source: Internet
Author: User
When the client initiates a query to the server, a connection is established with the server. MySQL provides the maximum number of connections. Therefore, each time a connection is established

When the client initiates a query to the server, a connection is established with the server. MySQL provides the maximum number of connections. Therefore, each time a connection is established

When the client initiates a query to the server, a connection is established with the server. MySQL provides the maximum number of connections. Therefore, each time a connection is established successfully, when the server assigns a processing thread to the connection, it will determine whether the current number of connections has operated the configured maximum number of connections. If it has exceeded, the thread will not be reallocated for processing, and the connection will be closed directly.

Static void create_new_thread (THD * thd)
{
DBUG_ENTER ("create_new_thread ");
/*
Don't allow too restart connections. We roughly check here that we allow
Only (max_connections + 1) connections.
*/
Mysql_mutex_lock (& LOCK_connection_count );
If (connection_count> = max_connections + 1 | abort_loop)
{// Determine whether the maximum connection exceeded or whether it indicates termination. The maximum connection is configured in the my. ini file,
Mysql_mutex_unlock (& LOCK_connection_count );
DBUG_PRINT ("error", ("Too many connections "));
Close_connection (thd, ER_CON_COUNT_ERROR );
Delete thd;
DBUG_VOID_RETURN;
}
+ + Connection_count; // If NO, increase the number of connections
If (connection_count> max_used_connections)
Max_used_connections = connection_count; // increase the maximum number of connections
Mysql_mutex_unlock (& LOCK_connection_count );
/* Start a new thread to handle connection .*/
Mysql_mutex_lock (& LOCK_thread_count );
/*
The initialization of thread_id is done in create_embedded_thd ()
The embedded library.
TODO: refactor this to avoid code duplication there
*/
Thd-> thread_id = thd-> variables. pseudo do_thread_id = thread_id ++;
Thread_count ++; // increase the number of threads and prepare to allocate threads for the connection)
MYSQL_CALLBACK (thread_schedconnection, add_connection, (thd ));
DBUG_VOID_RETURN;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.