diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2018-01-31 10:24:19 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2018-01-31 10:24:19 +0200 |
commit | c7d0448797a2013079c3e0b7ca97f7bdc1138696 (patch) | |
tree | 32229a9a3f46ebafef475cc45757ca1df4368c0b /storage/innobase/include | |
parent | bb441ca4ade0684603c3c5b8cd999f25def62105 (diff) | |
download | mariadb-git-c7d0448797a2013079c3e0b7ca97f7bdc1138696.tar.gz |
MDEV-15132 Avoid accessing the TRX_SYS page
InnoDB maintains an internal persistent sequence of transaction
identifiers. This sequence is used for assigning both transaction
start identifiers (DB_TRX_ID=trx->id) and end identifiers (trx->no)
as well as end identifiers for the mysql.transaction_registry table
that was introduced in MDEV-12894.
TRX_SYS_TRX_ID_WRITE_MARGIN: Remove. After this many updates of
the sequence we used to update the TRX_SYS page. We can avoid accessing
the TRX_SYS page if we modify the InnoDB startup so that resurrecting
the sequence from other pages of the transaction system.
TRX_SYS_TRX_ID_STORE: Deprecate. The field only exists for the purpose
of upgrading from an earlier version of MySQL or MariaDB.
Starting with this fix, MariaDB will rely on the fields
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in the undo log header page of
each non-committed transaction, and on the new field
TRX_RSEG_MAX_TRX_ID in rollback segment header pages.
Because of this change, setting innodb_force_recovery=5 or 6 may cause
the system to recover with trx_sys.get_max_trx_id()==0. We must adjust
checks for invalid DB_TRX_ID and PAGE_MAX_TRX_ID accordingly.
We will change the startup and shutdown messages to display the
trx_sys.get_max_trx_id() in addition to the log sequence number.
trx_sys_t::flush_max_trx_id(): Remove.
trx_undo_mem_create_at_db_start(), trx_undo_lists_init():
Add an output parameter max_trx_id, to be updated from
TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO.
TRX_RSEG_MAX_TRX_ID: New field, for persisting
trx_sys.get_max_trx_id() at the time of the latest transaction commit.
Startup is not reading the undo log pages of committed transactions.
We want to avoid additional page accesses on startup, as well as
trouble when all undo logs have been emptied.
On startup, we will simply determine the maximum value from all pages
that are being read anyway.
TRX_RSEG_FORMAT: Redefined from TRX_RSEG_MAX_SIZE.
Old versions of InnoDB wrote uninitialized garbage to unused data fields.
Because of this, we cannot simply introduce a new field in the
rollback segment pages and expect it to be always zero, like it would
if the database was created by a recent enough InnoDB version.
Luckily, it looks like the field TRX_RSEG_MAX_SIZE was always written
as 0xfffffffe. We will indicate a new subformat of the page by writing
0 to this field. This has the nice side effect that after a downgrade
to older versions of InnoDB, transactions should fail to allocate any
undo log, that is, writes will be blocked. So, there is no problem of
getting corrupted transaction identifiers after downgrading.
trx_rseg_t::max_size: Remove.
trx_rseg_header_create(): Remove the parameter max_size=ULINT_MAX.
trx_purge_add_undo_to_history(): Update TRX_RSEG_MAX_SIZE
(and TRX_RSEG_FORMAT if needed). This is invoked on transaction commit.
trx_rseg_mem_restore(): If TRX_RSEG_FORMAT contains 0,
read TRX_RSEG_MAX_SIZE.
trx_rseg_array_init(): Invoke trx_sys.init_max_trx_id(max_trx_id + 1)
where max_trx_id was the maximum that was encountered in the rollback
segment pages and the undo log pages of recovered active, XA PREPARE,
or some committed transactions. (See trx_purge_add_undo_to_history()
which invokes trx_rsegf_set_nth_undo(..., FIL_NULL, ...);
not all committed transactions will be immediately detached from the
rollback segment header.)
Diffstat (limited to 'storage/innobase/include')
-rw-r--r-- | storage/innobase/include/trx0rseg.h | 12 | ||||
-rw-r--r-- | storage/innobase/include/trx0sys.h | 45 | ||||
-rw-r--r-- | storage/innobase/include/trx0undo.h | 10 |
3 files changed, 19 insertions, 48 deletions
diff --git a/storage/innobase/include/trx0rseg.h b/storage/innobase/include/trx0rseg.h index f77d0fe40bd..73bfb4ac50a 100644 --- a/storage/innobase/include/trx0rseg.h +++ b/storage/innobase/include/trx0rseg.h @@ -77,7 +77,6 @@ trx_rsegf_undo_find_free(const trx_rsegf_t* rsegf); This function is called only when a new rollback segment is created in the database. @param[in] space space id -@param[in] max_size max size in pages @param[in] rseg_id rollback segment identifier @param[in,out] sys_header the TRX_SYS page (NULL for temporary rseg) @param[in,out] mtr mini-transaction @@ -85,7 +84,6 @@ the database. ulint trx_rseg_header_create( ulint space, - ulint max_size, ulint rseg_id, buf_block_t* sys_header, mtr_t* mtr); @@ -144,9 +142,6 @@ struct trx_rseg_t { /** page number of the rollback segment header */ ulint page_no; - /** maximum allowed size in pages */ - ulint max_size; - /** current size in pages */ ulint curr_size; @@ -217,8 +212,8 @@ struct trx_rseg_t { /* Transaction rollback segment header */ /*-------------------------------------------------------------*/ -#define TRX_RSEG_MAX_SIZE 0 /* Maximum allowed size for rollback - segment in pages */ +#define TRX_RSEG_FORMAT 0 /* -2 = pre-MariaDB 10.3.5 format; + 0=MariaDB 10.3.5 or later */ #define TRX_RSEG_HISTORY_SIZE 4 /* Number of file pages occupied by the logs in the history list */ #define TRX_RSEG_HISTORY 8 /* The update undo logs for committed @@ -228,6 +223,9 @@ struct trx_rseg_t { this page is placed */ #define TRX_RSEG_UNDO_SLOTS (8 + FLST_BASE_NODE_SIZE + FSEG_HEADER_SIZE) /* Undo log segment slots */ +/** Maximum transaction ID (valid only if TRX_RSEG_FORMAT is 0) */ +#define TRX_RSEG_MAX_TRX_ID (TRX_RSEG_UNDO_SLOTS + TRX_RSEG_N_SLOTS \ + * TRX_RSEG_SLOT_SIZE) /*-------------------------------------------------------------*/ /** Read the page number of an undo log slot. diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h index 41ce37e81b9..e7b0e75de10 100644 --- a/storage/innobase/include/trx0sys.h +++ b/storage/innobase/include/trx0sys.h @@ -175,18 +175,13 @@ trx_sys_create_rsegs(); /** Transaction system header */ /*------------------------------------------------------------- @{ */ -#define TRX_SYS_TRX_ID_STORE 0 /*!< the maximum trx id or trx - number modulo - TRX_SYS_TRX_ID_UPDATE_MARGIN - written to a file page by any - transaction; the assignment of - transaction ids continues from - this number rounded up by - TRX_SYS_TRX_ID_UPDATE_MARGIN - plus - TRX_SYS_TRX_ID_UPDATE_MARGIN - when the database is - started */ +/** In old versions of InnoDB, this persisted the value of +trx_sys.get_max_trx_id(). Starting with MariaDB 10.3.5, +the field TRX_RSEG_MAX_TRX_ID in rollback segment header pages +and the fields TRX_UNDO_TRX_ID, TRX_UNDO_TRX_NO in undo log pages +are used instead. The field only exists for the purpose of upgrading +from older MySQL or MariaDB versions. */ +#define TRX_SYS_TRX_ID_STORE 0 #define TRX_SYS_FSEG_HEADER 8 /*!< segment header for the tablespace segment the trx system is created into */ @@ -379,11 +374,6 @@ FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID. */ /** Size of the doublewrite block in pages */ #define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE FSP_EXTENT_SIZE - -/** When a trx id which is zero modulo this number (which must be a power of -two) is assigned, the field TRX_SYS_TRX_ID_STORE on the transaction system -page is updated */ -#define TRX_SYS_TRX_ID_WRITE_MARGIN ((trx_id_t) 256) /* @} */ trx_t* current_trx(); @@ -925,26 +915,14 @@ public: /** Allocates a new transaction id. - - VERY important: after the database is started, m_max_trx_id value is - divisible by TRX_SYS_TRX_ID_WRITE_MARGIN, and the following if - will evaluate to TRUE when this function is first time called, - and the value for trx id will be written to disk-based header! - Thus trx id values will not overlap when the database is - repeatedly started! - @return new, allocated trx id */ trx_id_t get_new_trx_id() { ut_ad(mutex_own(&mutex)); - trx_id_t id= static_cast<trx_id_t>(my_atomic_add64_explicit( + return static_cast<trx_id_t>(my_atomic_add64_explicit( reinterpret_cast<int64*>(&m_max_trx_id), 1, MY_MEMORY_ORDER_RELAXED)); - - if (UNIV_UNLIKELY(!(id % TRX_SYS_TRX_ID_WRITE_MARGIN))) - flush_max_trx_id(); - return(id); } @@ -1004,13 +982,6 @@ private: } return 0; } - - - /** - Writes the value of m_max_trx_id to the file based trx system header. - */ - - void flush_max_trx_id(); }; diff --git a/storage/innobase/include/trx0undo.h b/storage/innobase/include/trx0undo.h index c129bad3dcb..aeffbf1a65e 100644 --- a/storage/innobase/include/trx0undo.h +++ b/storage/innobase/include/trx0undo.h @@ -318,12 +318,14 @@ trx_undo_parse_page_header( page_t* page, mtr_t* mtr); /** Read an undo log when starting up the database. -@param[in,out] rseg rollback segment -@param[in] id rollback segment slot -@param[in] page_no undo log segment page number +@param[in,out] rseg rollback segment +@param[in] id rollback segment slot +@param[in] page_no undo log segment page number +@param[in,out] max_trx_id the largest observed transaction ID @return size of the undo log in pages */ ulint -trx_undo_mem_create_at_db_start(trx_rseg_t* rseg, ulint id, ulint page_no); +trx_undo_mem_create_at_db_start(trx_rseg_t* rseg, ulint id, ulint page_no, + trx_id_t& max_trx_id); /************************************************************************ Frees an undo log memory copy. */ void |