diff options
Diffstat (limited to 'storage/innobase/include')
-rw-r--r-- | storage/innobase/include/fil0fil.h | 3 | ||||
-rw-r--r-- | storage/innobase/include/lock0lock.h | 63 | ||||
-rw-r--r-- | storage/innobase/include/lock0priv.h | 139 | ||||
-rw-r--r-- | storage/innobase/include/lock0priv.ic | 12 | ||||
-rw-r--r-- | storage/innobase/include/lock0types.h | 192 | ||||
-rw-r--r-- | storage/innobase/include/log0recv.h | 18 | ||||
-rw-r--r-- | storage/innobase/include/trx0sys.h | 7 | ||||
-rw-r--r-- | storage/innobase/include/trx0trx.h | 22 | ||||
-rw-r--r-- | storage/innobase/include/ut0pool.h | 20 |
9 files changed, 245 insertions, 231 deletions
diff --git a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h index 968fd1573c6..eb00239ca4e 100644 --- a/storage/innobase/include/fil0fil.h +++ b/storage/innobase/include/fil0fil.h @@ -327,6 +327,9 @@ struct fil_node_t { { return(handle != OS_FILE_CLOSED); } + + /** Close the file handle. */ + void close(); }; /** Value of fil_node_t::magic_n */ diff --git a/storage/innobase/include/lock0lock.h b/storage/innobase/include/lock0lock.h index e4b8947ac3a..0f6fe158264 100644 --- a/storage/innobase/include/lock0lock.h +++ b/storage/innobase/include/lock0lock.h @@ -806,69 +806,6 @@ lock_trx_has_expl_x_lock( MY_ATTRIBUTE((nonnull, warn_unused_result)); #endif /* UNIV_DEBUG */ -/** -Allocate cached locks for the transaction. -@param trx allocate cached record locks for this transaction */ -void -lock_trx_alloc_locks(trx_t* trx); - -/** Lock modes and types */ -/* @{ */ -#define LOCK_MODE_MASK 0xFUL /*!< mask used to extract mode from the - type_mode field in a lock */ -/** Lock types */ -/* @{ */ -#define LOCK_TABLE 16U /*!< table lock */ -#define LOCK_REC 32U /*!< record lock */ -#define LOCK_TYPE_MASK 0xF0UL /*!< mask used to extract lock type from the - type_mode field in a lock */ -#if LOCK_MODE_MASK & LOCK_TYPE_MASK -# error "LOCK_MODE_MASK & LOCK_TYPE_MASK" -#endif - -#define LOCK_WAIT 256U /*!< Waiting lock flag; when set, it - means that the lock has not yet been - granted, it is just waiting for its - turn in the wait queue */ -/* Precise modes */ -#define LOCK_ORDINARY 0 /*!< this flag denotes an ordinary - next-key lock in contrast to LOCK_GAP - or LOCK_REC_NOT_GAP */ -#define LOCK_GAP 512U /*!< when this bit is set, it means that the - lock holds only on the gap before the record; - for instance, an x-lock on the gap does not - give permission to modify the record on which - the bit is set; locks of this type are created - when records are removed from the index chain - of records */ -#define LOCK_REC_NOT_GAP 1024U /*!< this bit means that the lock is only on - the index record and does NOT block inserts - to the gap before the index record; this is - used in the case when we retrieve a record - with a unique key, and is also used in - locking plain SELECTs (not part of UPDATE - or DELETE) when the user has set the READ - COMMITTED isolation level */ -#define LOCK_INSERT_INTENTION 2048U/*!< this bit is set when we place a waiting - gap type record lock request in order to let - an insert of an index record to wait until - there are no conflicting locks by other - transactions on the gap; note that this flag - remains set when the waiting lock is granted, - or if the lock is inherited to a neighboring - record */ -#define LOCK_PREDICATE 8192U /*!< Predicate lock */ -#define LOCK_PRDT_PAGE 16384U /*!< Page lock */ - - -#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION|LOCK_PREDICATE|LOCK_PRDT_PAGE)&LOCK_MODE_MASK -# error -#endif -#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION|LOCK_PREDICATE|LOCK_PRDT_PAGE)&LOCK_TYPE_MASK -# error -#endif -/* @} */ - /** Lock operation struct */ struct lock_op_t{ dict_table_t* table; /*!< table to be locked */ diff --git a/storage/innobase/include/lock0priv.h b/storage/innobase/include/lock0priv.h index f5b2b51acfc..d9377e97d40 100644 --- a/storage/innobase/include/lock0priv.h +++ b/storage/innobase/include/lock0priv.h @@ -42,19 +42,6 @@ those functions in lock/ */ #define UINT32_MAX (4294967295U) #endif -/** A table lock */ -struct lock_table_t { - dict_table_t* table; /*!< database table in dictionary - cache */ - UT_LIST_NODE_T(lock_t) - locks; /*!< list of locks on the same - table */ - /** Print the table lock into the given output stream - @param[in,out] out the output stream - @return the given output stream. */ - std::ostream& print(std::ostream& out) const; -}; - /** Print the table lock into the given output stream @param[in,out] out the output stream @return the given output stream. */ @@ -77,131 +64,11 @@ operator<<(std::ostream& out, const lock_table_t& lock) return(lock.print(out)); } -/** Record lock for a page */ -struct lock_rec_t { - ib_uint32_t space; /*!< space id */ - ib_uint32_t page_no; /*!< page number */ - ib_uint32_t n_bits; /*!< number of bits in the lock - bitmap; NOTE: the lock bitmap is - placed immediately after the - lock struct */ - - /** Print the record lock into the given output stream - @param[in,out] out the output stream - @return the given output stream. */ - std::ostream& print(std::ostream& out) const; -}; - -/** Print the record lock into the given output stream -@param[in,out] out the output stream -@return the given output stream. */ -inline -std::ostream& lock_rec_t::print(std::ostream& out) const -{ - out << "[lock_rec_t: space=" << space << ", page_no=" << page_no - << ", n_bits=" << n_bits << "]"; - return(out); -} - -inline -std::ostream& -operator<<(std::ostream& out, const lock_rec_t& lock) -{ - return(lock.print(out)); -} - -/** Lock struct; protected by lock_sys.mutex */ -struct lock_t { - trx_t* trx; /*!< transaction owning the - lock */ - UT_LIST_NODE_T(lock_t) - trx_locks; /*!< list of the locks of the - transaction */ - - dict_index_t* index; /*!< index for a record lock */ - - lock_t* hash; /*!< hash chain node for a record - lock. The link node in a singly linked - list, used during hashing. */ - - /* Statistics for how long lock has been held and time - how long this lock had to be waited before it was granted */ - time_t requested_time; /*!< Lock request time */ - ulint wait_time; /*!< Time waited this lock or 0 */ - - union { - lock_table_t tab_lock;/*!< table lock */ - lock_rec_t rec_lock;/*!< record lock */ - } un_member; /*!< lock details */ - - ib_uint32_t type_mode; /*!< lock type, mode, LOCK_GAP or - LOCK_REC_NOT_GAP, - LOCK_INSERT_INTENTION, - wait flag, ORed */ - - /** Determine if the lock object is a record lock. - @return true if record lock, false otherwise. */ - bool is_record_lock() const - { - return(type() == LOCK_REC); - } - - bool is_waiting() const - { - return(type_mode & LOCK_WAIT); - } - - bool is_gap() const - { - return(type_mode & LOCK_GAP); - } - - bool is_record_not_gap() const - { - return(type_mode & LOCK_REC_NOT_GAP); - } - - bool is_insert_intention() const - { - return(type_mode & LOCK_INSERT_INTENTION); - } - - ulint type() const { - return(type_mode & LOCK_TYPE_MASK); - } - - enum lock_mode mode() const - { - return(static_cast<enum lock_mode>(type_mode & LOCK_MODE_MASK)); - } - - /** Print the lock object into the given output stream. - @param[in,out] out the output stream - @return the given output stream. */ - std::ostream& print(std::ostream& out) const; - - /** Convert the member 'type_mode' into a human readable string. - @return human readable string */ - std::string type_mode_string() const; - - const char* type_string() const - { - switch (type_mode & LOCK_TYPE_MASK) { - case LOCK_REC: - return("LOCK_REC"); - case LOCK_TABLE: - return("LOCK_TABLE"); - default: - ut_error; - } - } -}; - /** Convert the member 'type_mode' into a human readable string. @return human readable string */ inline std::string -lock_t::type_mode_string() const +ib_lock_t::type_mode_string() const { std::ostringstream sout; sout << type_string(); @@ -227,7 +94,7 @@ lock_t::type_mode_string() const inline std::ostream& -lock_t::print(std::ostream& out) const +ib_lock_t::print(std::ostream& out) const { out << "[lock_t: type_mode=" << type_mode << "(" << type_mode_string() << ")"; @@ -244,7 +111,7 @@ lock_t::print(std::ostream& out) const inline std::ostream& -operator<<(std::ostream& out, const lock_t& lock) +operator<<(std::ostream& out, const ib_lock_t& lock) { return(lock.print(out)); } diff --git a/storage/innobase/include/lock0priv.ic b/storage/innobase/include/lock0priv.ic index 150a80b7be4..b5be9076644 100644 --- a/storage/innobase/include/lock0priv.ic +++ b/storage/innobase/include/lock0priv.ic @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 2007, 2014, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2018, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -388,17 +389,10 @@ lock_table_has( const dict_table_t* table, /*!< in: table */ lock_mode in_mode)/*!< in: lock mode */ { - if (trx->lock.table_locks.empty()) { - return(NULL); - } - - typedef lock_pool_t::const_reverse_iterator iterator; - - iterator end = trx->lock.table_locks.rend(); - /* Look for stronger locks the same trx already has on the table */ - for (iterator it = trx->lock.table_locks.rbegin(); it != end; ++it) { + for (lock_list::const_iterator it = trx->lock.table_locks.begin(), + end = trx->lock.table_locks.end(); it != end; ++it) { const lock_t* lock = *it; diff --git a/storage/innobase/include/lock0types.h b/storage/innobase/include/lock0types.h index 792a5f21acb..1aac5d20a59 100644 --- a/storage/innobase/include/lock0types.h +++ b/storage/innobase/include/lock0types.h @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2015, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2018, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -72,6 +73,195 @@ const char* lock_mode_string(enum lock_mode mode) } } -typedef UT_LIST_BASE_NODE_T(lock_t) trx_lock_list_t; +/** A table lock */ +struct lock_table_t { + dict_table_t* table; /*!< database table in dictionary + cache */ + UT_LIST_NODE_T(ib_lock_t) + locks; /*!< list of locks on the same + table */ + /** Print the table lock into the given output stream + @param[in,out] out the output stream + @return the given output stream. */ + std::ostream& print(std::ostream& out) const; +}; + +/** Record lock for a page */ +struct lock_rec_t { + ib_uint32_t space; /*!< space id */ + ib_uint32_t page_no; /*!< page number */ + ib_uint32_t n_bits; /*!< number of bits in the lock + bitmap; NOTE: the lock bitmap is + placed immediately after the + lock struct */ + + /** Print the record lock into the given output stream + @param[in,out] out the output stream + @return the given output stream. */ + std::ostream& print(std::ostream& out) const; +}; + +/** Print the record lock into the given output stream +@param[in,out] out the output stream +@return the given output stream. */ +inline +std::ostream& lock_rec_t::print(std::ostream& out) const +{ + out << "[lock_rec_t: space=" << space << ", page_no=" << page_no + << ", n_bits=" << n_bits << "]"; + return(out); +} + +inline +std::ostream& +operator<<(std::ostream& out, const lock_rec_t& lock) +{ + return(lock.print(out)); +} + +#define LOCK_MODE_MASK 0xFUL /*!< mask used to extract mode from the + type_mode field in a lock */ +/** Lock types */ +/* @{ */ +#define LOCK_TABLE 16U /*!< table lock */ +#define LOCK_REC 32U /*!< record lock */ +#define LOCK_TYPE_MASK 0xF0UL /*!< mask used to extract lock type from the + type_mode field in a lock */ +#if LOCK_MODE_MASK & LOCK_TYPE_MASK +# error "LOCK_MODE_MASK & LOCK_TYPE_MASK" +#endif + +#define LOCK_WAIT 256U /*!< Waiting lock flag; when set, it + means that the lock has not yet been + granted, it is just waiting for its + turn in the wait queue */ +/* Precise modes */ +#define LOCK_ORDINARY 0 /*!< this flag denotes an ordinary + next-key lock in contrast to LOCK_GAP + or LOCK_REC_NOT_GAP */ +#define LOCK_GAP 512U /*!< when this bit is set, it means that the + lock holds only on the gap before the record; + for instance, an x-lock on the gap does not + give permission to modify the record on which + the bit is set; locks of this type are created + when records are removed from the index chain + of records */ +#define LOCK_REC_NOT_GAP 1024U /*!< this bit means that the lock is only on + the index record and does NOT block inserts + to the gap before the index record; this is + used in the case when we retrieve a record + with a unique key, and is also used in + locking plain SELECTs (not part of UPDATE + or DELETE) when the user has set the READ + COMMITTED isolation level */ +#define LOCK_INSERT_INTENTION 2048U/*!< this bit is set when we place a waiting + gap type record lock request in order to let + an insert of an index record to wait until + there are no conflicting locks by other + transactions on the gap; note that this flag + remains set when the waiting lock is granted, + or if the lock is inherited to a neighboring + record */ +#define LOCK_PREDICATE 8192U /*!< Predicate lock */ +#define LOCK_PRDT_PAGE 16384U /*!< Page lock */ + + +#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION|LOCK_PREDICATE|LOCK_PRDT_PAGE)&LOCK_MODE_MASK +# error +#endif +#if (LOCK_WAIT|LOCK_GAP|LOCK_REC_NOT_GAP|LOCK_INSERT_INTENTION|LOCK_PREDICATE|LOCK_PRDT_PAGE)&LOCK_TYPE_MASK +# error +#endif +/* @} */ + +/** Lock struct; protected by lock_sys.mutex */ +struct ib_lock_t +{ + trx_t* trx; /*!< transaction owning the + lock */ + UT_LIST_NODE_T(ib_lock_t) + trx_locks; /*!< list of the locks of the + transaction */ + + dict_index_t* index; /*!< index for a record lock */ + + ib_lock_t* hash; /*!< hash chain node for a record + lock. The link node in a singly linked + list, used during hashing. */ + + /* Statistics for how long lock has been held and time + how long this lock had to be waited before it was granted */ + time_t requested_time; /*!< Lock request time */ + ulint wait_time; /*!< Time waited this lock or 0 */ + + union { + lock_table_t tab_lock;/*!< table lock */ + lock_rec_t rec_lock;/*!< record lock */ + } un_member; /*!< lock details */ + + ib_uint32_t type_mode; /*!< lock type, mode, LOCK_GAP or + LOCK_REC_NOT_GAP, + LOCK_INSERT_INTENTION, + wait flag, ORed */ + + /** Determine if the lock object is a record lock. + @return true if record lock, false otherwise. */ + bool is_record_lock() const + { + return(type() == LOCK_REC); + } + + bool is_waiting() const + { + return(type_mode & LOCK_WAIT); + } + + bool is_gap() const + { + return(type_mode & LOCK_GAP); + } + + bool is_record_not_gap() const + { + return(type_mode & LOCK_REC_NOT_GAP); + } + + bool is_insert_intention() const + { + return(type_mode & LOCK_INSERT_INTENTION); + } + + ulint type() const { + return(type_mode & LOCK_TYPE_MASK); + } + + enum lock_mode mode() const + { + return(static_cast<enum lock_mode>(type_mode & LOCK_MODE_MASK)); + } + + /** Print the lock object into the given output stream. + @param[in,out] out the output stream + @return the given output stream. */ + std::ostream& print(std::ostream& out) const; + + /** Convert the member 'type_mode' into a human readable string. + @return human readable string */ + std::string type_mode_string() const; + + const char* type_string() const + { + switch (type_mode & LOCK_TYPE_MASK) { + case LOCK_REC: + return("LOCK_REC"); + case LOCK_TABLE: + return("LOCK_TABLE"); + default: + ut_error; + } + } +}; + +typedef UT_LIST_BASE_NODE_T(ib_lock_t) trx_lock_list_t; #endif /* lock0types_h */ diff --git a/storage/innobase/include/log0recv.h b/storage/innobase/include/log0recv.h index 15ad34ba9a5..eda991661c1 100644 --- a/storage/innobase/include/log0recv.h +++ b/storage/innobase/include/log0recv.h @@ -139,9 +139,21 @@ bool recv_parse_log_recs(lsn_t checkpoint_lsn, store_t store, bool apply); /** Moves the parsing buffer data left to the buffer start. */ void recv_sys_justify_left_parsing_buf(); -/** Backup function checks whether the space id belongs to -the skip table list given in the mariabackup option. */ -extern bool(*check_if_backup_includes)(ulint space_id); +/** Report optimized DDL operation (without redo log), corresponding to MLOG_INDEX_LOAD. +@param[in] space_id tablespace identifier +*/ +extern void(*log_optimized_ddl_op)(ulint space_id); + +/** Report an operation to create, delete, or rename a file during backup. +@param[in] space_id tablespace identifier +@param[in] flags tablespace flags (NULL if not create) +@param[in] name file name (not NUL-terminated) +@param[in] len length of name, in bytes +@param[in] new_name new file name (NULL if not rename) +@param[in] new_len length of new_name, in bytes (0 if NULL) */ +extern void (*log_file_op)(ulint space_id, const byte* flags, + const byte* name, ulint len, + const byte* new_name, ulint new_len); /** Block of log record data */ struct recv_data_t{ diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h index 69374ab3fba..6af212d35ff 100644 --- a/storage/innobase/include/trx0sys.h +++ b/storage/innobase/include/trx0sys.h @@ -646,8 +646,11 @@ public: { mutex_enter(&element->mutex); lf_hash_search_unpin(pins); - if ((trx= element->trx)) - { + trx= element->trx; + if (!trx); + else if (UNIV_UNLIKELY(trx_id != trx->id)) + trx= NULL; + else { if (do_ref_count) trx->reference(); ut_d(validate_element(trx)); diff --git a/storage/innobase/include/trx0trx.h b/storage/innobase/include/trx0trx.h index 76d4e9caba0..d6a8b8c771b 100644 --- a/storage/innobase/include/trx0trx.h +++ b/storage/innobase/include/trx0trx.h @@ -476,7 +476,9 @@ Check transaction state */ @param t transaction handle */ #define assert_trx_is_free(t) do { \ ut_ad(trx_state_eq((t), TRX_STATE_NOT_STARTED)); \ - ut_ad(!trx->has_logged()); \ + ut_ad(!(t)->id); \ + ut_ad(!(t)->has_logged()); \ + ut_ad(!(t)->is_referenced()); \ ut_ad(!(t)->read_view.is_open()); \ ut_ad((t)->lock.wait_thr == NULL); \ ut_ad(UT_LIST_GET_LEN((t)->lock.trx_locks) == 0); \ @@ -517,7 +519,7 @@ The transaction must have mysql_thd assigned. */ # define assert_trx_nonlocking_or_in_list(trx) ((void)0) #endif /* UNIV_DEBUG */ -typedef std::vector<ib_lock_t*, ut_allocator<ib_lock_t*> > lock_pool_t; +typedef std::vector<ib_lock_t*, ut_allocator<ib_lock_t*> > lock_list; /*******************************************************************//** Latching protocol for trx_lock_t::que_state. trx_lock_t::que_state @@ -579,13 +581,19 @@ struct trx_lock_t { only be modified by the thread that is serving the running transaction. */ - lock_pool_t rec_pool; /*!< Pre-allocated record locks */ + /** Pre-allocated record locks */ + struct { + ib_lock_t lock; byte pad[256]; + } rec_pool[8]; - lock_pool_t table_pool; /*!< Pre-allocated table locks */ + /** Pre-allocated table locks */ + ib_lock_t table_pool[8]; - ulint rec_cached; /*!< Next free rec lock in pool */ + /** Next available rec_pool[] entry */ + unsigned rec_cached; - ulint table_cached; /*!< Next free table lock in pool */ + /** Next available table_pool[] entry */ + unsigned table_cached; mem_heap_t* lock_heap; /*!< memory heap for trx_locks; protected by lock_sys.mutex */ @@ -595,7 +603,7 @@ struct trx_lock_t { and lock_sys.mutex; removals are protected by lock_sys.mutex */ - lock_pool_t table_locks; /*!< All table locks requested by this + lock_list table_locks; /*!< All table locks requested by this transaction, including AUTOINC locks */ bool cancel; /*!< true if the transaction is being diff --git a/storage/innobase/include/ut0pool.h b/storage/innobase/include/ut0pool.h index 6367b53dbe6..d3ea733a440 100644 --- a/storage/innobase/include/ut0pool.h +++ b/storage/innobase/include/ut0pool.h @@ -125,8 +125,7 @@ struct Pool { elem = NULL; } - m_lock_strategy.exit(); - +#if defined HAVE_valgrind || defined __SANITIZE_ADDRESS__ if (elem) { /* Unpoison the memory for AddressSanitizer */ MEM_UNDEFINED(&elem->m_type, sizeof elem->m_type); @@ -135,10 +134,11 @@ struct Pool { actually initialized; we checked that by UNIV_MEM_ASSERT_RW() in mem_free() below. */ UNIV_MEM_VALID(&elem->m_type, sizeof elem->m_type); - return &elem->m_type; } +#endif - return NULL; + m_lock_strategy.exit(); + return elem ? &elem->m_type : NULL; } /** Add the object to the pool. @@ -151,8 +151,12 @@ struct Pool { elem = reinterpret_cast<Element*>(p - sizeof(*elem)); UNIV_MEM_ASSERT_RW(&elem->m_type, sizeof elem->m_type); - elem->m_pool->put(elem); + elem->m_pool->m_lock_strategy.enter(); + + elem->m_pool->putl(elem); MEM_NOACCESS(&elem->m_type, sizeof elem->m_type); + + elem->m_pool->m_lock_strategy.exit(); } protected: @@ -170,17 +174,13 @@ private: /** Release the object to the free pool @param elem element to free */ - void put(Element* elem) + void putl(Element* elem) { - m_lock_strategy.enter(); - ut_ad(elem >= m_start && elem < m_last); ut_ad(Factory::debug(&elem->m_type)); m_pqueue.push(elem); - - m_lock_strategy.exit(); } /** Initialise the elements. |