Bug #30389: connection_id() always return 0 in embedded server

  
Initialize thd->variables.pseudo_thread_id when a new embedded
thd is created.
parent c0fd0922
...@@ -564,6 +564,17 @@ void init_embedded_mysql(MYSQL *mysql, int client_flag) ...@@ -564,6 +564,17 @@ void init_embedded_mysql(MYSQL *mysql, int client_flag)
init_alloc_root(&mysql->field_alloc, 8192, 0); init_alloc_root(&mysql->field_alloc, 8192, 0);
} }
/**
@brief Initialize a new THD for a connection in the embedded server
@param client_flag Client capabilities which this thread supports
@return pointer to the created THD object
@todo
This function copies code from several places in the server, including
create_new_thread(), and prepare_new_connection_state(). This should
be refactored to avoid code duplication.
*/
void *create_embedded_thd(int client_flag) void *create_embedded_thd(int client_flag)
{ {
THD * thd= new THD; THD * thd= new THD;
......
...@@ -191,3 +191,7 @@ drop table table_26093; ...@@ -191,3 +191,7 @@ drop table table_26093;
drop function func_26093_a; drop function func_26093_a;
drop function func_26093_b; drop function func_26093_b;
End of 5.0 tests End of 5.0 tests
select connection_id() > 0;
connection_id() > 0
1
End of tests
...@@ -199,3 +199,11 @@ drop function func_26093_a; ...@@ -199,3 +199,11 @@ drop function func_26093_a;
drop function func_26093_b; drop function func_26093_b;
--echo End of 5.0 tests --echo End of 5.0 tests
#
# Bug #30389: connection_id() always return 0 in embedded server
#
select connection_id() > 0;
--echo End of tests
...@@ -4355,6 +4355,11 @@ static void create_new_thread(THD *thd) ...@@ -4355,6 +4355,11 @@ static void create_new_thread(THD *thd)
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
pthread_mutex_lock(&LOCK_thread_count); pthread_mutex_lock(&LOCK_thread_count);
/*
The initialization of thread_id is done in create_embedded_thd() for
the embedded library.
TODO: refactor this to avoid code duplication there
*/
thd->thread_id= thd->variables.pseudo_thread_id= thread_id++; thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
/* Start a new thread to handle connection */ /* Start a new thread to handle connection */
......
...@@ -1008,6 +1008,11 @@ void prepare_new_connection_state(THD* thd) ...@@ -1008,6 +1008,11 @@ void prepare_new_connection_state(THD* thd)
if (thd->client_capabilities & CLIENT_COMPRESS) if (thd->client_capabilities & CLIENT_COMPRESS)
thd->net.compress=1; // Use compression thd->net.compress=1; // Use compression
/*
Much of this is duplicated in create_embedded_thd() for the
embedded server library.
TODO: refactor this to avoid code duplication there
*/
thd->version= refresh_version; thd->version= refresh_version;
thd->proc_info= 0; thd->proc_info= 0;
thd->command= COM_SLEEP; thd->command= COM_SLEEP;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment