diff options
author | unknown <kostja@bodhi.(none)> | 2007-08-31 10:19:52 +0400 |
---|---|---|
committer | unknown <kostja@bodhi.(none)> | 2007-08-31 10:19:52 +0400 |
commit | ee040ef2b762d1a780a53bc347657484335b1a4c (patch) | |
tree | 14710401798f8ef572997a003e8792fb9353e947 | |
parent | 9cedd882e7027afeca5ea190e41df96a752194c5 (diff) | |
download | mariadb-git-ee040ef2b762d1a780a53bc347657484335b1a4c.tar.gz |
Never access thd->ha_data directly, use getters/setters from the plugin
API instead.
This is a pre-requisite of the fix for Bug 12713, which changes the
data type of thd->ha_data from void * to struct Ha_data.
include/mysql/plugin.h:
Provide accessors to thd->ha_data for simple and robust code.
sql/ha_ndbcluster_binlog.h:
Use getters/setters of thd->ha_data, instead of direct access.
sql/handler.cc:
Use a getter of thd->ha_data instead of direct access.
sql/log.cc:
Use getters/setters of thd->ha_data, instead of direct access.
sql/rpl_utility.h:
Fix a compilation warning (declaration order must match initialization
order in constructor).
storage/federated/ha_federated.cc:
Use interface accessors to thd->ha_data, instead of direct access.
-rw-r--r-- | include/mysql/plugin.h | 23 | ||||
-rw-r--r-- | sql/ha_ndbcluster_binlog.h | 6 | ||||
-rw-r--r-- | sql/handler.cc | 4 | ||||
-rw-r--r-- | sql/log.cc | 46 | ||||
-rw-r--r-- | sql/rpl_utility.h | 2 | ||||
-rw-r--r-- | storage/federated/ha_federated.cc | 12 |
6 files changed, 59 insertions, 34 deletions
diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index 61ed7be738f..50ec051d111 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -785,5 +785,28 @@ void mysql_query_cache_invalidate4(MYSQL_THD thd, } #endif +#ifdef __cplusplus +/** + Provide a handler data getter to simplify coding +*/ +inline +void * +thd_get_ha_data(const MYSQL_THD thd, const struct handlerton *hton) +{ + return *thd_ha_data(thd, hton); +} + +/** + Provide a handler data setter to simplify coding +*/ +inline +void +thd_set_ha_data(const MYSQL_THD thd, const struct handlerton *hton, + const void *ha_data) +{ + *thd_ha_data(thd, hton)= (void*) ha_data; +} +#endif + #endif diff --git a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h index b5b8d0d9745..53852028f08 100644 --- a/sql/ha_ndbcluster_binlog.h +++ b/sql/ha_ndbcluster_binlog.h @@ -216,10 +216,12 @@ inline void free_share(NDB_SHARE **share, bool have_lock= FALSE) inline Thd_ndb * -get_thd_ndb(THD *thd) { return (Thd_ndb *) thd->ha_data[ndbcluster_hton->slot]; } +get_thd_ndb(THD *thd) +{ return (Thd_ndb *) thd_get_ha_data(thd, ndbcluster_hton); } inline void -set_thd_ndb(THD *thd, Thd_ndb *thd_ndb) { thd->ha_data[ndbcluster_hton->slot]= thd_ndb; } +set_thd_ndb(THD *thd, Thd_ndb *thd_ndb) +{ thd_set_ha_data(thd, ndbcluster_hton, thd_ndb); } Ndb* check_ndb_in_thd(THD* thd); diff --git a/sql/handler.cc b/sql/handler.cc index 3e9524e9821..0479b3b1443 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -563,7 +563,7 @@ static my_bool closecon_handlerton(THD *thd, plugin_ref plugin, be rolled back already */ if (hton->state == SHOW_OPTION_YES && hton->close_connection && - thd->ha_data[hton->slot]) + thd_get_ha_data(thd, hton)) hton->close_connection(hton, thd); return FALSE; } @@ -1511,7 +1511,7 @@ void handler::ha_statistic_increment(ulong SSV::*offset) const void **handler::ha_data(THD *thd) const { - return (void **) thd->ha_data + ht->slot; + return thd_ha_data(thd, ht); } THD *handler::ha_thd(void) const diff --git a/sql/log.cc b/sql/log.cc index 3686459fedf..6296c7ffaf3 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1215,10 +1215,10 @@ binlog_trans_log_savepos(THD *thd, my_off_t *pos) { DBUG_ENTER("binlog_trans_log_savepos"); DBUG_ASSERT(pos != NULL); - if (thd->ha_data[binlog_hton->slot] == NULL) + if (thd_get_ha_data(thd, binlog_hton) == NULL) thd->binlog_setup_trx_data(); binlog_trx_data *const trx_data= - (binlog_trx_data*) thd->ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton); DBUG_ASSERT(mysql_bin_log.is_open()); *pos= trx_data->position(); DBUG_PRINT("return", ("*pos: %lu", (ulong) *pos)); @@ -1247,12 +1247,12 @@ binlog_trans_log_truncate(THD *thd, my_off_t pos) DBUG_ENTER("binlog_trans_log_truncate"); DBUG_PRINT("enter", ("pos: %lu", (ulong) pos)); - DBUG_ASSERT(thd->ha_data[binlog_hton->slot] != NULL); + DBUG_ASSERT(thd_get_ha_data(thd, binlog_hton) != NULL); /* Only true if binlog_trans_log_savepos() wasn't called before */ DBUG_ASSERT(pos != ~(my_off_t) 0); binlog_trx_data *const trx_data= - (binlog_trx_data*) thd->ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton); trx_data->truncate(pos); DBUG_VOID_RETURN; } @@ -1283,9 +1283,9 @@ int binlog_init(void *p) static int binlog_close_connection(handlerton *hton, THD *thd) { binlog_trx_data *const trx_data= - (binlog_trx_data*) thd->ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton); DBUG_ASSERT(trx_data->empty()); - thd->ha_data[binlog_hton->slot]= 0; + thd_set_ha_data(thd, binlog_hton, NULL); trx_data->~binlog_trx_data(); my_free((uchar*)trx_data, MYF(0)); return 0; @@ -1408,7 +1408,7 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all) { DBUG_ENTER("binlog_commit"); binlog_trx_data *const trx_data= - (binlog_trx_data*) thd->ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton); if (trx_data->empty()) { @@ -1435,7 +1435,7 @@ static int binlog_rollback(handlerton *hton, THD *thd, bool all) DBUG_ENTER("binlog_rollback"); int error=0; binlog_trx_data *const trx_data= - (binlog_trx_data*) thd->ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton); if (trx_data->empty()) { trx_data->reset(); @@ -3252,23 +3252,22 @@ int THD::binlog_setup_trx_data() { DBUG_ENTER("THD::binlog_setup_trx_data"); binlog_trx_data *trx_data= - (binlog_trx_data*) ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(this, binlog_hton); if (trx_data) DBUG_RETURN(0); // Already set up - ha_data[binlog_hton->slot]= trx_data= - (binlog_trx_data*) my_malloc(sizeof(binlog_trx_data), MYF(MY_ZEROFILL)); + trx_data= (binlog_trx_data*) my_malloc(sizeof(binlog_trx_data), MYF(MY_ZEROFILL)); if (!trx_data || open_cached_file(&trx_data->trans_log, mysql_tmpdir, LOG_PREFIX, binlog_cache_size, MYF(MY_WME))) { my_free((uchar*)trx_data, MYF(MY_ALLOW_ZERO_PTR)); - ha_data[binlog_hton->slot]= 0; DBUG_RETURN(1); // Didn't manage to set it up } + thd_set_ha_data(this, binlog_hton, trx_data); - trx_data= new (ha_data[binlog_hton->slot]) binlog_trx_data; + trx_data= new (thd_get_ha_data(this, binlog_hton)) binlog_trx_data; DBUG_RETURN(0); } @@ -3304,7 +3303,7 @@ int THD::binlog_setup_trx_data() void THD::binlog_start_trans_and_stmt() { - binlog_trx_data *trx_data= (binlog_trx_data*) ha_data[binlog_hton->slot]; + binlog_trx_data *trx_data= (binlog_trx_data*) thd_get_ha_data(this, binlog_hton); DBUG_ENTER("binlog_start_trans_and_stmt"); DBUG_PRINT("enter", ("trx_data: 0x%lx trx_data->before_stmt_pos: %lu", (long) trx_data, @@ -3324,7 +3323,7 @@ THD::binlog_start_trans_and_stmt() void THD::binlog_set_stmt_begin() { binlog_trx_data *trx_data= - (binlog_trx_data*) ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(this, binlog_hton); /* The call to binlog_trans_log_savepos() might create the trx_data @@ -3334,14 +3333,15 @@ void THD::binlog_set_stmt_begin() { */ my_off_t pos= 0; binlog_trans_log_savepos(this, &pos); - trx_data= (binlog_trx_data*) ha_data[binlog_hton->slot]; + trx_data= (binlog_trx_data*) thd_get_ha_data(this, binlog_hton); trx_data->before_stmt_pos= pos; } int THD::binlog_flush_transaction_cache() { DBUG_ENTER("binlog_flush_transaction_cache"); - binlog_trx_data *trx_data= (binlog_trx_data*) ha_data[binlog_hton->slot]; + binlog_trx_data *trx_data= (binlog_trx_data*) + thd_get_ha_data(this, binlog_hton); DBUG_PRINT("enter", ("trx_data=0x%lu", (ulong) trx_data)); if (trx_data) DBUG_PRINT("enter", ("trx_data->before_stmt_pos=%lu", @@ -3404,7 +3404,7 @@ Rows_log_event* THD::binlog_get_pending_rows_event() const { binlog_trx_data *const trx_data= - (binlog_trx_data*) ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(this, binlog_hton); /* This is less than ideal, but here's the story: If there is no trx_data, prepare_pending_rows_event() has never been called @@ -3417,11 +3417,11 @@ THD::binlog_get_pending_rows_event() const void THD::binlog_set_pending_rows_event(Rows_log_event* ev) { - if (ha_data[binlog_hton->slot] == NULL) + if (thd_get_ha_data(this, binlog_hton) == NULL) binlog_setup_trx_data(); binlog_trx_data *const trx_data= - (binlog_trx_data*) ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(this, binlog_hton); DBUG_ASSERT(trx_data); trx_data->set_pending(ev); @@ -3444,7 +3444,7 @@ MYSQL_BIN_LOG::flush_and_set_pending_rows_event(THD *thd, int error= 0; binlog_trx_data *const trx_data= - (binlog_trx_data*) thd->ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton); DBUG_ASSERT(trx_data); @@ -3595,7 +3595,7 @@ bool MYSQL_BIN_LOG::write(Log_event *event_info) goto err; binlog_trx_data *const trx_data= - (binlog_trx_data*) thd->ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton); IO_CACHE *trans_log= &trx_data->trans_log; my_off_t trans_log_pos= my_b_tell(trans_log); if (event_info->get_cache_stmt() || trans_log_pos != 0) @@ -5032,7 +5032,7 @@ int TC_LOG_BINLOG::log_xid(THD *thd, my_xid xid) DBUG_ENTER("TC_LOG_BINLOG::log"); Xid_log_event xle(thd, xid); binlog_trx_data *trx_data= - (binlog_trx_data*) thd->ha_data[binlog_hton->slot]; + (binlog_trx_data*) thd_get_ha_data(thd, binlog_hton); /* We always commit the entire transaction when writing an XID. Also note that the return value is inverted. diff --git a/sql/rpl_utility.h b/sql/rpl_utility.h index eac3d14dfc6..62b2ca23918 100644 --- a/sql/rpl_utility.h +++ b/sql/rpl_utility.h @@ -241,8 +241,8 @@ public: private: ulong m_size; // Number of elements in the types array field_type *m_type; // Array of type descriptors - uint16 *m_field_metadata; uint m_field_metadata_size; + uint16 *m_field_metadata; uchar *m_null_bits; uchar *m_memory; }; diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc index ded0ce88484..edcd1127dbd 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -3169,7 +3169,7 @@ int ha_federated::external_lock(THD *thd, int lock_type) #ifdef XXX_SUPERCEDED_BY_WL2952 if (lock_type != F_UNLCK) { - ha_federated *trx= (ha_federated *)thd->ha_data[ht->slot]; + ha_federated *trx= (ha_federated *)thd_get_ha_data(thd, ht); DBUG_PRINT("info",("federated not lock F_UNLCK")); if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))) @@ -3200,7 +3200,7 @@ int ha_federated::external_lock(THD *thd, int lock_type) DBUG_PRINT("info", ("error setting autocommit FALSE: %d", error)); DBUG_RETURN(error); } - thd->ha_data[ht->slot]= this; + thd_set_ha_data(thd, ht, this); trans_register_ha(thd, TRUE, ht); /* Send a lock table to the remote end. @@ -3230,7 +3230,7 @@ int ha_federated::external_lock(THD *thd, int lock_type) static int federated_commit(handlerton *hton, THD *thd, bool all) { int return_val= 0; - ha_federated *trx= (ha_federated *)thd->ha_data[hton->slot]; + ha_federated *trx= (ha_federated *) thd_get_ha_data(thd, hton); DBUG_ENTER("federated_commit"); if (all) @@ -3245,7 +3245,7 @@ static int federated_commit(handlerton *hton, THD *thd, bool all) if (error && !return_val) return_val= error; } - thd->ha_data[hton->slot]= NULL; + thd_set_ha_data(thd, hton, NULL); } DBUG_PRINT("info", ("error val: %d", return_val)); @@ -3256,7 +3256,7 @@ static int federated_commit(handlerton *hton, THD *thd, bool all) static int federated_rollback(handlerton *hton, THD *thd, bool all) { int return_val= 0; - ha_federated *trx= (ha_federated *)thd->ha_data[hton->slot]; + ha_federated *trx= (ha_federated *)thd_get_ha_data(thd, hton); DBUG_ENTER("federated_rollback"); if (all) @@ -3271,7 +3271,7 @@ static int federated_rollback(handlerton *hton, THD *thd, bool all) if (error && !return_val) return_val= error; } - thd->ha_data[hton->slot]= NULL; + thd_set_ha_data(thd, hton, NULL); } DBUG_PRINT("info", ("error val: %d", return_val)); |