296
296
uint32_t lower_case_table_names= 1;
297
297
uint32_t tc_heuristic_recover= 0;
298
298
uint32_t volatile thread_count, thread_running;
299
uint64_t thd_startup_options;
299
uint64_t session_startup_options;
300
300
ulong back_log, connect_timeout, server_id;
301
301
ulong table_cache_size, table_def_size;
302
302
ulong what_to_log;
1207
1207
Close a connection.
1209
@param thd Thread handle
1209
@param session Thread handle
1210
1210
@param errcode Error code to print to console
1211
1211
@param lock 1 if we have have to lock LOCK_thread_count
1214
1214
For the connection that is doing shutdown, this is called twice
1216
void close_connection(Session *thd, uint32_t errcode, bool lock)
1216
void close_connection(Session *session, uint32_t errcode, bool lock)
1220
1220
(void) pthread_mutex_lock(&LOCK_thread_count);
1221
thd->killed= Session::KILL_CONNECTION;
1222
if ((vio= thd->net.vio) != 0)
1221
session->killed= Session::KILL_CONNECTION;
1222
if ((vio= session->net.vio) != 0)
1225
net_send_error(thd, errcode, ER(errcode)); /* purecov: inspected */
1226
net_close(&(thd->net)); /* vio is freed in delete thd */
1225
net_send_error(session, errcode, ER(errcode)); /* purecov: inspected */
1226
net_close(&(session->net)); /* vio is freed in delete session */
1229
1229
(void) pthread_mutex_unlock(&LOCK_thread_count);
1236
1236
extern "C" RETSIGTYPE end_thread_signal(int sig __attribute__((unused)))
1238
Session *thd=current_thd;
1238
Session *session=current_session;
1241
1241
statistic_increment(killed_threads, &LOCK_status);
1242
thread_scheduler.end_thread(thd,0); /* purecov: inspected */
1242
thread_scheduler.end_thread(session,0); /* purecov: inspected */
1244
1244
return;; /* purecov: deadcode */
1249
Unlink thd from global list of available connections and free thd
1249
Unlink session from global list of available connections and free session
1253
session Thread handler
1256
1256
LOCK_thread_count is locked and left locked
1259
void unlink_thd(Session *thd)
1259
void unlink_session(Session *session)
1263
1263
pthread_mutex_lock(&LOCK_connection_count);
1264
1264
--connection_count;
1302
1302
pthread_cond_signal(&COND_flush_thread_cache);
1303
1303
if (wake_thread)
1307
thd= thread_cache.get();
1308
thd->thread_stack= (char*) &thd; // For store_globals
1309
(void) thd->store_globals();
1307
session= thread_cache.get();
1308
session->thread_stack= (char*) &session; // For store_globals
1309
(void) session->store_globals();
1311
1311
Session::mysys_var::abort is associated with physical thread rather
1312
1312
than with Session object. So we need to reset this flag before using
1313
1313
this thread for handling of new Session object/connection.
1315
thd->mysys_var->abort= 0;
1316
thd->thr_create_utime= my_micro_time();
1317
threads.append(thd);
1315
session->mysys_var->abort= 0;
1316
session->thr_create_utime= my_micro_time();
1317
threads.append(session);
1341
1341
0 Signal to handle_one_connection to reuse connection
1344
bool one_thread_per_connection_end(Session *thd, bool put_in_cache)
1344
bool one_thread_per_connection_end(Session *session, bool put_in_cache)
1346
unlink_session(session);
1347
1347
if (put_in_cache)
1348
1348
put_in_cache= cache_thread();
1349
1349
pthread_mutex_unlock(&LOCK_thread_count);
1453
1453
max_connections * sizeof(Session)) / 1024);
1455
1455
#ifdef HAVE_STACKTRACE
1456
Session *thd= current_thd;
1456
Session *session= current_session;
1458
1458
if (!(test_flags & TEST_NO_STACKTRACE))
1460
fprintf(stderr,"thd: 0x%lx\n",(long) thd);
1460
fprintf(stderr,"session: 0x%lx\n",(long) session);
1461
1461
fprintf(stderr,_("Attempting backtrace. You can use the following "
1462
1462
"information to find out\n"
1463
1463
"where mysqld died. If you see no messages after this, "
1464
1464
"something went\n"
1465
1465
"terribly wrong...\n"));
1466
print_stacktrace(thd ? (unsigned char*) thd->thread_stack : (unsigned char*) 0,
1466
print_stacktrace(session ? (unsigned char*) session->thread_stack : (unsigned char*) 0,
1467
1467
my_thread_stack_size);
1471
1471
const char *kreason= "UNKNOWN";
1472
switch (thd->killed) {
1472
switch (session->killed) {
1473
1473
case Session::NOT_KILLED:
1474
1474
kreason= "NOT_KILLED";
1489
1489
fprintf(stderr, _("Trying to get some variables.\n"
1490
1490
"Some pointers may be invalid and cause the "
1491
1491
"dump to abort...\n"));
1492
safe_print_str("thd->query", thd->query, 1024);
1493
fprintf(stderr, "thd->thread_id=%"PRIu32"\n", (uint32_t) thd->thread_id);
1494
fprintf(stderr, "thd->killed=%s\n", kreason);
1492
safe_print_str("session->query", session->query, 1024);
1493
fprintf(stderr, "session->thread_id=%"PRIu32"\n", (uint32_t) session->thread_id);
1494
fprintf(stderr, "session->killed=%s\n", kreason);
1496
1496
fflush(stderr);
1497
1497
#endif /* HAVE_STACKTRACE */
1809
1809
void my_message_sql(uint32_t error, const char *str, myf MyFlags)
1813
1813
Put here following assertion when situation with EE_* error codes
1816
if ((thd= current_thd))
1816
if ((session= current_session))
1818
1818
if (MyFlags & ME_FATALERROR)
1819
thd->is_fatal_error= 1;
1819
session->is_fatal_error= 1;
1822
1822
TODO: There are two exceptions mechanism (Session and sp_rcontext),
1823
1823
this could be improved by having a common stack of handlers.
1825
if (thd->handle_error(error, str,
1825
if (session->handle_error(error, str,
1826
1826
DRIZZLE_ERROR::WARN_LEVEL_ERROR))
1829
thd->is_slave_error= 1; // needed to catch query errors during replication
1829
session->is_slave_error= 1; // needed to catch query errors during replication
1832
thd->lex->current_select == 0 if lex structure is not inited
1832
session->lex->current_select == 0 if lex structure is not inited
1833
1833
(not query command (COM_QUERY))
1835
if (! (thd->lex->current_select &&
1836
thd->lex->current_select->no_error && !thd->is_fatal_error))
1835
if (! (session->lex->current_select &&
1836
session->lex->current_select->no_error && !session->is_fatal_error))
1838
if (! thd->main_da.is_error()) // Return only first message
1838
if (! session->main_da.is_error()) // Return only first message
1840
1840
if (error == 0)
1841
1841
error= ER_UNKNOWN_ERROR;
1842
1842
if (str == NULL)
1843
1843
str= ER(error);
1844
thd->main_da.set_error_status(thd, error, str);
1844
session->main_da.set_error_status(session, error, str);
1848
if (!thd->no_warnings_for_error && !thd->is_fatal_error)
1848
if (!session->no_warnings_for_error && !session->is_fatal_error)
1851
1851
Suppress infinite recursion if there a memory allocation error
1852
1852
inside push_warning.
1854
thd->no_warnings_for_error= true;
1855
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
1856
thd->no_warnings_for_error= false;
1854
session->no_warnings_for_error= true;
1855
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error, str);
1856
session->no_warnings_for_error= false;
1859
if (!thd || MyFlags & ME_NOREFRESH)
1859
if (!session || MyFlags & ME_NOREFRESH)
1860
1860
sql_print_error("%s: %s",my_progname,str); /* purecov: inspected */
2702
2702
This function will create new thread to handle the incoming
2703
2703
connection. If there are idle cached threads one will be used.
2704
'thd' will be pushed into 'threads'.
2704
'session' will be pushed into 'threads'.
2706
2706
In single-threaded mode (\#define ONE_THREAD) connection will be
2707
2707
handled inside this function.
2709
@param[in,out] thd Thread handle of future thread.
2709
@param[in,out] session Thread handle of future thread.
2712
static void create_new_thread(Session *thd)
2712
static void create_new_thread(Session *session)
2740
2740
pthread_mutex_lock(&LOCK_thread_count);
2743
The initialization of thread_id is done in create_embedded_thd() for
2743
The initialization of thread_id is done in create_embedded_session() for
2744
2744
the embedded library.
2745
2745
TODO: refactor this to avoid code duplication there
2747
thd->thread_id= thd->variables.pseudo_thread_id= thread_id++;
2747
session->thread_id= session->variables.pseudo_thread_id= thread_id++;
2749
2749
thread_count++;
2751
thread_scheduler.add_connection(thd);
2751
thread_scheduler.add_connection(session);
2866
2866
** Don't allow too many connections
2869
if (!(thd= new Session))
2869
if (!(session= new Session))
2871
2871
(void) shutdown(new_sock, SHUT_RDWR);
2872
2872
close(new_sock);
2875
if (net_init_sock(&thd->net, new_sock, sock == 0))
2875
if (net_init_sock(&session->net, new_sock, sock == 0))
2881
create_new_thread(thd);
2881
create_new_thread(session);
3915
3915
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
3918
static int show_net_compression(Session *thd __attribute__((unused)),
3918
static int show_net_compression(Session *session __attribute__((unused)),
3920
3920
char *buff __attribute__((unused)))
3922
3922
var->type= SHOW_MY_BOOL;
3923
var->value= (char *)&thd->net.compress;
3923
var->value= (char *)&session->net.compress;
3927
3927
static st_show_var_func_container
3928
3928
show_net_compression_cont= { &show_net_compression };
3930
static int show_starttime(Session *thd, SHOW_VAR *var, char *buff)
3930
static int show_starttime(Session *session, SHOW_VAR *var, char *buff)
3932
3932
var->type= SHOW_LONG;
3933
3933
var->value= buff;
3934
*((long *)buff)= (long) (thd->query_start() - server_start_time);
3934
*((long *)buff)= (long) (session->query_start() - server_start_time);
3938
3938
static st_show_var_func_container
3939
3939
show_starttime_cont= { &show_starttime };
3941
static int show_flushstatustime(Session *thd, SHOW_VAR *var, char *buff)
3941
static int show_flushstatustime(Session *session, SHOW_VAR *var, char *buff)
3943
3943
var->type= SHOW_LONG;
3944
3944
var->value= buff;
3945
*((long *)buff)= (long) (thd->query_start() - flush_status_time);
3945
*((long *)buff)= (long) (session->query_start() - flush_status_time);
3949
3949
static st_show_var_func_container
3950
3950
show_flushstatustime_cont= { &show_flushstatustime };
3952
static int show_slave_running(Session *thd __attribute__((unused)),
3952
static int show_slave_running(Session *session __attribute__((unused)),
3953
3953
SHOW_VAR *var, char *buff)
3955
3955
var->type= SHOW_MY_BOOL;
3964
3964
static st_show_var_func_container
3965
3965
show_slave_running_cont= { &show_slave_running };
3967
static int show_slave_retried_trans(Session *thd __attribute__((unused)),
3967
static int show_slave_retried_trans(Session *session __attribute__((unused)),
3968
3968
SHOW_VAR *var, char *buff)
3989
3989
static st_show_var_func_container
3990
3990
show_slave_retried_trans_cont= { &show_slave_retried_trans };
3992
static int show_slave_received_heartbeats(Session *thd __attribute__((unused)),
3992
static int show_slave_received_heartbeats(Session *session __attribute__((unused)),
3993
3993
SHOW_VAR *var, char *buff)
3995
3995
pthread_mutex_lock(&LOCK_active_mi);
4010
4010
static st_show_var_func_container
4011
4011
show_slave_received_heartbeats_cont= { &show_slave_received_heartbeats };
4013
static int show_heartbeat_period(Session *thd __attribute__((unused)),
4013
static int show_heartbeat_period(Session *session __attribute__((unused)),
4014
4014
SHOW_VAR *var, char *buff)
4016
4016
pthread_mutex_lock(&LOCK_active_mi);
4029
4029
static st_show_var_func_container
4030
4030
show_heartbeat_period_cont= { &show_heartbeat_period};
4032
static int show_open_tables(Session *thd __attribute__((unused)),
4032
static int show_open_tables(Session *session __attribute__((unused)),
4033
4033
SHOW_VAR *var, char *buff)
4035
4035
var->type= SHOW_LONG;
4247
4247
log_error_file_ptr= log_error_file;
4248
4248
language_ptr= language;
4249
4249
mysql_data_home= mysql_real_data_home;
4250
thd_startup_options= (OPTION_AUTO_IS_NULL | OPTION_BIN_LOG |
4250
session_startup_options= (OPTION_AUTO_IS_NULL | OPTION_BIN_LOG |
4251
4251
OPTION_QUOTE_SHOW_CREATE | OPTION_SQL_NOTES);
4252
4252
protocol_version= PROTOCOL_VERSION;
4253
4253
what_to_log= ~ (1L << (uint) COM_TIME);
4966
4966
/** Clear most status variables. */
4967
void refresh_status(Session *thd)
4967
void refresh_status(Session *session)
4969
4969
pthread_mutex_lock(&LOCK_status);
4971
4971
/* Add thread's status variabes to global status */
4972
add_to_status(&global_status_var, &thd->status_var);
4972
add_to_status(&global_status_var, &session->status_var);
4974
4974
/* Reset thread's status variables */
4975
memset(&thd->status_var, 0, sizeof(thd->status_var));
4975
memset(&session->status_var, 0, sizeof(session->status_var));
4977
4977
/* Reset some global variables */
4978
4978
reset_status_vars();