MySQL  8.0.20
Source Code Documentation
trx0types.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2020, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License, version 2.0, as published by the
7 Free Software Foundation.
8 
9 This program is also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 
25 *****************************************************************************/
26 
27 /** @file include/trx0types.h
28  Transaction system global type definitions
29 
30  Created 3/26/1996 Heikki Tuuri
31  *******************************************************/
32 
33 #ifndef trx0types_h
34 #define trx0types_h
35 
36 #include "page0size.h"
37 #include "sync0rw.h"
38 #include "ut0byte.h"
39 #include "ut0mutex.h"
40 #include "ut0new.h"
41 
42 #include <atomic>
43 #include <queue>
44 #include <set>
45 #include <vector>
46 
47 //#include <unordered_set>
48 
49 /** printf(3) format used for printing DB_TRX_ID and other system fields */
50 #define TRX_ID_FMT IB_ID_FMT
51 
52 /** Space id of the transaction system page (the system tablespace) */
53 static const space_id_t TRX_SYS_SPACE = 0;
54 
55 /** Page number of the transaction system page */
56 #define TRX_SYS_PAGE_NO FSP_TRX_SYS_PAGE_NO
57 
58 /** Random value to check for corruption of trx_t */
59 static const ulint TRX_MAGIC_N = 91118598;
60 
61 /** If this flag is set then the transaction cannot be rolled back
62 asynchronously. */
63 static const ib_uint32_t TRX_FORCE_ROLLBACK_DISABLE = 1 << 29;
64 
65 /** Was the transaction rolled back asynchronously or by the
66 owning thread. This flag is relevant only if TRX_FORCE_ROLLBACK
67 is set. */
68 static const ib_uint32_t TRX_FORCE_ROLLBACK_ASYNC = 1 << 30;
69 
70 /** Mark the transaction for forced rollback */
71 static const ib_uint32_t TRX_FORCE_ROLLBACK = 1 << 31;
72 
73 /** For masking out the above four flags */
74 static const ib_uint32_t TRX_FORCE_ROLLBACK_MASK = 0x1FFFFFFF;
75 
76 /** Transaction execution states when trx->state == TRX_STATE_ACTIVE */
77 enum trx_que_t {
78  TRX_QUE_RUNNING, /*!< transaction is running */
79  TRX_QUE_LOCK_WAIT, /*!< transaction is waiting for
80  a lock */
81  TRX_QUE_ROLLING_BACK, /*!< transaction is rolling back */
82  TRX_QUE_COMMITTING /*!< transaction is committing */
83 };
84 
85 /** Transaction states (trx_t::state) */
87 
89 
90  /** Same as not started but with additional semantics that it
91  was rolled back asynchronously the last time it was active. */
93 
95 
96  /** Support for 2PC/XA */
98 
100 };
101 
102 /** Type of data dictionary operation */
104  /** The transaction is not modifying the data dictionary. */
106  /** The transaction is creating a table or an index, or
107  dropping a table. The table must be dropped in crash
108  recovery. This and TRX_DICT_OP_NONE are the only possible
109  operation modes in crash recovery. */
111  /** The transaction is creating or dropping an index in an
112  existing table. In crash recovery, the data dictionary
113  must be locked, but the table must not be dropped. */
115 };
116 
117 /** Memory objects */
118 /* @{ */
119 /** Transaction */
120 struct trx_t;
121 /** The locks and state of an active transaction */
122 struct trx_lock_t;
123 /** Transaction system */
124 struct trx_sys_t;
125 /** Signal */
126 struct trx_sig_t;
127 /** Rollback segment */
128 struct trx_rseg_t;
129 /** Transaction undo log */
130 struct trx_undo_t;
131 /** The control structure used in the purge operation */
132 struct trx_purge_t;
133 /** Rollback command node in a query graph */
134 struct roll_node_t;
135 /** Commit command node in a query graph */
136 struct commit_node_t;
137 /** SAVEPOINT command node in a query graph */
139 /* @} */
140 
141 /** Row identifier (DB_ROW_ID, DATA_ROW_ID) */
142 typedef ib_id_t row_id_t;
143 /** Transaction identifier (DB_TRX_ID, DATA_TRX_ID) */
144 typedef ib_id_t trx_id_t;
145 /** Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR) */
146 typedef ib_id_t roll_ptr_t;
147 /** Undo number */
148 typedef ib_id_t undo_no_t;
149 
150 /** Maximum transaction identifier */
151 #define TRX_ID_MAX IB_ID_MAX
152 
153 /** Transaction savepoint */
154 struct trx_savept_t {
155  undo_no_t least_undo_no; /*!< least undo number to undo */
156 };
157 
158 /** File objects */
159 /* @{ */
160 /** Transaction system header */
161 typedef byte trx_sysf_t;
162 /** Rollback segment array header */
164 /** Rollback segment header */
166 /** Undo segment header */
168 /** Undo log header */
170 /** Undo log page header */
172 /** Undo log record */
174 /* @} */
175 
176 typedef ib_mutex_t RsegMutex;
177 typedef ib_mutex_t TrxMutex;
178 typedef ib_mutex_t UndoMutex;
179 typedef ib_mutex_t PQMutex;
180 typedef ib_mutex_t TrxSysMutex;
181 
182 /** The rollback segment memory object */
183 struct trx_rseg_t {
184 #ifdef UNIV_DEBUG
185  /** Validate the curr_size member by re-calculating it.
186  @param[in] take_mutex take the rseg->mutex. default is true.
187  @return true if valid, false otherwise. */
188  bool validate_curr_size(bool take_mutex = true);
189 #endif /* UNIV_DEBUG */
190 
191  /** Enter the rseg->mutex. */
192  void latch() {
193  mutex_enter(&mutex);
194  ut_ad(validate_curr_size(false));
195  }
196 
197  /** Exit the rseg->mutex. */
198  void unlatch() {
199  ut_ad(validate_curr_size(false));
200  mutex_exit(&mutex);
201  }
202 
203  /** Decrement the current size of the rollback segment by the given number
204  of pages.
205  @param[in] npages number of pages to reduce in size. */
206  void decr_curr_size(page_no_t npages = 1) {
207  ut_ad(curr_size >= npages);
208  curr_size -= npages;
209  }
210 
211  /** Increment the current size of the rollback segment by the given number
212  of pages. */
213  void incr_curr_size() { ++curr_size; }
214 
215  /* Get the current size of the rollback segment in pages.
216  @return current size of the rollback segment in pages. */
217  page_no_t get_curr_size() const { return (curr_size); }
218 
219  /* Set the current size of the rollback segment in pages.
220  @param[in] npages new value for the current size. */
221  void set_curr_size(page_no_t npages) { curr_size = npages; }
222 
223  /*--------------------------------------------------------*/
224  /** rollback segment id == the index of its slot in the trx
225  system file copy */
226  ulint id;
227 
228  /** mutex protecting the fields in this struct except id,space,page_no
229  which are constant */
231 
232  /** space ID where the rollback segment header is placed */
234 
235  /** page number of the rollback segment header */
237 
238  /** page size of the relevant tablespace */
240 
241  /** maximum allowed size in pages */
242  ulint max_size;
243 
244  private:
245  /** current size in pages */
247 
248  public:
249  /*--------------------------------------------------------*/
250  /* Fields for update undo logs */
251  /** List of update undo logs */
252  UT_LIST_BASE_NODE_T(trx_undo_t) update_undo_list;
253 
254  /** List of update undo log segments cached for fast reuse */
255  UT_LIST_BASE_NODE_T(trx_undo_t) update_undo_cached;
256 
257  /*--------------------------------------------------------*/
258  /* Fields for insert undo logs */
259  /** List of insert undo logs */
260  UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_list;
261 
262  /** List of insert undo log segments cached for fast reuse */
263  UT_LIST_BASE_NODE_T(trx_undo_t) insert_undo_cached;
264 
265  /*--------------------------------------------------------*/
266 
267  /** Page number of the last not yet purged log header in the history
268  list; FIL_NULL if all list purged */
270 
271  /** Byte offset of the last not yet purged log header */
272  ulint last_offset;
273 
274  /** Transaction number of the last not yet purged log */
276 
277  /** TRUE if the last not yet purged log needs purging */
279 
280  /** Reference counter to track rseg allocated transactions. */
281  std::atomic<ulint> trx_ref_count;
282 
283  std::ostream &print(std::ostream &out) const {
284  out << "[trx_rseg_t: this=" << (void *)this << ", id=" << id
285  << ", space_id=" << space_id << ", page_no=" << page_no
286  << ", curr_size=" << curr_size << "]";
287  return (out);
288  }
289 };
290 
291 inline std::ostream &operator<<(std::ostream &out, const trx_rseg_t &rseg) {
292  return (rseg.print(out));
293 }
294 
295 using Rsegs_Vector = std::vector<trx_rseg_t *, ut_allocator<trx_rseg_t *>>;
296 using Rseg_Iterator = Rsegs_Vector::iterator;
297 
298 /** This is a wrapper for a std::vector of trx_rseg_t object pointers. */
299 class Rsegs {
300  public:
301  /** Default constructor */
302  Rsegs() : m_rsegs(), m_latch(), m_state(INIT) {
303 #ifndef UNIV_HOTBACKUP
304  init();
305 #endif /* !UNIV_HOTBACKUP */
306  }
307 
308  ~Rsegs() {
309 #ifndef UNIV_HOTBACKUP
310  deinit();
311 #endif /* !UNIV_HOTBACKUP */
312  }
313 
314  /** Initialize */
315  void init();
316 
317  /** De-initialize */
318  void deinit();
319 
320  /** Clear the vector of cached rollback segments leaving the
321  reserved space allocated. */
322  void clear();
323 
324  /** Add rollback segment.
325  @param[in] rseg rollback segment to add. */
326  void push_back(trx_rseg_t *rseg) { m_rsegs.push_back(rseg); }
327 
328  /** Number of registered rsegs.
329  @return size of rseg list. */
330  ulint size() { return (m_rsegs.size()); }
331 
332  /** beginning iterator
333  @return an iterator to the first element */
334  Rseg_Iterator begin() { return (m_rsegs.begin()); }
335 
336  /** ending iterator
337  @return an iterator to the end */
338  Rseg_Iterator end() { return (m_rsegs.end()); }
339 
340  /** Find the rseg at the given slot in this vector.
341  @param[in] slot a slot within the vector.
342  @return an iterator to the end */
343  trx_rseg_t *at(ulint slot) { return (m_rsegs.at(slot)); }
344 
345  /** Find an rseg in the std::vector that uses the rseg_id given.
346  @param[in] rseg_id A slot in a durable array such as
347  the TRX_SYS page or RSEG_ARRAY page.
348  @return a pointer to an trx_rseg_t that uses the rseg_id. */
349  trx_rseg_t *find(ulint rseg_id);
350 
351  /** Sort the vector on trx_rseg_t::id */
352  void sort() {
353  if (m_rsegs.empty()) {
354  return;
355  }
356 
357  std::sort(
358  m_rsegs.begin(), m_rsegs.end(),
359  [](trx_rseg_t *lhs, trx_rseg_t *rhs) { return (rhs->id > lhs->id); });
360  }
361 
362  /** Get a shared lock on m_rsegs. */
363  void s_lock() { rw_lock_s_lock(m_latch); }
364 
365  /** Get a shared lock on m_rsegs. */
366  void s_unlock() { rw_lock_s_unlock(m_latch); }
367 
368  /** Get a shared lock on m_rsegs. */
369  void x_lock() { rw_lock_x_lock(m_latch); }
370 
371  /** Get a shared lock on m_rsegs. */
372  void x_unlock() { rw_lock_x_unlock(m_latch); }
373 
374  /** Return whether the undo tablespace is active.
375  @return true if active */
376  bool is_active() { return (m_state == ACTIVE); }
377 
378  /** Return whether the undo tablespace is inactive due to
379  implicit selection by the purge thread.
380  @return true if marked for truncation by the purge thread */
381  bool is_inactive_implicit() { return (m_state == INACTIVE_IMPLICIT); }
382 
383  /** Return whether the undo tablespace was made inactive by
384  ALTER TABLESPACE.
385  @return true if altered */
386  bool is_inactive_explicit() { return (m_state == INACTIVE_EXPLICIT); }
387 
388  /** Return whether the undo tablespace is empty and ready
389  to be dropped.
390  @return true if empty */
391  bool is_empty() { return (m_state == EMPTY); }
392 
393  /** Return whether the undo tablespace is being initialized.
394  @return true if empty */
395  bool is_init() { return (m_state == INIT); }
396 
397  /** Set the state of the rollback segments in this undo tablespace
398  to ACTIVE for use by new transactions. */
399  void set_active() { m_state = ACTIVE; }
400 
401  /** Set the state of the rollback segments in this undo
402  tablespace to inactive_implicit. This means that it will be
403  truncated and then made active again by the purge thread.
404  It will not be used for new transactions until it becomes
405  active again. */
407  ut_ad(m_state == ACTIVE || m_state == INACTIVE_EXPLICIT);
408  m_state = INACTIVE_IMPLICIT;
409  }
410 
411  /** Make the undo tablespace inactive so that it will not be
412  used for new transactions. The purge thread will clear out
413  all the undo logs, truncate it, and then mark it empty. */
414  void set_inactive_explicit() { m_state = INACTIVE_EXPLICIT; }
415 
416  /** Set the state of the undo tablespace to empty so that it
417  can be dropped. */
418  void set_empty() {
419  ut_ad(m_state == INACTIVE_EXPLICIT || m_state == ACTIVE ||
420  m_state == INIT || m_state == EMPTY);
421  m_state = EMPTY;
422  }
423 
424  /** std::vector of rollback segments */
426 
427  private:
428  /** RW lock to protect m_rsegs vector, m_active, and each
429  trx_rseg_t::trx_ref_count within it.
430  m_rsegs: x for adding elements, s for scanning, size etc.
431  m_active: x for modification, s for read
432  each trx_rseg_t::trx_ref_count within m_rsegs
433  s and atomic increment for modification, x for read */
435 
436  /* The four states of an undo tablespace.
437  INIT: The initial state of an undo space that is being created or opened.
438  ACTIVE: The rollback segments in this tablespace can be allocated to new
439  transactions. The undo tablespace is ready for undo logs.
440  INACTIVE_IMPLICIT: These rollback segments are no longer being used by new
441  transactions. They arre 'inactive'. The truncate process
442  is happening. This undo tablespace was selected by the
443  purge thread implicitly. When the truncation process
444  is complete, the next state is ACTIVE.
445  INACTIVE_EXPLICIT: These rollback segments are no longer being used by new
446  transactions. They arre 'inactive'. The truncate process
447  is happening. This undo tablespace was selected by the
448  an ALTER UNDO TABLESPACE SET INACTIVE command. When the
449  truncation process is complete, the next state is EMPTY.
450  EMPTY: The undo tablespace has been truncated but is no longer
451  active. It is ready to be either dropped or set active
452  explicitly. This state is also used when the undo tablespace and
453  its rollback segments are being inititalized.
454 
455  These states are changed under an exclusive lock on m_latch and are read
456  under a shared lock.
457 
458  The following actions can cause changes in these states:
459  Init: Implicit undo spaces are created at startup.
460  Create: Explicit undo tablespace creation at runtime.
461  Mark: Purge thread implicitly selects an undo space to truncate.
462  SetInactive: This ALTER UNDO TABLESPACE causes an explicit truncation.
463  SetActive: This ALTER UNDO TABLESPACE changes the target state from
464  EMPTY to ACTIVE.
465  Trucate: The truncate process is completed by the purge thread.
466  Drop: Delete an EMPTY undo tablespace
467  Crash: A crash occurs
468  Fixup: At startup, if an undo space was being truncated with a crash.
469  SaveDDState: At startup, once the DD is available the state saved there
470  will be applied. INACTIVE_IMPLICIT is never saved to the DD.
471  So the DD state INACTIVE means INACTIVE_EXPLICIT.
472  See apply_dd_undo_state()
473 
474  State changes allowed: (Actions on states not mentioned are not allowed.)
475  Init from null -> INIT -> ACTIVE see srv_start()
476  from null -> INIT -> EMPTY see trx_rsegs_init()
477  Create from null -> EMPTY -> ACTIVE
478  Mark from INACTIVE_EXPLICIT -> INACTIVE_EXPLICIT -> Truncate
479  from ACTIVE -> INACTIVE_IMPLICIT -> Truncate
480  SetInactive from ACTIVE -> INACTIVE_EXPLICIT -> Mark
481  from INACTIVE_IMPLICIT -> INACTIVE_EXPLICIT
482  from INACTIVE_EXPLICIT -> INACTIVE_EXPLICIT
483  from EMPTY -> EMPTY
484  SetActive from ACTIVE -> ACTIVE
485  from INACTIVE_IMPLICIT -> INACTIVE_IMPLICIT
486  from INACTIVE_EXPLICIT -> INACTIVE_IMPLICIT
487  from EMPTY -> ACTIVE
488  Truncate from INACTIVE_IMPLICIT -> ACTIVE
489  from INACTIVE_EXPLICIT -> EMPTY
490  Drop if ACTIVE -> error returned
491  if INACTIVE_IMPLICIT -> error returned
492  if INACTIVE_EXPLICIT -> error returned
493  from EMPTY -> null
494  Crash if ACTIVE, at startup: ACTIVE
495  if INACTIVE_IMPLICIT, at startup: Fixup
496  if INACTIVE_EXPLICIT, at startup: Fixup
497  if EMPTY, at startup: EMPTY
498  Fixup from INACTIVE_IMPLICIT before crash -> INACTIVE_IMPLICIT -> Mark
499  from INACTIVE_EXPLICIT before crash -> INACTIVE_IMPLICIT -> Mark
500  SaveDDState from ACTIVE before crash -> ACTIVE
501  from INACTIVE_IMPLICIT before crash -> ACTIVE
502  from INACTIVE_EXPLICIT before crash -> INACTIVE_EXPLICIT -> Mark
503  from EMPTY -> EMPTY
504  */
510  EMPTY
511  };
512 
513  /** The current state of this undo tablespace. */
514  enum undo_space_states m_state;
515 };
516 
517 /** Rollback segements from a given transaction with trx-no
518 scheduled for purge. */
520  public:
521  /** Default constructor */
522  TrxUndoRsegs() : m_trx_no() {}
523 
524  explicit TrxUndoRsegs(trx_id_t trx_no) : m_trx_no(trx_no) {
525  // Do nothing
526  }
527 
528  /** Get transaction number
529  @return trx_id_t - get transaction number. */
530  trx_id_t get_trx_no() const { return (m_trx_no); }
531 
532  /** Add rollback segment.
533  @param rseg rollback segment to add. */
534  void push_back(trx_rseg_t *rseg) { m_rsegs.push_back(rseg); }
535 
536  /** Erase the element pointed by given iterator.
537  @param[in] it iterator */
538  void erase(Rseg_Iterator &it) { m_rsegs.erase(it); }
539 
540  /** Number of registered rsegs.
541  @return size of rseg list. */
542  ulint size() const { return (m_rsegs.size()); }
543 
544  /**
545  @return an iterator to the first element */
546  Rseg_Iterator begin() { return (m_rsegs.begin()); }
547 
548  /**
549  @return an iterator to the end */
550  Rseg_Iterator end() { return (m_rsegs.end()); }
551 
552  /** Append rollback segments from referred instance to current
553  instance. */
554  void append(const TrxUndoRsegs &append_from) {
555  ut_ad(get_trx_no() == append_from.get_trx_no());
556 
557  m_rsegs.insert(m_rsegs.end(), append_from.m_rsegs.begin(),
558  append_from.m_rsegs.end());
559  }
560 
561  /** Compare two TrxUndoRsegs based on trx_no.
562  @param lhs first element to compare
563  @param rhs second element to compare
564  @return true if elem1 > elem2 else false.*/
565  bool operator()(const TrxUndoRsegs &lhs, const TrxUndoRsegs &rhs) {
566  return (lhs.m_trx_no > rhs.m_trx_no);
567  }
568 
569  /** Compiler defined copy-constructor/assignment operator
570  should be fine given that there is no reference to a memory
571  object outside scope of class object.*/
572 
573  private:
574  /** The rollback segments transaction number. */
576 
577  /** Rollback segments of a transaction, scheduled for purge. */
579 };
580 
581 typedef std::priority_queue<
582  TrxUndoRsegs, std::vector<TrxUndoRsegs, ut_allocator<TrxUndoRsegs>>,
583  TrxUndoRsegs>
585 
586 typedef std::vector<trx_id_t, ut_allocator<trx_id_t>> trx_ids_t;
587 
588 /** Mapping read-write transactions from id to transaction instance, for
589 creating read views and during trx id lookup for MVCC and locking. */
590 struct TrxTrack {
591  explicit TrxTrack(trx_id_t id, trx_t *trx = nullptr) : m_id(id), m_trx(trx) {
592  // Do nothing
593  }
594 
597 };
598 
599 struct TrxTrackHash {
600  size_t operator()(const TrxTrack &key) const { return (size_t(key.m_id)); }
601 };
602 
603 /**
604 Comparator for TrxMap */
606  bool operator()(const TrxTrack &lhs, const TrxTrack &rhs) const {
607  return (lhs.m_id == rhs.m_id);
608  }
609 };
610 
611 /**
612 Comparator for TrxMap */
613 struct TrxTrackCmp {
614  bool operator()(const TrxTrack &lhs, const TrxTrack &rhs) const {
615  return (lhs.m_id < rhs.m_id);
616  }
617 };
618 
619 // typedef std::unordered_set<TrxTrack, TrxTrackHash, TrxTrackHashCmp> TrxIdSet;
620 typedef std::set<TrxTrack, TrxTrackCmp, ut_allocator<TrxTrack>> TrxIdSet;
621 
622 struct TrxVersion {
623  TrxVersion(trx_t *trx);
624 
626  ulint m_version;
627 };
628 
629 typedef std::vector<TrxVersion, ut_allocator<TrxVersion>> hit_list_t;
630 #endif /* trx0types_h */
Rseg_Iterator end()
ending iterator
Definition: trx0types.h:338
static const ib_uint32_t TRX_FORCE_ROLLBACK_ASYNC
Was the transaction rolled back asynchronously or by the owning thread.
Definition: trx0types.h:68
void clear(Shards< COUNT > &shards) noexcept
Clear the counter - reset to 0.
Definition: ut0counter.h:326
Definition: trx0types.h:622
TrxUndoRsegs(trx_id_t trx_no)
Definition: trx0types.h:524
byte trx_undo_rec_t
Undo log record.
Definition: trx0types.h:173
bool operator()(const TrxTrack &lhs, const TrxTrack &rhs) const
Definition: trx0types.h:606
ib_mutex_t TrxMutex
Definition: trx0types.h:177
This is a wrapper for a std::vector of trx_rseg_t object pointers.
Definition: trx0types.h:299
Definition: trx0types.h:506
uint32 page_no_t
Page number.
Definition: api0api.h:57
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:556
static mysql_service_status_t deinit()
Component deinitialization.
Definition: audit_api_message_emit.cc:579
void push_back(trx_rseg_t *rseg)
Add rollback segment.
Definition: trx0types.h:326
ib_id_t roll_ptr_t
Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR)
Definition: trx0types.h:146
trx_state_t
Transaction states (trx_t::state)
Definition: trx0types.h:86
page_size_t page_size
page size of the relevant tablespace
Definition: trx0types.h:239
Support for 2PC/XA.
Definition: trx0types.h:97
byte trx_upagef_t
Undo log page header.
Definition: trx0types.h:171
byte trx_usegf_t
Undo segment header.
Definition: trx0types.h:167
bool operator()(const TrxTrack &lhs, const TrxTrack &rhs) const
Definition: trx0types.h:614
trx_rseg_t * at(ulint slot)
Find the rseg at the given slot in this vector.
Definition: trx0types.h:343
Definition: trx0types.h:99
page_no_t get_curr_size() const
Definition: trx0types.h:217
Definition: trx0trx.h:800
Comparator for TrxMap.
Definition: trx0types.h:613
pthread_mutex_t mutex
Definition: memcached.c:384
void unlatch()
Exit the rseg->mutex.
Definition: trx0types.h:198
TrxTrack(trx_id_t id, trx_t *trx=nullptr)
Definition: trx0types.h:591
trx_id_t get_trx_no() const
Get transaction number.
Definition: trx0types.h:530
RsegMutex mutex
mutex protecting the fields in this struct except id,space,page_no which are constant ...
Definition: trx0types.h:230
byte trx_ulogf_t
Undo log header.
Definition: trx0types.h:169
void set_active()
Set the state of the rollback segments in this undo tablespace to ACTIVE for use by new transactions...
Definition: trx0types.h:399
Same as not started but with additional semantics that it was rolled back asynchronously the last tim...
Definition: trx0types.h:92
void push_back(trx_rseg_t *rseg)
Add rollback segment.
Definition: trx0types.h:534
Rseg_Iterator end()
Definition: trx0types.h:550
Mapping read-write transactions from id to transaction instance, for creating read views and during t...
Definition: trx0types.h:590
rw_lock_t * m_latch
RW lock to protect m_rsegs vector, m_active, and each trx_rseg_t::trx_ref_count within it...
Definition: trx0types.h:434
void sort()
Sort the vector on trx_rseg_t::id.
Definition: trx0types.h:352
TrxUndoRsegs()
Default constructor.
Definition: trx0types.h:522
transaction is rolling back
Definition: trx0types.h:81
Rsegs_Vector::iterator Rseg_Iterator
Definition: trx0types.h:296
byte trx_rsegsf_t
Rollback segment array header.
Definition: trx0types.h:163
Commit command node in a query graph.
Definition: trx0trx.h:1254
ulint max_size
maximum allowed size in pages
Definition: trx0types.h:242
std::vector< trx_rseg_t *, ut_allocator< trx_rseg_t * > > Rsegs_Vector
Definition: trx0types.h:295
Rollback command node in a query graph.
Definition: trx0roll.h:154
transaction is waiting for a lock
Definition: trx0types.h:79
static const ib_uint32_t TRX_FORCE_ROLLBACK_MASK
For masking out the above four flags.
Definition: trx0types.h:74
ib_id_t row_id_t
Row identifier (DB_ROW_ID, DATA_ROW_ID)
Definition: trx0types.h:138
The rollback segment memory object.
Definition: trx0types.h:183
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:570
#define rw_lock_x_unlock(L)
Definition: sync0rw.h:314
Transaction savepoint.
Definition: trx0types.h:154
#define rw_lock_x_lock(M)
Definition: sync0rw.h:289
Definition: trx0types.h:88
std::atomic< ulint > trx_ref_count
Reference counter to track rseg allocated transactions.
Definition: trx0types.h:281
Definition: trx0types.h:508
Rseg_Iterator begin()
Definition: trx0types.h:546
void x_lock()
Get a shared lock on m_rsegs.
Definition: trx0types.h:369
~Rsegs()
Definition: trx0types.h:308
transaction is running
Definition: trx0types.h:78
Rollback segements from a given transaction with trx-no scheduled for purge.
Definition: trx0types.h:519
void s_lock()
Get a shared lock on m_rsegs.
Definition: trx0types.h:363
trx_id_t m_id
Definition: trx0types.h:595
std::priority_queue< TrxUndoRsegs, std::vector< TrxUndoRsegs, ut_allocator< TrxUndoRsegs > >, TrxUndoRsegs > purge_pq_t
Definition: trx0types.h:584
Rsegs()
Default constructor.
Definition: trx0types.h:302
page_no_t page_no
page number of the rollback segment header
Definition: trx0types.h:236
The read-write lock (for threads, not for database transactions)
trx_t * m_trx
Definition: trx0types.h:625
bool is_init()
Return whether the undo tablespace is being initialized.
Definition: trx0types.h:395
ulint size()
Number of registered rsegs.
Definition: trx0types.h:330
ulint m_version
Definition: trx0types.h:626
Rseg_Iterator begin()
beginning iterator
Definition: trx0types.h:334
ib_mutex_t PQMutex
Definition: trx0types.h:179
void s_unlock()
Get a shared lock on m_rsegs.
Definition: trx0types.h:366
static const ib_uint32_t TRX_FORCE_ROLLBACK
Mark the transaction for forced rollback.
Definition: trx0types.h:71
Instrumented memory allocator.
undo_space_states
Definition: trx0types.h:505
transaction is committing
Definition: trx0types.h:82
std::vector< TrxVersion, ut_allocator< TrxVersion > > hit_list_t
Definition: trx0types.h:629
trx_t * m_trx
Definition: trx0types.h:596
bool is_empty()
Return whether the undo tablespace is empty and ready to be dropped.
Definition: trx0types.h:391
The transaction is creating or dropping an index in an existing table.
Definition: trx0types.h:114
Definition: trx0types.h:509
Rsegs_Vector m_rsegs
std::vector of rollback segments
Definition: trx0types.h:425
static const ulint TRX_MAGIC_N
Random value to check for corruption of trx_t.
Definition: trx0types.h:59
Definition: trx0types.h:94
bool is_inactive_explicit()
Return whether the undo tablespace was made inactive by ALTER TABLESPACE.
Definition: trx0types.h:386
Utilities for byte operations.
The transaction is not modifying the data dictionary.
Definition: trx0types.h:105
void set_curr_size(page_no_t npages)
Definition: trx0types.h:221
ulint last_offset
Byte offset of the last not yet purged log header.
Definition: trx0types.h:272
std::set< TrxTrack, TrxTrackCmp, ut_allocator< TrxTrack > > TrxIdSet
Definition: trx0types.h:620
std::ostream & print(std::ostream &out) const
Definition: trx0types.h:283
Policy based mutexes.
undo_no_t least_undo_no
least undo number to undo
Definition: trx0types.h:155
static const char * key
Definition: suite_stubs.c:14
void append(const TrxUndoRsegs &append_from)
Append rollback segments from referred instance to current instance.
Definition: trx0types.h:554
void erase(Rseg_Iterator &it)
Erase the element pointed by given iterator.
Definition: trx0types.h:538
#define rw_lock_s_lock(M)
Definition: sync0rw.h:254
trx_que_t
Transaction execution states when trx->state == TRX_STATE_ACTIVE.
Definition: trx0types.h:77
Comparator for TrxMap.
Definition: trx0types.h:605
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
The transaction is creating a table or an index, or dropping a table.
Definition: trx0types.h:110
ibool last_del_marks
TRUE if the last not yet purged log needs purging.
Definition: trx0types.h:278
page_no_t last_page_no
Page number of the last not yet purged log header in the history list; FIL_NULL if all list purged...
Definition: trx0types.h:269
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:65
A savepoint set with SQL&#39;s "SAVEPOINT savepoint_id" command.
Definition: trx0roll.h:166
space_id_t space_id
space ID where the rollback segment header is placed
Definition: trx0types.h:233
void x_unlock()
Get a shared lock on m_rsegs.
Definition: trx0types.h:372
Page size descriptor.
Definition: page0size.h:49
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:144
#define UT_LIST_BASE_NODE_T(TYPE)
Definition: innodb_utility.h:47
void latch()
Enter the rseg->mutex.
Definition: trx0types.h:192
ib_mutex_t UndoMutex
Definition: trx0types.h:178
#define rw_lock_s_unlock(L)
Definition: sync0rw.h:313
#define mutex_enter(M)
Definition: ut0mutex.h:115
A class describing a page size.
trx_dict_op_t
Type of data dictionary operation.
Definition: trx0types.h:103
page_no_t curr_size
current size in pages
Definition: trx0types.h:246
ulint size() const
Number of registered rsegs.
Definition: trx0types.h:542
Transaction undo log memory object; this is protected by the undo_mutex in the corresponding transact...
Definition: trx0undo.h:335
trx_id_t last_trx_no
Transaction number of the last not yet purged log.
Definition: trx0types.h:275
void set_inactive_explicit()
Make the undo tablespace inactive so that it will not be used for new transactions.
Definition: trx0types.h:414
#define mutex_exit(M)
Definition: ut0mutex.h:122
trx_id_t m_trx_no
Compiler defined copy-constructor/assignment operator should be fine given that there is no reference...
Definition: trx0types.h:575
std::vector< trx_id_t, ut_allocator< trx_id_t > > trx_ids_t
Definition: trx0types.h:586
bool is_inactive_implicit()
Return whether the undo tablespace is inactive due to implicit selection by the purge thread...
Definition: trx0types.h:381
ulint id
rollback segment id == the index of its slot in the trx system file copy
Definition: trx0types.h:226
Rsegs_Vector m_rsegs
Rollback segments of a transaction, scheduled for purge.
Definition: trx0types.h:578
void decr_curr_size(page_no_t npages=1)
Decrement the current size of the rollback segment by the given number of pages.
Definition: trx0types.h:206
std::ostream & operator<<(std::ostream &out, const trx_rseg_t &rseg)
Definition: trx0types.h:291
The transaction system central memory data structure.
Definition: trx0sys.h:452
bool operator()(const TrxUndoRsegs &lhs, const TrxUndoRsegs &rhs)
Compare two TrxUndoRsegs based on trx_no.
Definition: trx0types.h:565
unsigned char byte
Blob class.
Definition: common.h:159
void incr_curr_size()
Increment the current size of the rollback segment by the given number of pages.
Definition: trx0types.h:213
static const space_id_t TRX_SYS_SPACE
Space id of the transaction system page (the system tablespace)
Definition: trx0types.h:53
Latching protocol for trx_lock_t::que_state.
Definition: trx0trx.h:552
ib_mutex_t TrxSysMutex
Definition: trx0types.h:180
static const ib_uint32_t TRX_FORCE_ROLLBACK_DISABLE
If this flag is set then the transaction cannot be rolled back asynchronously.
Definition: trx0types.h:63
size_t operator()(const TrxTrack &key) const
Definition: trx0types.h:600
Definition: trx0types.h:507
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:148
Definition: trx0types.h:599
ib_mutex_t RsegMutex
Definition: trx0types.h:176
void set_inactive_implicit()
Set the state of the rollback segments in this undo tablespace to inactive_implicit.
Definition: trx0types.h:406
byte trx_rsegf_t
Rollback segment header.
Definition: trx0types.h:165
bool is_active()
Return whether the undo tablespace is active.
Definition: trx0types.h:376
byte trx_sysf_t
File objects.
Definition: trx0types.h:161
const byte * find(const Pages *pages, const page_id_t &page_id) noexcept
Find a doublewrite copy of a page.
Definition: buf0dblwr.cc:2211
The control structure used in the purge operation.
Definition: trx0purge.h:963
void set_empty()
Set the state of the undo tablespace to empty so that it can be dropped.
Definition: trx0types.h:418