diff --git a/dbcon/mysql/ha_calpont.cpp b/dbcon/mysql/ha_calpont.cpp index d4ff366bd..552a895d6 100644 --- a/dbcon/mysql/ha_calpont.cpp +++ b/dbcon/mysql/ha_calpont.cpp @@ -181,87 +181,6 @@ static int infinidb_done_func(void* p) DBUG_RETURN(0); } -#if 0 -/** - @brief - Example of simple lock controls. The "share" it creates is a - structure we will pass to each example handler. Do you have to have - one of these? Well, you have pieces that are used for locking, and - they are needed to function. -*/ - -static CALPONT_SHARE* get_share(const char* table_name, TABLE* table) -{ - CALPONT_SHARE* share; - uint32_t length; - char* tmp_name; -#ifndef _MSC_VER - pthread_mutex_lock(&calpont_mutex); -#endif - length = (uint32_t) strlen(table_name); - - if (!(share = (CALPONT_SHARE*) hash_search(&calpont_open_tables, - (uchar*) table_name, - length))) - { - if (!(share = (CALPONT_SHARE*) - my_multi_malloc(MYF(MY_WME | MY_ZEROFILL), - &share, sizeof(*share), - &tmp_name, length + 1, - NullS))) - { - pthread_mutex_unlock(&calpont_mutex); - return NULL; - } - - share->use_count = 0; - share->table_name_length = length; - share->table_name = tmp_name; - strmov(share->table_name, table_name); - - if (my_hash_insert(&calpont_open_tables, (uchar*) share)) - goto error; - - thr_lock_init(&share->lock); - pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); - } - - share->use_count++; - pthread_mutex_unlock(&calpont_mutex); - - return share; - -error: - pthread_mutex_destroy(&share->mutex); - my_free(share, MYF(0)); - - return NULL; -} - -/** - @brief - Free lock controls. We call this whenever we close a table. If the table had - the last reference to the share, then we free memory associated with it. -*/ - -static int free_share(CALPONT_SHARE* share) -{ - pthread_mutex_lock(&calpont_mutex); - - if (!--share->use_count) - { - hash_delete(&calpont_open_tables, (uchar*) share); - thr_lock_delete(&share->lock); - pthread_mutex_destroy(&share->mutex); - my_free(share, MYF(0)); - } - - pthread_mutex_unlock(&calpont_mutex); - - return 0; -} -#endif - static handler* calpont_create_handler(handlerton* hton, TABLE_SHARE* table, MEM_ROOT* mem_root) diff --git a/dbcon/mysql/ha_calpont_impl.cpp b/dbcon/mysql/ha_calpont_impl.cpp index ae1904dee..57c17c6e7 100644 --- a/dbcon/mysql/ha_calpont_impl.cpp +++ b/dbcon/mysql/ha_calpont_impl.cpp @@ -3969,10 +3969,16 @@ int ha_calpont_impl_close_connection (handlerton* hton, THD* thd) execplan::CalpontSystemCatalog::removeCalpontSystemCatalog(tid2sid(thd->thread_id)); - if (get_fe_conn_info_ptr() == NULL) - set_fe_conn_info_ptr((void*)new cal_connection_info()); - - cal_connection_info* ci = reinterpret_cast(get_fe_conn_info_ptr()); + // MCOL-3247 Use THD::ha_data as a per-plugin per-session + // storage. Filled in external_lock when we remove a lock + // from vtable(lock_type = 2) + // An ugly way. I will use ha_data w/o external_lock. + // This in MCOL-2178 + cal_connection_info* ci = NULL; + if(thd_get_ha_data(thd, hton)) + { + ci = reinterpret_cast(thd_get_ha_data(thd, hton)); + } if (!ci) return 0; @@ -4195,6 +4201,9 @@ int ha_calpont_impl_external_lock(THD* thd, TABLE* table, int lock_type) ci->miniStats = ci->cal_conn_hndl->miniStats; ci->queryState = 0; thd->infinidb_vtable.override_largeside_estimate = false; + // MCOL-3247 Use THD::ha_data as a per-plugin per-session + // storage for cal_conn_hndl to use it later in close_connection + thd_set_ha_data(thd, calpont_hton, get_fe_conn_info_ptr()); } }