MySQL  8.0.20
Source Code Documentation
trx0purge.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/trx0purge.h
28  Purge old versions
29 
30  Created 3/26/1996 Heikki Tuuri
31  *******************************************************/
32 
33 #ifndef trx0purge_h
34 #define trx0purge_h
35 
36 #include "fil0fil.h"
37 #include "mtr0mtr.h"
38 #include "page0page.h"
39 #include "que0types.h"
40 #include "read0types.h"
41 #include "trx0sys.h"
42 #include "trx0types.h"
43 #include "univ.i"
44 #include "usr0sess.h"
45 #ifdef UNIV_HOTBACKUP
46 #include "trx0sys.h"
47 #endif /* UNIV_HOTBACKUP */
48 
49 /** The global data structure coordinating a purge */
50 extern trx_purge_t *purge_sys;
51 
52 /** Calculates the file address of an undo log header when we have the file
53  address of its history list node.
54  @return file address of the log */
55 UNIV_INLINE
57  fil_addr_t node_addr); /*!< in: file address of the history
58  list node of the log */
59 
60 /** Creates the global purge system control structure and inits the history
61 mutex.
62 @param[in] n_purge_threads number of purge threads
63 @param[in,out] purge_queue UNDO log min binary heap */
64 void trx_purge_sys_create(ulint n_purge_threads, purge_pq_t *purge_queue);
65 
66 /** Frees the global purge system control structure. */
67 void trx_purge_sys_close(void);
68 
69 /************************************************************************
70 Adds the update undo log as the first log in the history list. Removes the
71 update undo log segment from the rseg slot if it is too big for reuse. */
73  trx_t *trx, /*!< in: transaction */
74  trx_undo_ptr_t *undo_ptr, /*!< in: update undo log. */
75  page_t *undo_page, /*!< in: update undo log header page,
76  x-latched */
77  bool update_rseg_history_len,
78  /*!< in: if true: update rseg history
79  len else skip updating it. */
80  ulint n_added_logs, /*!< in: number of logs added */
81  mtr_t *mtr); /*!< in: mtr */
82 
83 /** This function runs a purge batch.
84  @return number of undo log pages handled in the batch */
85 ulint trx_purge(ulint n_purge_threads, /*!< in: number of purge tasks to
86  submit to task queue. */
87  ulint limit, /*!< in: the maximum number of
88  records to purge in one batch */
89  bool truncate); /*!< in: truncate history if true */
90 
91 /** Stop purge and wait for it to stop, move to PURGE_STATE_STOP. */
92 void trx_purge_stop(void);
93 /** Resume purge, move to PURGE_STATE_RUN. */
94 void trx_purge_run(void);
95 
96 /** Purge states */
98  PURGE_STATE_INIT, /*!< Purge instance created */
99  PURGE_STATE_RUN, /*!< Purge should be running */
100  PURGE_STATE_STOP, /*!< Purge should be stopped */
101  PURGE_STATE_EXIT, /*!< Purge has been shutdown */
102  PURGE_STATE_DISABLED /*!< Purge was never started */
103 };
104 
105 /** Get the purge state.
106  @return purge state. */
108 
109 // Forward declaration
110 struct TrxUndoRsegsIterator;
111 
112 /** This is the purge pointer/iterator. We need both the undo no and the
113 transaction no up to which purge has parsed and applied the records. */
114 struct purge_iter_t {
116  // Do nothing
117  }
118 
119  trx_id_t trx_no; /*!< Purge has advanced past all
120  transactions whose number is less
121  than this */
122  undo_no_t undo_no; /*!< Purge has advanced past all records
123  whose undo number is less than this */
125  /*!< Last undo record resided in this
126  space id. */
128  /*!< the transaction that created the
129  undo log record. Modifier trx id.*/
130 };
131 
132 /* Namespace to hold all the related functions and variables needed
133 to truncate an undo tablespace. */
134 namespace undo {
135 
136 /** Magic Number to indicate truncate action is complete. */
137 const ib_uint32_t s_magic = 76845412;
138 
139 /** Truncate Log file Prefix. */
140 const char *const s_log_prefix = "undo_";
141 
142 /** Truncate Log file Extension. */
143 const char *const s_log_ext = "trunc.log";
144 
145 /** The currently used undo space IDs for an undo space number
146 along with a boolean showing whether the undo space number is in use. */
149  bool in_use;
150 };
151 
152 /** List of currently used undo space IDs for each undo space number
153 along with a boolean showing whether the undo space number is in use. */
154 extern struct space_id_account *space_id_bank;
155 
156 /** Check if the space_id is an undo space ID in the reserved range.
157 @param[in] space_id undo tablespace ID
158 @return true if it is in the reserved undo space ID range. */
159 inline bool is_reserved(space_id_t space_id) {
160  return (space_id >= dict_sys_t::s_min_undo_space_id &&
161  space_id <= dict_sys_t::s_max_undo_space_id);
162 }
163 
164 /** Convert an undo space number (from 1 to 127) into the undo space_id,
165 given an index indicating which space_id from the pool assigned to that
166 undo number.
167 @param[in] space_num undo tablespace number
168 @param[in] ndx index of the space_id within that undo number
169 @return space_id of the undo tablespace */
170 inline space_id_t num2id(space_id_t space_num, size_t ndx) {
171  ut_ad(space_num > 0);
172  ut_ad(space_num <= FSP_MAX_UNDO_TABLESPACES);
174 
175  space_id_t space_id = dict_sys_t::s_max_undo_space_id + 1 - space_num -
176  static_cast<space_id_t>(ndx * FSP_MAX_UNDO_TABLESPACES);
177 
178  return (space_id);
179 }
180 
181 /** Convert an undo space number (from 1 to 127) into an undo space_id.
182 Use the undo::space_id_bank to return the curent space_id assigned to
183 that undo number.
184 @param[in] space_num undo tablespace number
185 @return space_id of the undo tablespace */
186 inline space_id_t num2id(space_id_t space_num) {
187  ut_ad(space_num > 0);
188  ut_ad(space_num <= FSP_MAX_UNDO_TABLESPACES);
189 
190  size_t slot = space_num - 1;
191 
192  /* The space_id_back is normally protected by undo::spaces::m_latch.
193  But this can only be called on a specific slot when truncation is not
194  happening on that slot, i.e. the undo tablespace is in use. */
195  ut_ad(undo::space_id_bank[slot].in_use);
196 
197  return (undo::space_id_bank[slot].space_id);
198 }
199 
200 /* clang-format off */
201 /** Convert an undo space ID into an undo space number.
202 NOTE: This may be an undo space_id from a pre-exisiting 5.7
203 database which used space_ids from 1 to 127. If so, the
204 space_id is the space_num.
205 The space_ids are assigned to number ranges in reverse from high to low.
206 In addition, the first space IDs for each undo number occur sequentionally
207 and descending before the second space_id.
208 
209 Since s_max_undo_space_id = 0xFFFFFFEF, FSP_MAX_UNDO_TABLESPACES = 127
210 and undo_space_id_range = 512:
211  Space ID Space Num Space ID Space Num ... Space ID Space Num
212  0xFFFFFFEF 1 0xFFFFFFEe 2 ... 0xFFFFFF71 127
213  0xFFFFFF70 1 0xFFFFFF6F 2 ... 0xFFFFFEF2 127
214  0xFFFFFEF1 1 0xFFFFFEF0 2 ... 0xFFFFFE73 127
215 ...
216 
217 This is done to maintain backward compatibility to when there was only one
218 space_id per undo space number.
219 @param[in] space_id undo tablespace ID
220 @return space number of the undo tablespace */
221 /* clang-format on */
222 inline space_id_t id2num(space_id_t space_id) {
223  if (!is_reserved(space_id)) {
224  return (space_id);
225  }
226 
227  return (((dict_sys_t::s_max_undo_space_id - space_id) %
229  1);
230 }
231 
232 /* Given a reserved undo space_id, return the next space_id for the associated
233 undo space number. */
234 inline space_id_t id2next_id(space_id_t space_id) {
235  ut_ad(is_reserved(space_id));
236 
237  space_id_t space_num = id2num(space_id);
238  space_id_t first_id = dict_sys_t::s_max_undo_space_id + 1 - space_num;
239  space_id_t last_id = first_id - (FSP_MAX_UNDO_TABLESPACES *
241 
242  return (space_id == SPACE_UNKNOWN || space_id == last_id
243  ? first_id
244  : space_id - FSP_MAX_UNDO_TABLESPACES);
245 }
246 
247 /** Initialize the undo tablespace space_id bank which is a lock free
248 repository for information about the space IDs used for undo tablespaces.
249 It is used during creation in order to assign an unused space number and
250 during truncation in order to assign the next space_id within that
251 space_number range. */
252 void init_space_id_bank();
253 
254 /** Note that the undo space number for a space ID is being used.
255 Put that space_id into the space_id_bank.
256 @param[in] space_id undo tablespace number */
257 void use_space_id(space_id_t space_id);
258 
259 /** Mark that the given undo space number is being used and
260 return the next available space_id for that space number.
261 @param[in] space_num undo tablespace number
262 @return the next tablespace ID to use */
264 
265 /** Mark an undo number associated with a given space_id as unused and
266 available to be resused. This happens when the fil_space_t is closed
267 associated with a drop undo tablespace.
268 @param[in] space_id Undo Tablespace ID */
269 void unuse_space_id(space_id_t space_id);
270 
271 /** Given a valid undo space_id or SPACE_UNKNOWN, return the next space_id
272 for the given space number.
273 @param[in] space_id undo tablespace ID
274 @param[in] space_num undo tablespace number
275 @return the next tablespace ID to use */
276 space_id_t next_space_id(space_id_t space_id, space_id_t space_num);
277 
278 /** Given a valid undo space_id, return the next space_id for that
279 space number.
280 @param[in] space_id undo tablespace ID
281 @return the next tablespace ID to use */
283 
284 /** Return the next available undo space ID to be used for a new explicit
285 undo tablespaces.
286 @retval if success, next available undo space number.
287 @retval if failure, SPACE_UNKNOWN */
289 
290 /** Build a standard undo tablespace name from a space_id.
291 @param[in] space_id id of the undo tablespace.
292 @return tablespace name of the undo tablespace file */
293 char *make_space_name(space_id_t space_id);
294 
295 /** Build a standard undo tablespace file name from a space_id.
296 @param[in] space_id id of the undo tablespace.
297 @return file_name of the undo tablespace file */
298 char *make_file_name(space_id_t space_id);
299 
300 /** An undo::Tablespace object is used to easily convert between
301 undo_space_id and undo_space_num and to create the automatic file_name
302 and space name. In addition, it is used in undo::Tablespaces to track
303 the trx_rseg_t objects in an Rsegs vector. So we do not allocate the
304 Rsegs vector for each object, only when requested by the constructor. */
305 struct Tablespace {
306  /** Constructor
307  @param[in] id tablespace id */
308  explicit Tablespace(space_id_t id)
309  : m_id(id),
310  m_num(undo::id2num(id)),
311  m_implicit(true),
312  m_new(false),
313  m_space_name(),
314  m_file_name(),
315  m_log_file_name(),
316  m_rsegs() {}
317 
318  /** Copy Constructor
319  @param[in] other undo tablespace to copy */
321  : m_id(other.id()),
322  m_num(undo::id2num(other.id())),
323  m_implicit(other.is_implicit()),
324  m_new(other.is_new()),
325  m_space_name(),
326  m_file_name(),
327  m_log_file_name(),
328  m_rsegs() {
329  ut_ad(m_id == 0 || is_reserved(m_id));
330 
331  set_space_name(other.space_name());
332  set_file_name(other.file_name());
333 
334  /* When the copy constructor is used, add an Rsegs
335  vector. This constructor is only used in the global
336  undo::Tablespaces object where rollback segments are
337  tracked. */
338  m_rsegs = UT_NEW_NOKEY(Rsegs());
339  }
340 
341  /** Destructor */
343  if (m_space_name != nullptr) {
344  ut_free(m_space_name);
345  m_space_name = nullptr;
346  }
347 
348  if (m_file_name != nullptr) {
349  ut_free(m_file_name);
350  m_file_name = nullptr;
351  }
352 
353  if (m_log_file_name != nullptr) {
354  ut_free(m_log_file_name);
355  m_log_file_name = nullptr;
356  }
357 
358  /* Clear the cached rollback segments. */
359  if (m_rsegs != nullptr) {
360  UT_DELETE(m_rsegs);
361  m_rsegs = nullptr;
362  }
363  }
364 
365  /* Determine if this undo space needs to be truncated.
366  @return true if it should be truncated, false if not. */
368  /* If it is already inactive, even implicitly, then proceed. */
369  m_rsegs->s_lock();
370  if (m_rsegs->is_inactive_implicit() || m_rsegs->is_inactive_explicit()) {
371  m_rsegs->s_unlock();
372  return (true);
373  }
374 
375  /* If implicit undo truncation is turned off, or if the rsegs don't exist
376  yet, don't bother checking the size. */
377  if (!srv_undo_log_truncate || m_rsegs == nullptr || m_rsegs->is_empty() ||
378  m_rsegs->is_init()) {
379  m_rsegs->s_unlock();
380  return (false);
381  }
382 
383  ut_ad(m_rsegs->is_active());
384  m_rsegs->s_unlock();
385 
386  page_no_t trunc_size = ut_max(
387  static_cast<page_no_t>(srv_max_undo_tablespace_size / srv_page_size),
388  static_cast<page_no_t>(SRV_UNDO_TABLESPACE_SIZE_IN_PAGES));
389  if (fil_space_get_size(id()) > trunc_size) {
390  return (true);
391  }
392 
393  return (false);
394  }
395 
396  /** Change the space_id from its current value.
397  @param[in] space_id The new undo tablespace ID */
398  void set_space_id(space_id_t space_id);
399 
400  /** Replace the standard undo space name if it exists with a copy
401  of the undo tablespace name provided.
402  @param[in] new_space_name non-standard undo space name */
403  void set_space_name(const char *new_space_name);
404 
405  /** Get the undo tablespace name. Make it if not yet made.
406  NOTE: This is only called from stack objects so there is no
407  race condition. If it is ever called from a shared object
408  like undo::spaces, then it must be protected by the caller.
409  @return tablespace name created from the space_id */
410  char *space_name() {
411  if (m_space_name == nullptr) {
412 #ifndef UNIV_HOTBACKUP
413  m_space_name = make_space_name(m_id);
414 #endif /* !UNIV_HOTBACKUP */
415  }
416 
417  return (m_space_name);
418  }
419 
420  /** Replace the standard undo file name if it exists with a copy
421  of the file name provided. This name can come in three forms:
422  absolute path, relative path, and basename. Undo ADD DATAFILE
423  does not accept a relative path. So if that comes in here, it
424  was the scaneed name and is relative to the datadir.
425  If this is just a basename, add it to srv_undo_dir.
426  @param[in] file_name explicit undo file name */
427  void set_file_name(const char *file_name);
428 
429  /** Get the undo space filename. Make it if not yet made.
430  NOTE: This is only called from stack objects so there is no
431  race condition. If it is ever called from a shared object
432  like undo::spaces, then it must be protected by the caller.
433  @return tablespace filename created from the space_id */
434  char *file_name() {
435  if (m_file_name == nullptr) {
436  m_file_name = make_file_name(m_id);
437  }
438 
439  return (m_file_name);
440  }
441 
442  /** Build a log file name based on space_id
443  @param[in] space_id id of the undo tablespace.
444  @return DB_SUCCESS or error code */
445  char *make_log_file_name(space_id_t space_id);
446 
447  /** Get the undo log filename. Make it if not yet made.
448  NOTE: This is only called from stack objects so there is no
449  race condition. If it is ever called from a shared object
450  like undo::spaces, then it must be protected by the caller.
451  @return tablespace filename created from the space_id */
452  char *log_file_name() {
453  if (m_log_file_name == nullptr) {
454  m_log_file_name = make_log_file_name(m_id);
455  }
456 
457  return (m_log_file_name);
458  }
459 
460  /** Get the undo tablespace ID.
461  @return tablespace ID */
462  space_id_t id() { return (m_id); }
463 
464  /** Get the undo tablespace number. This is the same as m_id
465  if m_id is 0 or this is a v5.6-5.7 undo tablespace. v8+ undo
466  tablespaces use a space_id from the reserved range.
467  @return undo tablespace number */
470 
471  return (m_num);
472  }
473 
474  /** Get a reference to the List of rollback segments within
475  this undo tablespace.
476  @return a reference to the Rsegs vector. */
477  Rsegs *rsegs() { return (m_rsegs); }
478 
479  /** Report whether this undo tablespace was explicitly created
480  by an SQL statement.
481  @return true if the tablespace was created explicitly. */
482  bool is_explicit() { return (!m_implicit); }
483 
484  /** Report whether this undo tablespace was implicitly created.
485  @return true if the tablespace was created implicitly. */
486  bool is_implicit() { return (m_implicit); }
487 
488  /** Report whether this undo tablespace was created at startup.
489  @retval true if created at startup.
490  @retval false if pre-existed at startup. */
491  bool is_new() { return (m_new); }
492 
493  /** Note that this undo tablespace is being created. */
494  void set_new() { m_new = true; }
495 
496  /** Return whether the undo tablespace is active.
497  @return true if active */
498  bool is_active() {
499  if (m_rsegs == nullptr) {
500  return (false);
501  }
502  m_rsegs->s_lock();
503  bool ret = m_rsegs->is_active();
504  m_rsegs->s_unlock();
505  return (ret);
506  }
507 
508  /** Return whether the undo tablespace is active. For optimization purposes,
509  do not take a latch.
510  @return true if active */
512  if (m_rsegs == nullptr) {
513  return (false);
514  }
515  return (m_rsegs->is_active());
516  }
517 
518  /** Return the rseg at the requested rseg slot if the undo space is active.
519  @param[in] slot The slot of the rseg. 1 to 127
520  @return Rseg pointer of nullptr if the space is not active. */
521  trx_rseg_t *get_active(ulint slot) {
522  m_rsegs->s_lock();
523  if (!m_rsegs->is_active()) {
524  m_rsegs->s_unlock();
525  return (nullptr);
526  }
527 
528  /* Mark the chosen rseg so that it will not be selected
529  for UNDO truncation. */
530  trx_rseg_t *rseg = m_rsegs->at(slot);
531  rseg->trx_ref_count++;
532 
533  m_rsegs->s_unlock();
534 
535  return (rseg);
536  }
537 
538  /** Return whether the undo tablespace is inactive due to
539  implicit selection by the purge thread.
540  @return true if marked for truncation by the purge thread */
542  if (m_rsegs == nullptr) {
543  return (false);
544  }
545  m_rsegs->s_lock();
546  bool ret = m_rsegs->is_inactive_implicit();
547  m_rsegs->s_unlock();
548  return (ret);
549  }
550 
551  /** Return whether the undo tablespace was made inactive by
552  ALTER TABLESPACE.
553  @return true if altered inactive */
555  if (m_rsegs == nullptr) {
556  return (false);
557  }
558  m_rsegs->s_lock();
559  bool ret = m_rsegs->is_inactive_explicit();
560  m_rsegs->s_unlock();
561  return (ret);
562  }
563 
564  /** Return whether the undo tablespace is empty and ready
565  to be dropped.
566  @return true if empty */
567  bool is_empty() {
568  if (m_rsegs == nullptr) {
569  return (true);
570  }
571  m_rsegs->s_lock();
572  bool ret = m_rsegs->is_empty();
573  m_rsegs->s_unlock();
574  return (ret);
575  }
576 
577  /** Set the undo tablespace active for use by transactions. */
578  void set_active() {
579  m_rsegs->x_lock();
580  m_rsegs->set_active();
581  m_rsegs->x_unlock();
582  }
583 
584  /** Set the state of the rollback segments in this undo tablespace to
585  inactive_implicit if currently active. If the state is inactive_explicit,
586  leave as is. Then put the space_id into the callers marked_space_id.
587  This is done when marking a space for truncate. It will not be used
588  for new transactions until it becomes active again. */
589  void set_inactive_implicit(space_id_t *marked_space_id) {
590  m_rsegs->x_lock();
591  if (m_rsegs->is_active()) {
592  m_rsegs->set_inactive_implicit();
593  }
594  *marked_space_id = m_id;
595 
596  m_rsegs->x_unlock();
597  }
598 
599  /** Make the undo tablespace inactive so that it will not be
600  used for new transactions. The purge thread will clear out
601  all the undo logs, truncate it, and then mark it empty. */
603  m_rsegs->x_lock();
604  m_rsegs->set_inactive_explicit();
605  m_rsegs->x_unlock();
606  }
607 
608  /** Make the undo tablespace active again so that it will
609  be used for new transactions.
610  If current State is ___ then do:
611  empty: Set active.
612  active_implicit: Ignore. It was not altered inactive. When it is done
613  being truncated it will go back to active.
614  active_explicit: Depends if it is marked for truncation.
615  marked: Set to inactive_implicit. the next state will be active.
616  not yet: Set to active so that it does not get truncated. */
617  void alter_active();
618 
619  /** Set the state of the undo tablespace to empty so that it
620  can be dropped. */
621  void set_empty() {
622  m_rsegs->x_lock();
623  m_rsegs->set_empty();
624  m_rsegs->x_unlock();
625  }
626 
627  private:
628  /** Undo Tablespace ID. */
630 
631  /** Undo Tablespace number, from 1 to 127. This is the
632  7-bit number that is used in a rollback pointer.
633  Use id2num() to get this number from a space_id. */
635 
636  /** True if this is an implicit undo tablespace */
638 
639  /** True if this undo tablespace was implicitly created when
640  this instance started up. False if it pre-existed. */
641  bool m_new;
642 
643  /** The tablespace name, auto-generated when needed from
644  the space number. */
646 
647  /** The tablespace file name, auto-generated when needed
648  from the space number. */
649  char *m_file_name;
650 
651  /** The tablespace log file name, auto-generated when needed
652  from the space number. */
654 
655  /** List of rollback segments within this tablespace.
656  This is not always used. Must call init_rsegs to use it. */
658 };
659 
660 /** List of undo tablespaces, each containing a list of
661 rollback segments. */
662 class Tablespaces {
663  using Tablespaces_Vector =
664  std::vector<Tablespace *, ut_allocator<Tablespace *>>;
665 
666  public:
667  Tablespaces() { init(); }
668 
670 
671  /** Initialize */
672  void init();
673 
674  /** De-initialize */
675  void deinit();
676 
677  /** Clear the contents of the list of Tablespace objects.
678  This does not deallocate any memory. */
679  void clear() {
680  for (auto undo_space : m_spaces) {
681  UT_DELETE(undo_space);
682  }
683  m_spaces.clear();
684  }
685 
686  /** Get the number of tablespaces tracked by this object. */
687  ulint size() { return (m_spaces.size()); }
688 
689  /** See if the list of tablespaces is empty. */
690  bool empty() { return (m_spaces.empty()); }
691 
692  /** Get the Tablespace tracked at a position. */
693  Tablespace *at(size_t pos) { return (m_spaces.at(pos)); }
694 
695  /** Add a new undo::Tablespace to the back of the vector.
696  The vector has been pre-allocated to 128 so read threads will
697  not loose what is pointed to. If tablespace_name and file_name
698  are standard names, they are optional.
699  @param[in] ref_undo_space undo tablespace */
700  void add(Tablespace &ref_undo_space);
701 
702  /** Drop an existing explicit undo::Tablespace.
703  @param[in] undo_space pointer to undo space */
704  void drop(Tablespace *undo_space);
705 
706  /** Drop an existing explicit undo::Tablespace.
707  @param[in] ref_undo_space reference to undo space */
708  void drop(Tablespace &ref_undo_space);
709 
710  /** Check if the given space_id is in the vector.
711  @param[in] num undo tablespace number
712  @return true if space_id is found, else false */
713  bool contains(space_id_t num) { return (find(num) != nullptr); }
714 
715  /** Find the given space_num in the vector.
716  @param[in] num undo tablespace number
717  @return pointer to an undo::Tablespace struct */
719  if (m_spaces.empty()) {
720  return (nullptr);
721  }
722 
723  /* The sort method above puts this vector in order by
724  Tablespace::num. If there are no gaps, then we should
725  be able to find it quickly. */
726  space_id_t slot = num - 1;
727  if (slot < m_spaces.size()) {
728  auto undo_space = m_spaces.at(slot);
729  if (undo_space->num() == num) {
730  return (undo_space);
731  }
732  }
733 
734  /* If there are gaps in the numbering, do a search. */
735  for (auto undo_space : m_spaces) {
736  if (undo_space->num() == num) {
737  return (undo_space);
738  }
739  }
740 
741  return (nullptr);
742  }
743 
744 #ifdef UNIV_DEBUG
745  /** Determine if this thread owns a lock on m_latch. */
746  bool own_latch() {
747  return (rw_lock_own(m_latch, RW_LOCK_X) || rw_lock_own(m_latch, RW_LOCK_S));
748  }
749 #endif /* UNIV_DEBUG */
750 
751  /** Get a shared lock on m_spaces. */
752  void s_lock() { rw_lock_s_lock(m_latch); }
753 
754  /** Release a shared lock on m_spaces. */
755  void s_unlock() { rw_lock_s_unlock(m_latch); }
756 
757  /** Get an exclusive lock on m_spaces. */
758  void x_lock() { rw_lock_x_lock(m_latch); }
759 
760  /** Release an exclusive lock on m_spaces. */
761  void x_unlock() { rw_lock_x_unlock(m_latch); }
762 
764 
765  private:
766  /** RW lock to protect m_spaces.
767  x for adding elements, s for scanning, size() etc. */
769 };
770 
771 /** Mutext for serializing undo tablespace related DDL. These have to do with
772 creating and dropping undo tablespaces. */
773 extern ib_mutex_t ddl_mutex;
774 
775 /** A global object that contains a vector of undo::Tablespace structs. */
776 extern Tablespaces *spaces;
777 
778 /** Create the truncate log file. Needed to track the state of truncate during
779 a crash. An auxiliary redo log file undo_<space_id>_trunc.log will be created
780 while the truncate of the UNDO is in progress. This file is required during
781 recovery to complete the truncate.
782 @param[in] undo_space undo tablespace to truncate.
783 @return DB_SUCCESS or error code.*/
784 dberr_t start_logging(Tablespace *undo_space);
785 
786 /** Mark completion of undo truncate action by writing magic number
787 to the log file and then removing it from the disk.
788 If we are going to remove it from disk then why write magic number?
789 This is to safeguard from unlink (file-system) anomalies that will
790 keep the link to the file even after unlink action is successful
791 and ref-count = 0.
792 @param[in] space_num number of the undo tablespace to truncate. */
793 void done_logging(space_id_t space_num);
794 
795 /** Check if TRUNCATE_DDL_LOG file exist.
796 @param[in] space_num undo tablespace number
797 @return true if exist else false. */
799 
800 /** list of undo tablespaces that need header pages and rollback
801 segments written to them at startup. This can be because they are
802 newly initialized, were being truncated and the system crashed, or
803 they were an old format at startup and were replaced when they were
804 opened. Old format undo tablespaces do not have space_ids between
805 dict_sys_t::s_min_undo_space_id and dict_sys_t::s_max_undo_space_id
806 and they do not contain an RSEG_ARRAY page. */
808 
809 /** Add undo tablespace to s_under_construction vector.
810 @param[in] space_id space id of tablespace to
811 truncate */
813 
814 /** Clear the s_under_construction vector. */
816 
817 /** Is an undo tablespace under constuction at the moment.
818 @param[in] space_id space id to check
819 @return true if marked for truncate, else false. */
820 bool is_under_construction(space_id_t space_id);
821 
822 /** Set an undo tablespace active. */
823 void set_active(space_id_t space_id);
824 
825 /* Return whether the undo tablespace is active. If this is a
826 non-undo tablespace, then it will not be found in spaces and it
827 will not be under construction, so this function will return true.
828 @param[in] space_id Undo Tablespace ID
829 @param[in] get_latch Specifies whether the rsegs->s_lock() is needed.
830 @return true if active (non-undo spaces are always active) */
831 bool is_active(space_id_t space_id, bool get_latch = true);
832 
833 /** Track an UNDO tablespace marked for truncate. */
834 class Truncate {
835  public:
837  : m_space_id_marked(SPACE_UNKNOWN),
838  m_purge_rseg_truncate_frequency(
839  static_cast<ulint>(srv_purge_rseg_truncate_frequency)) {
840  /* Do Nothing. */
841  }
842 
843  /** Is tablespace selected for truncate.
844  @return true if undo tablespace is marked for truncate */
845  bool is_marked() const { return (m_space_id_marked != SPACE_UNKNOWN); }
846 
847  /** Mark the undo tablespace selected for truncate as empty
848  so that it will be truncated next. */
849  void set_marked_space_empty() { m_marked_space_is_empty = true; }
850 
851  /** Is tablespace selected for truncate empty of undo logs yet?
852  @return true if the marked undo tablespace has no more undo logs */
853  bool is_marked_space_empty() const { return (m_marked_space_is_empty); }
854 
855  /** Mark the tablespace for truncate.
856  @param[in] undo_space undo tablespace to truncate. */
857  void mark(Tablespace *undo_space) {
858  /* Set the internal state of this undo space to inactive_implicit
859  so that its rsegs will not be allocated to any new transaction.
860  If the space is already in the inactive_explicit state, it will
861  stay there.
862  Note that the DD is not modified since in case of crash, the
863  action must be completed before the DD is available.
864  Set both the state and this marked id while this routine has
865  an x_lock on m_rsegs because a concurrent user thread might issue
866  undo_space->alter_active(). */
867  undo_space->set_inactive_implicit(&m_space_id_marked);
868 
869  m_marked_space_is_empty = false;
870 
871  /* We found an UNDO-tablespace to truncate so set the
872  local purge rseg truncate frequency to 3. This will help
873  accelerate the purge action and in turn truncate. */
874  set_rseg_truncate_frequency(3);
875  }
876 
877  /** Get the ID of the tablespace marked for truncate.
878  @return tablespace ID marked for truncate. */
880  return (id2num(m_space_id_marked));
881  }
882 
883  /** Reset for next rseg truncate. */
884  void reset() {
885  /* Sync with global value as we are done with
886  truncate now. */
887  set_rseg_truncate_frequency(
888  static_cast<ulint>(srv_purge_rseg_truncate_frequency));
889 
890  m_marked_space_is_empty = false;
891  m_space_id_marked = SPACE_UNKNOWN;
892  }
893 
894  /** Get the undo tablespace number to start a scan.
895  Re-adjust in case the spaces::size() went down.
896  @return UNDO space_num to start scanning. */
898  s_scan_pos = s_scan_pos % undo::spaces->size();
899 
900  Tablespace *undo_space = undo::spaces->at(s_scan_pos);
901 
902  return (undo_space->num());
903  }
904 
905  /** Increment the scanning position in a round-robin fashion.
906  @return UNDO space_num at incremented scanning position. */
908  /** Round-robin way of selecting an undo tablespace
909  for the truncate operation. Once we reach the end of
910  the list of known undo tablespace IDs, move back to
911  the first undo tablespace ID. This will scan active
912  as well as inactive undo tablespaces. */
913  s_scan_pos = (s_scan_pos + 1) % undo::spaces->size();
914 
915  return (get_scan_space_num());
916  }
917 
918  /** Get local rseg purge truncate frequency
919  @return rseg purge truncate frequency. */
921  return (m_purge_rseg_truncate_frequency);
922  }
923 
924  /** Set local rseg purge truncate frequency */
925  void set_rseg_truncate_frequency(ulint frequency) {
926  m_purge_rseg_truncate_frequency = frequency;
927  }
928 
929  /** Check if the given space id is equal to the space ID that is marked for
930  truncation.
931  @return true if they are equal, false otherwise. */
932  bool is_equal(space_id_t space_id) const {
933  return (m_space_id_marked == space_id);
934  }
935 
936  private:
937  /** UNDO space ID that is marked for truncate. */
939 
940  /** This is true if the marked space is empty of undo logs
941  and ready to truncate. We leave the rsegs object 'inactive'
942  until after it is truncated and rebuilt. This allow the
943  code to do the check for undo logs only once. */
945 
946  /** Rollback segment(s) purge frequency. This is a local
947  value maintained along with the global value. It is set
948  to the global value in the before each truncate. But when
949  a tablespace is marked for truncate it is updated to 1 and
950  then minimum value among 2 is used by the purge action. */
952 
953  /** Start scanning for UNDO tablespace from this
954  vector position. This is to avoid bias selection
955  of one tablespace always. */
956  static size_t s_scan_pos;
957 
958 }; /* class Truncate */
959 
960 } /* namespace undo */
961 
962 /** The control structure used in the purge operation */
963 struct trx_purge_t {
964  sess_t *sess; /*!< System session running the purge
965  query */
966  trx_t *trx; /*!< System transaction running the
967  purge query: this trx is not in the
968  trx list of the trx system and it
969  never ends */
970 #ifndef UNIV_HOTBACKUP
971  rw_lock_t latch; /*!< The latch protecting the purge
972  view. A purge operation must acquire an
973  x-latch here for the instant at which
974  it changes the purge view: an undo
975  log operation can prevent this by
976  obtaining an s-latch here. It also
977  protects state and running */
978 #endif /* !UNIV_HOTBACKUP */
979  os_event_t event; /*!< State signal event */
980  ulint n_stop; /*!< Counter to track number stops */
981  volatile bool running; /*!< true, if purge is active,
982  we check this without the latch too */
983  volatile purge_state_t state; /*!< Purge coordinator thread states,
984  we check this in several places
985  without holding the latch. */
986  que_t *query; /*!< The query graph which will do the
987  parallelized purge operation */
988  ReadView view; /*!< The purge will not remove undo logs
989  which are >= this view (purge view) */
990  bool view_active; /*!< true if view is active */
991  volatile ulint n_submitted; /*!< Count of total tasks submitted
992  to the task queue */
993  volatile ulint n_completed; /*!< Count of total tasks completed */
994 
995  /*------------------------------*/
996  /* The following two fields form the 'purge pointer' which advances
997  during a purge, and which is used in history list truncation */
998 
999  purge_iter_t iter; /* Limit up to which we have read and
1000  parsed the UNDO log records. Not
1001  necessarily purged from the indexes.
1002  Note that this can never be less than
1003  the limit below, we check for this
1004  invariant in trx0purge.cc */
1005  purge_iter_t limit; /* The 'purge pointer' which advances
1006  during a purge, and which is used in
1007  history list truncation */
1008 #ifdef UNIV_DEBUG
1009  purge_iter_t done; /* Indicate 'purge pointer' which have
1010  purged already accurately. */
1011 #endif /* UNIV_DEBUG */
1012  /*-----------------------------*/
1013  ibool next_stored; /*!< TRUE if the info of the next record
1014  to purge is stored below: if yes, then
1015  the transaction number and the undo
1016  number of the record are stored in
1017  purge_trx_no and purge_undo_no above */
1018  trx_rseg_t *rseg; /*!< Rollback segment for the next undo
1019  record to purge */
1020  page_no_t page_no; /*!< Page number for the next undo
1021  record to purge, page number of the
1022  log header, if dummy record */
1023  ulint offset; /*!< Page offset for the next undo
1024  record to purge, 0 if the dummy
1025  record */
1026  page_no_t hdr_page_no; /*!< Header page of the undo log where
1027  the next record to purge belongs */
1028  ulint hdr_offset; /*!< Header byte offset on the page */
1029 
1030  TrxUndoRsegsIterator *rseg_iter; /*!< Iterator to get the next rseg
1031  to process */
1032 
1033  purge_pq_t *purge_queue; /*!< Binary min-heap, ordered on
1034  TrxUndoRsegs::trx_no. It is protected
1035  by the pq_mutex */
1036  PQMutex pq_mutex; /*!< Mutex protecting purge_queue */
1037 
1038  undo::Truncate undo_trunc; /*!< Track UNDO tablespace marked
1039  for truncate. */
1040 
1041  mem_heap_t *heap; /*!< Heap for reading the undo log
1042  records */
1043 };
1044 
1045 /** Choose the rollback segment with the smallest trx_no. */
1047  /** Constructor */
1048  TrxUndoRsegsIterator(trx_purge_t *purge_sys);
1049 
1050  /** Sets the next rseg to purge in m_purge_sys.
1051  @return page size of the table for which the log is.
1052  NOTE: if rseg is NULL when this function returns this means that
1053  there are no rollback segments to purge and then the returned page
1054  size object should not be used. */
1055  const page_size_t set_next();
1056 
1057  private:
1058  // Disable copying
1060  TrxUndoRsegsIterator &operator=(const TrxUndoRsegsIterator &);
1061 
1062  /** The purge system pointer */
1064 
1065  /** The current element to process */
1067 
1068  /** Track the current element in m_trx_undo_rseg */
1070 
1071  /** Sentinel value */
1073 };
1074 
1075 #include "trx0purge.ic"
1076 
1077 #endif /* trx0purge_h */
void set_marked_space_empty()
Mark the undo tablespace selected for truncate as empty so that it will be truncated next...
Definition: trx0purge.h:849
The currently used undo space IDs for an undo space number along with a boolean showing whether the u...
Definition: trx0purge.h:147
space_id_t next_space_id(space_id_t space_id)
Given a valid undo space_id, return the next space_id for that space number.
Definition: trx0purge.cc:657
void set_active()
Set the undo tablespace active for use by transactions.
Definition: trx0purge.h:578
Truncate()
Definition: trx0purge.h:836
void trx_purge_sys_close(void)
Frees the global purge system control structure.
Definition: trx0purge.cc:255
Tablespace(Tablespace &other)
Copy Constructor.
Definition: trx0purge.h:320
purge_iter_t done
Definition: trx0purge.h:1009
This is a wrapper for a std::vector of trx_rseg_t object pointers.
Definition: trx0types.h:299
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
char * m_file_name
The tablespace file name, auto-generated when needed from the space number.
Definition: trx0purge.h:649
void add(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1)
Definition: suite_stubs.c:69
ib_mutex_t ddl_mutex
Mutext for serializing undo tablespace related DDL.
Definition: trx0purge.cc:583
undo::Truncate undo_trunc
Track UNDO tablespace marked for truncate.
Definition: trx0purge.h:1038
purge_state_t
Purge states.
Definition: trx0purge.h:97
Tablespace * at(size_t pos)
Get the Tablespace tracked at a position.
Definition: trx0purge.h:693
trx_t * trx
System transaction running the purge query: this trx is not in the trx list of the trx system and it ...
Definition: trx0purge.h:966
bool m_marked_space_is_empty
This is true if the marked space is empty of undo logs and ready to truncate.
Definition: trx0purge.h:944
void x_unlock()
Release an exclusive lock on m_spaces.
Definition: trx0purge.h:761
This is the purge pointer/iterator.
Definition: trx0purge.h:114
The low-level file system.
ulint size()
Get the number of tablespaces tracked by this object.
Definition: trx0purge.h:687
undo_no_t undo_no
Purge has advanced past all records whose undo number is less than this.
Definition: trx0purge.h:122
char * file_name()
Get the undo space filename.
Definition: trx0purge.h:434
static constexpr space_id_t undo_space_id_range
The number of space IDs dedicated to each undo tablespace.
Definition: dict0dict.h:1137
void x_lock()
Get an exclusive lock on m_spaces.
Definition: trx0purge.h:758
void set_rseg_truncate_frequency(ulint frequency)
Set local rseg purge truncate frequency.
Definition: trx0purge.h:925
bool is_active()
Return whether the undo tablespace is active.
Definition: trx0purge.h:498
~Tablespace()
Destructor.
Definition: trx0purge.h:342
Definition: trx0trx.h:800
Definition: trx0purge.h:134
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:47
#define FSP_MAX_ROLLBACK_SEGMENTS
Definition: fsp0types.h:403
void trx_purge_run(void)
Resume purge, move to PURGE_STATE_RUN.
Definition: trx0purge.cc:2358
dberr_t start_logging(Tablespace *undo_space)
Create the truncate log file.
Definition: trx0purge.cc:849
ibool rw_lock_own(rw_lock_t *lock, ulint lock_type)
Checks if the thread has locked the rw-lock in the specified mode, with the pass value == 0...
Definition: sync0rw.cc:933
void reset()
Reset for next rseg truncate.
Definition: trx0purge.h:884
page_no_t hdr_page_no
Header page of the undo log where the next record to purge belongs.
Definition: trx0purge.h:1026
TrxUndoRsegs m_trx_undo_rsegs
The current element to process.
Definition: trx0purge.h:1066
os_event_t event
State signal event.
Definition: trx0purge.h:979
space_id_t increment_scan() const
Increment the scanning position in a round-robin fashion.
Definition: trx0purge.h:907
#define FSP_MAX_UNDO_TABLESPACES
Definition: fsp0types.h:401
void init_space_id_bank()
Initialize the undo tablespace space_id bank which is a lock free repository for information about th...
Definition: trx0purge.cc:600
Tablespace * find(space_id_t num)
Find the given space_num in the vector.
Definition: trx0purge.h:718
void trx_purge_stop(void)
Stop purge and wait for it to stop, move to PURGE_STATE_STOP.
Definition: trx0purge.cc:2299
void use_space_id(space_id_t space_id)
Note that the undo space number for a space ID is being used.
Definition: trx0purge.cc:613
space_id_t id2next_id(space_id_t space_id)
Definition: trx0purge.h:234
Tablespaces * spaces
A global object that contains a vector of undo::Tablespace structs.
Definition: trx0purge.cc:586
ulong srv_page_size
Definition: srv0srv.cc:360
unsigned long id[MAX_DEAD]
Definition: xcom_base.c:426
static size_t s_scan_pos
Start scanning for UNDO tablespace from this vector position.
Definition: trx0purge.h:956
Purge should be running.
Definition: trx0purge.h:99
static constexpr space_id_t s_max_undo_space_id
The highest undo tablespace ID.
Definition: dict0dict.h:1144
Rsegs_Vector::iterator Rseg_Iterator
Definition: trx0types.h:296
bool is_implicit()
Report whether this undo tablespace was implicitly created.
Definition: trx0purge.h:486
trx_purge_t * m_purge_sys
The purge system pointer.
Definition: trx0purge.h:1063
space_id_t get_scan_space_num() const
Get the undo tablespace number to start a scan.
Definition: trx0purge.h:897
Cursor read.
Purge should be stopped.
Definition: trx0purge.h:100
bool is_active(space_id_t space_id, bool get_latch=true)
Definition: trx0purge.cc:1075
bool m_implicit
True if this is an implicit undo tablespace.
Definition: trx0purge.h:637
rw_lock_t * m_latch
RW lock to protect m_spaces.
Definition: trx0purge.h:768
Tablespaces()
Definition: trx0purge.h:667
void set_active(space_id_t space_id)
Set an undo tablespace active.
Definition: trx0purge.cc:1056
ulint trx_purge(ulint n_purge_threads, ulint limit, bool truncate)
This function runs a purge batch.
Definition: trx0purge.cc:2188
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:343
static constexpr space_id_t s_min_undo_space_id
The lowest undo tablespace ID.
Definition: dict0dict.h:1140
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
Definition: que0que.h:303
char * log_file_name()
Get the undo log filename.
Definition: trx0purge.h:452
#define rw_lock_x_lock(M)
Definition: sync0rw.h:289
purge_state_t trx_purge_state(void)
Get the purge state.
Definition: trx0purge.cc:2286
bool is_marked() const
Is tablespace selected for truncate.
Definition: trx0purge.h:845
Query graph global types.
space_id_t num()
Get the undo tablespace number.
Definition: trx0purge.h:468
std::atomic< ulint > trx_ref_count
Reference counter to track rseg allocated transactions.
Definition: trx0types.h:281
bool is_inactive_explicit()
Return whether the undo tablespace was made inactive by ALTER TABLESPACE.
Definition: trx0purge.h:554
Purge has been shutdown.
Definition: trx0purge.h:101
rw_lock_t latch
The latch protecting the purge view.
Definition: trx0purge.h:971
void set_inactive_explicit()
Make the undo tablespace inactive so that it will not be used for new transactions.
Definition: trx0purge.h:602
Rsegs * rsegs()
Get a reference to the List of rollback segments within this undo tablespace.
Definition: trx0purge.h:477
bool m_new
True if this undo tablespace was implicitly created when this instance started up.
Definition: trx0purge.h:641
const page_no_t SRV_UNDO_TABLESPACE_SIZE_IN_PAGES
Default size of UNDO tablespace while it is created new.
Definition: srv0srv.cc:175
trx_rseg_t * rseg
Rollback segment for the next undo record to purge.
Definition: trx0purge.h:1018
page_no_t page_no
Page number for the next undo record to purge, page number of the log header, if dummy record...
Definition: trx0purge.h:1020
Rollback segements from a given transaction with trx-no scheduled for purge.
Definition: trx0types.h:519
void clear()
Clear the contents of the list of Tablespace objects.
Definition: trx0purge.h:679
ibool next_stored
TRUE if the info of the next record to purge is stored below: if yes, then the transaction number and...
Definition: trx0purge.h:1013
std::vector< Tablespace *, ut_allocator< Tablespace * > > Tablespaces_Vector
Definition: trx0purge.h:664
bool is_empty()
Return whether the undo tablespace is empty and ready to be dropped.
Definition: trx0purge.h:567
space_id_t undo_rseg_space
Last undo record resided in this space id.
Definition: trx0purge.h:124
char * pos
Definition: do_ctype.cc:76
void add_space_to_construction_list(space_id_t space_id)
Add undo tablespace to s_under_construction vector.
Definition: trx0purge.cc:1035
ReadView view
The purge will not remove undo logs which are >= this view (purge view)
Definition: trx0purge.h:988
~Tablespaces()
Definition: trx0purge.h:669
bool srv_undo_log_truncate
Enable or Disable Truncate of UNDO tablespace.
Definition: srv0srv.cc:166
volatile ulint n_completed
Count of total tasks completed.
Definition: trx0purge.h:993
#define UT_DELETE(ptr)
Destroy, deallocate and trace the deallocation of an object created by UT_NEW() or UT_NEW_NOKEY()...
Definition: ut0new.h:1023
std::priority_queue< TrxUndoRsegs, std::vector< TrxUndoRsegs, ut_allocator< TrxUndoRsegs > >, TrxUndoRsegs > purge_pq_t
Definition: trx0types.h:584
Rseg_Iterator m_iter
Track the current element in m_trx_undo_rseg.
Definition: trx0purge.h:1069
Index page routines.
space_id_t m_space_id_marked
UNDO space ID that is marked for truncate.
Definition: trx0purge.h:938
UNIV_INLINE fil_addr_t trx_purge_get_log_from_hist(fil_addr_t node_addr)
Calculates the file address of an undo log header when we have the file address of its history list n...
bool empty()
See if the list of tablespaces is empty.
Definition: trx0purge.h:690
An undo::Tablespace object is used to easily convert between undo_space_id and undo_space_num and to ...
Definition: trx0purge.h:305
Sessions.
Definition: sync0types.h:216
#define UT_NEW_NOKEY(expr)
Allocate, trace the allocation and construct an object.
Definition: ut0new.h:1017
void trx_purge_sys_create(ulint n_purge_threads, purge_pq_t *purge_queue)
Creates the global purge system control structure and inits the history mutex.
Definition: trx0purge.cc:203
volatile purge_state_t state
Purge coordinator thread states, we check this in several places without holding the latch...
Definition: trx0purge.h:983
dberr_t
Definition: db0err.h:38
mem_heap_t * heap
Heap for reading the undo log records.
Definition: trx0purge.h:1041
space_id_t m_id
Undo Tablespace ID.
Definition: trx0purge.h:629
void set_empty()
Set the state of the undo tablespace to empty so that it can be dropped.
Definition: trx0purge.h:621
unsigned long long srv_max_undo_tablespace_size
Maximum size of undo tablespace.
Definition: srv0srv.cc:172
void s_lock()
Get a shared lock on m_spaces.
Definition: trx0purge.h:752
Definition: usr0sess.h:53
ib_mutex_t PQMutex
Definition: trx0types.h:179
trx_id_t trx_no
Purge has advanced past all transactions whose number is less than this.
Definition: trx0purge.h:119
space_id_t m_num
Undo Tablespace number, from 1 to 127.
Definition: trx0purge.h:634
void clear_construction_list()
Clear the s_under_construction vector.
Definition: trx0purge.cc:1040
space_id_t get_next_available_space_num()
Return the next available undo space ID to be used for a new explicit undo tablespaces.
Definition: trx0purge.cc:688
void set_inactive_implicit(space_id_t *marked_space_id)
Set the state of the rollback segments in this undo tablespace to inactive_implicit if currently acti...
Definition: trx0purge.h:589
#define true
Definition: config_static.h:44
File space address.
Definition: fil0fil.h:915
Track an UNDO tablespace marked for truncate.
Definition: trx0purge.h:834
const ib_uint32_t s_magic
Magic Number to indicate truncate action is complete.
Definition: trx0purge.h:137
bool is_under_construction(space_id_t space_id)
Is an undo tablespace under constuction at the moment.
Definition: trx0purge.cc:1045
bool needs_truncation()
Definition: trx0purge.h:367
const char *const s_log_prefix
Truncate Log file Prefix.
Definition: trx0purge.h:140
void s_unlock()
Release a shared lock on m_spaces.
Definition: trx0purge.h:755
ulint n_stop
Counter to track number stops.
Definition: trx0purge.h:980
trx_id_t modifier_trx_id
the transaction that created the undo log record.
Definition: trx0purge.h:127
space_id_t get_marked_space_num() const
Get the ID of the tablespace marked for truncate.
Definition: trx0purge.h:879
Transaction system global type definitions.
bool is_marked_space_empty() const
Is tablespace selected for truncate empty of undo logs yet?
Definition: trx0purge.h:853
bool is_new()
Report whether this undo tablespace was created at startup.
Definition: trx0purge.h:491
bool is_active_truncate_log_present(space_id_t space_num)
Check if TRUNCATE_DDL_LOG file exist.
Definition: trx0purge.cc:961
Definition: sync0types.h:217
purge_pq_t * purge_queue
Binary min-heap, ordered on TrxUndoRsegs::trx_no.
Definition: trx0purge.h:1033
space_id_t id2num(space_id_t space_id)
Convert an undo space ID into an undo space number.
Definition: trx0purge.h:222
void mark(Tablespace *undo_space)
Mark the tablespace for truncate.
Definition: trx0purge.h:857
#define rw_lock_s_lock(M)
Definition: sync0rw.h:254
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
ulong srv_purge_rseg_truncate_frequency
Rate at which UNDO records should be purged.
Definition: srv0srv.cc:158
bool in_use
Definition: trx0purge.h:149
constexpr space_id_t SPACE_UNKNOWN
Unknown space id.
Definition: fil0fil.h:904
char * m_log_file_name
The tablespace log file name, auto-generated when needed from the space number.
Definition: trx0purge.h:653
List of undo tablespace IDs.
Definition: trx0sys.h:433
space_id_t use_next_space_id(space_id_t space_num)
Mark that the given undo space number is being used and return the next available space_id for that s...
Definition: trx0purge.cc:670
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:65
purge_iter_t limit
Definition: trx0purge.h:1005
que_t * query
The query graph which will do the parallelized purge operation.
Definition: trx0purge.h:986
bool contains(space_id_t num)
Check if the given space_id is in the vector.
Definition: trx0purge.h:713
void set_new()
Note that this undo tablespace is being created.
Definition: trx0purge.h:494
Page size descriptor.
Definition: page0size.h:49
static const TrxUndoRsegs NullElement
Sentinel value.
Definition: trx0purge.h:1072
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:144
#define ut_max
Definition: ut0ut.h:150
Transaction system.
Purge instance created.
Definition: trx0purge.h:98
#define rw_lock_s_unlock(L)
Definition: sync0rw.h:313
char * space_name()
Get the undo tablespace name.
Definition: trx0purge.h:410
bool is_equal(space_id_t space_id) const
Check if the given space id is equal to the space ID that is marked for truncation.
Definition: trx0purge.h:932
Choose the rollback segment with the smallest trx_no.
Definition: trx0purge.h:1046
const char *const s_log_ext
Truncate Log file Extension.
Definition: trx0purge.h:143
trx_purge_t * purge_sys
The global data structure coordinating a purge.
Definition: trx0purge.cc:72
struct space_id_account * space_id_bank
List of currently used undo space IDs for each undo space number along with a boolean showing whether...
Definition: trx0purge.cc:590
bool drop(THD *thd, const Table *tp)
Remove SDI for a table.
Definition: sdi.cc:584
bool is_reserved(space_id_t space_id)
Check if the space_id is an undo space ID in the reserved range.
Definition: trx0purge.h:159
sess_t * sess
System session running the purge query.
Definition: trx0purge.h:964
bool is_explicit()
Report whether this undo tablespace was explicitly created by an SQL statement.
Definition: trx0purge.h:482
InnoDB condition variable.
Definition: os0event.cc:66
#define ut_free(ptr)
Definition: ut0new.h:1123
space_id_t id()
Get the undo tablespace ID.
Definition: trx0purge.h:462
space_id_t num2id(space_id_t space_num)
Convert an undo space number (from 1 to 127) into an undo space_id.
Definition: trx0purge.h:186
Tablespace(space_id_t id)
Constructor.
Definition: trx0purge.h:308
volatile ulint n_submitted
Count of total tasks submitted to the task queue.
Definition: trx0purge.h:991
byte page_t
Type of the index page.
Definition: page0types.h:148
purge_iter_t()
Definition: trx0purge.h:115
Mini-transaction buffer.
char * m_space_name
The tablespace name, auto-generated when needed from the space number.
Definition: trx0purge.h:645
Purge was never started.
Definition: trx0purge.h:102
trx_rseg_t * get_active(ulint slot)
Return the rseg at the requested rseg slot if the undo space is active.
Definition: trx0purge.h:521
The transaction handle.
Definition: trx0trx.h:763
space_id_t space_id
Definition: trx0purge.h:148
ulint get_rseg_truncate_frequency() const
Get local rseg purge truncate frequency.
Definition: trx0purge.h:920
void unuse_space_id(space_id_t space_id)
Mark an undo number associated with a given space_id as unused and available to be resused...
Definition: trx0purge.cc:626
List of undo tablespaces, each containing a list of rollback segments.
Definition: trx0purge.h:662
volatile bool running
true, if purge is active, we check this without the latch too
Definition: trx0purge.h:981
PQMutex pq_mutex
Mutex protecting purge_queue.
Definition: trx0purge.h:1036
Tablespaces_Vector m_spaces
Definition: trx0purge.h:763
ulint hdr_offset
Header byte offset on the page.
Definition: trx0purge.h:1028
Space_Ids s_under_construction
list of undo tablespaces that need header pages and rollback segments written to them at startup...
Definition: trx0purge.cc:1108
purge_iter_t iter
Definition: trx0purge.h:999
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:169
char * make_space_name(space_id_t space_id)
Build a standard undo tablespace name from a space_id.
Definition: trx0purge.cc:712
Rsegs * m_rsegs
List of rollback segments within this tablespace.
Definition: trx0purge.h:657
ulint m_purge_rseg_truncate_frequency
Rollback segment(s) purge frequency.
Definition: trx0purge.h:951
void trx_purge_add_update_undo_to_history(trx_t *trx, trx_undo_ptr_t *undo_ptr, page_t *undo_page, bool update_rseg_history_len, ulint n_added_logs, mtr_t *mtr)
in: mtr
Definition: trx0purge.cc:297
#define false
Definition: config_static.h:43
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:148
bool own_latch()
Determine if this thread owns a lock on m_latch.
Definition: trx0purge.h:746
bool is_inactive_implicit()
Return whether the undo tablespace is inactive due to implicit selection by the purge thread...
Definition: trx0purge.h:541
const byte * find(const Pages *pages, const page_id_t &page_id) noexcept
Find a doublewrite copy of a page.
Definition: buf0dblwr.cc:2211
ulint offset
Page offset for the next undo record to purge, 0 if the dummy record.
Definition: trx0purge.h:1023
bool is_active_no_latch()
Return whether the undo tablespace is active.
Definition: trx0purge.h:511
page_no_t fil_space_get_size(space_id_t space_id)
Returns the size of the space in pages.
Definition: fil0fil.cc:3340
The control structure used in the purge operation.
Definition: trx0purge.h:963
char * make_file_name(space_id_t space_id)
Build a standard undo tablespace file name from a space_id.
Definition: trx0purge.cc:731
void done_logging(space_id_t space_num)
Mark completion of undo truncate action by writing magic number to the log file and then removing it ...
Definition: trx0purge.cc:904
bool view_active
true if view is active
Definition: trx0purge.h:990
TrxUndoRsegsIterator * rseg_iter
Iterator to get the next rseg to process.
Definition: trx0purge.h:1030