diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-10-28 10:01:50 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-10-28 10:01:50 +0200 |
commit | a8de8f261d1b7621b8e16396e87dfaac14891162 (patch) | |
tree | 9b8ec45858c2757305e0bdecf237fcb59251020c /storage/innobase/dict | |
parent | e183aec1d75ea7b424ebe237e6b1643961903f2d (diff) | |
parent | 42e1815ad850384fad292534665ff61b78dd96f6 (diff) | |
download | mariadb-git-a8de8f261d1b7621b8e16396e87dfaac14891162.tar.gz |
Merge 10.2 into 10.3
Diffstat (limited to 'storage/innobase/dict')
-rw-r--r-- | storage/innobase/dict/dict0dict.cc | 149 | ||||
-rw-r--r-- | storage/innobase/dict/dict0mem.cc | 48 | ||||
-rw-r--r-- | storage/innobase/dict/dict0stats.cc | 10 |
3 files changed, 47 insertions, 160 deletions
diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index a6d6e9e6b3c..2e165a3a7bc 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -60,7 +60,6 @@ extern uint ibuf_debug; #include "lock0lock.h" #include "mach0data.h" #include "mem0mem.h" -#include "os0once.h" #include "page0page.h" #include "page0zip.h" #include "pars0pars.h" @@ -263,76 +262,6 @@ dict_mutex_exit_for_mysql(void) mutex_exit(&dict_sys->mutex); } -/** Allocate and init a dict_table_t's stats latch. -This function must not be called concurrently on the same table object. -@param[in,out] table_void table whose stats latch to create */ -static -void -dict_table_stats_latch_alloc( - void* table_void) -{ - dict_table_t* table = static_cast<dict_table_t*>(table_void); - - /* Note: rw_lock_create() will call the constructor */ - - table->stats_latch = static_cast<rw_lock_t*>( - ut_malloc_nokey(sizeof(rw_lock_t))); - - ut_a(table->stats_latch != NULL); - - rw_lock_create(dict_table_stats_key, table->stats_latch, - SYNC_INDEX_TREE); -} - -/** Deinit and free a dict_table_t's stats latch. -This function must not be called concurrently on the same table object. -@param[in,out] table table whose stats latch to free */ -static -void -dict_table_stats_latch_free( - dict_table_t* table) -{ - rw_lock_free(table->stats_latch); - ut_free(table->stats_latch); -} - -/** Create a dict_table_t's stats latch or delay for lazy creation. -This function is only called from either single threaded environment -or from a thread that has not shared the table object with other threads. -@param[in,out] table table whose stats latch to create -@param[in] enabled if false then the latch is disabled -and dict_table_stats_lock()/unlock() become noop on this table. */ -void -dict_table_stats_latch_create( - dict_table_t* table, - bool enabled) -{ - if (!enabled) { - table->stats_latch = NULL; - table->stats_latch_created = os_once::DONE; - return; - } - - /* We create this lazily the first time it is used. */ - table->stats_latch = NULL; - table->stats_latch_created = os_once::NEVER_DONE; -} - -/** Destroy a dict_table_t's stats latch. -This function is only called from either single threaded environment -or from a thread that has not shared the table object with other threads. -@param[in,out] table table whose stats latch to destroy */ -void -dict_table_stats_latch_destroy( - dict_table_t* table) -{ - if (table->stats_latch_created == os_once::DONE - && table->stats_latch != NULL) { - - dict_table_stats_latch_free(table); - } -} - /** Lock the appropriate latch to protect a given table's statistics. @param[in] table table whose stats to lock @param[in] latch_mode RW_S_LATCH or RW_X_LATCH */ @@ -344,23 +273,12 @@ dict_table_stats_lock( ut_ad(table != NULL); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); - os_once::do_or_wait_for_done( - &table->stats_latch_created, - dict_table_stats_latch_alloc, table); - - if (table->stats_latch == NULL) { - /* This is a dummy table object that is private in the current - thread and is not shared between multiple threads, thus we - skip any locking. */ - return; - } - switch (latch_mode) { case RW_S_LATCH: - rw_lock_s_lock(table->stats_latch); + rw_lock_s_lock(&table->stats_latch); break; case RW_X_LATCH: - rw_lock_x_lock(table->stats_latch); + rw_lock_x_lock(&table->stats_latch); break; case RW_NO_LATCH: /* fall through */ @@ -380,19 +298,12 @@ dict_table_stats_unlock( ut_ad(table != NULL); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); - if (table->stats_latch == NULL) { - /* This is a dummy table object that is private in the current - thread and is not shared between multiple threads, thus we - skip any locking. */ - return; - } - switch (latch_mode) { case RW_S_LATCH: - rw_lock_s_unlock(table->stats_latch); + rw_lock_s_unlock(&table->stats_latch); break; case RW_X_LATCH: - rw_lock_x_unlock(table->stats_latch); + rw_lock_x_unlock(&table->stats_latch); break; case RW_NO_LATCH: /* fall through */ @@ -734,34 +645,6 @@ dict_table_get_nth_v_col_mysql( return(dict_table_get_nth_v_col(table, i)); } -/** Allocate and init the autoinc latch of a given table. -This function must not be called concurrently on the same table object. -@param[in,out] table_void table whose autoinc latch to create */ -static -void -dict_table_autoinc_alloc( - void* table_void) -{ - dict_table_t* table = static_cast<dict_table_t*>(table_void); - table->autoinc_mutex = UT_NEW_NOKEY(ib_mutex_t()); - ut_a(table->autoinc_mutex != NULL); - mutex_create(LATCH_ID_AUTOINC, table->autoinc_mutex); -} - -/** Allocate and init the zip_pad_mutex of a given index. -This function must not be called concurrently on the same index object. -@param[in,out] index_void index whose zip_pad_mutex to create */ -static -void -dict_index_zip_pad_alloc( - void* index_void) -{ - dict_index_t* index = static_cast<dict_index_t*>(index_void); - index->zip_pad.mutex = UT_NEW_NOKEY(SysMutex()); - ut_a(index->zip_pad.mutex != NULL); - mutex_create(LATCH_ID_ZIP_PAD_MUTEX, index->zip_pad.mutex); -} - /********************************************************************//** Acquire the autoinc lock. */ void @@ -769,11 +652,7 @@ dict_table_autoinc_lock( /*====================*/ dict_table_t* table) /*!< in/out: table */ { - os_once::do_or_wait_for_done( - &table->autoinc_mutex_created, - dict_table_autoinc_alloc, table); - - mutex_enter(table->autoinc_mutex); + mysql_mutex_lock(&table->autoinc_mutex); } /** Acquire the zip_pad_mutex latch. @@ -783,11 +662,7 @@ void dict_index_zip_pad_lock( dict_index_t* index) { - os_once::do_or_wait_for_done( - &index->zip_pad.mutex_created, - dict_index_zip_pad_alloc, index); - - mutex_enter(index->zip_pad.mutex); + mysql_mutex_lock(&index->zip_pad.mutex); } /** Get all the FTS indexes on a table. @@ -822,7 +697,7 @@ dict_table_autoinc_unlock( /*======================*/ dict_table_t* table) /*!< in/out: table */ { - mutex_exit(table->autoinc_mutex); + mysql_mutex_unlock(&table->autoinc_mutex); } /** Looks for column n in an index. @@ -1254,6 +1129,7 @@ dict_table_t::add_to_cache() ut_ad(dict_lru_validate()); ut_ad(mutex_own(&dict_sys->mutex)); + mysql_mutex_init(0, &autoinc_mutex, NULL); cached = TRUE; ulint fold = ut_fold_string(name.m_name); @@ -1395,7 +1271,7 @@ dict_index_t *dict_index_t::clone() const (mem_heap_zalloc(heap, n_uniq * sizeof *stat_n_sample_sizes)); index->stat_n_non_null_key_vals= static_cast<ib_uint64_t*> (mem_heap_zalloc(heap, n_uniq * sizeof *stat_n_non_null_key_vals)); - memset(&index->zip_pad, 0, sizeof index->zip_pad); + mysql_mutex_init(0, &index->zip_pad.mutex, NULL); return index; } @@ -2086,8 +1962,15 @@ dict_table_remove_from_cache_low( UT_DELETE(table->vc_templ); } + mysql_mutex_destroy(&table->autoinc_mutex); #ifdef BTR_CUR_HASH_ADAPT if (UNIV_UNLIKELY(UT_LIST_GET_LEN(table->freed_indexes) != 0)) { + if (table->fts) { + fts_optimize_remove_table(table); + fts_free(table); + table->fts = NULL; + } + table->vc_templ = NULL; table->id = 0; return; diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index 78ed717156c..a7201f165c0 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -115,19 +115,24 @@ operator<<( return(s << ut_get_name(NULL, table_name.m_name)); } -/**********************************************************************//** -Creates a table memory object. +/** Create a table memory object. +@param name table name +@param space tablespace +@param n_cols total number of columns (both virtual and non-virtual) +@param n_v_cols number of virtual columns +@param flags table flags +@param flags2 table flags2 +@param init_stats_latch whether to init the stats latch @return own: table object */ dict_table_t* dict_mem_table_create( -/*==================*/ - const char* name, /*!< in: table name */ - fil_space_t* space, /*!< in: tablespace */ - ulint n_cols, /*!< in: total number of columns including - virtual and non-virtual columns */ - ulint n_v_cols,/*!< in: number of virtual columns */ - ulint flags, /*!< in: table flags */ - ulint flags2) /*!< in: table flags2 */ + const char* name, + fil_space_t* space, + ulint n_cols, + ulint n_v_cols, + ulint flags, + ulint flags2, + bool init_stats_latch) { dict_table_t* table; mem_heap_t* heap; @@ -171,16 +176,9 @@ dict_mem_table_create( table->v_cols = static_cast<dict_v_col_t*>( mem_heap_alloc(heap, n_v_cols * sizeof(*table->v_cols))); - /* true means that the stats latch will be enabled - - dict_table_stats_lock() will not be noop. */ - dict_table_stats_latch_create(table, true); - table->autoinc_lock = static_cast<ib_lock_t*>( mem_heap_alloc(heap, lock_get_size())); - /* lazy creation of table autoinc latch */ - dict_table_autoinc_create_lazy(table); - /* If the table has an FTS index or we are in the process of building one, create the table->fts */ if (dict_table_has_fts_index(table) @@ -195,6 +193,12 @@ dict_mem_table_create( new(&table->foreign_set) dict_foreign_set(); new(&table->referenced_set) dict_foreign_set(); + if (init_stats_latch) { + rw_lock_create(dict_table_stats_key, &table->stats_latch, + SYNC_INDEX_TREE); + table->stats_latch_inited = true; + } + return(table); } @@ -223,9 +227,7 @@ dict_mem_table_free( } } - dict_table_autoinc_destroy(table); dict_mem_table_free_foreign_vcol_set(table); - dict_table_stats_latch_destroy(table); table->foreign_set.~dict_foreign_set(); table->referenced_set.~dict_foreign_set(); @@ -246,6 +248,10 @@ dict_mem_table_free( UT_DELETE(table->s_cols); } + if (table->stats_latch_inited) { + rw_lock_free(&table->stats_latch); + } + mem_heap_free(table->heap); } @@ -778,7 +784,7 @@ dict_mem_index_create( dict_mem_fill_index_struct(index, heap, index_name, type, n_fields); - dict_index_zip_pad_mutex_create_lazy(index); + mysql_mutex_init(0, &index->zip_pad.mutex, NULL); if (type & DICT_SPATIAL) { index->rtr_track = static_cast<rtr_info_track_t*>( @@ -1093,7 +1099,7 @@ dict_mem_index_free( ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); - dict_index_zip_pad_mutex_destroy(index); + mysql_mutex_destroy(&index->zip_pad.mutex); if (dict_index_is_spatial(index)) { rtr_info_active::iterator it; diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc index 758a95017c9..2c0ba38886f 100644 --- a/storage/innobase/dict/dict0stats.cc +++ b/storage/innobase/dict/dict0stats.cc @@ -33,6 +33,7 @@ Created Jan 06, 2010 Vasil Dimov #include "pars0pars.h" #include <mysql_com.h> #include "btr0btr.h" +#include "sync0sync.h" #include <algorithm> #include <map> @@ -418,11 +419,6 @@ dict_stats_table_clone_create( t->corrupted = table->corrupted; - /* This private object "t" is not shared with other threads, so - we do not need the stats_latch (thus we pass false below). The - dict_table_stats_lock()/unlock() routines will do nothing. */ - dict_table_stats_latch_create(t, false); - UT_LIST_INIT(t->indexes, &dict_index_t::indexes); #ifdef BTR_CUR_HASH_ADAPT UT_LIST_INIT(t->freed_indexes, &dict_index_t::indexes); @@ -488,6 +484,8 @@ dict_stats_table_clone_create( ut_d(t->magic_n = DICT_TABLE_MAGIC_N); + rw_lock_create(dict_table_stats_key, &t->stats_latch, SYNC_INDEX_TREE); + return(t); } @@ -500,7 +498,7 @@ dict_stats_table_clone_free( /*========================*/ dict_table_t* t) /*!< in: dummy table object to free */ { - dict_table_stats_latch_destroy(t); + rw_lock_free(&t->stats_latch); mem_heap_free(t->heap); } |