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