diff options
author | Sergey Vojtovich <svoj@mariadb.org> | 2014-12-02 14:50:18 +0400 |
---|---|---|
committer | Sergey Vojtovich <svoj@mariadb.org> | 2014-12-05 11:01:49 +0400 |
commit | 9bc5cec0f115d7d0c277a49b91b96109560280f4 (patch) | |
tree | 0513fb2a87651c5a3d948733141a09399b17a67f | |
parent | faf169d245d05a835ec8ebcf1defb556c85f2766 (diff) | |
download | mariadb-git-9bc5cec0f115d7d0c277a49b91b96109560280f4.tar.gz |
MDEV-7004 - Merge scalability fixes from 10.0-power
Preallocate locks on THD mem_root to avoid expensive malloc.
-rw-r--r-- | sql/lock.cc | 31 | ||||
-rw-r--r-- | sql/lock.h | 6 |
2 files changed, 19 insertions, 18 deletions
diff --git a/sql/lock.cc b/sql/lock.cc index 170795a1662..a0796db7367 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -404,9 +404,10 @@ void mysql_unlock_tables(THD *thd, MYSQL_LOCK *sql_lock, bool free_lock) void mysql_unlock_some_tables(THD *thd, TABLE **table,uint count) { - MYSQL_LOCK *sql_lock; - if ((sql_lock= get_lock_data(thd, table, count, GET_LOCK_UNLOCK))) - mysql_unlock_tables(thd, sql_lock, 1); + MYSQL_LOCK *sql_lock= + get_lock_data(thd, table, count, GET_LOCK_UNLOCK | GET_LOCK_ON_THD); + if (sql_lock) + mysql_unlock_tables(thd, sql_lock, 0); } @@ -553,11 +554,10 @@ void mysql_lock_abort(THD *thd, TABLE *table, bool upgrade_lock) MYSQL_LOCK *locked; DBUG_ENTER("mysql_lock_abort"); - if ((locked= get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK))) + if ((locked= get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK | GET_LOCK_ON_THD))) { for (uint i=0; i < locked->lock_count; i++) thr_abort_locks(locked->locks[i]->lock, upgrade_lock); - my_free(locked); } DBUG_VOID_RETURN; } @@ -581,7 +581,7 @@ bool mysql_lock_abort_for_thread(THD *thd, TABLE *table) bool result= FALSE; DBUG_ENTER("mysql_lock_abort_for_thread"); - if ((locked= get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK))) + if ((locked= get_lock_data(thd, &table, 1, GET_LOCK_UNLOCK | GET_LOCK_ON_THD))) { for (uint i=0; i < locked->lock_count; i++) { @@ -589,7 +589,6 @@ bool mysql_lock_abort_for_thread(THD *thd, TABLE *table) table->in_use->thread_id)) result= TRUE; } - my_free(locked); } DBUG_RETURN(result); } @@ -707,7 +706,6 @@ MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags) TABLE **to, **table_buf; DBUG_ENTER("get_lock_data"); - DBUG_ASSERT((flags == GET_LOCK_UNLOCK) || (flags == GET_LOCK_STORE_LOCKS)); DBUG_PRINT("info", ("count %d", count)); for (i=lock_count=table_count=0 ; i < count ; i++) @@ -728,11 +726,12 @@ MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags) update the table values. So the second part of the array is copied from the first part immediately before calling thr_multi_lock(). */ - if (!(sql_lock= (MYSQL_LOCK*) - my_malloc(sizeof(*sql_lock) + - sizeof(THR_LOCK_DATA*) * lock_count * 2 + - sizeof(table_ptr) * table_count, - MYF(0)))) + size_t amount= sizeof(*sql_lock) + + sizeof(THR_LOCK_DATA*) * lock_count * 2 + + sizeof(table_ptr) * table_count; + if (!(sql_lock= (MYSQL_LOCK*) (flags & GET_LOCK_ON_THD ? + thd->alloc(amount) : + my_malloc(amount, MYF(0))))) DBUG_RETURN(0); locks= locks_buf= sql_lock->locks= (THR_LOCK_DATA**) (sql_lock + 1); to= table_buf= sql_lock->table= (TABLE**) (locks + lock_count * 2); @@ -751,9 +750,9 @@ MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags) DBUG_ASSERT(lock_type != TL_WRITE_DEFAULT && lock_type != TL_READ_DEFAULT); locks_start= locks; locks= table->file->store_lock(thd, locks, - (flags & GET_LOCK_UNLOCK) ? TL_IGNORE : - lock_type); - if (flags & GET_LOCK_STORE_LOCKS) + (flags & GET_LOCK_ACTION_MASK) == GET_LOCK_UNLOCK ? TL_IGNORE : + lock_type); + if ((flags & GET_LOCK_ACTION_MASK) == GET_LOCK_STORE_LOCKS) { table->lock_position= (uint) (to - table_buf); table->lock_data_start= (uint) (locks_start - locks_buf); diff --git a/sql/lock.h b/sql/lock.h index a4833cdc38e..ca2f267f3d5 100644 --- a/sql/lock.h +++ b/sql/lock.h @@ -42,8 +42,10 @@ bool lock_object_name(THD *thd, MDL_key::enum_mdl_namespace mdl_type, const char *db, const char *name); /* flags for get_lock_data */ -#define GET_LOCK_UNLOCK 1 -#define GET_LOCK_STORE_LOCKS 2 +#define GET_LOCK_UNLOCK 0 +#define GET_LOCK_STORE_LOCKS 1 +#define GET_LOCK_ACTION_MASK 1 +#define GET_LOCK_ON_THD (1 << 1) MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, uint flags); void reset_lock_data(MYSQL_LOCK *sql_lock, bool unlock); |