MySQL  8.0.19
Source Code Documentation
trx0purge.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 1996, 2019, 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. */
339  }
340 
341  /** Destructor */
343  if (m_space_name != nullptr) {
345  m_space_name = nullptr;
346  }
347 
348  if (m_file_name != nullptr) {
350  m_file_name = nullptr;
351  }
352 
353  if (m_log_file_name != nullptr) {
355  m_log_file_name = nullptr;
356  }
357 
358  /* Clear the cached rollback segments. */
359  if (m_rsegs != nullptr) {
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. */
370  return (true);
371  }
372 
373  /* If implicit undo truncation is turned off, or if the rsegs don't exist
374  yet, don't bother checking the size. */
375  if (!srv_undo_log_truncate || m_rsegs == nullptr || m_rsegs->is_empty() ||
376  m_rsegs->is_init()) {
377  return (false);
378  }
379 
380  ut_ad(m_rsegs->is_active());
381 
382  page_no_t trunc_size = ut_max(
385  if (fil_space_get_size(id()) > trunc_size) {
386  return (true);
387  }
388 
389  return (false);
390  }
391 
392  /** Change the space_id from its current value.
393  @param[in] space_id The new undo tablespace ID */
394  void set_space_id(space_id_t space_id);
395 
396  /** Replace the standard undo space name if it exists with a copy
397  of the undo tablespace name provided.
398  @param[in] new_space_name non-standard undo space name */
399  void set_space_name(const char *new_space_name);
400 
401  /** Get the undo tablespace name. Make it if not yet made.
402  NOTE: This is only called from stack objects so there is no
403  race condition. If it is ever called from a shared object
404  like undo::spaces, then it must be protected by the caller.
405  @return tablespace name created from the space_id */
406  char *space_name() {
407  if (m_space_name == nullptr) {
408 #ifndef UNIV_HOTBACKUP
410 #endif /* !UNIV_HOTBACKUP */
411  }
412 
413  return (m_space_name);
414  }
415 
416  /** Replace the standard undo file name if it exists with a copy
417  of the file name provided. This name can come in three forms:
418  absolute path, relative path, and basename. Undo ADD DATAFILE
419  does not accept a relative path. So if that comes in here, it
420  was the scaneed name and is relative to the datadir.
421  If this is just a basename, add it to srv_undo_dir.
422  @param[in] file_name explicit undo file name */
423  void set_file_name(const char *file_name);
424 
425  /** Get the undo space filename. Make it if not yet made.
426  NOTE: This is only called from stack objects so there is no
427  race condition. If it is ever called from a shared object
428  like undo::spaces, then it must be protected by the caller.
429  @return tablespace filename created from the space_id */
430  char *file_name() {
431  if (m_file_name == nullptr) {
433  }
434 
435  return (m_file_name);
436  }
437 
438  /** Build a log file name based on space_id
439  @param[in] space_id id of the undo tablespace.
440  @return DB_SUCCESS or error code */
441  char *make_log_file_name(space_id_t space_id);
442 
443  /** Get the undo log filename. Make it if not yet made.
444  NOTE: This is only called from stack objects so there is no
445  race condition. If it is ever called from a shared object
446  like undo::spaces, then it must be protected by the caller.
447  @return tablespace filename created from the space_id */
448  char *log_file_name() {
449  if (m_log_file_name == nullptr) {
451  }
452 
453  return (m_log_file_name);
454  }
455 
456  /** Get the undo tablespace ID.
457  @return tablespace ID */
458  space_id_t id() { return (m_id); }
459 
460  /** Get the undo tablespace number. This is the same as m_id
461  if m_id is 0 or this is a v5.6-5.7 undo tablespace. v8+ undo
462  tablespaces use a space_id from the reserved range.
463  @return undo tablespace number */
466 
467  return (m_num);
468  }
469 
470  /** Get a reference to the List of rollback segments within
471  this undo tablespace.
472  @return a reference to the Rsegs vector. */
473  Rsegs *rsegs() { return (m_rsegs); }
474 
475  /** Report whether this undo tablespace was explicitly created
476  by an SQL statement.
477  @return true if the tablespace was created explicitly. */
478  bool is_explicit() { return (!m_implicit); }
479 
480  /** Report whether this undo tablespace was implicitly created.
481  @return true if the tablespace was created implicitly. */
482  bool is_implicit() { return (m_implicit); }
483 
484  /** Report whether this undo tablespace was created at startup.
485  @retval true if created at startup.
486  @retval false if pre-existed at startup. */
487  bool is_new() { return (m_new); }
488 
489  /** Note that this undo tablespace is being created. */
490  void set_new() { m_new = true; }
491 
492  /** Return whether the undo tablespace is active.
493  @return true if active */
494  bool is_active() {
495  if (m_rsegs == nullptr) {
496  return (false);
497  }
498  m_rsegs->s_lock();
499  bool ret = m_rsegs->is_active();
500  m_rsegs->s_unlock();
501  return (ret);
502  }
503 
504  /** Return whether the undo tablespace is active. For optimization purposes,
505  do not take a latch.
506  @return true if active */
508  if (m_rsegs == nullptr) {
509  return (false);
510  }
511  return (m_rsegs->is_active());
512  }
513 
514  /** Return the rseg at the requested rseg slot if the undo space is active.
515  @param[in] slot The slot of the rseg. 1 to 127
516  @return Rseg pointer of nullptr if the space is not active. */
517  trx_rseg_t *get_active(ulint slot) {
518  m_rsegs->s_lock();
519  if (!m_rsegs->is_active()) {
520  m_rsegs->s_unlock();
521  return (nullptr);
522  }
523 
524  /* Mark the chosen rseg so that it will not be selected
525  for UNDO truncation. */
526  trx_rseg_t *rseg = m_rsegs->at(slot);
527  rseg->trx_ref_count++;
528 
529  m_rsegs->s_unlock();
530 
531  return (rseg);
532  }
533 
534  /** Return whether the undo tablespace is inactive due to
535  implicit selection by the purge thread.
536  @return true if marked for truncation by the purge thread */
538  if (m_rsegs == nullptr) {
539  return (false);
540  }
541  m_rsegs->s_lock();
542  bool ret = m_rsegs->is_inactive_implicit();
543  m_rsegs->s_unlock();
544  return (ret);
545  }
546 
547  /** Return whether the undo tablespace was made inactive by
548  ALTER TABLESPACE.
549  @return true if altered inactive */
551  if (m_rsegs == nullptr) {
552  return (false);
553  }
554  m_rsegs->s_lock();
555  bool ret = m_rsegs->is_inactive_explicit();
556  m_rsegs->s_unlock();
557  return (ret);
558  }
559 
560  /** Return whether the undo tablespace is empty and ready
561  to be dropped.
562  @return true if empty */
563  bool is_empty() {
564  if (m_rsegs == nullptr) {
565  return (true);
566  }
567  m_rsegs->s_lock();
568  bool ret = m_rsegs->is_empty();
569  m_rsegs->s_unlock();
570  return (ret);
571  }
572 
573  /** Set the undo tablespace active for use by transactions. */
574  void set_active() {
575  m_rsegs->x_lock();
576  m_rsegs->set_active();
577  m_rsegs->x_unlock();
578  }
579 
580  /** Set the state of the rollback segments in this undo tablespace to
581  inactive_implicit if currently active. If the state is inactive_explicit,
582  leave as is. Then put the space_id into the callers marked_space_id.
583  This is done when marking a space for truncate. It will not be used
584  for new transactions until it becomes active again. */
585  void set_inactive_implicit(space_id_t *marked_space_id) {
586  m_rsegs->x_lock();
587  if (m_rsegs->is_active()) {
589  }
590  *marked_space_id = m_id;
591 
592  m_rsegs->x_unlock();
593  }
594 
595  /** Make the undo tablespace inactive so that it will not be
596  used for new transactions. The purge thread will clear out
597  all the undo logs, truncate it, and then mark it empty. */
599  m_rsegs->x_lock();
601  m_rsegs->x_unlock();
602  }
603 
604  /** Make the undo tablespace active again so that it will
605  be used for new transactions.
606  If current State is ___ then do:
607  empty: Set active.
608  active_implicit: Ignore. It was not altered inactive. When it is done
609  being truncated it will go back to active.
610  active_explicit: Depends if it is marked for truncation.
611  marked: Set to inactive_implicit. the next state will be active.
612  not yet: Set to active so that it does not get truncated. */
613  void alter_active();
614 
615  /** Set the state of the undo tablespace to empty so that it
616  can be dropped. */
617  void set_empty() {
618  m_rsegs->x_lock();
619  m_rsegs->set_empty();
620  m_rsegs->x_unlock();
621  }
622 
623  private:
624  /** Undo Tablespace ID. */
626 
627  /** Undo Tablespace number, from 1 to 127. This is the
628  7-bit number that is used in a rollback pointer.
629  Use id2num() to get this number from a space_id. */
631 
632  /** True if this is an implicit undo tablespace */
634 
635  /** True if this undo tablespace was implicitly created when
636  this instance started up. False if it pre-existed. */
637  bool m_new;
638 
639  /** The tablespace name, auto-generated when needed from
640  the space number. */
642 
643  /** The tablespace file name, auto-generated when needed
644  from the space number. */
645  char *m_file_name;
646 
647  /** The tablespace log file name, auto-generated when needed
648  from the space number. */
650 
651  /** List of rollback segments within this tablespace.
652  This is not always used. Must call init_rsegs to use it. */
654 };
655 
656 /** List of undo tablespaces, each containing a list of
657 rollback segments. */
658 class Tablespaces {
659  using Tablespaces_Vector =
660  std::vector<Tablespace *, ut_allocator<Tablespace *>>;
661 
662  public:
663  Tablespaces() { init(); }
664 
666 
667  /** Initialize */
668  void init();
669 
670  /** De-initialize */
671  void deinit();
672 
673  /** Clear the contents of the list of Tablespace objects.
674  This does not deallocate any memory. */
675  void clear() {
676  for (auto undo_space : m_spaces) {
677  UT_DELETE(undo_space);
678  }
679  m_spaces.clear();
680  }
681 
682  /** Get the number of tablespaces tracked by this object. */
683  ulint size() { return (m_spaces.size()); }
684 
685  /** See if the list of tablespaces is empty. */
686  bool empty() { return (m_spaces.empty()); }
687 
688  /** Get the Tablespace tracked at a position. */
689  Tablespace *at(size_t pos) { return (m_spaces.at(pos)); }
690 
691  /** Add a new undo::Tablespace to the back of the vector.
692  The vector has been pre-allocated to 128 so read threads will
693  not loose what is pointed to. If tablespace_name and file_name
694  are standard names, they are optional.
695  @param[in] ref_undo_space undo tablespace */
696  void add(Tablespace &ref_undo_space);
697 
698  /** Drop an existing explicit undo::Tablespace.
699  @param[in] undo_space pointer to undo space */
700  void drop(Tablespace *undo_space);
701 
702  /** Drop an existing explicit undo::Tablespace.
703  @param[in] ref_undo_space reference to undo space */
704  void drop(Tablespace &ref_undo_space);
705 
706  /** Check if the given space_id is in the vector.
707  @param[in] num undo tablespace number
708  @return true if space_id is found, else false */
709  bool contains(space_id_t num) { return (find(num) != nullptr); }
710 
711  /** Find the given space_num in the vector.
712  @param[in] num undo tablespace number
713  @return pointer to an undo::Tablespace struct */
715  if (m_spaces.empty()) {
716  return (nullptr);
717  }
718 
719  /* The sort method above puts this vector in order by
720  Tablespace::num. If there are no gaps, then we should
721  be able to find it quickly. */
722  space_id_t slot = num - 1;
723  if (slot < m_spaces.size()) {
724  auto undo_space = m_spaces.at(slot);
725  if (undo_space->num() == num) {
726  return (undo_space);
727  }
728  }
729 
730  /* If there are gaps in the numbering, do a search. */
731  for (auto undo_space : m_spaces) {
732  if (undo_space->num() == num) {
733  return (undo_space);
734  }
735  }
736 
737  return (nullptr);
738  }
739 
740 #ifdef UNIV_DEBUG
741  /** Determine if this thread owns a lock on m_latch. */
742  bool own_latch() {
744  }
745 #endif /* UNIV_DEBUG */
746 
747  /** Get a shared lock on m_spaces. */
749 
750  /** Release a shared lock on m_spaces. */
752 
753  /** Get an exclusive lock on m_spaces. */
755 
756  /** Release an exclusive lock on m_spaces. */
758 
760 
761  private:
762  /** RW lock to protect m_spaces.
763  x for adding elements, s for scanning, size() etc. */
765 };
766 
767 /** Mutext for serializing undo tablespace related DDL. These have to do with
768 creating and dropping undo tablespaces. */
769 extern ib_mutex_t ddl_mutex;
770 
771 /** A global object that contains a vector of undo::Tablespace structs. */
772 extern Tablespaces *spaces;
773 
774 /** Create the truncate log file. Needed to track the state of truncate during
775 a crash. An auxiliary redo log file undo_<space_id>_trunc.log will be created
776 while the truncate of the UNDO is in progress. This file is required during
777 recovery to complete the truncate.
778 @param[in] undo_space undo tablespace to truncate.
779 @return DB_SUCCESS or error code.*/
780 dberr_t start_logging(Tablespace *undo_space);
781 
782 /** Mark completion of undo truncate action by writing magic number
783 to the log file and then removing it from the disk.
784 If we are going to remove it from disk then why write magic number?
785 This is to safeguard from unlink (file-system) anomalies that will
786 keep the link to the file even after unlink action is successful
787 and ref-count = 0.
788 @param[in] space_num number of the undo tablespace to truncate. */
789 void done_logging(space_id_t space_num);
790 
791 /** Check if TRUNCATE_DDL_LOG file exist.
792 @param[in] space_num undo tablespace number
793 @return true if exist else false. */
795 
796 /** list of undo tablespaces that need header pages and rollback
797 segments written to them at startup. This can be because they are
798 newly initialized, were being truncated and the system crashed, or
799 they were an old format at startup and were replaced when they were
800 opened. Old format undo tablespaces do not have space_ids between
801 dict_sys_t::s_min_undo_space_id and dict_sys_t::s_max_undo_space_id
802 and they do not contain an RSEG_ARRAY page. */
804 
805 /** Add undo tablespace to s_under_construction vector.
806 @param[in] space_id space id of tablespace to
807 truncate */
809 
810 /** Clear the s_under_construction vector. */
812 
813 /** Is an undo tablespace under constuction at the moment.
814 @param[in] space_id space id to check
815 @return true if marked for truncate, else false. */
816 bool is_under_construction(space_id_t space_id);
817 
818 /** Set an undo tablespace active. */
819 void set_active(space_id_t space_id);
820 
821 /* Return whether the undo tablespace is active. If this is a
822 non-undo tablespace, then it will not be found in spaces and it
823 will not be under construction, so this function will return true.
824 @param[in] space_id Undo Tablespace ID
825 @param[in] get_latch Specifies whether the rsegs->s_lock() is needed.
826 @return true if active (non-undo spaces are always active) */
827 bool is_active(space_id_t space_id, bool get_latch = true);
828 
829 /** Track an UNDO tablespace marked for truncate. */
830 class Truncate {
831  public:
835  static_cast<ulint>(srv_purge_rseg_truncate_frequency)) {
836  /* Do Nothing. */
837  }
838 
839  /** Is tablespace selected for truncate.
840  @return true if undo tablespace is marked for truncate */
841  bool is_marked() const { return (m_space_id_marked != SPACE_UNKNOWN); }
842 
843  /** Mark the undo tablespace selected for truncate as empty
844  so that it will be truncated next. */
846 
847  /** Is tablespace selected for truncate empty of undo logs yet?
848  @return true if the marked undo tablespace has no more undo logs */
850 
851  /** Mark the tablespace for truncate.
852  @param[in] undo_space undo tablespace to truncate. */
853  void mark(Tablespace *undo_space) {
854  /* Set the internal state of this undo space to inactive_implicit
855  so that its rsegs will not be allocated to any new transaction.
856  If the space is already in the inactive_explicit state, it will
857  stay there.
858  Note that the DD is not modified since in case of crash, the
859  action must be completed before the DD is available.
860  Set both the state and this marked id while this routine has
861  an x_lock on m_rsegs because a concurrent user thread might issue
862  undo_space->alter_active(). */
864 
865  m_marked_space_is_empty = false;
866 
867  /* We found an UNDO-tablespace to truncate so set the
868  local purge rseg truncate frequency to 3. This will help
869  accelerate the purge action and in turn truncate. */
871  }
872 
873  /** Get the ID of the tablespace marked for truncate.
874  @return tablespace ID marked for truncate. */
876  return (id2num(m_space_id_marked));
877  }
878 
879  /** Reset for next rseg truncate. */
880  void reset() {
881  /* Sync with global value as we are done with
882  truncate now. */
884  static_cast<ulint>(srv_purge_rseg_truncate_frequency));
885 
886  m_marked_space_is_empty = false;
888  }
889 
890  /** Get the undo tablespace number to start a scan.
891  Re-adjust in case the spaces::size() went down.
892  @return UNDO space_num to start scanning. */
895 
896  Tablespace *undo_space = undo::spaces->at(s_scan_pos);
897 
898  return (undo_space->num());
899  }
900 
901  /** Increment the scanning position in a round-robin fashion.
902  @return UNDO space_num at incremented scanning position. */
904  /** Round-robin way of selecting an undo tablespace
905  for the truncate operation. Once we reach the end of
906  the list of known undo tablespace IDs, move back to
907  the first undo tablespace ID. This will scan active
908  as well as inactive undo tablespaces. */
909  s_scan_pos = (s_scan_pos + 1) % undo::spaces->size();
910 
911  return (get_scan_space_num());
912  }
913 
914  /** Get local rseg purge truncate frequency
915  @return rseg purge truncate frequency. */
918  }
919 
920  /** Set local rseg purge truncate frequency */
921  void set_rseg_truncate_frequency(ulint frequency) {
923  }
924 
925  private:
926  /** UNDO space ID that is marked for truncate. */
928 
929  /** This is true if the marked space is empty of undo logs
930  and ready to truncate. We leave the rsegs object 'inactive'
931  until after it is truncated and rebuilt. This allow the
932  code to do the check for undo logs only once. */
934 
935  /** Rollback segment(s) purge frequency. This is a local
936  value maintained along with the global value. It is set
937  to the global value in the before each truncate. But when
938  a tablespace is marked for truncate it is updated to 1 and
939  then minimum value among 2 is used by the purge action. */
941 
942  /** Start scanning for UNDO tablespace from this
943  vector position. This is to avoid bias selection
944  of one tablespace always. */
945  static size_t s_scan_pos;
946 
947 }; /* class Truncate */
948 
949 } /* namespace undo */
950 
951 /** The control structure used in the purge operation */
952 struct trx_purge_t {
953  sess_t *sess; /*!< System session running the purge
954  query */
955  trx_t *trx; /*!< System transaction running the
956  purge query: this trx is not in the
957  trx list of the trx system and it
958  never ends */
959 #ifndef UNIV_HOTBACKUP
960  rw_lock_t latch; /*!< The latch protecting the purge
961  view. A purge operation must acquire an
962  x-latch here for the instant at which
963  it changes the purge view: an undo
964  log operation can prevent this by
965  obtaining an s-latch here. It also
966  protects state and running */
967 #endif /* !UNIV_HOTBACKUP */
968  os_event_t event; /*!< State signal event */
969  ulint n_stop; /*!< Counter to track number stops */
970  volatile bool running; /*!< true, if purge is active,
971  we check this without the latch too */
972  volatile purge_state_t state; /*!< Purge coordinator thread states,
973  we check this in several places
974  without holding the latch. */
975  que_t *query; /*!< The query graph which will do the
976  parallelized purge operation */
977  ReadView view; /*!< The purge will not remove undo logs
978  which are >= this view (purge view) */
979  bool view_active; /*!< true if view is active */
980  volatile ulint n_submitted; /*!< Count of total tasks submitted
981  to the task queue */
982  volatile ulint n_completed; /*!< Count of total tasks completed */
983 
984  /*------------------------------*/
985  /* The following two fields form the 'purge pointer' which advances
986  during a purge, and which is used in history list truncation */
987 
988  purge_iter_t iter; /* Limit up to which we have read and
989  parsed the UNDO log records. Not
990  necessarily purged from the indexes.
991  Note that this can never be less than
992  the limit below, we check for this
993  invariant in trx0purge.cc */
994  purge_iter_t limit; /* The 'purge pointer' which advances
995  during a purge, and which is used in
996  history list truncation */
997 #ifdef UNIV_DEBUG
998  purge_iter_t done; /* Indicate 'purge pointer' which have
999  purged already accurately. */
1000 #endif /* UNIV_DEBUG */
1001  /*-----------------------------*/
1002  ibool next_stored; /*!< TRUE if the info of the next record
1003  to purge is stored below: if yes, then
1004  the transaction number and the undo
1005  number of the record are stored in
1006  purge_trx_no and purge_undo_no above */
1007  trx_rseg_t *rseg; /*!< Rollback segment for the next undo
1008  record to purge */
1009  page_no_t page_no; /*!< Page number for the next undo
1010  record to purge, page number of the
1011  log header, if dummy record */
1012  ulint offset; /*!< Page offset for the next undo
1013  record to purge, 0 if the dummy
1014  record */
1015  page_no_t hdr_page_no; /*!< Header page of the undo log where
1016  the next record to purge belongs */
1017  ulint hdr_offset; /*!< Header byte offset on the page */
1018 
1019  TrxUndoRsegsIterator *rseg_iter; /*!< Iterator to get the next rseg
1020  to process */
1021 
1022  purge_pq_t *purge_queue; /*!< Binary min-heap, ordered on
1023  TrxUndoRsegs::trx_no. It is protected
1024  by the pq_mutex */
1025  PQMutex pq_mutex; /*!< Mutex protecting purge_queue */
1026 
1027  undo::Truncate undo_trunc; /*!< Track UNDO tablespace marked
1028  for truncate. */
1029 
1030  mem_heap_t *heap; /*!< Heap for reading the undo log
1031  records */
1032 };
1033 
1034 /** Choose the rollback segment with the smallest trx_no. */
1036  /** Constructor */
1038 
1039  /** Sets the next rseg to purge in m_purge_sys.
1040  @return page size of the table for which the log is.
1041  NOTE: if rseg is NULL when this function returns this means that
1042  there are no rollback segments to purge and then the returned page
1043  size object should not be used. */
1044  const page_size_t set_next();
1045 
1046  private:
1047  // Disable copying
1050 
1051  /** The purge system pointer */
1053 
1054  /** The current element to process */
1056 
1057  /** Track the current element in m_trx_undo_rseg */
1059 
1060  /** Sentinel value */
1062 };
1063 
1064 #include "trx0purge.ic"
1065 
1066 #endif /* trx0purge_h */
trx_purge_t::running
volatile bool running
true, if purge is active, we check this without the latch too
Definition: trx0purge.h:970
undo::Tablespace::is_empty
bool is_empty()
Return whether the undo tablespace is empty and ready to be dropped.
Definition: trx0purge.h:563
page_no_t
uint32 page_no_t
Page number.
Definition: api0api.h:57
undo::Truncate::mark
void mark(Tablespace *undo_space)
Mark the tablespace for truncate.
Definition: trx0purge.h:853
trx0sys.h
undo::id2num
space_id_t id2num(space_id_t space_id)
Convert an undo space ID into an undo space number.
Definition: trx0purge.h:222
Rsegs::is_active
bool is_active()
Return whether the undo tablespace is active.
Definition: trx0types.h:328
Rsegs::set_active
void set_active()
Set the state of the rollback segments in this undo tablespace to ACTIVE for use by new transactions.
Definition: trx0types.h:351
undo::Truncate
Track an UNDO tablespace marked for truncate.
Definition: trx0purge.h:830
undo::spaces
Tablespaces * spaces
A global object that contains a vector of undo::Tablespace structs.
Definition: trx0purge.cc:591
purge_iter_t
This is the purge pointer/iterator.
Definition: trx0purge.h:114
undo::Tablespaces::Tablespaces
Tablespaces()
Definition: trx0purge.h:663
trx_purge_t::state
volatile purge_state_t state
Purge coordinator thread states, we check this in several places without holding the latch.
Definition: trx0purge.h:972
undo::space_id_account
The currently used undo space IDs for an undo space number along with a boolean showing whether the u...
Definition: trx0purge.h:147
undo::Tablespaces::size
ulint size()
Get the number of tablespaces tracked by this object.
Definition: trx0purge.h:683
undo::use_next_space_id
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:675
undo::Tablespace::set_file_name
void set_file_name(const char *file_name)
Replace the standard undo file name if it exists with a copy of the file name provided.
Definition: trx0purge.cc:778
undo::s_under_construction
Space_Ids s_under_construction
list of undo tablespaces that need header pages and rollback segments written to them at startup.
Definition: trx0purge.cc:1124
undo::space_id_bank
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:595
page_t
byte page_t
Type of the index page.
Definition: page0types.h:133
undo_no_t
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:152
undo::Tablespace::Tablespace
Tablespace(Tablespace &other)
Copy Constructor.
Definition: trx0purge.h:320
undo::Truncate::is_marked
bool is_marked() const
Is tablespace selected for truncate.
Definition: trx0purge.h:841
trx_purge_add_update_undo_to_history
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
read0types.h
PURGE_STATE_DISABLED
@ PURGE_STATE_DISABLED
Purge was never started.
Definition: trx0purge.h:102
undo::Tablespaces::drop
void drop(Tablespace *undo_space)
Drop an existing explicit undo::Tablespace.
Definition: trx0purge.cc:2449
trx_purge_sys_create
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
trx_purge_t::query
que_t * query
The query graph which will do the parallelized purge operation.
Definition: trx0purge.h:975
undo::Truncate::set_rseg_truncate_frequency
void set_rseg_truncate_frequency(ulint frequency)
Set local rseg purge truncate frequency.
Definition: trx0purge.h:921
trx_id_t
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:148
undo::space_id_account::space_id
space_id_t space_id
Definition: trx0purge.h:148
Rsegs::set_inactive_implicit
void set_inactive_implicit()
Set the state of the rollback segments in this undo tablespace to inactive_implicit.
Definition: trx0types.h:358
dict_sys_t::s_min_undo_space_id
static constexpr space_id_t s_min_undo_space_id
The lowest undo tablespace ID.
Definition: dict0dict.h:1139
undo::add_space_to_construction_list
void add_space_to_construction_list(space_id_t space_id)
Add undo tablespace to s_under_construction vector.
Definition: trx0purge.cc:1051
PQMutex
ib_mutex_t PQMutex
Definition: trx0types.h:183
rw_lock_own
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:960
purge_state_t
purge_state_t
Purge states.
Definition: trx0purge.h:97
undo::Tablespace::is_implicit
bool is_implicit()
Report whether this undo tablespace was implicitly created.
Definition: trx0purge.h:482
trx_purge_run
void trx_purge_run(void)
Resume purge, move to PURGE_STATE_RUN.
Definition: trx0purge.cc:2367
ut_ad
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:65
FSP_MAX_UNDO_TABLESPACES
#define FSP_MAX_UNDO_TABLESPACES
Definition: fsp0types.h:391
Rsegs::set_empty
void set_empty()
Set the state of the undo tablespace to empty so that it can be dropped.
Definition: trx0types.h:370
Rsegs::at
trx_rseg_t * at(ulint slot)
Find the rseg at the given slot in this vector.
Definition: trx0types.h:295
undo::Tablespace::m_id
space_id_t m_id
Undo Tablespace ID.
Definition: trx0purge.h:625
undo::Tablespace::~Tablespace
~Tablespace()
Destructor.
Definition: trx0purge.h:342
undo::Tablespaces::m_latch
rw_lock_t * m_latch
RW lock to protect m_spaces.
Definition: trx0purge.h:764
undo::Tablespaces::add
void add(Tablespace &ref_undo_space)
Add a new undo::Tablespace to the back of the vector.
Definition: trx0purge.cc:2435
undo::Tablespaces::clear
void clear()
Clear the contents of the list of Tablespace objects.
Definition: trx0purge.h:675
undo::is_under_construction
bool is_under_construction(space_id_t space_id)
Is an undo tablespace under constuction at the moment.
Definition: trx0purge.cc:1061
mtr_t
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:169
undo::Tablespace::m_num
space_id_t m_num
Undo Tablespace number, from 1 to 127.
Definition: trx0purge.h:630
os_event
InnoDB condition variable.
Definition: os0event.cc:66
trx_purge_t::limit
purge_iter_t limit
Definition: trx0purge.h:994
pos
char * pos
Definition: do_ctype.cc:76
trx_purge_t::n_completed
volatile ulint n_completed
Count of total tasks completed.
Definition: trx0purge.h:982
undo::Truncate::reset
void reset()
Reset for next rseg truncate.
Definition: trx0purge.h:880
undo::Tablespaces::~Tablespaces
~Tablespaces()
Definition: trx0purge.h:665
trx_purge_t::purge_queue
purge_pq_t * purge_queue
Binary min-heap, ordered on TrxUndoRsegs::trx_no.
Definition: trx0purge.h:1022
undo::Tablespace::set_inactive_explicit
void set_inactive_explicit()
Make the undo tablespace inactive so that it will not be used for new transactions.
Definition: trx0purge.h:598
PURGE_STATE_RUN
@ PURGE_STATE_RUN
Purge should be running.
Definition: trx0purge.h:99
trx_purge_t::n_stop
ulint n_stop
Counter to track number stops.
Definition: trx0purge.h:969
undo::Tablespace::needs_truncation
bool needs_truncation()
Definition: trx0purge.h:367
Rseg_Iterator
Rsegs_Vector::iterator Rseg_Iterator
Definition: trx0types.h:248
Rsegs::x_lock
void x_lock()
Get a shared lock on m_rsegs.
Definition: trx0types.h:321
TrxUndoRsegsIterator::m_iter
Rseg_Iterator m_iter
Track the current element in m_trx_undo_rseg.
Definition: trx0purge.h:1058
SRV_UNDO_TABLESPACE_SIZE_IN_PAGES
const page_no_t SRV_UNDO_TABLESPACE_SIZE_IN_PAGES
Default size of UNDO tablespace while it is created new.
Definition: srv0srv.cc:172
undo::is_active_truncate_log_present
bool is_active_truncate_log_present(space_id_t space_num)
Check if TRUNCATE_DDL_LOG file exist.
Definition: trx0purge.cc:977
undo::Tablespace::m_file_name
char * m_file_name
The tablespace file name, auto-generated when needed from the space number.
Definition: trx0purge.h:645
dberr_t
dberr_t
Definition: db0err.h:38
undo::Tablespace::set_active
void set_active()
Set the undo tablespace active for use by transactions.
Definition: trx0purge.h:574
undo::s_magic
const ib_uint32_t s_magic
Magic Number to indicate truncate action is complete.
Definition: trx0purge.h:137
undo::Tablespaces::init
void init()
Initialize.
Definition: trx0purge.cc:2407
undo::Tablespace::m_space_name
char * m_space_name
The tablespace name, auto-generated when needed from the space number.
Definition: trx0purge.h:641
undo::Truncate::s_scan_pos
static size_t s_scan_pos
Start scanning for UNDO tablespace from this vector position.
Definition: trx0purge.h:945
undo::done_logging
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:920
dict_sys_t::s_max_undo_space_id
static constexpr space_id_t s_max_undo_space_id
The highest undo tablespace ID.
Definition: dict0dict.h:1143
undo::Tablespace::m_implicit
bool m_implicit
True if this is an implicit undo tablespace.
Definition: trx0purge.h:633
true
#define true
Definition: config_static.h:44
trx_purge_t::hdr_offset
ulint hdr_offset
Header byte offset on the page.
Definition: trx0purge.h:1017
undo
Definition: trx0purge.h:134
TrxUndoRsegsIterator::set_next
const page_size_t set_next()
Sets the next rseg to purge in m_purge_sys.
Definition: trx0purge.cc:96
trx_purge_t::n_submitted
volatile ulint n_submitted
Count of total tasks submitted to the task queue.
Definition: trx0purge.h:980
srv_undo_log_truncate
bool srv_undo_log_truncate
Enable or Disable Truncate of UNDO tablespace.
Definition: srv0srv.cc:163
undo::Tablespaces
List of undo tablespaces, each containing a list of rollback segments.
Definition: trx0purge.h:658
purge_iter_t::undo_rseg_space
space_id_t undo_rseg_space
Last undo record resided in this space id.
Definition: trx0purge.h:124
rw_lock_x_lock
#define rw_lock_x_lock(M)
Definition: sync0rw.h:288
PURGE_STATE_EXIT
@ PURGE_STATE_EXIT
Purge has been shutdown.
Definition: trx0purge.h:101
undo::s_log_ext
const char *const s_log_ext
Truncate Log file Extension.
Definition: trx0purge.h:143
que0types.h
mem_block_info_t
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:337
trx_purge_t::offset
ulint offset
Page offset for the next undo record to purge, 0 if the dummy record.
Definition: trx0purge.h:1012
Rsegs
This is a wrapper for a std::vector of trx_rseg_t object pointers.
Definition: trx0types.h:251
undo::space_id_account::in_use
bool in_use
Definition: trx0purge.h:149
trx_rseg_t
The rollback segment memory object.
Definition: trx0types.h:187
undo::Truncate::is_marked_space_empty
bool is_marked_space_empty() const
Is tablespace selected for truncate empty of undo logs yet?
Definition: trx0purge.h:849
undo::Truncate::get_scan_space_num
space_id_t get_scan_space_num() const
Get the undo tablespace number to start a scan.
Definition: trx0purge.h:893
undo::Tablespace::num
space_id_t num()
Get the undo tablespace number.
Definition: trx0purge.h:464
undo::Tablespace::is_inactive_implicit
bool is_inactive_implicit()
Return whether the undo tablespace is inactive due to implicit selection by the purge thread.
Definition: trx0purge.h:537
undo::unuse_space_id
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:631
undo::Tablespace
An undo::Tablespace object is used to easily convert between undo_space_id and undo_space_num and to ...
Definition: trx0purge.h:305
undo::is_reserved
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
undo::Tablespace::get_active
trx_rseg_t * get_active(ulint slot)
Return the rseg at the requested rseg slot if the undo space is active.
Definition: trx0purge.h:517
purge_iter_t::trx_no
trx_id_t trx_no
Purge has advanced past all transactions whose number is less than this.
Definition: trx0purge.h:119
undo::num2id
space_id_t num2id(space_id_t space_num, size_t ndx)
Convert an undo space number (from 1 to 127) into the undo space_id, given an index indicating which ...
Definition: trx0purge.h:170
purge_iter_t::undo_no
undo_no_t undo_no
Purge has advanced past all records whose undo number is less than this.
Definition: trx0purge.h:122
srv_page_size
ulong srv_page_size
Definition: srv0srv.cc:361
undo::Tablespaces::own_latch
bool own_latch()
Determine if this thread owns a lock on m_latch.
Definition: trx0purge.h:742
purge_pq_t
std::priority_queue< TrxUndoRsegs, std::vector< TrxUndoRsegs, ut_allocator< TrxUndoRsegs > >, TrxUndoRsegs > purge_pq_t
Definition: trx0types.h:536
undo::Truncate::m_space_id_marked
space_id_t m_space_id_marked
UNDO space ID that is marked for truncate.
Definition: trx0purge.h:927
Rsegs::is_init
bool is_init()
Return whether the undo tablespace is being initialized.
Definition: trx0types.h:347
page_size_t
Page size descriptor.
Definition: page0size.h:50
trx_purge_t::iter
purge_iter_t iter
Definition: trx0purge.h:988
undo::init_space_id_bank
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:605
undo::Tablespace::m_log_file_name
char * m_log_file_name
The tablespace log file name, auto-generated when needed from the space number.
Definition: trx0purge.h:649
Rsegs::s_unlock
void s_unlock()
Get a shared lock on m_rsegs.
Definition: trx0types.h:318
Space_Ids
List of undo tablespace IDs.
Definition: trx0sys.h:405
trx_purge_t::rseg_iter
TrxUndoRsegsIterator * rseg_iter
Iterator to get the next rseg to process.
Definition: trx0purge.h:1019
rw_lock_x_unlock
#define rw_lock_x_unlock(L)
Definition: sync0rw.h:313
TrxUndoRsegsIterator::operator=
TrxUndoRsegsIterator & operator=(const TrxUndoRsegsIterator &)
trx_purge_t::done
purge_iter_t done
Definition: trx0purge.h:998
Rsegs::is_empty
bool is_empty()
Return whether the undo tablespace is empty and ready to be dropped.
Definition: trx0types.h:343
purge_sys
trx_purge_t * purge_sys
The global data structure coordinating a purge.
Definition: trx0purge.cc:72
undo::make_space_name
char * make_space_name(space_id_t space_id)
Build a standard undo tablespace name from a space_id.
Definition: trx0purge.cc:717
TrxUndoRsegs
Rollback segements from a given transaction with trx-no scheduled for purge.
Definition: trx0types.h:471
trx_purge_t::hdr_page_no
page_no_t hdr_page_no
Header page of the undo log where the next record to purge belongs.
Definition: trx0purge.h:1015
undo::Tablespaces::s_unlock
void s_unlock()
Release a shared lock on m_spaces.
Definition: trx0purge.h:751
undo::use_space_id
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:618
undo::make_file_name
char * make_file_name(space_id_t space_id)
Build a standard undo tablespace file name from a space_id.
Definition: trx0purge.cc:736
undo::Tablespace::is_active
bool is_active()
Return whether the undo tablespace is active.
Definition: trx0purge.h:494
undo::Tablespaces::find
Tablespace * find(space_id_t num)
Find the given space_num in the vector.
Definition: trx0purge.h:714
Rsegs::is_inactive_explicit
bool is_inactive_explicit()
Return whether the undo tablespace was made inactive by ALTER TABLESPACE.
Definition: trx0types.h:338
trx_purge_t::sess
sess_t * sess
System session running the purge query.
Definition: trx0purge.h:953
Rsegs::x_unlock
void x_unlock()
Get a shared lock on m_rsegs.
Definition: trx0types.h:324
undo::Truncate::increment_scan
space_id_t increment_scan() const
Increment the scanning position in a round-robin fashion.
Definition: trx0purge.h:903
undo::next_space_id
space_id_t next_space_id(space_id_t space_id, space_id_t space_num)
Given a valid undo space_id or SPACE_UNKNOWN, return the next space_id for the given space number.
Definition: trx0purge.cc:645
TrxUndoRsegsIterator::m_trx_undo_rsegs
TrxUndoRsegs m_trx_undo_rsegs
The current element to process.
Definition: trx0purge.h:1055
undo::Tablespace::is_explicit
bool is_explicit()
Report whether this undo tablespace was explicitly created by an SQL statement.
Definition: trx0purge.h:478
undo::Tablespace::id
space_id_t id()
Get the undo tablespace ID.
Definition: trx0purge.h:458
undo::Tablespace::is_new
bool is_new()
Report whether this undo tablespace was created at startup.
Definition: trx0purge.h:487
trx_rseg_t::trx_ref_count
std::atomic< ulint > trx_ref_count
Reference counter to track rseg allocated transactions.
Definition: trx0types.h:244
Rsegs::s_lock
void s_lock()
Get a shared lock on m_rsegs.
Definition: trx0types.h:315
trx0types.h
undo::Tablespace::set_inactive_implicit
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:585
undo::Truncate::m_purge_rseg_truncate_frequency
ulint m_purge_rseg_truncate_frequency
Rollback segment(s) purge frequency.
Definition: trx0purge.h:940
trx_purge_stop
void trx_purge_stop(void)
Stop purge and wait for it to stop, move to PURGE_STATE_STOP.
Definition: trx0purge.cc:2308
trx_purge_t::pq_mutex
PQMutex pq_mutex
Mutex protecting purge_queue.
Definition: trx0purge.h:1025
undo::id2next_id
space_id_t id2next_id(space_id_t space_id)
Definition: trx0purge.h:234
trx_purge_get_log_from_hist
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...
undo::Tablespace::is_inactive_explicit
bool is_inactive_explicit()
Return whether the undo tablespace was made inactive by ALTER TABLESPACE.
Definition: trx0purge.h:550
trx_purge_t::view_active
bool view_active
true if view is active
Definition: trx0purge.h:979
TrxUndoRsegsIterator::NullElement
static const TrxUndoRsegs NullElement
Sentinel value.
Definition: trx0purge.h:1061
undo::Truncate::get_marked_space_num
space_id_t get_marked_space_num() const
Get the ID of the tablespace marked for truncate.
Definition: trx0purge.h:875
UT_DELETE
#define UT_DELETE(ptr)
Destroy, deallocate and trace the deallocation of an object created by UT_NEW() or UT_NEW_NOKEY().
Definition: ut0new.h:1018
RW_LOCK_S
@ RW_LOCK_S
Definition: sync0types.h:216
trx_purge_t::next_stored
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:1002
undo::Tablespaces::s_lock
void s_lock()
Get a shared lock on m_spaces.
Definition: trx0purge.h:748
undo::ddl_mutex
ib_mutex_t ddl_mutex
Mutext for serializing undo tablespace related DDL.
Definition: trx0purge.cc:588
undo::Tablespace::make_log_file_name
char * make_log_file_name(space_id_t space_id)
Build a log file name based on space_id.
Definition: trx0purge.cc:829
Rsegs::is_inactive_implicit
bool is_inactive_implicit()
Return whether the undo tablespace is inactive due to implicit selection by the purge thread.
Definition: trx0types.h:333
trx_purge_t::rseg
trx_rseg_t * rseg
Rollback segment for the next undo record to purge.
Definition: trx0purge.h:1007
undo::Tablespace::set_new
void set_new()
Note that this undo tablespace is being created.
Definition: trx0purge.h:490
undo::set_active
void set_active(space_id_t space_id)
Set an undo tablespace active.
Definition: trx0purge.cc:1072
undo::Tablespace::set_space_id
void set_space_id(space_id_t space_id)
Change the space_id from its current value.
Definition: trx0purge.cc:709
srv_max_undo_tablespace_size
unsigned long long srv_max_undo_tablespace_size
Maximum size of undo tablespace.
Definition: srv0srv.cc:169
ReadView
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:47
page0page.h
undo::Tablespace::m_rsegs
Rsegs * m_rsegs
List of rollback segments within this tablespace.
Definition: trx0purge.h:653
undo::Tablespace::log_file_name
char * log_file_name()
Get the undo log filename.
Definition: trx0purge.h:448
RW_LOCK_X
@ RW_LOCK_X
Definition: sync0types.h:217
undo::Tablespace::file_name
char * file_name()
Get the undo space filename.
Definition: trx0purge.h:430
undo::Tablespace::alter_active
void alter_active()
Make the undo tablespace active again so that it will be used for new transactions.
Definition: trx0purge.cc:851
undo::Truncate::set_marked_space_empty
void set_marked_space_empty()
Mark the undo tablespace selected for truncate as empty so that it will be truncated next.
Definition: trx0purge.h:845
undo::Tablespaces::deinit
void deinit()
De-initialize.
Definition: trx0purge.cc:2421
trx_purge_t::trx
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:955
undo::Tablespaces::contains
bool contains(space_id_t num)
Check if the given space_id is in the vector.
Definition: trx0purge.h:709
trx_purge_state
purge_state_t trx_purge_state(void)
Get the purge state.
Definition: trx0purge.cc:2295
TrxUndoRsegsIterator::m_purge_sys
trx_purge_t * m_purge_sys
The purge system pointer.
Definition: trx0purge.h:1052
PURGE_STATE_INIT
@ PURGE_STATE_INIT
Purge instance created.
Definition: trx0purge.h:98
undo::Tablespace::set_space_name
void set_space_name(const char *new_space_name)
Replace the standard undo space name if it exists with a copy of the undo tablespace name provided.
Definition: trx0purge.cc:766
undo::Tablespaces::Tablespaces_Vector
std::vector< Tablespace *, ut_allocator< Tablespace * > > Tablespaces_Vector
Definition: trx0purge.h:660
que_fork_t
Definition: que0que.h:303
undo::Tablespaces::x_unlock
void x_unlock()
Release an exclusive lock on m_spaces.
Definition: trx0purge.h:757
undo::Tablespace::Tablespace
Tablespace(space_id_t id)
Constructor.
Definition: trx0purge.h:308
undo::Tablespace::rsegs
Rsegs * rsegs()
Get a reference to the List of rollback segments within this undo tablespace.
Definition: trx0purge.h:473
sess_t
Definition: usr0sess.h:53
undo::start_logging
dberr_t start_logging(Tablespace *undo_space)
Create the truncate log file.
Definition: trx0purge.cc:865
usr0sess.h
undo::is_active
bool is_active(space_id_t space_id, bool get_latch=true)
Definition: trx0purge.cc:1091
TrxUndoRsegsIterator
Choose the rollback segment with the smallest trx_no.
Definition: trx0purge.h:1035
trx_purge_sys_close
void trx_purge_sys_close(void)
Frees the global purge system control structure.
Definition: trx0purge.cc:255
fil0fil.h
undo::Tablespaces::empty
bool empty()
See if the list of tablespaces is empty.
Definition: trx0purge.h:686
trx_purge_t::event
os_event_t event
State signal event.
Definition: trx0purge.h:968
rw_lock_s_lock
#define rw_lock_s_lock(M)
Definition: sync0rw.h:253
mtr0mtr.h
undo::Tablespaces::m_spaces
Tablespaces_Vector m_spaces
Definition: trx0purge.h:759
space_id_t
uint32 space_id_t
Tablespace identifier.
Definition: api0api.h:59
rw_lock_t
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:555
undo::Tablespace::m_new
bool m_new
True if this undo tablespace was implicitly created when this instance started up.
Definition: trx0purge.h:637
srv_purge_rseg_truncate_frequency
ulong srv_purge_rseg_truncate_frequency
Rate at which UNDO records should be purged.
Definition: srv0srv.cc:155
undo::Truncate::m_marked_space_is_empty
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:933
trx_purge
ulint trx_purge(ulint n_purge_threads, ulint limit, bool truncate)
This function runs a purge batch.
Definition: trx0purge.cc:2197
Rsegs::set_inactive_explicit
void set_inactive_explicit()
Make the undo tablespace inactive so that it will not be used for new transactions.
Definition: trx0types.h:366
SPACE_UNKNOWN
constexpr space_id_t SPACE_UNKNOWN
Unknown space id.
Definition: fil0fil.h:890
trx_purge_t::undo_trunc
undo::Truncate undo_trunc
Track UNDO tablespace marked for truncate.
Definition: trx0purge.h:1027
undo::Tablespaces::x_lock
void x_lock()
Get an exclusive lock on m_spaces.
Definition: trx0purge.h:754
TrxUndoRsegsIterator::TrxUndoRsegsIterator
TrxUndoRsegsIterator(trx_purge_t *purge_sys)
Constructor.
Definition: trx0purge.cc:86
rw_lock_s_unlock
#define rw_lock_s_unlock(L)
Definition: sync0rw.h:312
fil_space_get_size
page_no_t fil_space_get_size(space_id_t space_id)
Returns the size of the space in pages.
Definition: fil0fil.cc:3342
undo::Truncate::get_rseg_truncate_frequency
ulint get_rseg_truncate_frequency() const
Get local rseg purge truncate frequency.
Definition: trx0purge.h:916
trx_purge_t::view
ReadView view
The purge will not remove undo logs which are >= this view (purge view)
Definition: trx0purge.h:977
purge_iter_t::modifier_trx_id
trx_id_t modifier_trx_id
the transaction that created the undo log record.
Definition: trx0purge.h:127
PURGE_STATE_STOP
@ PURGE_STATE_STOP
Purge should be stopped.
Definition: trx0purge.h:100
fil_addr_t
File space address.
Definition: fil0fil.h:901
trx_purge_t::page_no
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:1009
dict_sys_t::undo_space_id_range
static constexpr space_id_t undo_space_id_range
The number of space IDs dedicated to each undo tablespace.
Definition: dict0dict.h:1136
FSP_MAX_ROLLBACK_SEGMENTS
#define FSP_MAX_ROLLBACK_SEGMENTS
Definition: fsp0types.h:393
undo::get_next_available_space_num
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:693
ut_max
#define ut_max
Definition: ut0ut.h:150
undo::clear_construction_list
void clear_construction_list()
Clear the s_under_construction vector.
Definition: trx0purge.cc:1056
undo::Tablespace::space_name
char * space_name()
Get the undo tablespace name.
Definition: trx0purge.h:406
undo::Tablespaces::at
Tablespace * at(size_t pos)
Get the Tablespace tracked at a position.
Definition: trx0purge.h:689
UT_NEW_NOKEY
#define UT_NEW_NOKEY(expr)
Allocate, trace the allocation and construct an object.
Definition: ut0new.h:1012
purge_iter_t::purge_iter_t
purge_iter_t()
Definition: trx0purge.h:115
ut_free
#define ut_free(ptr)
Definition: ut0new.h:1095
trx_purge_t
The control structure used in the purge operation.
Definition: trx0purge.h:952
undo::Tablespace::is_active_no_latch
bool is_active_no_latch()
Return whether the undo tablespace is active.
Definition: trx0purge.h:507
trx_t
Definition: trx0trx.h:780
trx_purge_t::heap
mem_heap_t * heap
Heap for reading the undo log records.
Definition: trx0purge.h:1030
trx_undo_ptr_t
The transaction handle.
Definition: trx0trx.h:751
undo::s_log_prefix
const char *const s_log_prefix
Truncate Log file Prefix.
Definition: trx0purge.h:140
undo::Tablespace::set_empty
void set_empty()
Set the state of the undo tablespace to empty so that it can be dropped.
Definition: trx0purge.h:617
undo::Truncate::Truncate
Truncate()
Definition: trx0purge.h:832
false
#define false
Definition: config_static.h:43
trx_purge_t::latch
rw_lock_t latch
The latch protecting the purge view.
Definition: trx0purge.h:960