Commit 4cb86b79 authored by Sergey Vojtovich's avatar Sergey Vojtovich

MDEV-7728 - Improve xid cache scalability by using lock-free hash

Spider support for new xid cache implementation.
parent 6bd24dea
...@@ -41,11 +41,13 @@ ...@@ -41,11 +41,13 @@
#include "spd_malloc.h" #include "spd_malloc.h"
ulong *spd_db_att_thread_id; ulong *spd_db_att_thread_id;
#if MYSQL_VERSION_ID < 100103
#ifdef XID_CACHE_IS_SPLITTED #ifdef XID_CACHE_IS_SPLITTED
uint *spd_db_att_xid_cache_split_num; uint *spd_db_att_xid_cache_split_num;
#endif #endif
pthread_mutex_t *spd_db_att_LOCK_xid_cache; pthread_mutex_t *spd_db_att_LOCK_xid_cache;
HASH *spd_db_att_xid_cache; HASH *spd_db_att_xid_cache;
#endif
struct charset_info_st *spd_charset_utf8_bin; struct charset_info_st *spd_charset_utf8_bin;
const char **spd_defaults_extra_file; const char **spd_defaults_extra_file;
const char **spd_defaults_file; const char **spd_defaults_file;
...@@ -6263,7 +6265,7 @@ int spider_db_init( ...@@ -6263,7 +6265,7 @@ int spider_db_init(
"?LOCK_xid_cache@@3PAUst_mysql_mutex@@A")); "?LOCK_xid_cache@@3PAUst_mysql_mutex@@A"));
spd_db_att_xid_cache = *((HASH **) spd_db_att_xid_cache = *((HASH **)
GetProcAddress(current_module, "?xid_cache@@3PAUst_hash@@A")); GetProcAddress(current_module, "?xid_cache@@3PAUst_hash@@A"));
#else #elif MYSQL_VERSION_ID < 100103
spd_db_att_LOCK_xid_cache = (pthread_mutex_t *) spd_db_att_LOCK_xid_cache = (pthread_mutex_t *)
#if MYSQL_VERSION_ID < 50500 #if MYSQL_VERSION_ID < 50500
GetProcAddress(current_module, GetProcAddress(current_module,
...@@ -6289,7 +6291,7 @@ int spider_db_init( ...@@ -6289,7 +6291,7 @@ int spider_db_init(
spd_db_att_xid_cache_split_num = &opt_xid_cache_split_num; spd_db_att_xid_cache_split_num = &opt_xid_cache_split_num;
spd_db_att_LOCK_xid_cache = LOCK_xid_cache; spd_db_att_LOCK_xid_cache = LOCK_xid_cache;
spd_db_att_xid_cache = xid_cache; spd_db_att_xid_cache = xid_cache;
#else #elif MYSQL_VERSION_ID < 100103
spd_db_att_LOCK_xid_cache = &LOCK_xid_cache; spd_db_att_LOCK_xid_cache = &LOCK_xid_cache;
spd_db_att_xid_cache = &xid_cache; spd_db_att_xid_cache = &xid_cache;
#endif #endif
......
...@@ -38,11 +38,13 @@ ...@@ -38,11 +38,13 @@
#include "spd_ping_table.h" #include "spd_ping_table.h"
#include "spd_malloc.h" #include "spd_malloc.h"
#if MYSQL_VERSION_ID < 100103
#ifdef XID_CACHE_IS_SPLITTED #ifdef XID_CACHE_IS_SPLITTED
extern uint *spd_db_att_xid_cache_split_num; extern uint *spd_db_att_xid_cache_split_num;
#endif #endif
extern pthread_mutex_t *spd_db_att_LOCK_xid_cache; extern pthread_mutex_t *spd_db_att_LOCK_xid_cache;
extern HASH *spd_db_att_xid_cache; extern HASH *spd_db_att_xid_cache;
#endif
extern struct charset_info_st *spd_charset_utf8_bin; extern struct charset_info_st *spd_charset_utf8_bin;
extern handlerton *spider_hton_ptr; extern handlerton *spider_hton_ptr;
...@@ -1641,6 +1643,13 @@ int spider_xa_lock( ...@@ -1641,6 +1643,13 @@ int spider_xa_lock(
int error_num; int error_num;
const char *old_proc_info; const char *old_proc_info;
DBUG_ENTER("spider_xa_lock"); DBUG_ENTER("spider_xa_lock");
#if MYSQL_VERSION_ID >= 100103
old_proc_info = thd_proc_info(thd, "Locking xid by Spider");
error_num= 0;
if (xid_cache_insert(thd, xid_state))
error_num= thd->get_stmt_da()->sql_errno() == ER_XAER_DUPID ?
ER_SPIDER_XA_LOCKED_NUM : HA_ERR_OUT_OF_MEM;
#else
#ifdef SPIDER_HAS_HASH_VALUE_TYPE #ifdef SPIDER_HAS_HASH_VALUE_TYPE
my_hash_value_type hash_value = my_calc_hash(spd_db_att_xid_cache, my_hash_value_type hash_value = my_calc_hash(spd_db_att_xid_cache,
(uchar*) xid_state->xid.key(), xid_state->xid.key_length()); (uchar*) xid_state->xid.key(), xid_state->xid.key_length());
...@@ -1698,6 +1707,7 @@ error: ...@@ -1698,6 +1707,7 @@ error:
pthread_mutex_unlock(&spd_db_att_LOCK_xid_cache[idx]); pthread_mutex_unlock(&spd_db_att_LOCK_xid_cache[idx]);
#else #else
pthread_mutex_unlock(spd_db_att_LOCK_xid_cache); pthread_mutex_unlock(spd_db_att_LOCK_xid_cache);
#endif
#endif #endif
thd_proc_info(thd, old_proc_info); thd_proc_info(thd, old_proc_info);
DBUG_RETURN(error_num); DBUG_RETURN(error_num);
...@@ -1709,6 +1719,10 @@ int spider_xa_unlock( ...@@ -1709,6 +1719,10 @@ int spider_xa_unlock(
THD *thd = current_thd; THD *thd = current_thd;
const char *old_proc_info; const char *old_proc_info;
DBUG_ENTER("spider_xa_unlock"); DBUG_ENTER("spider_xa_unlock");
#if MYSQL_VERSION_ID >= 100103
old_proc_info = thd_proc_info(thd, "Unlocking xid by Spider");
xid_cache_delete(thd, xid_state);
#else
#if defined(SPIDER_HAS_HASH_VALUE_TYPE) && defined(HASH_UPDATE_WITH_HASH_VALUE) #if defined(SPIDER_HAS_HASH_VALUE_TYPE) && defined(HASH_UPDATE_WITH_HASH_VALUE)
my_hash_value_type hash_value = my_calc_hash(spd_db_att_xid_cache, my_hash_value_type hash_value = my_calc_hash(spd_db_att_xid_cache,
(uchar*) xid_state->xid.key(), xid_state->xid.key_length()); (uchar*) xid_state->xid.key(), xid_state->xid.key_length());
...@@ -1737,6 +1751,7 @@ int spider_xa_unlock( ...@@ -1737,6 +1751,7 @@ int spider_xa_unlock(
pthread_mutex_unlock(&spd_db_att_LOCK_xid_cache[idx]); pthread_mutex_unlock(&spd_db_att_LOCK_xid_cache[idx]);
#else #else
pthread_mutex_unlock(spd_db_att_LOCK_xid_cache); pthread_mutex_unlock(spd_db_att_LOCK_xid_cache);
#endif
#endif #endif
thd_proc_info(thd, old_proc_info); thd_proc_info(thd, old_proc_info);
DBUG_RETURN(0); DBUG_RETURN(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment