44
44
#include "drizzled/table_proto.h"
45
45
#include "drizzled/db.h"
46
46
#include "drizzled/pthread_globals.h"
47
#include "drizzled/transaction_services.h"
48
49
#include "plugin/myisam/myisam.h"
49
50
#include "drizzled/internal/iocache.h"
72
74
extern pthread_key_t THR_Session;
73
75
extern pthread_key_t THR_Mem_root;
74
76
extern uint32_t max_used_connections;
75
extern drizzled::atomic<uint32_t> connection_count;
77
extern atomic<uint32_t> connection_count;
77
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
79
template class List<Key>;
80
template class List_iterator<Key>;
81
template class List<Key_part_spec>;
82
template class List_iterator<Key_part_spec>;
83
template class List<AlterDrop>;
84
template class List_iterator<AlterDrop>;
85
template class List<AlterColumn>;
86
template class List_iterator<AlterColumn>;
89
80
/****************************************************************************
119
110
extern "C" int mysql_tmpfile(const char *prefix)
121
112
char filename[FN_REFLEN];
122
int fd = create_temp_file(filename, drizzle_tmpdir, prefix, MYF(MY_WME));
113
int fd = internal::create_temp_file(filename, drizzle_tmpdir, prefix, MYF(MY_WME));
124
115
unlink(filename);
218
209
the destructor works OK in case of an error. The main_mem_root
219
210
will be re-initialized in init_for_queries().
221
init_sql_alloc(&main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
212
memory::init_sql_alloc(&main_mem_root, memory::ROOT_MIN_BLOCK_SIZE, 0);
222
213
thread_stack= NULL;
223
214
count_cuted_fields= CHECK_FIELD_IGNORE;
224
215
killed= NOT_KILLED;
243
233
memset(ha_data, 0, sizeof(ha_data));
246
235
dbug_sentry=Session_SENTRY_MAGIC;
247
236
cleanup_done= abort_on_warning= no_warnings_for_error= false;
249
237
pthread_mutex_init(&LOCK_delete, MY_MUTEX_INIT_FAST);
251
239
/* Variables with default values */
278
266
memset(&status_var, 0, sizeof(status_var));
280
268
/* Initialize sub structures */
281
init_sql_alloc(&warn_root, WARN_ALLOC_BLOCK_SIZE, WARN_ALLOC_PREALLOC_SIZE);
269
memory::init_sql_alloc(&warn_root, WARN_ALLOC_BLOCK_SIZE, WARN_ALLOC_PREALLOC_SIZE);
282
270
hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0,
283
271
(hash_get_key) get_var_key,
284
272
(hash_free_key) free_user_var, 0);
400
389
if (client->isConnected())
402
391
if (global_system_variables.log_warnings)
403
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),my_progname,
392
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),internal::my_progname,
405
394
(security_ctx.user.c_str() ?
406
395
security_ctx.user.c_str() : ""));
418
407
plugin_sessionvar_cleanup(this);
420
409
free_root(&warn_root,MYF(0));
421
free_root(&transaction.mem_root,MYF(0));
422
410
mysys_var=0; // Safety (shouldn't be needed)
423
411
dbug_sentry= Session_SENTRY_GONE;
526
514
Remember the location of thread info, the structure needed for
527
sql_alloc() and the structure for the net buffer
515
memory::sql_alloc() and the structure for the net buffer
529
517
bool Session::storeGlobals()
570
558
set_proc_info(NULL);
571
559
command= COM_SLEEP;
573
ha_enable_transaction(this,true);
575
562
reset_root_defaults(mem_root, variables.query_alloc_block_size,
576
563
variables.query_prealloc_size);
577
reset_root_defaults(&transaction.mem_root,
578
variables.trans_alloc_block_size,
579
variables.trans_prealloc_size);
580
564
transaction.xid_state.xid.null();
581
565
transaction.xid_state.in_session=1;
689
673
bool Session::checkUser(const char *passwd, uint32_t passwd_len, const char *in_db)
675
LEX_STRING db_str= { (char *) in_db, in_db ? strlen(in_db) : 0 };
691
676
bool is_authenticated;
693
678
if (passwd_len != 0 && passwd_len != SCRAMBLE_LENGTH)
713
698
/* Change database if necessary */
714
699
if (in_db && in_db[0])
716
const string database_name_string(in_db);
717
NonNormalisedDatabaseName database_name(database_name_string);
718
NormalisedDatabaseName normalised_database_name(database_name);
720
if (mysql_change_db(this, normalised_database_name, false))
701
if (mysql_change_db(this, &db_str, false))
722
703
/* mysql_change_db() has pushed the error message. */
776
757
in_packet_length--;
779
/* We must allocate some extra memory for the cached query string */
780
query_length= 0; /* Extra safety: Avoid races */
781
query= (char*) memdup_w_gap((unsigned char*) in_packet, in_packet_length, db.length() + 1);
760
query.assign(in_packet, in_packet + in_packet_length);
785
query[in_packet_length]=0;
786
query_length= in_packet_length;
807
784
* (Which of course should never happen...)
809
786
server_status&= ~SERVER_STATUS_IN_TRANS;
787
if (transaction_services.ha_commit_trans(this, true))
812
789
options&= ~(OPTION_BEGIN);
813
790
transaction.all.modified_non_trans_table= false;
825
802
case ROLLBACK_AND_CHAIN:
827
804
server_status&= ~SERVER_STATUS_IN_TRANS;
828
if (ha_rollback(this))
805
if (transaction_services.ha_rollback_trans(this, true))
830
807
options&= ~(OPTION_BEGIN);
831
808
transaction.all.modified_non_trans_table= false;
858
836
if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
860
838
server_status&= ~SERVER_STATUS_IN_TRANS;
839
if (transaction_services.ha_commit_trans(this, true))
864
842
options&= ~(OPTION_BEGIN);
943
/* routings to adding tables to list of changed in transaction tables */
944
inline static void list_include(CHANGED_TableList** prev,
945
CHANGED_TableList* curr,
946
CHANGED_TableList* new_table)
951
(*prev)->next = curr;
955
/* add table to list of changed in transaction tables */
957
void Session::add_changed_table(Table *table)
959
assert((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
960
table->cursor->has_transactions());
961
add_changed_table(table->s->table_cache_key.str,
962
(long) table->s->table_cache_key.length);
966
void Session::add_changed_table(const char *key, long key_length)
968
CHANGED_TableList **prev_changed = &transaction.changed_tables;
969
CHANGED_TableList *curr = transaction.changed_tables;
971
for (; curr; prev_changed = &(curr->next), curr = curr->next)
973
int cmp = (long)curr->key_length - (long)key_length;
976
list_include(prev_changed, curr, changed_table_dup(key, key_length));
981
cmp = memcmp(curr->key, key, curr->key_length);
984
list_include(prev_changed, curr, changed_table_dup(key, key_length));
993
*prev_changed = changed_table_dup(key, key_length);
997
CHANGED_TableList* Session::changed_table_dup(const char *key, long key_length)
999
CHANGED_TableList* new_table =
1000
(CHANGED_TableList*) trans_alloc(ALIGN_SIZE(sizeof(CHANGED_TableList))+
1004
my_error(EE_OUTOFMEMORY, MYF(ME_BELL),
1005
ALIGN_SIZE(sizeof(TableList)) + key_length + 1);
1006
killed= KILL_CONNECTION;
1010
new_table->key= ((char*)new_table)+ ALIGN_SIZE(sizeof(CHANGED_TableList));
1011
new_table->next = 0;
1012
new_table->key_length = key_length;
1013
::memcpy(new_table->key, key, key_length);
1018
921
int Session::send_explain_fields(select_result *result)
1020
923
List<Item> field_list;
1070
973
(void) end_io_cache(cache);
1071
(void) my_close(file, MYF(0));
1072
(void) my_delete(path, MYF(0)); // Delete file on error
974
(void) internal::my_close(file, MYF(0));
975
(void) internal::my_delete(path, MYF(0)); // Delete file on error
1078
981
bool select_to_file::send_eof()
1080
983
int error= test(end_io_cache(cache));
1081
if (my_close(file, MYF(MY_WME)))
984
if (internal::my_close(file, MYF(MY_WME)))
1150
static int create_file(Session *session, char *path, file_exchange *exchange, IO_CACHE *cache)
1053
static int create_file(Session *session, char *path, file_exchange *exchange, internal::IO_CACHE *cache)
1153
1056
uint32_t option= MY_UNPACK_FILENAME | MY_RELATIVE_PATH;
1156
1059
option|= MY_REPLACE_DIR; // Force use of db directory
1159
if (!dirname_length(exchange->file_name))
1062
if (!internal::dirname_length(exchange->file_name))
1161
1064
strcpy(path, drizzle_real_data_home);
1162
1065
if (! session->db.empty())
1163
1066
strncat(path, session->db.c_str(), FN_REFLEN-strlen(drizzle_real_data_home)-1);
1164
(void) fn_format(path, exchange->file_name, path, "", option);
1067
(void) internal::fn_format(path, exchange->file_name, path, "", option);
1167
(void) fn_format(path, exchange->file_name, drizzle_real_data_home, "", option);
1070
(void) internal::fn_format(path, exchange->file_name, drizzle_real_data_home, "", option);
1169
1072
if (opt_secure_file_priv &&
1170
1073
strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv)))
1182
1085
/* Create the file world readable */
1183
if ((file= my_create(path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
1086
if ((file= internal::my_create(path, 0666, O_WRONLY|O_EXCL, MYF(MY_WME))) < 0)
1185
1088
(void) fchmod(file, 0666); // Because of umask()
1186
if (init_io_cache(cache, file, 0L, WRITE_CACHE, 0L, 1, MYF(MY_WME)))
1089
if (init_io_cache(cache, file, 0L, internal::WRITE_CACHE, 0L, 1, MYF(MY_WME)))
1188
my_close(file, MYF(0));
1189
my_delete(path, MYF(0)); // Delete file on error, it was just created
1091
internal::my_close(file, MYF(0));
1092
internal::my_delete(path, MYF(0)); // Delete file on error, it was just created
1740
1642
set_open_tables_state(backup);
1744
bool Session::set_db(const NormalisedDatabaseName &new_db)
1645
bool Session::set_db(const char *new_db, size_t length)
1746
db= new_db.to_string();
1647
/* Do not reallocate memory if current chunk is big enough. */
1751
void Session::clear_db()
2082
1979
if (backups_available == false)
1981
TransactionServices &transaction_services= TransactionServices::singleton();
2084
1982
main_da.can_overwrite_status= true;
2085
ha_autocommit_or_rollback(this, is_error());
1983
transaction_services.ha_autocommit_or_rollback(this, is_error());
2086
1984
main_da.can_overwrite_status= false;
2087
1985
transaction.stmt.reset();