Commit 213af08d authored by Monty's avatar Monty

MDEV-13393 SEQUENCE related crash when running concurrent I_S.TABLES and FLUSH queries

Problem was that SEQUENCE::table was shared among threads, which caused
several threads to use the same object at the same time.
parent cf9e0bf3
...@@ -341,7 +341,7 @@ bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *table_list) ...@@ -341,7 +341,7 @@ bool sequence_insert(THD *thd, LEX *lex, TABLE_LIST *table_list)
/* Create a SQUENCE object */ /* Create a SQUENCE object */
SEQUENCE::SEQUENCE() :all_values_used(0), initialized(SEQ_UNINTIALIZED), table(0) SEQUENCE::SEQUENCE() :all_values_used(0), initialized(SEQ_UNINTIALIZED)
{ {
mysql_rwlock_init(key_LOCK_SEQUENCE, &mutex); mysql_rwlock_init(key_LOCK_SEQUENCE, &mutex);
} }
...@@ -389,7 +389,7 @@ void SEQUENCE::read_unlock(TABLE *table) ...@@ -389,7 +389,7 @@ void SEQUENCE::read_unlock(TABLE *table)
This is called from ha_open() when the table is not yet locked This is called from ha_open() when the table is not yet locked
*/ */
int SEQUENCE::read_initial_values(TABLE *table_arg) int SEQUENCE::read_initial_values(TABLE *table)
{ {
int error= 0; int error= 0;
enum thr_lock_type save_lock_type; enum thr_lock_type save_lock_type;
...@@ -398,7 +398,6 @@ int SEQUENCE::read_initial_values(TABLE *table_arg) ...@@ -398,7 +398,6 @@ int SEQUENCE::read_initial_values(TABLE *table_arg)
if (likely(initialized != SEQ_UNINTIALIZED)) if (likely(initialized != SEQ_UNINTIALIZED))
DBUG_RETURN(0); DBUG_RETURN(0);
table= table_arg;
write_lock(table); write_lock(table);
if (likely(initialized == SEQ_UNINTIALIZED)) if (likely(initialized == SEQ_UNINTIALIZED))
{ {
...@@ -438,7 +437,8 @@ int SEQUENCE::read_initial_values(TABLE *table_arg) ...@@ -438,7 +437,8 @@ int SEQUENCE::read_initial_values(TABLE *table_arg)
thd->mdl_context.release_lock(mdl_request.ticket); thd->mdl_context.release_lock(mdl_request.ticket);
DBUG_RETURN(HA_ERR_LOCK_WAIT_TIMEOUT); DBUG_RETURN(HA_ERR_LOCK_WAIT_TIMEOUT);
} }
if (!(error= read_stored_values())) DBUG_ASSERT(table->reginfo.lock_type == TL_READ);
if (!(error= read_stored_values(table)))
initialized= SEQ_READY_TO_USE; initialized= SEQ_READY_TO_USE;
mysql_unlock_tables(thd, lock, 0); mysql_unlock_tables(thd, lock, 0);
if (mdl_lock_used) if (mdl_lock_used)
...@@ -467,7 +467,7 @@ int SEQUENCE::read_initial_values(TABLE *table_arg) ...@@ -467,7 +467,7 @@ int SEQUENCE::read_initial_values(TABLE *table_arg)
Called once from when table is opened Called once from when table is opened
*/ */
int SEQUENCE::read_stored_values() int SEQUENCE::read_stored_values(TABLE *table)
{ {
int error; int error;
my_bitmap_map *save_read_set; my_bitmap_map *save_read_set;
...@@ -621,7 +621,7 @@ int sequence_definition::write(TABLE *table, bool all_fields) ...@@ -621,7 +621,7 @@ int sequence_definition::write(TABLE *table, bool all_fields)
push_warning_printf(WARN_LEVEL_WARN) has been called push_warning_printf(WARN_LEVEL_WARN) has been called
@retval 0 Next number or error. Check error variable @retval 0 Next number or error. Check error variable
# Next sequence number # Next sequence number
NOTES: NOTES:
...@@ -755,7 +755,7 @@ void SEQUENCE_LAST_VALUE::set_version(TABLE *table) ...@@ -755,7 +755,7 @@ void SEQUENCE_LAST_VALUE::set_version(TABLE *table)
@param in next_round Round for 'next_value' (in cace of cycles) @param in next_round Round for 'next_value' (in cace of cycles)
@param in is_used 1 if next_val is already used @param in is_used 1 if next_val is already used
@retval 0 ok, value adjusted @retval 0 ok, value adjusted
1 value was less than current value or 1 value was less than current value or
error when storing value error when storing value
......
...@@ -93,7 +93,7 @@ class SEQUENCE :public sequence_definition ...@@ -93,7 +93,7 @@ class SEQUENCE :public sequence_definition
SEQUENCE(); SEQUENCE();
~SEQUENCE(); ~SEQUENCE();
int read_initial_values(TABLE *table); int read_initial_values(TABLE *table);
int read_stored_values(); int read_stored_values(TABLE *table);
void write_lock(TABLE *table); void write_lock(TABLE *table);
void write_unlock(TABLE *table); void write_unlock(TABLE *table);
void read_lock(TABLE *table); void read_lock(TABLE *table);
...@@ -132,7 +132,6 @@ class SEQUENCE :public sequence_definition ...@@ -132,7 +132,6 @@ class SEQUENCE :public sequence_definition
seq_init initialized; seq_init initialized;
private: private:
TABLE *table;
mysql_rwlock_t mutex; mysql_rwlock_t mutex;
}; };
......
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