36
36
#include <drizzled/item/return_int.h>
37
37
#include <drizzled/item/empty_string.h>
38
38
#include <drizzled/show.h>
39
#include <drizzled/plugin/client.h>
40
#include "drizzled/plugin/scheduler.h"
41
#include "drizzled/plugin/authentication.h"
42
#include "drizzled/plugin/logging.h"
43
#include "drizzled/plugin/transactional_storage_engine.h"
44
#include "drizzled/probes.h"
45
#include "drizzled/table_proto.h"
46
#include "drizzled/db.h"
47
#include "drizzled/pthread_globals.h"
48
#include "drizzled/transaction_services.h"
50
#include "plugin/myisam/myisam.h"
51
#include "drizzled/internal/iocache.h"
39
#include <drizzled/scheduling.h>
54
41
#include <algorithm>
57
43
using namespace std;
44
using namespace drizzled;
75
60
extern pthread_key_t THR_Session;
76
61
extern pthread_key_t THR_Mem_root;
77
62
extern uint32_t max_used_connections;
78
extern atomic<uint32_t> connection_count;
63
extern drizzled::atomic<uint32_t> connection_count;
65
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
67
template class List<Key>;
68
template class List_iterator<Key>;
69
template class List<Key_part_spec>;
70
template class List_iterator<Key_part_spec>;
71
template class List<Alter_drop>;
72
template class List_iterator<Alter_drop>;
73
template class List<Alter_column>;
74
template class List_iterator<Alter_column>;
81
77
/****************************************************************************
174
165
return (int) session->variables.tx_isolation;
177
Session::Session(plugin::Client *client_arg)
169
void session_inc_row_count(Session *session)
171
session->row_count++;
174
Session::Session(plugin::Protocol *protocol_arg)
179
176
Open_tables_state(refresh_version),
180
177
mem_root(&main_mem_root),
185
181
scheduler_arg(NULL),
186
182
lock_id(&main_lock_id),
188
ha_data(plugin::num_trx_monitored_objects),
189
184
arg_of_last_insert_id_function(false),
190
185
first_successful_insert_id_in_prev_stmt(0),
191
186
first_successful_insert_id_in_cur_stmt(0),
200
195
derived_tables_processing(false),
201
196
tablespace_op(false),
204
transaction_message(NULL),
205
statement_message(NULL)
207
200
memset(process_list_info, 0, PROCESS_LIST_WIDTH);
208
client->setSession(this);
211
203
Pass nominal parameters to init_alloc_root only to ensure that
212
204
the destructor works OK in case of an error. The main_mem_root
213
205
will be re-initialized in init_for_queries().
215
memory::init_sql_alloc(&main_mem_root, memory::ROOT_MIN_BLOCK_SIZE, 0);
207
init_sql_alloc(&main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
216
208
thread_stack= NULL;
217
209
count_cuted_fields= CHECK_FIELD_IGNORE;
218
210
killed= NOT_KILLED;
266
263
memset(&status_var, 0, sizeof(status_var));
268
265
/* Initialize sub structures */
269
memory::init_sql_alloc(&warn_root, WARN_ALLOC_BLOCK_SIZE, WARN_ALLOC_PREALLOC_SIZE);
266
init_sql_alloc(&warn_root, WARN_ALLOC_BLOCK_SIZE, WARN_ALLOC_PREALLOC_SIZE);
270
267
hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
271
268
(hash_get_key) get_var_key,
272
269
(hash_free_key) free_user_var, 0);
271
protocol= protocol_arg;
272
protocol->setSession(this);
274
274
substitute_null_with_insert_id = false;
275
275
thr_lock_info_init(&lock_info); /* safety: will be reset after start */
276
276
thr_lock_owner_init(&main_lock_id, &lock_info);
384
383
Session::~Session()
385
Session_CHECK_SENTRY(this);
387
386
add_to_status(&global_status_var, &status_var);
389
if (client->isConnected())
388
if (protocol->isConnected())
391
390
if (global_system_variables.log_warnings)
392
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),internal::my_progname,
391
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),my_progname,
394
(getSecurityContext().getUser().c_str() ?
395
getSecurityContext().getUser().c_str() : ""));
393
(security_ctx.user.c_str() ?
394
security_ctx.user.c_str() : ""));
396
395
disconnect(0, false);
399
398
/* Close connection */
403
402
if (cleanup_done == false)
406
plugin::StorageEngine::closeConnection(this);
405
ha_close_connection(this);
407
406
plugin_sessionvar_cleanup(this);
409
413
free_root(&warn_root,MYF(0));
414
free_root(&transaction.mem_root,MYF(0));
410
415
mysys_var=0; // Safety (shouldn't be needed)
411
416
dbug_sentry= Session_SENTRY_GONE;
413
418
free_root(&main_mem_root, MYF(0));
414
419
pthread_setspecific(THR_Session, 0);
416
plugin::Logging::postEndDo(this);
418
422
/* Ensure that no one is using Session */
419
423
pthread_mutex_unlock(&LOCK_delete);
433
437
If this assumption will change, then we have to explictely add
434
438
the other variables after the while loop
436
void add_to_status(system_status_var *to_var, system_status_var *from_var)
440
void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var)
438
442
ulong *end= (ulong*) ((unsigned char*) to_var +
439
offsetof(system_status_var, last_system_status_var) +
443
offsetof(STATUS_VAR, last_system_status_var) +
441
445
ulong *to= (ulong*) to_var, *from= (ulong*) from_var;
457
461
This function assumes that all variables are long/ulong.
459
void add_diff_to_status(system_status_var *to_var, system_status_var *from_var,
460
system_status_var *dec_var)
463
void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var,
462
ulong *end= (ulong*) ((unsigned char*) to_var + offsetof(system_status_var,
466
ulong *end= (ulong*) ((unsigned char*) to_var + offsetof(STATUS_VAR,
463
467
last_system_status_var) +
465
469
ulong *to= (ulong*) to_var, *from= (ulong*) from_var, *dec= (ulong*) dec_var;
625
632
/* TODO replace will better error message */
626
633
snprintf(error_message_buff, sizeof(error_message_buff),
627
634
ER(ER_CANT_CREATE_THREAD), 1);
628
client->sendError(ER_CANT_CREATE_THREAD, error_message_buff);
635
protocol->sendError(ER_CANT_CREATE_THREAD, error_message_buff);
636
const char* Session::enter_cond(pthread_cond_t *cond,
637
pthread_mutex_t* mutex,
640
const char* old_msg = get_proc_info();
641
safe_mutex_assert_owner(mutex);
642
mysys_var->current_mutex = mutex;
643
mysys_var->current_cond = cond;
644
this->set_proc_info(msg);
648
void Session::exit_cond(const char* old_msg)
651
Putting the mutex unlock in exit_cond() ensures that
652
mysys_var->current_mutex is always unlocked _before_ mysys_var->mutex is
653
locked (if that would not be the case, you'll get a deadlock if someone
654
does a Session::awake() on you).
656
pthread_mutex_unlock(mysys_var->current_mutex);
657
pthread_mutex_lock(&mysys_var->mutex);
658
mysys_var->current_mutex = 0;
659
mysys_var->current_cond = 0;
660
this->set_proc_info(old_msg);
661
pthread_mutex_unlock(&mysys_var->mutex);
664
642
bool Session::authenticate()
667
if (client->authenticate())
645
if (protocol->authenticate())
670
648
statistic_increment(aborted_connects, &LOCK_status);
674
652
bool Session::checkUser(const char *passwd, uint32_t passwd_len, const char *in_db)
676
const string passwd_str(passwd, passwd_len);
677
bool is_authenticated=
678
plugin::Authentication::isAuthenticated(getSecurityContext(),
654
LEX_STRING db_str= { (char *) in_db, in_db ? strlen(in_db) : 0 };
655
bool is_authenticated;
658
Clear session->db as it points to something, that will be freed when
659
connection is closed. We don't want to accidentally free a wrong
660
pointer if connect failed. Also in case of 'CHANGE USER' failure,
661
current database will be switched to 'no database selected'.
665
if (passwd_len != 0 && passwd_len != SCRAMBLE_LENGTH)
667
my_error(ER_HANDSHAKE_ERROR, MYF(0), security_ctx.ip.c_str());
671
is_authenticated= authenticate_user(this, passwd);
681
673
if (is_authenticated != true)
683
/* isAuthenticated has pushed the error message */
675
my_error(ER_ACCESS_DENIED_ERROR, MYF(0),
676
security_ctx.user.c_str(),
677
security_ctx.ip.c_str(),
678
passwd_len ? ER(ER_YES) : ER(ER_NO));
683
security_ctx.skip_grants();
687
685
/* Change database if necessary */
688
686
if (in_db && in_db[0])
690
SchemaIdentifier identifier(in_db);
691
if (mysql_change_db(this, identifier))
688
if (mysql_change_db(this, &db_str, false))
693
690
/* mysql_change_db() has pushed the error message. */
747
742
in_packet_length--;
750
query.assign(in_packet, in_packet + in_packet_length);
745
/* We must allocate some extra memory for the cached query string */
746
query_length= 0; /* Extra safety: Avoid races */
747
query= (char*) memdup_w_gap((unsigned char*) in_packet, in_packet_length, db_length + 1);
751
query[in_packet_length]=0;
752
query_length= in_packet_length;
754
/* Reclaim some memory */
755
packet.shrink(variables.net_buffer_length);
756
convert_buffer.shrink(variables.net_buffer_length);
822
828
if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
824
830
server_status&= ~SERVER_STATUS_IN_TRANS;
825
if (transaction_services.ha_commit_trans(this, true))
828
options&= ~(OPTION_BEGIN);
834
options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
835
transaction.all.modified_non_trans_table= false;
832
bool Session::startTransaction(start_transaction_option_t opt)
839
bool Session::startTransaction()
834
841
bool result= true;
836
843
if (! endActiveTransaction())
842
847
options|= OPTION_BEGIN;
843
848
server_status|= SERVER_STATUS_IN_TRANS;
845
if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
849
if (lex->start_transaction_opt & DRIZZLE_START_TRANS_OPT_WITH_CONS_SNAPSHOT)
850
if (ha_start_consistent_snapshot(this))
886
888
@return NULL on failure, or pointer to the LEX_STRING object
888
890
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str,
889
const std::string &str,
890
bool allocate_lex_string)
892
return make_lex_string(lex_str, str.c_str(), str.length(), allocate_lex_string);
895
LEX_STRING *Session::make_lex_string(LEX_STRING *lex_str,
896
const char* str, uint32_t length,
897
bool allocate_lex_string)
891
const char* str, uint32_t length,
892
bool allocate_lex_string)
899
894
if (allocate_lex_string)
900
895
if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING))))
903
/* routings to adding tables to list of changed in transaction tables */
904
inline static void list_include(CHANGED_TableList** prev,
905
CHANGED_TableList* curr,
906
CHANGED_TableList* new_table)
911
(*prev)->next = curr;
915
/* add table to list of changed in transaction tables */
917
void Session::add_changed_table(Table *table)
919
assert((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
920
table->file->has_transactions());
921
add_changed_table(table->s->table_cache_key.str,
922
(long) table->s->table_cache_key.length);
926
void Session::add_changed_table(const char *key, long key_length)
928
CHANGED_TableList **prev_changed = &transaction.changed_tables;
929
CHANGED_TableList *curr = transaction.changed_tables;
931
for (; curr; prev_changed = &(curr->next), curr = curr->next)
933
int cmp = (long)curr->key_length - (long)key_length;
936
list_include(prev_changed, curr, changed_table_dup(key, key_length));
941
cmp = memcmp(curr->key, key, curr->key_length);
944
list_include(prev_changed, curr, changed_table_dup(key, key_length));
953
*prev_changed = changed_table_dup(key, key_length);
957
CHANGED_TableList* Session::changed_table_dup(const char *key, long key_length)
959
CHANGED_TableList* new_table =
960
(CHANGED_TableList*) trans_alloc(ALIGN_SIZE(sizeof(CHANGED_TableList))+
964
my_error(EE_OUTOFMEMORY, MYF(ME_BELL),
965
ALIGN_SIZE(sizeof(TableList)) + key_length + 1);
966
killed= KILL_CONNECTION;
970
new_table->key= ((char*)new_table)+ ALIGN_SIZE(sizeof(CHANGED_TableList));
972
new_table->key_length = key_length;
973
::memcpy(new_table->key, key, key_length);
908
978
int Session::send_explain_fields(select_result *result)
910
980
List<Item> field_list;
989
1054
/* In case of error send_eof() may be not called: close the file here. */
992
(void) end_io_cache(cache);
993
(void) internal::my_close(file, MYF(0));
1057
(void) end_io_cache(&cache);
1058
(void) my_close(file,MYF(0));
1000
select_to_file::select_to_file(file_exchange *ex)
1003
cache(static_cast<internal::IO_CACHE *>(memory::sql_calloc(sizeof(internal::IO_CACHE)))),
1009
1066
select_to_file::~select_to_file()
1069
{ // This only happens in case of error
1070
(void) end_io_cache(&cache);
1071
(void) my_close(file,MYF(0));
1014
1076
/***************************************************************************
1040
static int create_file(Session *session, char *path, file_exchange *exchange, internal::IO_CACHE *cache)
1102
static File create_file(Session *session, char *path, file_exchange *exchange, IO_CACHE *cache)
1043
1105
uint32_t option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
1045
1107
#ifdef DONT_ALLOW_FULL_LOAD_DATA_PATHS
1046
1108
option|= MY_REPLACE_DIR; // Force use of db directory
1049
if (!internal::dirname_length(exchange->file_name))
1111
if (!dirname_length(exchange->file_name))
1051
1113
strcpy(path, drizzle_real_data_home);
1052
if (! session->db.empty())
1053
strncat(path, session->db.c_str(), FN_REFLEN-strlen(drizzle_real_data_home)-1);
1054
(void) internal::fn_format(path, exchange->file_name, path, "", option);
1115
strncat(path, session->db, FN_REFLEN-strlen(drizzle_real_data_home)-1);
1116
(void) fn_format(path, exchange->file_name, path, "", option);
1057
(void) internal::fn_format(path, exchange->file_name, drizzle_real_data_home, "", option);
1119
(void) fn_format(path, exchange->file_name, drizzle_real_data_home, "", option);
1059
1121
if (opt_secure_file_priv &&
1060
1122
strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv)))
1072
1134
/* Create the file world readable */
1073
if ((file= internal::my_create(path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
1135
if ((file= my_create(path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
1075
1138
(void) fchmod(file, 0666); // Because of umask()
1076
if (init_io_cache(cache, file, 0L, internal::WRITE_CACHE, 0L, 1, MYF(MY_WME)))
1140
(void) chmod(path, 0666);
1142
if (init_io_cache(cache, file, 0L, WRITE_CACHE, 0L, 1, MYF(MY_WME)))
1078
internal::my_close(file, MYF(0));
1079
internal::my_delete(path, MYF(0)); // Delete file on error, it was just created
1144
my_close(file, MYF(0));
1145
my_delete(path, MYF(0)); // Delete file on error, it was just created
1140
if ((file= create_file(session, path, exchange, cache)) < 0)
1206
if ((file= create_file(session, path, exchange, &cache)) < 0)
1213
#define NEED_ESCAPING(x) ((int) (unsigned char) (x) == escape_char || \
1214
(enclosed ? (int) (unsigned char) (x) == field_sep_char \
1215
: (int) (unsigned char) (x) == field_term_char) || \
1216
(int) (unsigned char) (x) == line_sep_char || \
1146
1219
bool select_export::send_data(List<Item> &items)
1148
1221
char buff[MAX_FIELD_WIDTH],null_buff[2],space[MAX_FIELD_WIDTH];
1171
1244
res=item->str_result(&tmp);
1172
1245
if (res && enclosed)
1174
if (my_b_write(cache,(unsigned char*) exchange->enclosed->ptr(),
1175
exchange->enclosed->length()))
1247
if (my_b_write(&cache,(unsigned char*) exchange->enclosed->ptr(),
1248
exchange->enclosed->length()))
1180
1253
if (!fixed_row_size)
1182
if (escape_char != -1) // Use \N syntax
1184
null_buff[0]=escape_char;
1186
if (my_b_write(cache,(unsigned char*) null_buff,2))
1189
else if (my_b_write(cache,(unsigned char*) "NULL",4))
1255
if (escape_char != -1) // Use \N syntax
1257
null_buff[0]=escape_char;
1259
if (my_b_write(&cache,(unsigned char*) null_buff,2))
1262
else if (my_b_write(&cache,(unsigned char*) "NULL",4))
1194
used_length=0; // Fill with space
1267
used_length=0; // Fill with space
1202
1275
used_length= res->length();
1204
1277
if ((result_type == STRING_RESULT || is_unsafe_field_sep) &&
1207
1280
char *pos, *start, *end;
1208
1281
const CHARSET_INFO * const res_charset= res->charset();
1209
1282
const CHARSET_INFO * const character_set_client= default_charset_info;
1211
1284
bool check_second_byte= (res_charset == &my_charset_bin) &&
1212
character_set_client->
1213
escape_with_backslash_is_dangerous;
1285
character_set_client->
1286
escape_with_backslash_is_dangerous;
1214
1287
assert(character_set_client->mbmaxlen == 2 ||
1215
1288
!character_set_client->escape_with_backslash_is_dangerous);
1216
for (start=pos=(char*) res->ptr(),end=pos+used_length ;
1220
if (use_mb(res_charset))
1223
if ((l=my_ismbchar(res_charset, pos, end)))
1289
for (start=pos=(char*) res->ptr(),end=pos+used_length ;
1293
if (use_mb(res_charset))
1296
if ((l=my_ismbchar(res_charset, pos, end)))
1231
1304
Special case when dumping BINARY/VARBINARY/BLOB values
1259
1332
assert before the loop makes that sure.
1262
if ((needs_escaping(*pos, enclosed) ||
1335
if ((NEED_ESCAPING(*pos) ||
1263
1336
(check_second_byte &&
1264
1337
my_mbcharlen(character_set_client, (unsigned char) *pos) == 2 &&
1265
1338
pos + 1 < end &&
1266
needs_escaping(pos[1], enclosed))) &&
1339
NEED_ESCAPING(pos[1]))) &&
1268
Don't escape field_term_char by doubling - doubling is only
1269
valid for ENCLOSED BY characters:
1341
Don't escape field_term_char by doubling - doubling is only
1342
valid for ENCLOSED BY characters:
1271
1344
(enclosed || !is_ambiguous_field_term ||
1272
1345
(int) (unsigned char) *pos != field_term_char))
1275
1348
tmp_buff[0]= ((int) (unsigned char) *pos == field_sep_char &&
1276
1349
is_ambiguous_field_sep) ?
1277
field_sep_char : escape_char;
1278
tmp_buff[1]= *pos ? *pos : '0';
1279
if (my_b_write(cache,(unsigned char*) start,(uint32_t) (pos-start)) ||
1280
my_b_write(cache,(unsigned char*) tmp_buff,2))
1285
if (my_b_write(cache,(unsigned char*) start,(uint32_t) (pos-start)))
1350
field_sep_char : escape_char;
1351
tmp_buff[1]= *pos ? *pos : '0';
1352
if (my_b_write(&cache,(unsigned char*) start,(uint32_t) (pos-start)) ||
1353
my_b_write(&cache,(unsigned char*) tmp_buff,2))
1358
if (my_b_write(&cache,(unsigned char*) start,(uint32_t) (pos-start)))
1288
else if (my_b_write(cache,(unsigned char*) res->ptr(),used_length))
1361
else if (my_b_write(&cache,(unsigned char*) res->ptr(),used_length))
1291
1364
if (fixed_row_size)
1292
1365
{ // Fill with space
1293
1366
if (item->max_length > used_length)
1295
/* QQ: Fix by adding a my_b_fill() function */
1299
memset(space, ' ', sizeof(space));
1301
uint32_t length=item->max_length-used_length;
1302
for (; length > sizeof(space) ; length-=sizeof(space))
1304
if (my_b_write(cache,(unsigned char*) space,sizeof(space)))
1307
if (my_b_write(cache,(unsigned char*) space,length))
1368
/* QQ: Fix by adding a my_b_fill() function */
1372
memset(space, ' ', sizeof(space));
1374
uint32_t length=item->max_length-used_length;
1375
for (; length > sizeof(space) ; length-=sizeof(space))
1377
if (my_b_write(&cache,(unsigned char*) space,sizeof(space)))
1380
if (my_b_write(&cache,(unsigned char*) space,length))
1311
1384
if (res && enclosed)
1313
if (my_b_write(cache, (unsigned char*) exchange->enclosed->ptr(),
1386
if (my_b_write(&cache, (unsigned char*) exchange->enclosed->ptr(),
1314
1387
exchange->enclosed->length()))
1317
1390
if (--items_left)
1319
if (my_b_write(cache, (unsigned char*) exchange->field_term->ptr(),
1392
if (my_b_write(&cache, (unsigned char*) exchange->field_term->ptr(),
1320
1393
field_term_length))
1324
if (my_b_write(cache,(unsigned char*) exchange->line_term->ptr(),
1325
exchange->line_term->length()))
1397
if (my_b_write(&cache,(unsigned char*) exchange->line_term->ptr(),
1398
exchange->line_term->length()))
1366
1439
res=item->str_result(&tmp);
1367
1440
if (!res) // If NULL
1369
if (my_b_write(cache,(unsigned char*) "",1))
1442
if (my_b_write(&cache,(unsigned char*) "",1))
1372
else if (my_b_write(cache,(unsigned char*) res->ptr(),res->length()))
1445
else if (my_b_write(&cache,(unsigned char*) res->ptr(),res->length()))
1374
my_error(ER_ERROR_ON_WRITE, MYF(0), path, errno);
1447
my_error(ER_ERROR_ON_WRITE, MYF(0), path, my_errno);
1617
1696
set_open_tables_state(backup);
1620
bool Session::set_db(const std::string &new_db)
1700
bool Session::set_db(const char *new_db, size_t new_db_len)
1622
1702
/* Do not reallocate memory if current chunk is big enough. */
1623
if (new_db.length())
1703
if (db && new_db && db_length >= new_db_len)
1704
memcpy(db, new_db, new_db_len+1);
1711
db= (char *)malloc(new_db_len + 1);
1714
memcpy(db, new_db, new_db_len);
1721
db_length= db ? new_db_len : 0;
1722
return new_db && !db;
1635
1727
Check the killed state of a user thread
1636
1728
@param session user thread
1646
Return the session id of a user session
1647
@param pointer to Session object
1648
@return session's id
1738
Return the thread id of a user thread
1739
@param session user thread
1650
1742
extern "C" unsigned long session_get_thread_id(const Session *session)
1652
return (unsigned long) session->getSessionId();
1744
return((unsigned long)session->thread_id);
1749
LEX_STRING *session_make_lex_string(Session *session, LEX_STRING *lex_str,
1750
const char *str, unsigned int size,
1751
int allocate_lex_string)
1753
return session->make_lex_string(lex_str, str, size,
1754
(bool) allocate_lex_string);
1656
1757
const struct charset_info_st *session_charset(Session *session)
1658
1759
return(session->charset());
1762
char **session_query(Session *session)
1764
return(&session->query);
1661
1767
int session_non_transactional_update(const Session *session)
1663
return(session->transaction.all.hasModifiedNonTransData());
1769
return(session->transaction.all.modified_non_trans_table);
1666
1772
void session_mark_transaction_to_rollback(Session *session, bool all)
1689
1795
plugin_sessionvar_cleanup(this);
1691
1797
/* If necessary, log any aborted or unauthorized connections */
1692
if (killed || client->wasAborted())
1798
if (killed || protocol->wasAborted())
1693
1799
statistic_increment(aborted_threads, &LOCK_status);
1695
if (client->wasAborted())
1801
if (protocol->wasAborted())
1697
1803
if (! killed && variables.log_warnings > 1)
1699
SecurityContext *sctx= &security_ctx;
1805
Security_context *sctx= &security_ctx;
1701
1807
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_NEW_ABORTING_CONNECTION)
1703
, (db.empty() ? "unconnected" : db.c_str())
1704
, sctx->getUser().empty() == false ? sctx->getUser().c_str() : "unauthenticated"
1705
, sctx->getIp().c_str()
1809
, (db ? db : "unconnected")
1810
, sctx->user.empty() == false ? sctx->user.c_str() : "unauthenticated"
1706
1812
, (main_da.is_error() ? main_da.message() : ER(ER_UNKNOWN_ERROR)));
1738
1844
server_status&= ~ (SERVER_MORE_RESULTS_EXISTS |
1739
1845
SERVER_QUERY_NO_INDEX_USED |
1740
1846
SERVER_QUERY_NO_GOOD_INDEX_USED);
1848
If in autocommit mode and not in a transaction, reset
1849
OPTION_STATUS_NO_TRANS_UPDATE | OPTION_KEEP_LOG to not get warnings
1850
in ha_rollback_trans() about some tables couldn't be rolled back.
1852
if (!(options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
1854
options&= ~OPTION_KEEP_LOG;
1855
transaction.all.modified_non_trans_table= false;
1743
1859
main_da.reset_diagnostics_area();
1790
1908
if (temporary_tables)
1791
1909
table->next->prev= NULL;
1911
close_temporary(table, free_share, delete_table);
1797
Close and drop a temporary table
1915
Close and delete a temporary table
1800
1918
This dosn't unlink table from session->temporary
1801
1919
If this is needed, use close_temporary_table()
1804
void Session::nukeTable(Table *table)
1922
void Session::close_temporary(Table *table, bool free_share, bool delete_table)
1806
plugin::StorageEngine *table_type= table->s->db_type();
1924
StorageEngine *table_type= table->s->db_type();
1808
1926
table->free_io_cache();
1809
1927
table->closefrm(false);
1811
TableIdentifier identifier(table->s->getSchemaName(), table->s->table_name.str, table->s->path.str);
1812
rm_temporary_table(table_type, identifier);
1814
table->s->free_table_share();
1816
/* This makes me sad, but we're allocating it via malloc */
1930
rm_temporary_table(table_type, table->s->path.str);
1934
table->s->free_table_share();
1935
/* This makes me sad, but we're allocating it via malloc */
1820
1940
/** Clear most status variables. */
2001
2122
if (open_tables_from_list(&tables, &counter))
2004
if (not lock_tables(tables, counter, &need_reopen))
2125
if (!lock_tables(tables, counter, &need_reopen))
2006
if (not need_reopen)
2008
2129
close_tables_for_reopen(&tables);
2010
2131
if ((mysql_handle_derived(lex, &mysql_derived_prepare) ||
2011
2132
(fill_derived_tables() &&
2012
2133
mysql_handle_derived(lex, &mysql_derived_filling))))
2134
return true; /* purecov: inspected */
2022
2143
assert(ret == false);
2023
2144
if (open_tables_from_list(&tables, &counter, flags) ||
2024
2145
mysql_handle_derived(lex, &mysql_derived_prepare))
2029
bool Session::rm_temporary_table(TableIdentifier &identifier)
2031
if (plugin::StorageEngine::dropTable(*this, identifier))
2033
errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2034
identifier.getSQLPath().c_str(), errno);
2035
dumpTemporaryTableNames("rm_temporary_table()");
2043
bool Session::rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier)
2146
return true; /* purecov: inspected */
2150
bool Session::rm_temporary_table(StorageEngine *base, char *path)
2047
if (plugin::StorageEngine::dropTable(*this, *base, identifier))
2156
if (delete_table_proto_file(path))
2157
error=1; /* purecov: inspected */
2159
if (base->deleteTable(this, path))
2049
2162
errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2050
identifier.getSQLPath().c_str(), errno);
2051
dumpTemporaryTableNames("rm_temporary_table()");
2060
@note this will be removed, I am looking through Hudson to see if it is finding
2061
any tables that are missed during cleanup.
2063
void Session::dumpTemporaryTableNames(const char *foo)
2067
if (not temporary_tables)
2070
cerr << "Begin Run: " << foo << "\n";
2071
for (table= temporary_tables; table; table= table->next)
2073
bool have_proto= false;
2075
message::Table *proto= table->s->getTableProto();
2076
if (table->s->getTableProto())
2079
const char *answer= have_proto ? "true" : "false";
2083
cerr << "\tTable Name " << table->s->getSchemaName() << "." << table->s->table_name.str << " : " << answer << "\n";
2084
cerr << "\t\t Proto " << proto->schema() << " " << proto->name() << "\n";
2087
cerr << "\tTabl;e Name " << table->s->getSchemaName() << "." << table->s->table_name.str << " : " << answer << "\n";
2091
bool Session::storeTableMessage(TableIdentifier &identifier, message::Table &table_message)
2093
table_message_cache.insert(make_pair(identifier.getPath(), table_message));
2098
bool Session::removeTableMessage(TableIdentifier &identifier)
2100
TableMessageCache::iterator iter;
2102
iter= table_message_cache.find(identifier.getPath());
2104
if (iter == table_message_cache.end())
2107
table_message_cache.erase(iter);
2112
bool Session::getTableMessage(TableIdentifier &identifier, message::Table &table_message)
2114
TableMessageCache::iterator iter;
2116
iter= table_message_cache.find(identifier.getPath());
2118
if (iter == table_message_cache.end())
2121
table_message.CopyFrom(((*iter).second));
2126
bool Session::doesTableMessageExist(TableIdentifier &identifier)
2128
TableMessageCache::iterator iter;
2130
iter= table_message_cache.find(identifier.getPath());
2132
if (iter == table_message_cache.end())
2140
bool Session::renameTableMessage(TableIdentifier &from, TableIdentifier &to)
2142
TableMessageCache::iterator iter;
2144
table_message_cache[to.getPath()]= table_message_cache[from.getPath()];
2146
iter= table_message_cache.find(to.getPath());
2148
if (iter == table_message_cache.end())
2153
(*iter).second.set_schema(to.getSchemaName());
2154
(*iter).second.set_name(to.getTableName());
2159
} /* namespace drizzled */