From: Jonas Oreland Date: October 17 2011 12:44pm Subject: bzr push into mysql-5.1-telco-7.0 branch (jonas.oreland:4601 to 4602) List-Archive: http://lists.mysql.com/commits/141472 Message-Id: <20111017124412.9E2BE9FCF01@perch.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4602 Jonas Oreland 2011-10-17 ndb - add information_schema table exposing map between mysql connection id and ndb transid modified: sql/ha_ndb_index_stat.cc sql/ha_ndbcluster.cc sql/ha_ndbcluster.h sql/ha_ndbcluster_binlog.cc sql/ha_ndbcluster_connection.cc sql/ha_ndbinfo.cc sql/ha_ndbinfo.h storage/ndb/include/ndbapi/Ndb.hpp storage/ndb/src/ndbapi/Ndb.cpp storage/ndb/src/ndbapi/NdbImpl.hpp storage/ndb/src/ndbapi/Ndbinit.cpp 4601 magnus.blaudd@stripped 2011-10-17 Fix compilation error on Windows in MCP patch for bug#13001491 - s/snprintf/my_snprintf/ modified: tests/mysql_client_test.c === modified file 'sql/ha_ndb_index_stat.cc' --- a/sql/ha_ndb_index_stat.cc 2011-10-08 16:56:43 +0000 +++ b/sql/ha_ndb_index_stat.cc 2011-10-17 12:43:31 +0000 @@ -1984,7 +1984,7 @@ ndb_index_stat_thread_func(void *arg __a } /* Get thd_ndb for this thread */ - if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb())) + if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb(thd))) { sql_print_error("Could not allocate Thd_ndb object"); pthread_mutex_lock(&LOCK_ndb_index_stat_thread); === modified file 'sql/ha_ndbcluster.cc' --- a/sql/ha_ndbcluster.cc 2011-10-08 16:54:19 +0000 +++ b/sql/ha_ndbcluster.cc 2011-10-17 12:43:31 +0000 @@ -11419,7 +11419,8 @@ int ha_ndbcluster::close(void) wait on condition for a Ndb object to be released. - Alt.2 Seize/release from pool, wait until next release */ -Thd_ndb* ha_ndbcluster::seize_thd_ndb() +Thd_ndb* +ha_ndbcluster::seize_thd_ndb(THD * thd) { Thd_ndb *thd_ndb; DBUG_ENTER("seize_thd_ndb"); @@ -11442,6 +11443,10 @@ Thd_ndb* ha_ndbcluster::seize_thd_ndb() delete thd_ndb; thd_ndb= NULL; } + else + { + thd_ndb->ndb->setCustomData64(thd_get_thread_id(thd)); + } DBUG_RETURN(thd_ndb); } @@ -11478,7 +11483,10 @@ bool Thd_ndb::recycle_ndb(THD* thd) ndb->getNdbError().message)); DBUG_RETURN(false); } - + else + { + ndb->setCustomData64(thd_get_thread_id(thd)); + } DBUG_RETURN(true); } @@ -11516,7 +11524,7 @@ Ndb* check_ndb_in_thd(THD* thd, bool val Thd_ndb *thd_ndb= get_thd_ndb(thd); if (!thd_ndb) { - if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb())) + if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb(thd))) return NULL; set_thd_ndb(thd, thd_ndb); } @@ -14850,7 +14858,7 @@ pthread_handler_t ndb_util_thread_func(v pthread_mutex_unlock(&LOCK_ndb_util_thread); /* Get thd_ndb for this thread */ - if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb())) + if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb(thd))) { sql_print_error("Could not allocate Thd_ndb object"); pthread_mutex_lock(&LOCK_ndb_util_thread); @@ -17310,12 +17318,8 @@ struct st_mysql_storage_engine ndbcluste { MYSQL_HANDLERTON_INTERFACE_VERSION }; -#include "ha_ndbinfo.h" - -extern struct st_mysql_sys_var* ndbinfo_system_variables[]; - -struct st_mysql_storage_engine ndbinfo_storage_engine= -{ MYSQL_HANDLERTON_INTERFACE_VERSION }; +extern struct st_mysql_plugin i_s_ndb_transid_mysql_connection_map_plugin; +extern struct st_mysql_plugin ndbinfo_plugin; mysql_declare_plugin(ndbcluster) { @@ -17332,20 +17336,9 @@ mysql_declare_plugin(ndbcluster) system_variables, /* system variables */ NULL /* config options */ }, -{ - MYSQL_STORAGE_ENGINE_PLUGIN, - &ndbinfo_storage_engine, - "ndbinfo", - "Sun Microsystems Inc.", - "MySQL Cluster system information storage engine", - PLUGIN_LICENSE_GPL, - ndbinfo_init, /* plugin init */ - ndbinfo_deinit, /* plugin deinit */ - 0x0001, /* plugin version */ - NULL, /* status variables */ - ndbinfo_system_variables, /* system variables */ - NULL /* config options */ -} +ndbinfo_plugin, /* ndbinfo plugin */ +/* IS plugin table which maps between mysql connection id and ndb trans-id */ +i_s_ndb_transid_mysql_connection_map_plugin mysql_declare_plugin_end; #endif === modified file 'sql/ha_ndbcluster.h' --- a/sql/ha_ndbcluster.h 2011-09-07 22:50:01 +0000 +++ b/sql/ha_ndbcluster.h 2011-10-17 12:43:31 +0000 @@ -682,7 +682,7 @@ class ha_ndbcluster: public handler int ndb_update_row(const uchar *old_data, uchar *new_data, int is_bulk_update); - static Thd_ndb* seize_thd_ndb(); + static Thd_ndb* seize_thd_ndb(THD*); static void release_thd_ndb(Thd_ndb* thd_ndb); static void set_dbname(const char *pathname, char *dbname); === modified file 'sql/ha_ndbcluster_binlog.cc' --- a/sql/ha_ndbcluster_binlog.cc 2011-09-29 13:32:44 +0000 +++ b/sql/ha_ndbcluster_binlog.cc 2011-10-17 12:43:31 +0000 @@ -2098,7 +2098,7 @@ int ndbcluster_log_schema_op(THD *thd, Thd_ndb *thd_ndb= get_thd_ndb(thd); if (!thd_ndb) { - if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb())) + if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb(thd))) { sql_print_error("Could not allocate Thd_ndb object"); DBUG_RETURN(1); @@ -6765,7 +6765,7 @@ restart_cluster_failure: int have_injector_mutex_lock= 0; do_ndbcluster_binlog_close_connection= BCCC_exit; - if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb())) + if (!(thd_ndb= ha_ndbcluster::seize_thd_ndb(thd))) { sql_print_error("Could not allocate Thd_ndb object"); ndb_binlog_thread_running= -1; === modified file 'sql/ha_ndbcluster_connection.cc' --- a/sql/ha_ndbcluster_connection.cc 2011-06-30 15:59:25 +0000 +++ b/sql/ha_ndbcluster_connection.cc 2011-10-17 12:43:31 +0000 @@ -306,4 +306,115 @@ void ndb_get_connection_stats(Uint64* st } } +static ST_FIELD_INFO ndb_transid_mysql_connection_map_fields_info[] = +{ + { + "mysql_connection_id", + MY_INT64_NUM_DECIMAL_DIGITS, + MYSQL_TYPE_LONGLONG, + 0, + MY_I_S_UNSIGNED, + "", + SKIP_OPEN_TABLE + }, + + { + "node_id", + MY_INT64_NUM_DECIMAL_DIGITS, + MYSQL_TYPE_LONG, + 0, + MY_I_S_UNSIGNED, + "", + SKIP_OPEN_TABLE + }, + { + "ndb_transid", + MY_INT64_NUM_DECIMAL_DIGITS, + MYSQL_TYPE_LONGLONG, + 0, + MY_I_S_UNSIGNED, + "", + SKIP_OPEN_TABLE + }, + + { 0, 0, MYSQL_TYPE_NULL, 0, 0, "", SKIP_OPEN_TABLE } +}; + +static +int +ndb_transid_mysql_connection_map_fill_table(THD* thd, TABLE_LIST* tables, COND* cond) +{ + DBUG_ENTER("ndb_transid_mysql_connection_map_fill_table"); + + if (check_global_access(thd, PROCESS_ACL)) + { + DBUG_RETURN(0); + } + + TABLE* table= tables->table; + for (uint i = 0; ilock_ndb_objects(); + const Ndb * p = g_pool[i]->get_next_ndb_object(0); + while (p) + { + table->field[0]->set_notnull(); + table->field[0]->store(p->getCustomData64(), true); + table->field[1]->set_notnull(); + table->field[1]->store(g_pool[i]->node_id()); + table->field[2]->set_notnull(); + table->field[2]->store(p->getNextTransactionId(), true); + schema_table_store_record(thd, table); + p = g_pool[i]->get_next_ndb_object(p); + } + g_pool[i]->unlock_ndb_objects(); + } + } + + DBUG_RETURN(0); +} + +static +int +ndb_transid_mysql_connection_map_init(void *p) +{ + DBUG_ENTER("ndb_transid_mysql_connection_map_init"); + ST_SCHEMA_TABLE* schema = reinterpret_cast(p); + schema->fields_info = ndb_transid_mysql_connection_map_fields_info; + schema->fill_table = ndb_transid_mysql_connection_map_fill_table; + DBUG_RETURN(0); +} + +static +int +ndb_transid_mysql_connection_map_deinit(void *p) +{ + DBUG_ENTER("ndb_transid_mysql_connection_map_deinit"); + DBUG_RETURN(0); +} + +#include +static struct st_mysql_information_schema i_s_info = +{ + MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION +}; + +struct st_mysql_plugin i_s_ndb_transid_mysql_connection_map_plugin = +{ + MYSQL_INFORMATION_SCHEMA_PLUGIN, + &i_s_info, + "ndb_transid_mysql_connection_map", + "Oracle Corporation", + "Map between mysql connection id and ndb transaction id", + PLUGIN_LICENSE_GPL, + ndb_transid_mysql_connection_map_init, + ndb_transid_mysql_connection_map_deinit, + 0x0001, + NULL, + NULL, + NULL +}; + #endif /* WITH_NDBCLUSTER_STORAGE_ENGINE */ === modified file 'sql/ha_ndbinfo.cc' --- a/sql/ha_ndbinfo.cc 2011-08-27 09:54:26 +0000 +++ b/sql/ha_ndbinfo.cc 2011-10-17 12:43:31 +0000 @@ -736,7 +736,9 @@ ndbinfo_find_files(handlerton *hton, THD handlerton* ndbinfo_hton; -int ndbinfo_init(void *plugin) +static +int +ndbinfo_init(void *plugin) { DBUG_ENTER("ndbinfo_init"); @@ -779,7 +781,9 @@ int ndbinfo_init(void *plugin) DBUG_RETURN(0); } -int ndbinfo_deinit(void *plugin) +static +int +ndbinfo_deinit(void *plugin) { DBUG_ENTER("ndbinfo_deinit"); @@ -804,6 +808,27 @@ struct st_mysql_sys_var* ndbinfo_system_ NULL }; +struct st_mysql_storage_engine ndbinfo_storage_engine= +{ + MYSQL_HANDLERTON_INTERFACE_VERSION +}; + +struct st_mysql_plugin ndbinfo_plugin = +{ + MYSQL_STORAGE_ENGINE_PLUGIN, + &ndbinfo_storage_engine, + "ndbinfo", + "Sun Microsystems Inc.", + "MySQL Cluster system information storage engine", + PLUGIN_LICENSE_GPL, + ndbinfo_init, /* plugin init */ + ndbinfo_deinit, /* plugin deinit */ + 0x0001, /* plugin version */ + NULL, /* status variables */ + ndbinfo_system_variables, /* system variables */ + NULL /* config options */ +}; + template class Vector; #endif === modified file 'sql/ha_ndbinfo.h' --- a/sql/ha_ndbinfo.h 2011-06-30 15:59:25 +0000 +++ b/sql/ha_ndbinfo.h 2011-10-17 12:43:31 +0000 @@ -20,9 +20,6 @@ #include -int ndbinfo_init(void *plugin); -int ndbinfo_deinit(void *plugin); - class ha_ndbinfo: public handler { public: === modified file 'storage/ndb/include/ndbapi/Ndb.hpp' --- a/storage/ndb/include/ndbapi/Ndb.hpp 2011-09-09 10:48:14 +0000 +++ b/storage/ndb/include/ndbapi/Ndb.hpp 2011-10-17 12:43:31 +0000 @@ -1762,7 +1762,19 @@ public: /* Get/Set per-Ndb custom data pointer */ void setCustomData(void*); void* getCustomData() const; - + + /* Get/Set per-Ndb custom data pointer */ + /* NOTE: shares storage with void* + * i.e can not be used together with setCustomData + */ + void setCustomData64(Uint64); + Uint64 getCustomData64() const; + + /** + * transid next startTransaction() on this ndb-object will get + */ + Uint64 getNextTransactionId() const; + /* Some client behaviour counters to assist * optimisation */ === modified file 'storage/ndb/src/ndbapi/Ndb.cpp' --- a/storage/ndb/src/ndbapi/Ndb.cpp 2011-09-07 17:12:12 +0000 +++ b/storage/ndb/src/ndbapi/Ndb.cpp 2011-10-17 12:43:31 +0000 @@ -2254,13 +2254,31 @@ Ndb::getNdbErrorDetail(const NdbError& e void Ndb::setCustomData(void* _customDataPtr) { - theImpl->customDataPtr = _customDataPtr; + theImpl->customData = Uint64(_customDataPtr); } void* Ndb::getCustomData() const { - return theImpl->customDataPtr; + return (void*)theImpl->customData; +} + +void +Ndb::setCustomData64(Uint64 _customData) +{ + theImpl->customData = _customData; +} + +Uint64 +Ndb::getCustomData64() const +{ + return theImpl->customData; +} + +Uint64 +Ndb::getNextTransactionId() const +{ + return theFirstTransId; } Uint32 === modified file 'storage/ndb/src/ndbapi/NdbImpl.hpp' --- a/storage/ndb/src/ndbapi/NdbImpl.hpp 2011-09-09 10:48:14 +0000 +++ b/storage/ndb/src/ndbapi/NdbImpl.hpp 2011-10-17 12:43:31 +0000 @@ -129,7 +129,7 @@ public: BaseString m_systemPrefix; // Buffer for preformatted for // - void* customDataPtr; + Uint64 customData; Uint64 clientStats[ Ndb::NumClientStatistics ]; === modified file 'storage/ndb/src/ndbapi/Ndbinit.cpp' --- a/storage/ndb/src/ndbapi/Ndbinit.cpp 2011-09-09 10:48:14 +0000 +++ b/storage/ndb/src/ndbapi/Ndbinit.cpp 2011-10-17 12:43:31 +0000 @@ -207,7 +207,7 @@ NdbImpl::NdbImpl(Ndb_cluster_connection wakeHandler(0), wakeContext(~Uint32(0)), m_ev_op(0), - customDataPtr(0) + customData(0) { int i; for (i = 0; i < MAX_NDB_NODES; i++) { No bundle (reason: useless for push emails).