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