MySQL 8.1.0
Source Code Documentation
trx0sys.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1996, 2023, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27/** @file include/trx0sys.h
28 Transaction system
29
30 Created 3/26/1996 Heikki Tuuri
31 *******************************************************/
32
33#ifndef trx0sys_h
34#define trx0sys_h
35
36#include "univ.i"
37
38#include "buf0buf.h"
39#include "fil0fil.h"
40#include "trx0types.h"
41#ifndef UNIV_HOTBACKUP
42#include "mem0mem.h"
43#include "mtr0mtr.h"
44#include "page0types.h"
45#include "ut0byte.h"
46#include "ut0class_life_cycle.h"
47#include "ut0guarded.h"
48#include "ut0lst.h"
49#include "ut0mutex.h"
50#endif /* !UNIV_HOTBACKUP */
51#include <atomic>
52#include <unordered_map>
53#include <vector>
54#include "trx0trx.h"
55
56#ifndef UNIV_HOTBACKUP
57
58// Forward declaration
59class MVCC;
60class ReadView;
61
62/** The transaction system */
63extern trx_sys_t *trx_sys;
64
65/** Checks if a page address is the trx sys header page.
66@param[in] page_id page id
67@return true if trx sys header page */
68static inline bool trx_sys_hdr_page(const page_id_t &page_id);
69
70/** Creates and initializes the central memory structures for the transaction
71 system. This is called when the database is started.
72 @return min binary heap of rsegs to purge */
74/** Creates the trx_sys instance and initializes purge_queue and mutex. */
75void trx_sys_create(void);
76/** Creates and initializes the transaction system at the database creation. */
78
79/** Find the page number in the TRX_SYS page for a given slot/rseg_id
80@param[in] rseg_id slot number in the TRX_SYS page rseg array
81@return page number from the TRX_SYS page rseg array */
83
84/** Look for a free slot for a rollback segment in the trx system file copy.
85@param[in,out] mtr mtr
86@return slot index or ULINT_UNDEFINED if not found */
88
89/** Gets a pointer to the transaction system file copy and x-locks its page.
90 @return pointer to system file copy, page x-locked */
91static inline trx_sysf_t *trx_sysf_get(mtr_t *mtr); /*!< in: mtr */
92
93/** Gets the space of the nth rollback segment slot in the trx system
94file copy.
95@param[in] sys_header trx sys file copy
96@param[in] i slot index == rseg id
97@param[in] mtr mtr
98@return space id */
100 ulint i, mtr_t *mtr);
101
102/** Gets the page number of the nth rollback segment slot in the trx system
103file copy.
104@param[in] sys_header trx sys file copy
105@param[in] i slot index == rseg id
106@param[in] mtr mtr
107@return page number, FIL_NULL if slot unused */
109 ulint i, mtr_t *mtr);
110
111/** Sets the space id of the nth rollback segment slot in the trx system
112file copy.
113@param[in] sys_header trx sys file copy
114@param[in] i slot index == rseg id
115@param[in] space space id
116@param[in] mtr mtr */
117static inline void trx_sysf_rseg_set_space(trx_sysf_t *sys_header, ulint i,
118 space_id_t space, mtr_t *mtr);
119
120/** Set the page number of the nth rollback segment slot in the trx system
121file copy.
122@param[in] sys_header trx sys file copy
123@param[in] i slot index == rseg id
124@param[in] page_no page number, FIL_NULL if the slot is reset to
125 unused
126@param[in] mtr mtr */
127static inline void trx_sysf_rseg_set_page_no(trx_sysf_t *sys_header, ulint i,
128 page_no_t page_no, mtr_t *mtr);
129
130/** Allocates a new transaction id (for trx->id). Before calling,
131the trx_sys_mutex must be acquired.
132@return new, allocated trx id */
134
135/** Allocates a new transaction number (for trx->no). Before calling,
136the trx_sys_serialisation_mutex must be acquired.
137@return new, allocated trx no */
139
140/** Retrieves a next value that will be allocated if trx_sys_allocate_trx_id()
141or trx_sys_allocate_trx_id_trx_no() was called.
142@return the next trx->id or trx->no that will be allocated */
144
145#ifdef UNIV_DEBUG
146/* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */
147extern uint trx_rseg_n_slots_debug;
148#endif
149#endif /* !UNIV_HOTBACKUP */
150
151/** Writes a trx id to an index page. In case that the id size changes in some
152future version, this function should be used instead of mach_write_...
153@param[in] ptr pointer to memory where written
154@param[in] id id */
155static inline void trx_write_trx_id(byte *ptr, trx_id_t id);
156
157#ifndef UNIV_HOTBACKUP
158/** Reads a trx id from an index page. In case that the id size changes in
159 some future version, this function should be used instead of
160 mach_read_...
161 @return id */
163 const byte *ptr); /*!< in: pointer to memory from where to read */
164
165/** Checks if a rw transaction with the given id is active.
166Please note, that positive result means only that the trx was active
167at some moment during the call, but it might have already become
168TRX_STATE_COMMITTED_IN_MEMORY before the call returns to the caller, as this
169transition is protected by trx->mutex and Trx_shard's mutex, but it is
170impossible for the caller to hold any of these mutexes when calling this
171function as the function itself internally acquires Trx_shard's mutex which
172would cause recurrent mutex acquisition if caller already had the same mutex,
173or latching order violation in case of holding trx->mutex.
174@param[in] trx_id trx id of the transaction
175@param[in] do_ref_count if true then increment the trx_t::n_ref_count
176@return transaction instance if active, or NULL; */
177static inline trx_t *trx_rw_is_active(trx_id_t trx_id, bool do_ref_count);
178
179/** Persist transaction number limit below which all transaction GTIDs
180are persisted to disk table.
181@param[in] gtid_trx_no transaction number */
182void trx_sys_persist_gtid_num(trx_id_t gtid_trx_no);
183
184/** @return oldest transaction number yet to be committed. */
186
187/** Get a list of all binlog prepared transactions.
188@param[out] trx_ids all prepared transaction IDs. */
189void trx_sys_get_binlog_prepared(std::vector<trx_id_t> &trx_ids);
190
191/** Get current binary log positions stored.
192@param[out] file binary log file name
193@param[out] offset binary log file offset */
194void trx_sys_read_binlog_position(char *file, uint64_t &offset);
195
196/** Update binary log position if not already updated. This is called
197by clone to update any stale binary log position if any transaction
198is yet to update the binary log position in SE.
199@param[in] last_file last noted binary log file name
200@param[in] last_offset last noted binary log offset
201@param[in] file current binary log file name
202@param[in] offset current binary log file offset
203@return true, if binary log position is updated with current. */
204bool trx_sys_write_binlog_position(const char *last_file, uint64_t last_offset,
205 const char *file, uint64_t offset);
206
207/** Updates the offset information about the end of the MySQL binlog entry
208which corresponds to the transaction being committed, external XA transaction
209being prepared or rolled back. In a MySQL replication slave updates the latest
210master binlog position up to which replication has proceeded.
211@param[in] trx Current transaction
212@param[in,out] mtr Mini-transaction for update */
214
215/** Shutdown/Close the transaction system. */
216void trx_sys_close(void);
217
218/** Determine if there are incomplete transactions in the system.
219@return whether incomplete transactions need rollback */
220static inline bool trx_sys_need_rollback();
221
222/** Reads number of recovered transactions which have state
223equal to TRX_STATE_ACTIVE (so are not prepared transactions).
224@return number of active recovered transactions */
226
227/** Validates lists of transactions at the very beginning of the
228pre-dd-shutdown phase. */
230
231/** Validates lists of transactions at the very end of the
232pre-dd-shutdown phase. */
234
235/** Validates lists of transactions after all background threads
236of InnoDB exited during shutdown of MySQL. */
238
239/** Add the transaction to the RW transaction set.
240@param trx transaction instance to add */
241static inline void trx_sys_rw_trx_add(trx_t *trx);
242
243#endif /* !UNIV_HOTBACKUP */
244
245#ifdef UNIV_DEBUG
246/** Validate the trx_sys_t::rw_trx_list.
247 @return true if the list is valid */
249#endif /* UNIV_DEBUG */
250
251/** Initialize trx_sys_undo_spaces, called once during srv_start(). */
253
254/** Free the resources occupied by trx_sys_undo_spaces,
255called once during thread de-initialization. */
257
258/** The automatically created system rollback segment has this id */
259constexpr uint32_t TRX_SYS_SYSTEM_RSEG_ID = 0;
260
261/** The offset of the transaction system header on the page */
262constexpr uint32_t TRX_SYS = FSEG_PAGE_DATA;
263
264/** Transaction system header */
265/*------------------------------------------------------------- @{ */
266/** the maximum trx id or trx number modulo TRX_SYS_TRX_ID_UPDATE_MARGIN written
267 to a file page by any transaction; the assignment of transaction ids
268 continues from this number rounded up by TRX_SYS_TRX_ID_UPDATE_MARGIN plus
269 TRX_SYS_TRX_ID_UPDATE_MARGIN when the database is started */
270constexpr uint32_t TRX_SYS_TRX_ID_STORE = 0;
271/** segment header for the tablespace segment the trx system is created into */
272constexpr uint32_t TRX_SYS_FSEG_HEADER = 8;
273/** the start of the array of rollback segment specification slots */
274constexpr uint32_t TRX_SYS_RSEGS = 8 + FSEG_HEADER_SIZE;
275/*------------------------------------------------------------- @} */
276
277/* Originally, InnoDB defined TRX_SYS_N_RSEGS as 256 but created only one
278rollback segment. It initialized some arrays with this number of entries.
279We must remember this limit in order to keep file compatibility. */
280constexpr size_t TRX_SYS_OLD_N_RSEGS = 256;
281
282/* The system temporary tablespace was originally allocated rseg_id slot
283numbers 1 through 32 in the TRX_SYS page. But those slots were not used
284because those Rollback segments were recreated at startup and after any
285crash. These slots are now used for redo-enabled rollback segments.
286The default number of rollback segments in the temporary tablespace
287remains the same. */
288constexpr size_t TRX_SYS_OLD_TMP_RSEGS = 32;
289
290/** Maximum length of MySQL binlog file name, in bytes. */
291constexpr uint32_t TRX_SYS_MYSQL_LOG_NAME_LEN = 512;
292/** Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD */
293constexpr uint32_t TRX_SYS_MYSQL_LOG_MAGIC_N = 873422344;
294
295static_assert(UNIV_PAGE_SIZE_MIN >= 4096, "UNIV_PAGE_SIZE_MIN < 4096");
296/** The offset of the MySQL binlog offset info in the trx system header */
297#define TRX_SYS_MYSQL_LOG_INFO (UNIV_PAGE_SIZE - 1000)
298/** magic number which is TRX_SYS_MYSQL_LOG_MAGIC_N if we have valid data in the
299 MySQL binlog info */
300constexpr uint32_t TRX_SYS_MYSQL_LOG_MAGIC_N_FLD = 0;
301/** high 4 bytes of the offset within that file */
302constexpr uint32_t TRX_SYS_MYSQL_LOG_OFFSET_HIGH = 4;
303/** low 4 bytes of the offset within that file */
304constexpr uint32_t TRX_SYS_MYSQL_LOG_OFFSET_LOW = 8;
305/** MySQL log file name */
306constexpr uint32_t TRX_SYS_MYSQL_LOG_NAME = 12;
307
308/** Reserve next 8 bytes for transaction number up to which GTIDs
309are persisted to table */
310#define TRX_SYS_TRX_NUM_GTID \
311 (TRX_SYS_MYSQL_LOG_INFO + TRX_SYS_MYSQL_LOG_NAME + TRX_SYS_MYSQL_LOG_NAME_LEN)
312#define TRX_SYS_TRX_NUM_END (TRX_SYS_TRX_NUM_GTID + 8)
313/** Doublewrite buffer */
314/** @{ */
315/** The offset of the doublewrite buffer header on the trx system header page */
316#define TRX_SYS_DOUBLEWRITE (UNIV_PAGE_SIZE - 200)
317/*-------------------------------------------------------------*/
318/** fseg header of the fseg containing the doublewrite buffer */
319constexpr uint32_t TRX_SYS_DOUBLEWRITE_FSEG = 0;
320/** 4-byte magic number which shows if we already have created the doublewrite
321 buffer */
323/** page number of the first page in the first sequence of 64 (=
324 FSP_EXTENT_SIZE) consecutive pages in the doublewrite buffer */
326/** page number of the first page in the second sequence of 64 consecutive pages
327 in the doublewrite buffer */
329/** we repeat TRX_SYS_DOUBLEWRITE_MAGIC, TRX_SYS_DOUBLEWRITE_BLOCK1,
330 TRX_SYS_DOUBLEWRITE_BLOCK2 so that if the trx sys header is half-written to
331 disk, we still may be able to recover the information */
332constexpr uint32_t TRX_SYS_DOUBLEWRITE_REPEAT = 12;
333/** If this is not yet set to TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N,
334we must reset the doublewrite buffer, because starting from 4.1.x the
335space id of a data page is stored into
336FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID. */
338
339/*-------------------------------------------------------------*/
340/** Contents of TRX_SYS_DOUBLEWRITE_MAGIC */
341constexpr uint32_t TRX_SYS_DOUBLEWRITE_MAGIC_N = 536853855;
342/** Contents of TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED */
343constexpr uint32_t TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N = 1783657386;
344
345/** Size of the doublewrite block in pages */
346#define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE FSP_EXTENT_SIZE
347/** @} */
348
349/** List of undo tablespace IDs. */
350class Space_Ids : public std::vector<space_id_t, ut::allocator<space_id_t>> {
351 public:
352 void sort() { std::sort(begin(), end()); }
353
355 if (size() == 0) {
356 return (false);
357 }
358
359 iterator it = std::find(begin(), end(), id);
360
361 return (it != end());
362 }
363
364 iterator find(space_id_t id) { return (std::find(begin(), end(), id)); }
365};
366
367/** Number of shards created for transactions. */
368constexpr size_t TRX_SHARDS_N = 256;
369
370/** Computes shard number for a given trx_id.
371@param[in] trx_id trx_id for which shard_no should be computed
372@return the computed shard number (number in range 0..TRX_SHARDS_N-1) */
373inline size_t trx_get_shard_no(trx_id_t trx_id) {
374 ut_ad(trx_id != 0);
375 return trx_id % TRX_SHARDS_N;
376}
377
378#ifndef UNIV_HOTBACKUP
381 size_t operator()(const trx_id_t &key) const {
382 return static_cast<size_t>(key / TRX_SHARDS_N);
383 }
384 };
385
386 using By_id = std::unordered_map<trx_id_t, trx_t *, Trx_track_hash>;
388
389 /** For observers which use Trx_shard::mutex protection: each transaction id
390 in the m_by_id is guaranteed to be at least m_min_id.
391 Writes are protected with Trx_shard::mutex.
392 Reads can be performed without any latch before accessing m_by_id,
393 but care must be taken to interpret the result -
394 @see trx_rw_is_active for details.*/
395 std::atomic<trx_id_t> m_min_id{0};
396
397 public:
398 By_id const &by_id() const { return m_by_id; }
399 trx_id_t min_id() const { return m_min_id.load(); }
400 trx_t *get(trx_id_t trx_id) const {
401 const auto it = m_by_id.find(trx_id);
402 trx_t *trx = it == m_by_id.end() ? nullptr : it->second;
403 /* We remove trx from active_rw_trxs and change state to
404 TRX_STATE_COMMITTED_IN_MEMORY in a same critical section protected by
405 Trx_shard's mutex, which we happen to hold here, so we expect the state
406 of trx to match its presence in that set */
407 ut_ad(trx == nullptr || !trx_state_eq(trx, TRX_STATE_COMMITTED_IN_MEMORY));
408 return trx;
409 }
410 void insert(trx_t &trx) {
411 const trx_id_t trx_id = trx.id;
412 ut_ad(0 == m_by_id.count(trx_id));
413 m_by_id.emplace(trx_id, &trx);
414 if (m_by_id.size() == 1 ||
415 trx_id < m_min_id.load(std::memory_order_relaxed)) {
416 m_min_id.store(trx_id, std::memory_order_release);
417 }
418 }
419 void erase(trx_id_t trx_id) {
420 ut_ad(1 == m_by_id.count(trx_id));
421 m_by_id.erase(trx_id);
422 if (m_min_id.load(std::memory_order_relaxed) == trx_id) {
423 // We want at most 1 release store, so we use a local variable for the
424 // loop.
425 trx_id_t new_min = trx_id + TRX_SHARDS_N;
426 if (!m_by_id.empty()) {
427#ifdef UNIV_DEBUG
428 // These asserts ensure while loop terminates:
429 const trx_id_t some_id = m_by_id.begin()->first;
430 ut_a(new_min <= some_id);
431 ut_a((some_id - new_min) % TRX_SHARDS_N == 0);
432#endif /* UNIV_DEBUG */
433 while (m_by_id.count(new_min) == 0) {
434 new_min += TRX_SHARDS_N;
435 }
436 }
437 m_min_id.store(new_min, std::memory_order_release);
438 }
439 }
440};
441
442/** Shard for subset of transactions. */
443struct Trx_shard {
444 /** Mapping from trx->id to trx of active rw transactions.
445 The peek() interface can only be used safely for the min_id().
446 Use latch_and_execute() interface to access other members. */
449};
450
451/** The transaction system central memory data structure. */
452struct trx_sys_t {
453 /* Members protected by neither trx_sys_t::mutex nor serialisation_mutex. */
455
456 /** @{ */
457
458 /** Multi version concurrency control manager */
459
461
462 /** Vector of pointers to rollback segments. These rsegs are iterated
463 and added to the end under a read lock. They are deleted under a write
464 lock while the vector is adjusted. They are created and destroyed in
465 single-threaded mode. */
467
468 /** Vector of pointers to rollback segments within the temp tablespace;
469 This vector is created and destroyed in single-threaded mode so it is not
470 protected by any mutex because it is read-only during multi-threaded
471 operation. */
473
474 /** Length of the TRX_RSEG_HISTORY list (update undo logs for committed
475 transactions). */
476 std::atomic<uint64_t> rseg_history_len;
477
478 /** @} */
479
480 /* Members protected by either trx_sys_t::mutex or serialisation_mutex. */
482
483 /** @{ */
484
485 /** The smallest number not yet assigned as a transaction id
486 or transaction number. This is declared as atomic because it
487 can be accessed without holding any mutex during AC-NL-RO
488 view creation. When it is used for assignment of the trx->id,
489 it is synchronized by the trx_sys_t::mutex. When it is used
490 for assignment of the trx->no, it is synchronized by the
491 trx_sys_t::serialisation_mutex. Note: it might be in parallel
492 used for both trx->id and trx->no assignments (for different
493 trx_t objects). */
494 std::atomic<trx_id_t> next_trx_id_or_no;
495
496 /** @} */
497
498 /* Members protected by serialisation_mutex. */
500
501 /** @{ */
502
503 /** Mutex to protect serialisation_list. */
505
506 /** Tracks minimal transaction id which has received trx->no, but has
507 not yet finished commit for the mtr writing the trx commit. Protected
508 by the serialisation_mutex. Ordered on the trx->no field. */
509 UT_LIST_BASE_NODE_T(trx_t, no_list) serialisation_list;
510
511#ifdef UNIV_DEBUG
512 /** Max trx number of read-write transactions added for purge. */
514#endif /* UNIV_DEBUG */
515
517
518 /* The minimum trx->no inside the serialisation_list. Protected by
519 the serialisation_mutex. Might be read without the mutex. */
520 std::atomic<trx_id_t> serialisation_min_trx_no;
521
522 /** @} */
523
524 /* Members protected by the trx_sys_t::mutex. */
526
527 /** @{ */
528
529 /** Mutex protecting most fields in this structure (the default one). */
531
533
534 /** List of active and committed in memory read-write transactions, sorted
535 on trx id, biggest first. Recovered transactions are always on this list. */
536 UT_LIST_BASE_NODE_T(trx_t, trx_list) rw_trx_list;
537
539
540 /** List of transactions created for MySQL. All user transactions are
541 on mysql_trx_list. The rw_trx_list can contain system transactions and
542 recovered transactions that will not be in the mysql_trx_list.
543 Additionally, mysql_trx_list may contain transactions that have not yet
544 been started in InnoDB. */
545 UT_LIST_BASE_NODE_T(trx_t, mysql_trx_list) mysql_trx_list;
546
547 /** Array of Read write transaction IDs for MVCC snapshot. A ReadView would
548 take a snapshot of these transactions whose changes are not visible to it.
549 We should remove transactions from the list before committing in memory and
550 releasing locks to ensure right order of removal and consistent snapshot. */
552
554
555 /** Mapping from transaction id to transaction instance. */
557
558 /** Number of transactions currently in the XA PREPARED state. */
560
561 /** True if XA PREPARED trxs are found. */
563
564 /** @} */
565
567
569 return trx_sys->shards[trx_get_shard_no(trx_id)];
570 }
571 template <typename F>
573 const ut::Location &loc) {
574 return get_shard_by_trx_id(trx_id).active_rw_trxs.latch_and_execute(
575 [&](Trx_by_id_with_min &trx_by_id_with_min) {
576 return std::forward<F>(f)(trx_by_id_with_min.get(trx_id));
577 },
578 loc);
579 }
580};
581
582#endif /* !UNIV_HOTBACKUP */
583
584/** A list of undo tablespace IDs found in the TRX_SYS page.
585This cannot be part of the trx_sys_t object because it is initialized before
586that object is created. These are the old type of undo tablespaces that do not
587have space_IDs in the reserved range nor contain an RSEG_ARRAY page. */
589
590#ifndef UNIV_HOTBACKUP
591
592/** When a trx id which is zero modulo this number (which must be a power of
593two) is assigned, the field TRX_SYS_TRX_ID_STORE on the transaction system
594page is updated */
596
597/** Acquire the trx_sys->mutex. */
598static inline void trx_sys_mutex_enter() { mutex_enter(&trx_sys->mutex); }
599
600/** Release the trx_sys->mutex. */
601static inline void trx_sys_mutex_exit() { trx_sys->mutex.exit(); }
602
603#ifdef UNIV_DEBUG
604
605/** Test if trx_sys->mutex is owned. */
606static inline bool trx_sys_mutex_own() { return trx_sys->mutex.is_owned(); }
607
608/** Test if trx_sys->serialisation_mutex is owned. */
610 return trx_sys->serialisation_mutex.is_owned();
611}
612#endif
613
614/** Acquire the trx_sys->serialisation_mutex. */
617}
618
619/** Release the trx_sys->serialisation_mutex. */
622}
623
624#endif /* !UNIV_HOTBACKUP */
625
626#include "trx0sys.ic"
627
628#endif
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:50
uint32_t page_no_t
Page number.
Definition: api0api.h:48
The database buffer pool high-level routines.
The MVCC read view manager.
Definition: read0read.h:43
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:47
This is a wrapper for a std::vector of trx_rseg_t object pointers.
Definition: trx0types.h:293
List of undo tablespace IDs.
Definition: trx0sys.h:350
void sort()
Definition: trx0sys.h:352
bool contains(space_id_t id)
Definition: trx0sys.h:354
iterator find(space_id_t id)
Definition: trx0sys.h:364
Definition: trx0sys.h:379
std::atomic< trx_id_t > m_min_id
For observers which use Trx_shard::mutex protection: each transaction id in the m_by_id is guaranteed...
Definition: trx0sys.h:395
trx_t * get(trx_id_t trx_id) const
Definition: trx0sys.h:400
By_id const & by_id() const
Definition: trx0sys.h:398
trx_id_t min_id() const
Definition: trx0sys.h:399
void erase(trx_id_t trx_id)
Definition: trx0sys.h:419
void insert(trx_t &trx)
Definition: trx0sys.h:410
std::unordered_map< trx_id_t, trx_t *, Trx_track_hash > By_id
Definition: trx0sys.h:386
By_id m_by_id
Definition: trx0sys.h:387
Page identifier.
Definition: buf0types.h:206
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:221
The low-level file system.
constexpr uint32_t FSEG_PAGE_DATA
On a page of any file segment, data may be put starting from this offset.
Definition: fsp0types.h:78
constexpr uint32_t FSEG_HEADER_SIZE
Length of the file system header, in bytes.
Definition: fsp0types.h:93
The memory management.
Mini-transaction buffer.
const byte * find(const Pages *pages, const page_id_t &page_id) noexcept
Find a doublewrite copy of a page.
Definition: buf0dblwr.cc:3574
Definition: os0file.h:85
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:191
constexpr size_t INNODB_CACHE_LINE_SIZE
CPU cache line size.
Definition: ut0cpu_cache.h:40
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2873
Index page routines.
required string key
Definition: replication_asynchronous_connection_failover.proto:59
Definition: trx0sys.h:380
size_t operator()(const trx_id_t &key) const
Definition: trx0sys.h:381
Shard for subset of transactions.
Definition: trx0sys.h:443
ut::Cacheline_padded< ut::Guarded< Trx_by_id_with_min, LATCH_ID_TRX_SYS_SHARD > > active_rw_trxs
Mapping from trx->id to trx of active rw transactions.
Definition: trx0sys.h:448
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:176
The transaction system central memory data structure.
Definition: trx0sys.h:452
UT_LIST_BASE_NODE_T(trx_t, no_list) serialisation_list
Tracks minimal transaction id which has received trx->no, but has not yet finished commit for the mtr...
TrxSysMutex serialisation_mutex
Mutex to protect serialisation_list.
Definition: trx0sys.h:504
char pad3[ut::INNODB_CACHE_LINE_SIZE]
Definition: trx0sys.h:516
UT_LIST_BASE_NODE_T(trx_t, mysql_trx_list) mysql_trx_list
List of transactions created for MySQL.
UT_LIST_BASE_NODE_T(trx_t, trx_list) rw_trx_list
List of active and committed in memory read-write transactions, sorted on trx id, biggest first.
std::atomic< trx_id_t > next_trx_id_or_no
The smallest number not yet assigned as a transaction id or transaction number.
Definition: trx0sys.h:494
std::atomic< uint64_t > rseg_history_len
Length of the TRX_RSEG_HISTORY list (update undo logs for committed transactions).
Definition: trx0sys.h:476
auto latch_and_execute_with_active_trx(trx_id_t trx_id, F &&f, const ut::Location &loc)
Definition: trx0sys.h:572
std::atomic< trx_id_t > serialisation_min_trx_no
Definition: trx0sys.h:520
Rsegs rsegs
Vector of pointers to rollback segments.
Definition: trx0sys.h:466
char pad7[ut::INNODB_CACHE_LINE_SIZE]
Definition: trx0sys.h:553
char pad2[ut::INNODB_CACHE_LINE_SIZE]
Definition: trx0sys.h:499
trx_id_t rw_max_trx_no
Max trx number of read-write transactions added for purge.
Definition: trx0sys.h:513
Rsegs tmp_rsegs
Vector of pointers to rollback segments within the temp tablespace; This vector is created and destro...
Definition: trx0sys.h:472
char pad4[ut::INNODB_CACHE_LINE_SIZE]
Definition: trx0sys.h:525
char pad1[ut::INNODB_CACHE_LINE_SIZE]
Definition: trx0sys.h:481
bool found_prepared_trx
True if XA PREPARED trxs are found.
Definition: trx0sys.h:562
MVCC * mvcc
Multi version concurrency control manager.
Definition: trx0sys.h:460
Trx_shard & get_shard_by_trx_id(trx_id_t trx_id)
Definition: trx0sys.h:568
Trx_shard shards[TRX_SHARDS_N]
Mapping from transaction id to transaction instance.
Definition: trx0sys.h:556
char pad5[ut::INNODB_CACHE_LINE_SIZE]
Definition: trx0sys.h:532
ulint n_prepared_trx
Number of transactions currently in the XA PREPARED state.
Definition: trx0sys.h:559
TrxSysMutex mutex
Mutex protecting most fields in this structure (the default one).
Definition: trx0sys.h:530
char pad0[ut::INNODB_CACHE_LINE_SIZE]
Definition: trx0sys.h:454
char pad_after[ut::INNODB_CACHE_LINE_SIZE]
Definition: trx0sys.h:566
char pad6[ut::INNODB_CACHE_LINE_SIZE]
Definition: trx0sys.h:538
trx_ids_t rw_trx_ids
Array of Read write transaction IDs for MVCC snapshot.
Definition: trx0sys.h:551
Definition: trx0trx.h:685
trx_id_t id
transaction id
Definition: trx0trx.h:737
A utility wrapper class, which adds padding at the end of the wrapped structure, so that the next obj...
Definition: ut0cpu_cache.h:54
Definition: ut0core.h:35
Space_Ids * trx_sys_undo_spaces
A list of undo tablespace IDs found in the TRX_SYS page.
Definition: trx0sys.cc:760
constexpr size_t TRX_SYS_OLD_TMP_RSEGS
Definition: trx0sys.h:288
constexpr size_t TRX_SHARDS_N
Number of shards created for transactions.
Definition: trx0sys.h:368
constexpr trx_id_t TRX_SYS_TRX_ID_WRITE_MARGIN
When a trx id which is zero modulo this number (which must be a power of two) is assigned,...
Definition: trx0sys.h:595
static void trx_sysf_rseg_set_page_no(trx_sysf_t *sys_header, ulint i, page_no_t page_no, mtr_t *mtr)
Set the page number of the nth rollback segment slot in the trx system file copy.
constexpr uint32_t TRX_SYS_MYSQL_LOG_NAME
MySQL log file name.
Definition: trx0sys.h:306
void trx_sys_update_mysql_binlog_offset(trx_t *trx, mtr_t *mtr)
Updates the offset information about the end of the MySQL binlog entry which corresponds to the trans...
Definition: trx0sys.cc:312
constexpr size_t TRX_SYS_OLD_N_RSEGS
Definition: trx0sys.h:280
constexpr uint32_t TRX_SYS_MYSQL_LOG_OFFSET_HIGH
high 4 bytes of the offset within that file
Definition: trx0sys.h:302
size_t trx_get_shard_no(trx_id_t trx_id)
Computes shard number for a given trx_id.
Definition: trx0sys.h:373
constexpr uint32_t TRX_SYS_DOUBLEWRITE_MAGIC
4-byte magic number which shows if we already have created the doublewrite buffer
Definition: trx0sys.h:322
page_no_t trx_sysf_rseg_find_page_no(ulint rseg_id)
Find the page number in the TRX_SYS page for a given slot/rseg_id.
Definition: trx0sys.cc:333
static bool trx_sys_hdr_page(const page_id_t &page_id)
Checks if a page address is the trx sys header page.
static void trx_sys_mutex_exit()
Release the trx_sys->mutex.
Definition: trx0sys.h:601
static void trx_write_trx_id(byte *ptr, trx_id_t id)
Writes a trx id to an index page.
void trx_sys_get_binlog_prepared(std::vector< trx_id_t > &trx_ids)
Get a list of all binlog prepared transactions.
Definition: trx0sys.cc:160
static void trx_sys_serialisation_mutex_exit()
Release the trx_sys->serialisation_mutex.
Definition: trx0sys.h:620
void trx_sys_after_pre_dd_shutdown_validate()
Validates lists of transactions at the very end of the pre-dd-shutdown phase.
Definition: trx0sys.cc:684
static void trx_sys_serialisation_mutex_enter()
Acquire the trx_sys->serialisation_mutex.
Definition: trx0sys.h:615
constexpr uint32_t TRX_SYS_SYSTEM_RSEG_ID
The automatically created system rollback segment has this id.
Definition: trx0sys.h:259
static trx_t * trx_rw_is_active(trx_id_t trx_id, bool do_ref_count)
Checks if a rw transaction with the given id is active.
static trx_sysf_t * trx_sysf_get(mtr_t *mtr)
Gets a pointer to the transaction system file copy and x-locks its page.
void trx_sys_read_binlog_position(char *file, uint64_t &offset)
Get current binary log positions stored.
Definition: trx0sys.cc:244
constexpr uint32_t TRX_SYS
The offset of the transaction system header on the page.
Definition: trx0sys.h:262
void trx_sys_create(void)
Creates the trx_sys instance and initializes purge_queue and mutex.
Definition: trx0sys.cc:559
trx_id_t trx_sys_oldest_trx_no()
Definition: trx0sys.cc:150
size_t trx_sys_recovered_active_trxs_count()
Reads number of recovered transactions which have state equal to TRX_STATE_ACTIVE (so are not prepare...
Definition: trx0sys.cc:722
void trx_sys_undo_spaces_deinit()
Free the resources occupied by trx_sys_undo_spaces, called once during thread de-initialization.
Definition: trx0sys.cc:772
constexpr uint32_t TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N
Contents of TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED.
Definition: trx0sys.h:343
void trx_sys_before_pre_dd_shutdown_validate()
Validates lists of transactions at the very beginning of the pre-dd-shutdown phase.
Definition: trx0sys.cc:661
constexpr uint32_t TRX_SYS_MYSQL_LOG_MAGIC_N
Contents of TRX_SYS_MYSQL_LOG_MAGIC_N_FLD.
Definition: trx0sys.h:293
constexpr uint32_t TRX_SYS_DOUBLEWRITE_FSEG
fseg header of the fseg containing the doublewrite buffer
Definition: trx0sys.h:319
purge_pq_t * trx_sys_init_at_db_start(void)
Creates and initializes the central memory structures for the transaction system.
Definition: trx0sys.cc:436
ulint trx_sysf_rseg_find_free(mtr_t *mtr)
Look for a free slot for a rollback segment in the trx system file copy.
Definition: trx0sys.cc:350
void trx_sys_close(void)
Shutdown/Close the transaction system.
Definition: trx0sys.cc:605
static space_id_t trx_sysf_rseg_get_space(trx_sysf_t *sys_header, ulint i, mtr_t *mtr)
Gets the space of the nth rollback segment slot in the trx system file copy.
constexpr uint32_t TRX_SYS_DOUBLEWRITE_REPEAT
we repeat TRX_SYS_DOUBLEWRITE_MAGIC, TRX_SYS_DOUBLEWRITE_BLOCK1, TRX_SYS_DOUBLEWRITE_BLOCK2 so that i...
Definition: trx0sys.h:332
trx_id_t trx_sys_allocate_trx_no()
Allocates a new transaction number (for trx->no).
Definition: trx0sys.ic:262
static trx_id_t trx_read_trx_id(const byte *ptr)
Reads a trx id from an index page.
static bool trx_sys_need_rollback()
Determine if there are incomplete transactions in the system.
bool trx_sys_validate_trx_list()
Validate the trx_sys_t::rw_trx_list.
Definition: trx0sys.cc:739
static void trx_sysf_rseg_set_space(trx_sysf_t *sys_header, ulint i, space_id_t space, mtr_t *mtr)
Sets the space id of the nth rollback segment slot in the trx system file copy.
static void trx_sys_rw_trx_add(trx_t *trx)
Add the transaction to the RW transaction set.
constexpr uint32_t TRX_SYS_MYSQL_LOG_NAME_LEN
Maximum length of MySQL binlog file name, in bytes.
Definition: trx0sys.h:291
bool trx_sys_write_binlog_position(const char *last_file, uint64_t last_offset, const char *file, uint64_t offset)
Update binary log position if not already updated.
Definition: trx0sys.cc:296
void trx_sys_create_sys_pages(void)
Creates and initializes the transaction system at the database creation.
Definition: trx0sys.cc:593
constexpr uint32_t TRX_SYS_DOUBLEWRITE_BLOCK1
page number of the first page in the first sequence of 64 (= FSP_EXTENT_SIZE) consecutive pages in th...
Definition: trx0sys.h:325
void trx_sys_undo_spaces_init()
Initialize trx_sys_undo_spaces, called once during srv_start().
Definition: trx0sys.cc:763
static bool trx_sys_mutex_own()
Test if trx_sys->mutex is owned.
Definition: trx0sys.h:606
constexpr uint32_t TRX_SYS_TRX_ID_STORE
Transaction system header.
Definition: trx0sys.h:270
void trx_sys_after_background_threads_shutdown_validate()
Validates lists of transactions after all background threads of InnoDB exited during shutdown of MySQ...
Definition: trx0sys.cc:716
constexpr uint32_t TRX_SYS_MYSQL_LOG_OFFSET_LOW
low 4 bytes of the offset within that file
Definition: trx0sys.h:304
trx_id_t trx_sys_allocate_trx_id()
Allocates a new transaction id (for trx->id).
Definition: trx0sys.ic:257
void trx_sys_persist_gtid_num(trx_id_t gtid_trx_no)
Persist transaction number limit below which all transaction GTIDs are persisted to disk table.
Definition: trx0sys.cc:139
constexpr uint32_t TRX_SYS_DOUBLEWRITE_MAGIC_N
Contents of TRX_SYS_DOUBLEWRITE_MAGIC.
Definition: trx0sys.h:341
static void trx_sys_mutex_enter()
Acquire the trx_sys->mutex.
Definition: trx0sys.h:598
static page_no_t trx_sysf_rseg_get_page_no(trx_sysf_t *sys_header, ulint i, mtr_t *mtr)
Gets the page number of the nth rollback segment slot in the trx system file copy.
uint trx_rseg_n_slots_debug
Definition: trx0sys.cc:96
constexpr uint32_t TRX_SYS_MYSQL_LOG_MAGIC_N_FLD
magic number which is TRX_SYS_MYSQL_LOG_MAGIC_N if we have valid data in the MySQL binlog info
Definition: trx0sys.h:300
trx_sys_t * trx_sys
The transaction system.
Definition: trx0sys.cc:57
constexpr uint32_t TRX_SYS_DOUBLEWRITE_BLOCK2
page number of the first page in the second sequence of 64 consecutive pages in the doublewrite buffe...
Definition: trx0sys.h:328
constexpr uint32_t TRX_SYS_FSEG_HEADER
segment header for the tablespace segment the trx system is created into
Definition: trx0sys.h:272
constexpr uint32_t TRX_SYS_RSEGS
the start of the array of rollback segment specification slots
Definition: trx0sys.h:274
static bool trx_sys_serialisation_mutex_own()
Test if trx_sys->serialisation_mutex is owned.
Definition: trx0sys.h:609
trx_id_t trx_sys_get_next_trx_id_or_no()
Retrieves a next value that will be allocated if trx_sys_allocate_trx_id() or trx_sys_allocate_trx_id...
Definition: trx0sys.ic:273
constexpr uint32_t TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED
If this is not yet set to TRX_SYS_DOUBLEWRITE_SPACE_ID_STORED_N, we must reset the doublewrite buffer...
Definition: trx0sys.h:337
Transaction system.
The transaction.
static bool trx_state_eq(const trx_t *trx, trx_state_t state)
Determines if a transaction is in the given state.
Transaction system global type definitions.
@ TRX_STATE_COMMITTED_IN_MEMORY
Definition: trx0types.h:92
std::priority_queue< TrxUndoRsegs, std::vector< TrxUndoRsegs, ut::allocator< TrxUndoRsegs > >, TrxUndoRsegs > purge_pq_t
Definition: trx0types.h:593
std::vector< trx_id_t, ut::allocator< trx_id_t > > trx_ids_t
Definition: trx0types.h:595
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:137
byte trx_sysf_t
File objects.
Definition: trx0types.h:154
ib_mutex_t TrxSysMutex
Definition: trx0types.h:173
Version control for database, common definitions, and include files.
constexpr uint32_t UNIV_PAGE_SIZE_MIN
Minimum page size InnoDB currently supports.
Definition: univ.i:320
unsigned long int ulint
Definition: univ.i:405
Utilities for byte operations.
Utilities related to class lifecycle.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:68
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:56
The ut::Guarded template which protects access to another class with mutex.
List utilities.
Policy based mutexes.
#define mutex_enter(M)
Definition: ut0mutex.h:116