19
19
Handler-calling-functions
22
#ifdef USE_PRAGMA_IMPLEMENTATION
23
#pragma implementation // gcc: Class implementation
26
22
#include <drizzled/server_includes.h>
27
23
#include "rpl_filter.h"
28
#include <drizzled/drizzled_error_messages.h>
24
#include <drizzled/error.h>
25
#include <drizzled/gettext.h>
31
28
While we have legacy_db_type, we have this array to
72
static plugin_ref ha_default_plugin(THD *thd)
67
static plugin_ref ha_default_plugin(Session *session)
74
if (thd->variables.table_plugin)
75
return thd->variables.table_plugin;
76
return my_plugin_lock(thd, &global_system_variables.table_plugin);
69
if (session->variables.table_plugin)
70
return session->variables.table_plugin;
71
return my_plugin_lock(session, &global_system_variables.table_plugin);
81
76
Return the default storage engine handlerton for thread
83
@param ha_default_handlerton(thd)
84
@param thd current thread
78
@param ha_default_handlerton(session)
79
@param session current thread
87
82
pointer to handlerton
89
handlerton *ha_default_handlerton(THD *thd)
84
handlerton *ha_default_handlerton(Session *session)
91
plugin_ref plugin= ha_default_plugin(thd);
86
plugin_ref plugin= ha_default_plugin(session);
93
88
handlerton *hton= plugin_data(plugin, handlerton*);
100
95
Return the storage engine handlerton for the supplied name
102
@param thd current thread
97
@param session current thread
103
98
@param name name of storage engine
106
101
pointer to storage engine plugin handle
108
plugin_ref ha_resolve_by_name(THD *thd, const LEX_STRING *name)
103
plugin_ref ha_resolve_by_name(Session *session, const LEX_STRING *name)
110
105
const LEX_STRING *table_alias;
111
106
plugin_ref plugin;
114
109
/* my_strnncoll is a macro and gcc doesn't do early expansion of macro */
115
if (thd && !my_charset_utf8_general_ci.coll->strnncoll(&my_charset_utf8_general_ci,
110
if (session && !my_charset_utf8_general_ci.coll->strnncoll(&my_charset_utf8_general_ci,
116
111
(const unsigned char *)name->str, name->length,
117
112
(const unsigned char *)STRING_WITH_LEN("DEFAULT"), 0))
118
return ha_default_plugin(thd);
113
return ha_default_plugin(session);
120
if ((plugin= my_plugin_lock_by_name(thd, name, DRIZZLE_STORAGE_ENGINE_PLUGIN)))
115
if ((plugin= my_plugin_lock_by_name(session, name, DRIZZLE_STORAGE_ENGINE_PLUGIN)))
122
117
handlerton *hton= plugin_data(plugin, handlerton *);
123
118
if (!(hton->flags & HTON_NOT_USER_SELECTABLE))
150
plugin_ref ha_lock_engine(THD *thd, handlerton *hton)
145
plugin_ref ha_lock_engine(Session *session, handlerton *hton)
154
149
st_plugin_int **plugin= hton2plugin + hton->slot;
156
return my_plugin_lock(thd, &plugin);
151
return my_plugin_lock(session, &plugin);
162
handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type)
157
handlerton *ha_resolve_by_legacy_type(Session *session, enum legacy_db_type db_type)
164
159
plugin_ref plugin;
165
160
switch (db_type) {
166
161
case DB_TYPE_DEFAULT:
167
return ha_default_handlerton(thd);
162
return ha_default_handlerton(session);
169
164
if (db_type > DB_TYPE_UNKNOWN && db_type < DB_TYPE_DEFAULT &&
170
(plugin= ha_lock_engine(thd, installed_htons[db_type])))
165
(plugin= ha_lock_engine(session, installed_htons[db_type])))
171
166
return plugin_data(plugin, handlerton*);
172
167
/* fall through */
173
168
case DB_TYPE_UNKNOWN:
180
175
Use other database handler if databasehandler is not compiled in.
182
handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
177
handlerton *ha_checktype(Session *session, enum legacy_db_type database_type,
183
178
bool no_substitute, bool report_error)
185
handlerton *hton= ha_resolve_by_legacy_type(thd, database_type);
180
handlerton *hton= ha_resolve_by_legacy_type(session, database_type);
186
181
if (ha_storage_engine_is_enabled(hton))
215
210
Try the default table type
216
Here the call to current_thd() is ok as we call this function a lot of
211
Here the call to current_session() is ok as we call this function a lot of
217
212
times but we enter this branch very seldom.
219
return(get_new_handler(share, alloc, ha_default_handlerton(current_thd)));
214
return(get_new_handler(share, alloc, ha_default_handlerton(current_session)));
487
482
don't bother to rollback here, it's done already
489
void ha_close_connection(THD* thd)
484
void ha_close_connection(Session* session)
491
plugin_foreach(thd, closecon_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, 0);
486
plugin_foreach(session, closecon_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, 0);
494
489
/* ========================================================================
595
590
The server stores its transaction-related data in
596
thd->transaction. This structure has two members of type
597
THD_TRANS. These members correspond to the statement and
591
session->transaction. This structure has two members of type
592
Session_TRANS. These members correspond to the statement and
598
593
normal transactions respectively:
600
- thd->transaction.stmt contains a list of engines
595
- session->transaction.stmt contains a list of engines
601
596
that are participating in the given statement
602
- thd->transaction.all contains a list of engines that
597
- session->transaction.all contains a list of engines that
603
598
have participated in any of the statement transactions started
604
599
within the context of the normal transaction.
605
600
Each element of the list contains a pointer to the storage
606
601
engine, engine-specific transactional data, and engine-specific
607
602
transaction flags.
609
In autocommit mode thd->transaction.all is empty.
610
Instead, data of thd->transaction.stmt is
604
In autocommit mode session->transaction.all is empty.
605
Instead, data of session->transaction.stmt is
611
606
used to commit/rollback the normal transaction.
613
608
The list of registered engines has a few important properties:
644
639
- if the user has requested so, by issuing ROLLBACK SQL
646
641
- if one of the storage engines requested a rollback
647
by setting thd->transaction_rollback_request. This may
642
by setting session->transaction_rollback_request. This may
648
643
happen in case, e.g., when the transaction in the engine was
649
644
chosen a victim of the internal deadlock resolution algorithm
650
645
and rolled back internally. When such a situation happens, there
750
745
---------------------------------------------------
752
747
DDLs and operations with non-transactional engines
753
do not "register" in thd->transaction lists, and thus do not
748
do not "register" in session->transaction lists, and thus do not
754
749
modify the transaction state. Besides, each DDL in
755
750
MySQL is prefixed with an implicit normal transaction commit
756
751
(a call to end_active_trans()), and thus leaves nothing
797
792
times per transaction.
800
void trans_register_ha(THD *thd, bool all, handlerton *ht_arg)
795
void trans_register_ha(Session *session, bool all, handlerton *ht_arg)
797
Session_TRANS *trans;
803
798
Ha_trx_info *ha_info;
807
trans= &thd->transaction.all;
808
thd->server_status|= SERVER_STATUS_IN_TRANS;
802
trans= &session->transaction.all;
803
session->server_status|= SERVER_STATUS_IN_TRANS;
811
trans= &thd->transaction.stmt;
806
trans= &session->transaction.stmt;
813
ha_info= thd->ha_data[ht_arg->slot].ha_info + static_cast<unsigned>(all);
808
ha_info= session->ha_data[ht_arg->slot].ha_info + static_cast<unsigned>(all);
815
810
if (ha_info->is_started())
816
811
return; /* already registered, return */
843
838
handlerton *ht= ha_info->ht();
844
status_var_increment(thd->status_var.ha_prepare_count);
839
status_var_increment(session->status_var.ha_prepare_count);
847
if ((err= ht->prepare(ht, thd, all)))
842
if ((err= ht->prepare(ht, session, all)))
849
844
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
850
ha_rollback_trans(thd, all);
845
ha_rollback_trans(session, all);
857
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
852
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
858
853
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
859
854
ha_resolve_storage_engine_name(ht));
896
Ha_trx_info *ha_info_all= &thd->ha_data[ha_info->ht()->slot].ha_info[1];
891
Ha_trx_info *ha_info_all= &session->ha_data[ha_info->ht()->slot].ha_info[1];
897
892
assert(ha_info != ha_info_all);
899
894
Merge read-only/read-write information about statement
900
895
transaction to its enclosing normal transaction. Do this
901
896
only if in a real transaction -- that is, if we know
902
that ha_info_all is registered in thd->transaction.all.
897
that ha_info_all is registered in session->transaction.all.
903
898
Since otherwise we only clutter the normal transaction flags.
905
900
if (ha_info_all->is_started()) /* false if autocommit. */
933
928
stored functions or triggers. So we simply do nothing now.
934
929
TODO: This should be fixed in later ( >= 5.1) releases.
936
int ha_commit_trans(THD *thd, bool all)
931
int ha_commit_trans(Session *session, bool all)
938
933
int error= 0, cookie= 0;
940
935
'all' means that this is either an explicit commit issued by
941
936
user, or an implicit commit issued by a DDL.
943
THD_TRANS *trans= all ? &thd->transaction.all : &thd->transaction.stmt;
944
bool is_real_trans= all || thd->transaction.all.ha_list == 0;
938
Session_TRANS *trans= all ? &session->transaction.all : &session->transaction.stmt;
939
bool is_real_trans= all || session->transaction.all.ha_list == 0;
945
940
Ha_trx_info *ha_info= trans->ha_list;
946
my_xid xid= thd->transaction.xid_state.xid.get_my_xid();
941
my_xid xid= session->transaction.xid_state.xid.get_my_xid();
949
944
We must not commit the normal transaction if a statement
951
946
flags will not get propagated to its normal transaction's
954
assert(thd->transaction.stmt.ha_list == NULL ||
955
trans == &thd->transaction.stmt);
949
assert(session->transaction.stmt.ha_list == NULL ||
950
trans == &session->transaction.stmt);
957
if (thd->in_sub_stmt)
960
Since we don't support nested statement transactions in 5.0,
961
we can't commit or rollback stmt transactions while we are inside
962
stored functions or triggers. So we simply do nothing now.
963
TODO: This should be fixed in later ( >= 5.1) releases.
968
We assume that all statements which commit or rollback main transaction
969
are prohibited inside of stored functions or triggers. So they should
970
bail out with error even before ha_commit_trans() call. To be 100% safe
971
let us throw error in non-debug builds.
974
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
981
if (is_real_trans && wait_if_global_read_lock(thd, 0, 0))
956
if (is_real_trans && wait_if_global_read_lock(session, 0, 0))
983
ha_rollback_trans(thd, all);
958
ha_rollback_trans(session, all);
987
962
if ( is_real_trans
989
&& ! thd->slave_thread
964
&& ! session->slave_thread
992
967
my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
993
ha_rollback_trans(thd, all);
968
ha_rollback_trans(session, all);
998
must_2pc= ha_check_and_coalesce_trx_read_only(thd, ha_info, all);
973
must_2pc= ha_check_and_coalesce_trx_read_only(session, ha_info, all);
1000
975
if (!trans->no_2pc && must_2pc)
1014
989
Sic: we know that prepare() is not NULL since otherwise
1015
990
trans->no_2pc would have been set.
1017
if ((err= ht->prepare(ht, thd, all)))
992
if ((err= ht->prepare(ht, session, all)))
1019
994
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
1022
status_var_increment(thd->status_var.ha_prepare_count);
997
status_var_increment(session->status_var.ha_prepare_count);
1024
999
if (error || (is_real_trans && xid &&
1025
(error= !(cookie= tc_log->log_xid(thd, xid)))))
1000
(error= !(cookie= tc_log->log_xid(session, xid)))))
1027
ha_rollback_trans(thd, all);
1002
ha_rollback_trans(session, all);
1032
error=ha_commit_one_phase(thd, all) ? (cookie ? 2 : 1) : 0;
1007
error=ha_commit_one_phase(session, all) ? (cookie ? 2 : 1) : 0;
1034
1009
tc_log->unlog(cookie, xid);
1036
1011
if (is_real_trans)
1037
start_waiting_global_read_lock(thd);
1012
start_waiting_global_read_lock(session);
1044
1019
This function does not care about global read lock. A caller should.
1046
int ha_commit_one_phase(THD *thd, bool all)
1021
int ha_commit_one_phase(Session *session, bool all)
1049
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
1050
bool is_real_trans=all || thd->transaction.all.ha_list == 0;
1024
Session_TRANS *trans=all ? &session->transaction.all : &session->transaction.stmt;
1025
bool is_real_trans=all || session->transaction.all.ha_list == 0;
1051
1026
Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
1057
1032
handlerton *ht= ha_info->ht();
1058
if ((err= ht->commit(ht, thd, all)))
1033
if ((err= ht->commit(ht, session, all)))
1060
1035
my_error(ER_ERROR_DURING_COMMIT, MYF(0), err);
1063
status_var_increment(thd->status_var.ha_commit_count);
1038
status_var_increment(session->status_var.ha_commit_count);
1064
1039
ha_info_next= ha_info->next();
1065
1040
ha_info->reset(); /* keep it conveniently zero-filled */
1067
1042
trans->ha_list= 0;
1068
1043
trans->no_2pc=0;
1069
1044
if (is_real_trans)
1070
thd->transaction.xid_state.xid.null();
1045
session->transaction.xid_state.xid.null();
1073
thd->variables.tx_isolation=thd->session_tx_isolation;
1074
thd->transaction.cleanup();
1048
session->variables.tx_isolation=session->session_tx_isolation;
1049
session->transaction.cleanup();
1081
int ha_rollback_trans(THD *thd, bool all)
1056
int ha_rollback_trans(Session *session, bool all)
1084
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
1059
Session_TRANS *trans=all ? &session->transaction.all : &session->transaction.stmt;
1085
1060
Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
1086
bool is_real_trans=all || thd->transaction.all.ha_list == 0;
1061
bool is_real_trans=all || session->transaction.all.ha_list == 0;
1089
1064
We must not rollback the normal transaction if a statement
1090
1065
transaction is pending.
1092
assert(thd->transaction.stmt.ha_list == NULL ||
1093
trans == &thd->transaction.stmt);
1067
assert(session->transaction.stmt.ha_list == NULL ||
1068
trans == &session->transaction.stmt);
1095
if (thd->in_sub_stmt)
1098
If we are inside stored function or trigger we should not commit or
1099
rollback current statement transaction. See comment in ha_commit_trans()
1100
call for more information.
1105
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
1110
1072
for (; ha_info; ha_info= ha_info_next)
1113
1075
handlerton *ht= ha_info->ht();
1114
if ((err= ht->rollback(ht, thd, all)))
1076
if ((err= ht->rollback(ht, session, all)))
1115
1077
{ // cannot happen
1116
1078
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1119
status_var_increment(thd->status_var.ha_rollback_count);
1081
status_var_increment(session->status_var.ha_rollback_count);
1120
1082
ha_info_next= ha_info->next();
1121
1083
ha_info->reset(); /* keep it conveniently zero-filled */
1123
1085
trans->ha_list= 0;
1124
1086
trans->no_2pc=0;
1125
1087
if (is_real_trans)
1126
thd->transaction.xid_state.xid.null();
1088
session->transaction.xid_state.xid.null();
1129
thd->variables.tx_isolation=thd->session_tx_isolation;
1130
thd->transaction.cleanup();
1091
session->variables.tx_isolation=session->session_tx_isolation;
1092
session->transaction.cleanup();
1134
thd->transaction_rollback_request= false;
1096
session->transaction_rollback_request= false;
1137
1099
If a non-transactional table was updated, warn; don't warn if this is a
1142
1104
the error log; but we don't want users to wonder why they have this
1143
1105
message in the error log, so we don't send it.
1145
if (is_real_trans && thd->transaction.all.modified_non_trans_table &&
1146
!thd->slave_thread && thd->killed != THD::KILL_CONNECTION)
1147
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1107
if (is_real_trans && session->transaction.all.modified_non_trans_table &&
1108
!session->slave_thread && session->killed != Session::KILL_CONNECTION)
1109
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1148
1110
ER_WARNING_NOT_COMPLETE_ROLLBACK,
1149
1111
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
1161
1123
the user has used LOCK TABLES then that mechanism does not know to do the
1164
int ha_autocommit_or_rollback(THD *thd, int error)
1126
int ha_autocommit_or_rollback(Session *session, int error)
1166
if (thd->transaction.stmt.ha_list)
1128
if (session->transaction.stmt.ha_list)
1170
if (ha_commit_trans(thd, 0))
1132
if (ha_commit_trans(session, 0))
1175
(void) ha_rollback_trans(thd, 0);
1176
if (thd->transaction_rollback_request && !thd->in_sub_stmt)
1177
(void) ha_rollback(thd);
1137
(void) ha_rollback_trans(session, 0);
1138
if (session->transaction_rollback_request)
1139
(void) ha_rollback(session);
1180
thd->variables.tx_isolation=thd->session_tx_isolation;
1142
session->variables.tx_isolation=session->session_tx_isolation;
1418
1380
This function should be called when MySQL sends rows of a SELECT result set
1419
1381
or the EOF mark to the client. It releases a possible adaptive hash index
1420
S-latch held by thd in InnoDB and also releases a possible InnoDB query
1421
FIFO ticket to enter InnoDB. To save CPU time, InnoDB allows a thd to
1382
S-latch held by session in InnoDB and also releases a possible InnoDB query
1383
FIFO ticket to enter InnoDB. To save CPU time, InnoDB allows a session to
1422
1384
keep them over several calls of the InnoDB handler interface when a join
1423
1385
is executed. But when we let the control to pass to the client they have
1424
1386
to be released because if the application program uses mysql_use_result(),
1426
1388
performs another SQL query. In MySQL-4.1 this is even more important because
1427
1389
there a connection can have several SELECT queries open at the same time.
1429
@param thd the thread handle of the current connection
1391
@param session the thread handle of the current connection
1434
static bool release_temporary_latches(THD *thd, plugin_ref plugin,
1396
static bool release_temporary_latches(Session *session, plugin_ref plugin,
1435
1397
void *unused __attribute__((unused)))
1437
1399
handlerton *hton= plugin_data(plugin, handlerton *);
1439
1401
if (hton->state == SHOW_OPTION_YES && hton->release_temporary_latches)
1440
hton->release_temporary_latches(hton, thd);
1402
hton->release_temporary_latches(hton, session);
1446
int ha_release_temporary_latches(THD *thd)
1408
int ha_release_temporary_latches(Session *session)
1448
plugin_foreach(thd, release_temporary_latches, DRIZZLE_STORAGE_ENGINE_PLUGIN,
1410
plugin_foreach(session, release_temporary_latches, DRIZZLE_STORAGE_ENGINE_PLUGIN,
1454
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv)
1416
int ha_rollback_to_savepoint(Session *session, SAVEPOINT *sv)
1457
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
1458
&thd->transaction.all);
1419
Session_TRANS *trans= &session->transaction.all;
1459
1420
Ha_trx_info *ha_info, *ha_info_next;
1461
1422
trans->no_2pc=0;
1469
1430
handlerton *ht= ha_info->ht();
1471
1432
assert(ht->savepoint_set != 0);
1472
if ((err= ht->savepoint_rollback(ht, thd,
1433
if ((err= ht->savepoint_rollback(ht, session,
1473
1434
(unsigned char *)(sv+1)+ht->savepoint_offset)))
1474
1435
{ // cannot happen
1475
1436
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1478
status_var_increment(thd->status_var.ha_savepoint_rollback_count);
1439
status_var_increment(session->status_var.ha_savepoint_rollback_count);
1479
1440
trans->no_2pc|= ht->prepare == 0;
1489
1450
handlerton *ht= ha_info->ht();
1490
if ((err= ht->rollback(ht, thd, !thd->in_sub_stmt)))
1451
if ((err= ht->rollback(ht, session, !(0))))
1491
1452
{ // cannot happen
1492
1453
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1495
status_var_increment(thd->status_var.ha_rollback_count);
1456
status_var_increment(session->status_var.ha_rollback_count);
1496
1457
ha_info_next= ha_info->next();
1497
1458
ha_info->reset(); /* keep it conveniently zero-filled */
1506
1467
section "4.33.4 SQL-statements and transaction states",
1507
1468
SAVEPOINT is *not* transaction-initiating SQL-statement
1509
int ha_savepoint(THD *thd, SAVEPOINT *sv)
1470
int ha_savepoint(Session *session, SAVEPOINT *sv)
1512
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
1513
&thd->transaction.all);
1473
Session_TRANS *trans= &session->transaction.all;
1514
1474
Ha_trx_info *ha_info= trans->ha_list;
1515
1475
for (; ha_info; ha_info= ha_info->next())
1526
if ((err= ht->savepoint_set(ht, thd, (unsigned char *)(sv+1)+ht->savepoint_offset)))
1486
if ((err= ht->savepoint_set(ht, session, (unsigned char *)(sv+1)+ht->savepoint_offset)))
1527
1487
{ // cannot happen
1528
1488
my_error(ER_GET_ERRNO, MYF(0), err);
1531
status_var_increment(thd->status_var.ha_savepoint_count);
1491
status_var_increment(session->status_var.ha_savepoint_count);
1534
1494
Remember the list of registered storage engines. All new
1565
static bool snapshot_handlerton(THD *thd, plugin_ref plugin, void *arg)
1525
static bool snapshot_handlerton(Session *session, plugin_ref plugin, void *arg)
1567
1527
handlerton *hton= plugin_data(plugin, handlerton *);
1568
1528
if (hton->state == SHOW_OPTION_YES &&
1569
1529
hton->start_consistent_snapshot)
1571
hton->start_consistent_snapshot(hton, thd);
1531
hton->start_consistent_snapshot(hton, session);
1572
1532
*((bool *)arg)= false;
1577
int ha_start_consistent_snapshot(THD *thd)
1537
int ha_start_consistent_snapshot(Session *session)
1579
1539
bool warn= true;
1581
plugin_foreach(thd, snapshot_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, &warn);
1541
plugin_foreach(session, snapshot_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, &warn);
1584
1544
Same idea as when one wants to CREATE TABLE in one engine which does not
1588
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
1548
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
1589
1549
"This MySQL server does not support any "
1590
1550
"consistent-read capable storage engine");
1595
static bool flush_handlerton(THD *thd __attribute__((unused)),
1555
static bool flush_handlerton(Session *session __attribute__((unused)),
1596
1556
plugin_ref plugin,
1597
1557
void *arg __attribute__((unused)))
1674
1634
This should return ENOENT if the file doesn't exists.
1675
1635
The .frm file will be deleted only if we return 0 or ENOENT
1677
int ha_delete_table(THD *thd, handlerton *table_type, const char *path,
1637
int ha_delete_table(Session *session, handlerton *table_type, const char *path,
1678
1638
const char *db, const char *alias, bool generate_warning)
1715
1675
file->change_table_ptr(&dummy_table, &dummy_share);
1717
thd->push_internal_handler(&ha_delete_table_error_handler);
1677
session->push_internal_handler(&ha_delete_table_error_handler);
1718
1678
file->print_error(error, 0);
1720
thd->pop_internal_handler();
1680
session->pop_internal_handler();
1723
1683
XXX: should we convert *all* errors to warnings here?
1724
1684
What if the error is fatal?
1726
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error,
1686
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error,
1727
1687
ha_delete_table_error_handler.buff);
1758
1718
status_var_increment(table->in_use->status_var.*offset);
1761
void **handler::ha_data(THD *thd) const
1721
void **handler::ha_data(Session *session) const
1763
return thd_ha_data(thd, ht);
1723
return session_ha_data(session, ht);
1766
THD *handler::ha_thd(void) const
1726
Session *handler::ha_session(void) const
1768
assert(!table || !table->in_use || table->in_use == current_thd);
1769
return (table && table->in_use) ? table->in_use : current_thd;
1728
assert(!table || !table->in_use || table->in_use == current_session);
1729
return (table && table->in_use) ? table->in_use : current_session;
1898
1858
void handler::adjust_next_insert_id_after_explicit_value(uint64_t nr)
1901
If we have set THD::next_insert_id previously and plan to insert an
1861
If we have set Session::next_insert_id previously and plan to insert an
1902
1862
explicitely-specified value larger than this, we need to increase
1903
THD::next_insert_id to be greater than the explicit value.
1863
Session::next_insert_id to be greater than the explicit value.
1905
1865
if ((next_insert_id > 0) && (nr >= next_insert_id))
1906
1866
set_next_insert_id(compute_next_insert_id(nr, &table->in_use->variables));
1990
1950
start counting from the inserted value.
1992
1952
This function's "outputs" are: the table's auto_increment field is filled
1993
with a value, thd->next_insert_id is filled with the value to use for the
1953
with a value, session->next_insert_id is filled with the value to use for the
1994
1954
next row, if a value was autogenerated for the current row it is stored in
1995
thd->insert_id_for_cur_row, if get_auto_increment() was called
1996
thd->auto_inc_interval_for_cur_row is modified, if that interval is not
1997
present in thd->auto_inc_intervals_in_cur_stmt_for_binlog it is added to
1955
session->insert_id_for_cur_row, if get_auto_increment() was called
1956
session->auto_inc_interval_for_cur_row is modified, if that interval is not
1957
present in session->auto_inc_intervals_in_cur_stmt_for_binlog it is added to
2139
2099
auto_inc_interval_for_cur_row.replace(nr, nb_reserved_values,
2140
2100
variables->auto_increment_increment);
2141
2101
/* Row-based replication does not need to store intervals in binlog */
2142
if (!thd->current_stmt_binlog_row_based)
2143
thd->auto_inc_intervals_in_cur_stmt_for_binlog.append(auto_inc_interval_for_cur_row.minimum(),
2102
if (!session->current_stmt_binlog_row_based)
2103
session->auto_inc_intervals_in_cur_stmt_for_binlog.append(auto_inc_interval_for_cur_row.minimum(),
2144
2104
auto_inc_interval_for_cur_row.values(),
2145
2105
variables->auto_increment_increment);
2560
2520
strxmov(path, table->s->normalized_path.str, reg_ext, NULL);
2562
if ((file= my_open(path, O_RDWR|O_BINARY, MYF(MY_WME))) >= 0)
2522
if ((file= my_open(path, O_RDWR, MYF(MY_WME))) >= 0)
2564
2524
unsigned char version[4];
2565
2525
char *key= table->s->table_cache_key.str;
2999
2959
is an optimization hint that storage engine is free to ignore.
3000
2960
So, let's commit an open transaction (if any) now.
3002
if (!(error= ha_commit_trans(thd, 0)))
3003
error= end_trans(thd, COMMIT);
2962
if (!(error= ha_commit_trans(session, 0)))
2963
error= end_trans(session, COMMIT);
3079
3039
const char *name;
3080
3040
TABLE_SHARE share;
3082
init_tmp_table_share(thd, &share, db, 0, table_name, path);
3083
if (open_table_def(thd, &share, 0) ||
3084
open_table_from_share(thd, &share, "", 0, (uint) READ_ALL, 0, &table,
3042
init_tmp_table_share(session, &share, db, 0, table_name, path);
3043
if (open_table_def(session, &share, 0) ||
3044
open_table_from_share(session, &share, "", 0, (uint) READ_ALL, 0, &table,
3126
3086
TABLE_SHARE share;
3128
3088
memset(&create_info, 0, sizeof(create_info));
3129
if ((error= ha_discover(thd, db, name, &frmblob, &frmlen)))
3089
if ((error= ha_discover(session, db, name, &frmblob, &frmlen)))
3131
3091
/* Table could not be discovered and thus not created */
3147
init_tmp_table_share(thd, &share, db, 0, name, path);
3148
if (open_table_def(thd, &share, 0))
3107
init_tmp_table_share(session, &share, db, 0, name, path);
3108
if (open_table_def(session, &share, 0))
3152
if (open_table_from_share(thd, &share, "" ,0, 0, 0, &table, OTM_OPEN))
3112
if (open_table_from_share(session, &share, "" ,0, 0, 0, &table, OTM_OPEN))
3154
3114
free_table_share(&share);
3280
3240
size_t *frmlen;
3283
static bool discover_handlerton(THD *thd, plugin_ref plugin,
3243
static bool discover_handlerton(Session *session, plugin_ref plugin,
3286
3246
st_discover_args *vargs= (st_discover_args *)arg;
3287
3247
handlerton *hton= plugin_data(plugin, handlerton *);
3288
3248
if (hton->state == SHOW_OPTION_YES && hton->discover &&
3289
(!(hton->discover(hton, thd, vargs->db, vargs->name,
3249
(!(hton->discover(hton, session, vargs->db, vargs->name,
3290
3250
vargs->frmblob,
3291
3251
vargs->frmlen))))
3303
3263
if (is_prefix(name,tmp_file_prefix)) /* skip temporary tables */
3306
if (plugin_foreach(thd, discover_handlerton,
3266
if (plugin_foreach(session, discover_handlerton,
3307
3267
DRIZZLE_STORAGE_ENGINE_PLUGIN, &args))
3311
status_var_increment(thd->status_var.ha_discover_count);
3271
status_var_increment(session->status_var.ha_discover_count);
3364
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name)
3324
int ha_table_exists_in_engine(Session* session, const char* db, const char* name)
3366
3326
st_table_exists_in_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE};
3367
plugin_foreach(thd, table_exists_in_engine_handlerton,
3327
plugin_foreach(session, table_exists_in_engine_handlerton,
3368
3328
DRIZZLE_STORAGE_ENGINE_PLUGIN, &args);
3369
3329
return(args.err);
4401
4361
handlerton *hton= plugin_data(plugin, handlerton *);
4403
4363
if (hton->state == SHOW_OPTION_YES && hton->create &&
4404
(file= hton->create(hton, (TABLE_SHARE*) 0, current_thd->mem_root)))
4364
(file= hton->create(hton, (TABLE_SHARE*) 0, current_session->mem_root)))
4406
4366
List_iterator_fast<char> it(*found_exts);
4407
4367
const char **ext, *old_ext;
4455
static bool stat_print(THD *thd, const char *type, uint32_t type_len,
4415
static bool stat_print(Session *session, const char *type, uint32_t type_len,
4456
4416
const char *file, uint32_t file_len,
4457
4417
const char *status, uint32_t status_len)
4459
Protocol *protocol= thd->protocol;
4419
Protocol *protocol= session->protocol;
4460
4420
protocol->prepare_for_resend();
4461
4421
protocol->store(type, type_len, system_charset_info);
4462
4422
protocol->store(file, file_len, system_charset_info);
4513
4473
assert(table->s->cached_row_logging_check == 0 ||
4514
4474
table->s->cached_row_logging_check == 1);
4516
return (thd->current_stmt_binlog_row_based &&
4476
return (session->current_stmt_binlog_row_based &&
4517
4477
table->s->cached_row_logging_check &&
4518
(thd->options & OPTION_BIN_LOG) &&
4478
(session->options & OPTION_BIN_LOG) &&
4519
4479
mysql_bin_log.is_open());
4525
4485
to the binary log.
4527
4487
This function will generate and write table maps for all tables
4528
that are locked by the thread 'thd'. Either manually locked
4529
(stored in THD::locked_tables) and automatically locked (stored
4530
in THD::lock) are considered.
4488
that are locked by the thread 'session'. Either manually locked
4489
(stored in Session::locked_tables) and automatically locked (stored
4490
in Session::lock) are considered.
4532
@param thd Pointer to THD structure
4492
@param session Pointer to Session structure
4534
4494
@retval 0 All OK
4535
4495
@retval 1 Failed to write all table maps
4499
Session::locked_tables
4542
static int write_locked_table_maps(THD *thd)
4502
static int write_locked_table_maps(Session *session)
4544
if (thd->get_binlog_table_maps() == 0)
4504
if (session->get_binlog_table_maps() == 0)
4546
4506
DRIZZLE_LOCK *locks[3];
4547
locks[0]= thd->extra_lock;
4548
locks[1]= thd->lock;
4549
locks[2]= thd->locked_tables;
4507
locks[0]= session->extra_lock;
4508
locks[1]= session->lock;
4509
locks[2]= session->locked_tables;
4550
4510
for (uint32_t i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )
4552
4512
DRIZZLE_LOCK const *const lock= locks[i];
4561
4521
Table *const table= *table_ptr;
4562
4522
if (table->current_lock == F_WRLCK &&
4563
check_table_binlog_row_based(thd, table))
4523
check_table_binlog_row_based(session, table))
4565
4525
int const has_trans= table->file->has_transactions();
4566
int const error= thd->binlog_write_table_map(table, has_trans);
4526
int const error= session->binlog_write_table_map(table, has_trans);
4568
4528
If an error occurs, it is the responsibility of the caller to
4569
4529
roll back the transaction.
4581
typedef bool Log_func(THD*, Table*, bool, const unsigned char*, const unsigned char*);
4541
typedef bool Log_func(Session*, Table*, bool, const unsigned char*, const unsigned char*);
4583
4543
static int binlog_log_row(Table* table,
4584
4544
const unsigned char *before_record,
4588
4548
if (table->no_replicate)
4591
THD *const thd= table->in_use;
4551
Session *const session= table->in_use;
4593
if (check_table_binlog_row_based(thd, table))
4553
if (check_table_binlog_row_based(session, table))
4596
4556
If there are no table maps written to the binary log, this is
4597
4557
the first row handled in this statement. In that case, we need
4598
4558
to write table maps for all locked tables to the binary log.
4600
if (likely(!(error= write_locked_table_maps(thd))))
4560
if (likely(!(error= write_locked_table_maps(session))))
4602
4562
bool const has_trans= table->file->has_transactions();
4603
error= (*log_func)(thd, table, has_trans, before_record, after_record);
4563
error= (*log_func)(session, table, has_trans, before_record, after_record);
4606
4566
return error ? HA_ERR_RBR_LOGGING_FAILED : 0;
4609
int handler::ha_external_lock(THD *thd, int lock_type)
4569
int handler::ha_external_lock(Session *session, int lock_type)
4612
4572
Whether this is lock or unlock, this should be true, and is to verify that