MySQL 26.7.0
Source Code Documentation
mtr0mtr.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2026, Oracle and/or its affiliates.
4Copyright (c) 2012, Facebook Inc.
5
6This program is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License, version 2.0, as published by the
8Free Software Foundation.
9
10This program is designed to work with certain software (including
11but not limited to OpenSSL) that is licensed under separate terms,
12as designated in a particular file or component or in included license
13documentation. The authors of MySQL hereby grant you an additional
14permission to link the program and your derivative works with the
15separately licensed software that they have either included with
16the program or referenced in the documentation.
17
18This program is distributed in the hope that it will be useful, but WITHOUT
19ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
21for more details.
22
23You should have received a copy of the GNU General Public License along with
24this program; if not, write to the Free Software Foundation, Inc.,
2551 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
27*****************************************************************************/
28
29/** @file include/mtr0mtr.h
30 Mini-transaction buffer
31
32 Created 11/26/1995 Heikki Tuuri
33 *******************************************************/
34
35#ifndef mtr0mtr_h
36#define mtr0mtr_h
37
38#include <stddef.h>
39
40#include "univ.i"
41
42#include "buf0types.h"
43#include "dyn0buf.h"
44#include "fil0fil.h"
45#include "mtr0types.h"
46#include "srv0srv.h"
47#include "trx0types.h"
48
49/** Start a mini-transaction. */
50#define mtr_start(m) (m)->start()
51
52/** Start a synchronous mini-transaction */
53#define mtr_start_sync(m) (m)->start(true)
54
55/** Commit a mini-transaction. */
56#define mtr_commit(m) (m)->commit()
57
58/** Set and return a savepoint in mtr.
59@return savepoint */
60#define mtr_set_savepoint(m) (m)->get_savepoint()
61
62/** Release the (index tree) s-latch stored in an mtr memo after a
63savepoint. */
64#define mtr_release_s_latch_at_savepoint(m, s, l) \
65 (m)->release_s_latch_at_savepoint((s), (l))
66
67/** Get the logging mode of a mini-transaction.
68@return logging mode: MTR_LOG_NONE, ... */
69#define mtr_get_log_mode(m) (m)->get_log_mode()
70
71/** Change the logging mode of a mini-transaction.
72@return old mode */
73#define mtr_set_log_mode(m, d) (m)->set_log_mode((d))
74
75/** Get the flush observer of a mini-transaction.
76@return flush observer object */
77#define mtr_get_flush_observer(m) (m)->get_flush_observer()
78
79/** Set the flush observer of a mini-transaction. */
80#define mtr_set_flush_observer(m, d) (m)->set_flush_observer((d))
81
82/** Read 1 - 4 bytes from a file page buffered in the buffer pool.
83@return value read */
84#define mtr_read_ulint(p, t, m) (m)->read_ulint((p), (t))
85
86/** Release an object in the memo stack.
87@return true if released */
88#define mtr_memo_release(m, o, t) (m)->memo_release((o), (t))
89
90#ifdef UNIV_DEBUG
91
92/** Check if memo contains the given item ignore if table is intrinsic
93@return true if contains or table is intrinsic. */
94#define mtr_is_block_fix(m, o, t, table) \
95 (mtr_memo_contains(m, o, t) || table->is_intrinsic())
96
97/** Check if memo contains the given page ignore if table is intrinsic
98@return true if contains or table is intrinsic. */
99#define mtr_is_page_fix(m, p, t, table) \
100 (mtr_memo_contains_page(m, p, t) || table->is_intrinsic())
101
102/** Check if memo contains the given item.
103@return true if contains */
104#define mtr_memo_contains(m, o, t) (m)->memo_contains((m)->get_memo(), (o), (t))
105
106/** Check if memo contains the given page.
107@return true if contains */
108#define mtr_memo_contains_page(m, p, t) \
109 (m)->memo_contains_page_flagged((p), (t))
110#endif /* UNIV_DEBUG */
111
112/** Print info of an mtr handle. */
113#define mtr_print(m) (m)->print()
114
115/** Return the log object of a mini-transaction buffer.
116@return log */
117#define mtr_get_log(m) (m)->get_log()
118
119/** Push an object to an mtr memo stack. */
120#define mtr_memo_push(m, o, t) (m)->memo_push(o, t)
121
122/** Lock an rw-lock in s-mode. */
123#define mtr_s_lock(l, m, loc) (m)->s_lock((l), loc)
124
125/** Lock an rw-lock in x-mode. */
126#define mtr_x_lock(l, m, loc) (m)->x_lock((l), loc)
127
128/** Lock a tablespace in x-mode. */
129#define mtr_x_lock_space(s, m) (m)->x_lock_space((s), UT_LOCATION_HERE)
130
131/** Lock an rw-lock in sx-mode. */
132#define mtr_sx_lock(l, m, loc) (m)->sx_lock((l), loc)
133
134#define mtr_memo_contains_flagged(m, p, l) (m)->memo_contains_flagged((p), (l))
135
136#define mtr_memo_contains_page_flagged(m, p, l) \
137 (m)->memo_contains_page_flagged((p), (l))
138
139#define mtr_release_block_at_savepoint(m, s, b) \
140 (m)->release_block_at_savepoint((s), (b))
141
142#define mtr_block_sx_latch_at_savepoint(m, s, b) \
143 (m)->sx_latch_at_savepoint((s), (b))
144
145#define mtr_block_x_latch_at_savepoint(m, s, b) \
146 (m)->x_latch_at_savepoint((s), (b))
147
148/** Forward declaration of a tablespace object */
149class fil_space_t;
150
151/** Mini-transaction memo stack slot. */
153 /** Pointer to the object - either buf_block_t or rw_lock_t */
154 void *object;
155
156 /** type of the stored object (MTR_MEMO_S_LOCK, ...) */
158
159 /** Check if the object stored in this slot is a lock (rw_lock_t).
160 @return true if it is a lock object, false otherwise. */
161 bool is_lock() const {
162 return type == MTR_MEMO_S_LOCK || type == MTR_MEMO_X_LOCK ||
164 }
165
166 std::ostream &print(std::ostream &out) const;
167};
168
169inline std::ostream &operator<<(std::ostream &out, const mtr_memo_slot_t &obj) {
170 return obj.print(out);
171}
172
173/** Mini-transaction handle and buffer */
174struct mtr_t {
175 /** State variables of the mtr */
176 struct Impl {
177 /** memo stack for locks etc. */
179
180 /** mini-transaction log */
182
183 /** true if inside ibuf changes */
185
186 /** true if the mini-transaction might have modified buffer pool pages */
188
189 /** true if mtr is forced to NO_LOG mode because redo logging is
190 disabled globally. In this case, mtr increments the global counter
191 at ::start and must decrement it back at ::commit. */
193
194 /** Shard index used for incrementing global counter at ::start. We need
195 to use the same shard while decrementing counter at ::commit. */
197
198 /** Count of how many page initial log records have been
199 written to the mtr log */
200 uint32_t m_n_log_recs;
201
202 /** specifies which operations should be logged; default
203 value MTR_LOG_ALL */
205
206 /** State of the transaction */
208
209 /** Flush Observer */
211
212#ifdef UNIV_DEBUG
213 /** For checking corruption. */
215
216#endif /* UNIV_DEBUG */
217
218 /** Owning mini-transaction */
220 };
221
222#ifndef UNIV_HOTBACKUP
223 /** mtr global logging */
224 class Logging {
225 public:
226 /** mtr global redo logging state.
227 Enable Logging :
228 [ENABLED] -> [ENABLED_RESTRICT] -> [DISABLED]
229
230 Disable Logging :
231 [DISABLED] -> [ENABLED_RESTRICT] -> [ENABLED_DBLWR] -> [ENABLED] */
232
233 enum State : uint32_t {
234 /* Redo Logging is enabled. Server is crash safe. */
236 /* Redo logging is enabled. All non-logging mtr are finished with the
237 pages flushed to disk. Double write is enabled. Some pages could be
238 still getting written to disk without double-write. Not safe to crash. */
240 /* Redo logging is enabled but there could be some mtrs still running
241 in no logging mode. Redo archiving and clone are not allowed to start.
242 No double-write */
244 /* Redo logging is disabled and all new mtrs would not generate any redo.
245 Redo archiving and clone are not allowed. */
247 };
248
249 /** Initialize logging state at server start up. */
250 void init() {
251 m_state.store(ENABLED);
252 /* We use sharded counter and force sequentially consistent counting
253 which is the general default for c++ atomic operation. If we try to
254 optimize it further specific to current operations, we could use
255 Release-Acquire ordering i.e. std::memory_order_release during counting
256 and std::memory_order_acquire while checking for the count. However,
257 sharding looks to be good enough for now and we should go for non default
258 memory ordering only with some visible proof for improvement. */
259 m_count_nologging_mtr.set_order(std::memory_order_seq_cst);
261 }
262
263 /** Disable mtr redo logging. Server is crash unsafe without logging.
264 @param[in] thd server connection THD
265 @return mysql error code. */
266 int disable(THD *thd);
267
268 /** Enable mtr redo logging. Ensure that the server is crash safe
269 before returning.
270 @param[in] thd server connection THD
271 @return mysql error code. */
272 int enable(THD *thd);
273
274 /** Mark a no-logging mtr to indicate that it would not generate redo log
275 and system is crash unsafe.
276 @return true iff logging is disabled and mtr is marked. */
277 bool mark_mtr(size_t index) {
278 /* Have initial check to avoid incrementing global counter for regular
279 case when redo logging is enabled. */
280 if (is_disabled()) {
281 /* Increment counter to restrict state change DISABLED to ENABLED. */
283
284 /* Check if the no-logging is still disabled. At this point, if we
285 find the state disabled, it is no longer possible for the state move
286 back to enabled till the mtr finishes and we unmark the mtr. */
287 if (is_disabled()) {
288 return (true);
289 }
291 }
292 return (false);
293 }
294
295 /** unmark a no logging mtr. */
296 void unmark_mtr(size_t index) {
297 ut_ad(!is_enabled());
300 }
301
302 /* @return flush loop count for faster response when logging is disabled. */
303 uint32_t get_nolog_flush_loop() const { return (NOLOG_MAX_FLUSH_LOOP); }
304
305 /** @return true iff redo logging is enabled and server is crash safe. */
306 bool is_enabled() const { return (m_state.load() == ENABLED); }
307
308 /** @return true iff redo logging is disabled and new mtrs are not going
309 to generate redo log. */
310 bool is_disabled() const { return (m_state.load() == DISABLED); }
311
312 /** @return true iff we can skip data page double write. */
313 bool dblwr_disabled() const {
314 auto state = m_state.load();
315 return (state == DISABLED || state == ENABLED_RESTRICT);
316 }
317
318 /* Force faster flush loop for quicker adaptive flush response when logging
319 is disabled. When redo logging is disabled the system operates faster with
320 dirty pages generated at much faster rate. */
321 static constexpr uint32_t NOLOG_MAX_FLUSH_LOOP = 5;
322
323 private:
324 /** Wait till all no-logging mtrs are finished.
325 @return mysql error code. */
326 int wait_no_log_mtr(THD *thd);
327
328 private:
329 /** Global redo logging state. */
330 std::atomic<State> m_state;
331
333
334 /** Number of no logging mtrs currently running. */
336 };
337
338 /** Check if redo logging is disabled globally and mark
339 the global counter till mtr ends. */
341
342 /** Check if the mtr has marked the global no log counter and
343 unmark it. */
345#endif /* !UNIV_HOTBACKUP */
346
349 m_impl.m_marked_nolog = false;
351 }
352
354#ifdef UNIV_DEBUG
355 switch (m_impl.m_state) {
356 case MTR_STATE_ACTIVE:
357 ut_ad(m_impl.m_memo.size() == 0);
359 break;
360 case MTR_STATE_INIT:
362 break;
364 ut_error;
365 }
366#endif /* UNIV_DEBUG */
367#ifndef UNIV_HOTBACKUP
368 /* Safety check in case mtr is not committed. */
371 }
372#endif /* !UNIV_HOTBACKUP */
373 }
374
375#ifdef UNIV_DEBUG
376 /** Removed the MTR from the s_my_thread_active_mtrs list. */
377 void remove_from_debug_list() const;
378
379 /** Assure that there are no slots that are latching any resources. Only
380 buffer fixing a page is allowed. */
381 void check_is_not_latching() const;
382#endif /* UNIV_DEBUG */
383
384 /** Start a mini-transaction.
385 @param sync true if it is a synchronous mini-transaction */
386 void start(bool sync = true);
387
388 /** @return whether this is an asynchronous mini-transaction. */
389 bool is_async() const { return (!m_sync); }
390
391 /** Request a future commit to be synchronous. */
392 void set_sync() { m_sync = true; }
393
394 /** Commit the mini-transaction. */
395 void commit();
396
397 /** Return current size of the buffer.
398 @return savepoint */
399 [[nodiscard]] ulint get_savepoint() const {
400 ut_ad(is_active());
402
403 return (m_impl.m_memo.size());
404 }
405
406 /** Release the (index tree) s-latch stored in an mtr memo after a
407 savepoint.
408 @param savepoint value returned by @see set_savepoint.
409 @param lock latch to release */
410 inline void release_s_latch_at_savepoint(ulint savepoint, rw_lock_t *lock);
411
412 /** Release the block in an mtr memo after a savepoint. */
413 inline void release_block_at_savepoint(ulint savepoint, buf_block_t *block);
414
415 /** SX-latch a not yet latched block after a savepoint. */
416 inline void sx_latch_at_savepoint(ulint savepoint, buf_block_t *block);
417
418 /** X-latch a not yet latched block after a savepoint. */
419 inline void x_latch_at_savepoint(ulint savepoint, buf_block_t *block);
420
421 /** Get the logging mode.
422 @return logging mode */
423 [[nodiscard]] inline mtr_log_t get_log_mode() const;
424
425 /** Change the logging mode.
426 @param mode logging mode
427 @return old mode */
429
430 /** Read 1 - 4 bytes from a file page buffered in the buffer pool.
431 @param ptr pointer from where to read
432 @param type MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES
433 @return value read */
434 [[nodiscard]] inline uint32_t read_ulint(const byte *ptr,
435 mlog_id_t type) const;
436
437 /** Locks a rw-latch in S mode.
438 NOTE: use mtr_s_lock().
439 @param lock rw-lock
440 @param location location from where called */
441 inline void s_lock(rw_lock_t *lock, ut::Location location);
442
443 /** Locks a rw-latch in X mode.
444 NOTE: use mtr_x_lock().
445 @param lock rw-lock
446 @param location location where name from where called */
447 inline void x_lock(rw_lock_t *lock, ut::Location location);
448
449 /** Locks a rw-latch in X mode.
450 NOTE: use mtr_sx_lock().
451 @param lock rw-lock
452 @param location location from where called */
453 inline void sx_lock(rw_lock_t *lock, ut::Location location);
454
455 /** Acquire a tablespace X-latch.
456 NOTE: use mtr_x_lock_space().
457 @param[in] space tablespace instance
458 @param[in] location location from where called */
459 void x_lock_space(fil_space_t *space, ut::Location location);
460
461 /** Release an object in the memo stack.
462 @param object object
463 @param type object type: MTR_MEMO_S_LOCK, ... */
464 void memo_release(const void *object, ulint type);
465
466 /** Release a page latch.
467 @param[in] ptr pointer to within a page frame
468 @param[in] type object type: MTR_MEMO_PAGE_X_FIX, ... */
469 void release_page(const void *ptr, mtr_memo_type_t type);
470
471 /** Note that the mini-transaction might have modified a buffer pool page.
472 As it's called from mlog_open(), which is called from fil_op_write_log() and
473 perhaps other places which do not modify any page, this can be a false
474 positive. */
476
477 /** Checks if this mtr has modified any buffer pool page.
478 It errs on the safe side: may return true even if it didn't modify any page.
479 This is used in MTR_LOG_NO_REDO mode to detect that pages should be added to
480 flush lists during commit() even though no redo log will be produced.
481 @return true if the mini-transaction might have modified buffer pool pages. */
482 [[nodiscard]] bool has_modifications() const {
483 return m_impl.m_modifications;
484 }
485
486 /** Get the LSN of commit().
487 @return the commit LSN
488 @retval 0 if the transaction only modified temporary tablespaces or logging
489 is disabled globally. */
490 [[nodiscard]] lsn_t commit_lsn() const {
493 return (m_commit_lsn);
494 }
495
496 /** Note that we are inside the change buffer code. */
497 void enter_ibuf() { m_impl.m_inside_ibuf = true; }
498
499 /** Note that we have exited from the change buffer code. */
500 void exit_ibuf() { m_impl.m_inside_ibuf = false; }
501
502 /** @return true if we are inside the change buffer code */
503 [[nodiscard]] bool is_inside_ibuf() const { return (m_impl.m_inside_ibuf); }
504
505 /*
506 @return true if the mini-transaction is active */
507 [[nodiscard]] bool is_active() const {
508 return (m_impl.m_state == MTR_STATE_ACTIVE);
509 }
510
511 /** Get flush observer
512 @return flush observer */
513 [[nodiscard]] Flush_observer *get_flush_observer() const {
514 return (m_impl.m_flush_observer);
515 }
516
517 /** Set flush observer
518 @param[in] observer flush observer */
520 ut_ad(observer == nullptr || m_impl.m_log_mode == MTR_LOG_NO_REDO);
521
522 m_impl.m_flush_observer = observer;
523 }
524
525 /** Print the memo objects (mtr_memo_slot_t) of mtr_t to the given output
526 stream.
527 @param[in] out the output stream for printing
528 @return the output stream. */
529 std::ostream &print_memos(std::ostream &out) const;
530
531#ifdef UNIV_DEBUG
532 /** Check if memo contains the given item.
533 @param memo memo stack
534 @param object object to search
535 @param type type of object
536 @return true if contains */
537 [[nodiscard]] static bool memo_contains(const mtr_buf_t *memo,
538 const void *object, ulint type);
539
540 /** Check if memo contains the given item.
541 @param ptr object to search
542 @param flags specify types of object (can be ORred) of
543 MTR_MEMO_PAGE_S_FIX ... values
544 @return true if contains */
545 [[nodiscard]] bool memo_contains_flagged(const void *ptr, ulint flags) const;
546
547 /** Check if memo contains the given page.
548 @param[in] ptr pointer to within buffer frame
549 @param[in] flags specify types of object with OR of
550 MTR_MEMO_PAGE_S_FIX... values
551 @return the block
552 @retval NULL if not found */
553 [[nodiscard]] buf_block_t *memo_contains_page_flagged(const byte *ptr,
554 ulint flags) const;
555
556 /** Mark the given latched page as modified.
557 @param[in] ptr pointer to within buffer frame */
558 void memo_modify_page(const byte *ptr);
559
560 /** Print info of an mtr handle. */
561 void print() const;
562
563 /** @return true if the mini-transaction has committed */
564 [[nodiscard]] bool has_committed() const {
566 }
567
568 /** @return true if the mini-transaction is committing */
569 bool is_committing() const {
571 }
572
573 /** Check if the changes done in this mtr conflicts with changes done
574 in the given mtr. Two mtrs are said to conflict with each other, if
575 they modify the same buffer block.
576 @param[in] mtr2 the given mtr.
577 @return true if there is conflict, false otherwise. */
578 [[nodiscard]] bool conflicts_with(const mtr_t *mtr2) const;
579
580 /** @return the memo stack */
581 [[nodiscard]] const mtr_buf_t *get_memo() const { return (&m_impl.m_memo); }
582
583 /** @return the memo stack */
584 [[nodiscard]] mtr_buf_t *get_memo() { return (&m_impl.m_memo); }
585
586 /** Computes the number of bytes that would be written to the redo
587 log if mtr was committed right now (excluding headers of log blocks).
588 @return number of bytes of the collected log records increased
589 by 1 if MLOG_MULTI_REC_END would already be required */
590 size_t get_expected_log_size() const {
591 return (m_impl.m_log.size() + (m_impl.m_n_log_recs > 1 ? 1 : 0));
592 }
593
594 void wait_for_flush();
595#endif /* UNIV_DEBUG */
596
597 /** Note that a record has been added to the log */
599
600 /** Checks if this mtr has generated any redo log records which should be
601 written to the redo log during commit().
602 Note: If redo logging is disabled by set_log_mode(MTR_LOG_NONE) or
603 set_log_mode(MTR_LOG_NO_REDO) or globally by s_logging.disable(..), then it
604 will return false, even if set_modified() was called.
605 Note: Redo log records can be generated for things other than page
606 modifications, for example for tablespace rename, or other metadata updates.
607 Note: Redo log records can be generated for modifications of pages which were
608 already marked as dirty in BP.
609 @return true iff there is at least one redo log record generated */
611
612 /** Get the buffered redo log of this mini-transaction.
613 @return redo log */
614 [[nodiscard]] const mtr_buf_t *get_log() const {
616
617 return (&m_impl.m_log);
618 }
619
620 /** Get the buffered redo log of this mini-transaction.
621 @return redo log */
622 [[nodiscard]] mtr_buf_t *get_log() {
624
625 return (&m_impl.m_log);
626 }
627
628 /** Push an object to an mtr memo stack.
629 @param object object
630 @param type object type: MTR_MEMO_S_LOCK, ... */
631 inline void memo_push(void *object, mtr_memo_type_t type);
632
633#ifdef UNIV_DEBUG
634 /** Iterate all MTRs created in this thread to assure they are not latching
635 any resources. Violating this could lead to deadlocks under
636 log_free_check(). */
638 for (auto &it : s_my_thread_active_mtrs) {
639 it->check_is_not_latching();
640 }
641 }
642 /** This method is useful to detect if the thread is already inside an mtr.
643 We should not do the log_free_check() in the child mtrs if a thread is
644 already inside an mtr.
645 @return true if thread is not inside an mtr, false otherwise */
647 return !s_my_thread_active_mtrs.empty();
648 }
649#endif
650
651 /** Matrix to check if a mode update request should be ignored. */
653
654#ifdef UNIV_DEBUG
655 /** For checking invalid mode update requests. */
657
658 /** Count the number of times the same mtr object has been committed and
659 restarted. */
661#endif /* UNIV_DEBUG */
662
663#ifndef UNIV_HOTBACKUP
664 /** Instance level logging information for all mtrs. */
666#endif /* !UNIV_HOTBACKUP */
667
668 private:
670
671 /** LSN at commit time */
673
674 /** true if it is synchronous mini-transaction */
675 bool m_sync;
676
677#ifdef UNIV_DEBUG
678 /** List of all non-committed MTR instances created in this thread. Used for
679 debug purposes in the log_free_check(). */
681#endif
682
683 class Command;
684
685 friend class Command;
686};
687
688#ifndef UNIV_HOTBACKUP
689#ifdef UNIV_DEBUG
690
691/** Reserves space in the log buffer and writes a single MLOG_TEST.
692@param[in] payload number of extra bytes within the record,
693 not greater than 1024
694@return end_lsn pointing to the first byte after the written record */
695lsn_t mtr_commit_mlog_test(size_t payload = 0);
696
697/** Reserves space in the log buffer and writes a single MLOG_TEST.
698Adjusts size of the payload in the record, in order to fill the current
699block up to its boundary. If nothing else is happening in parallel,
700we could expect to see afterwards:
701(cur_lsn + space_left) % OS_FILE_LOG_BLOCK_SIZE == LOG_BLOCK_HDR_SIZE,
702where cur_lsn = ib::redo::handler->peek_first_unassigned_lsn().
703@param[in] space_left extra bytes left to the boundary of block,
704 must be not greater than 496 */
705void mtr_commit_mlog_test_filling_block(size_t space_left = 0);
706
707#endif /* UNIV_DEBUG */
708#endif /* !UNIV_HOTBACKUP */
709
710#include "mtr0mtr.ic"
711
712#endif /* mtr0mtr_h */
The database buffer pool global types for the directory.
We use Flush_observer to track flushing of non-redo logged pages in bulk create index(btr0load....
Definition: buf0flu.h:283
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:36
ulint size() const
Returns the size of the total stored data.
Definition: dyn0buf.h:280
Tablespace or log data space.
Definition: fil0fil.h:506
UNIV_HOTBACKUP.
Definition: mtr0mtr.cc:360
mtr global logging
Definition: mtr0mtr.h:224
bool dblwr_disabled() const
Definition: mtr0mtr.h:313
State
mtr global redo logging state.
Definition: mtr0mtr.h:233
@ ENABLED
Definition: mtr0mtr.h:235
@ ENABLED_RESTRICT
Definition: mtr0mtr.h:243
@ ENABLED_DBLWR
Definition: mtr0mtr.h:239
@ DISABLED
Definition: mtr0mtr.h:246
void unmark_mtr(size_t index)
unmark a no logging mtr.
Definition: mtr0mtr.h:296
bool mark_mtr(size_t index)
Mark a no-logging mtr to indicate that it would not generate redo log and system is crash unsafe.
Definition: mtr0mtr.h:277
int disable(THD *thd)
Disable mtr redo logging.
Definition: mtr0mtr.cc:862
uint32_t get_nolog_flush_loop() const
Definition: mtr0mtr.h:303
int wait_no_log_mtr(THD *thd)
Wait till all no-logging mtrs are finished.
Definition: mtr0mtr.cc:909
static constexpr uint32_t NOLOG_MAX_FLUSH_LOOP
Definition: mtr0mtr.h:321
bool is_disabled() const
Definition: mtr0mtr.h:310
int enable(THD *thd)
Enable mtr redo logging.
Definition: mtr0mtr.cc:816
std::atomic< State > m_state
Global redo logging state.
Definition: mtr0mtr.h:330
void init()
Initialize logging state at server start up.
Definition: mtr0mtr.h:250
bool is_enabled() const
Definition: mtr0mtr.h:306
Shards m_count_nologging_mtr
Number of no logging mtrs currently running.
Definition: mtr0mtr.h:335
The dynamically allocated buffer implementation.
The low-level file system.
static int flags[50]
Definition: hp_test1.cc:40
uint64_t lsn_t
Type used for all log sequence number storage and arithmetic.
Definition: log0types.h:63
void mtr_commit_mlog_test_filling_block(size_t space_left=0)
Reserves space in the log buffer and writes a single MLOG_TEST.
Definition: mtr0mtr.cc:1150
std::ostream & operator<<(std::ostream &out, const mtr_memo_slot_t &obj)
Definition: mtr0mtr.h:169
lsn_t mtr_commit_mlog_test(size_t payload=0)
Reserves space in the log buffer and writes a single MLOG_TEST.
Definition: mtr0mtr.cc:1023
Mini-transaction buffer.
Mini-transaction buffer global types.
mlog_id_t
Definition: mtr0types.h:63
constexpr uint32_t MTR_MAGIC_N
Definition: mtr0types.h:334
mtr_log_t
Logging modes for a mini-transaction.
Definition: mtr0types.h:42
@ MTR_LOG_ALL
Default mode: log all operations modifying disk-based data.
Definition: mtr0types.h:44
@ MTR_LOG_NO_REDO
Don't generate REDO log but add dirty pages to flush list.
Definition: mtr0types.h:50
@ MTR_LOG_MODE_MAX
Last element.
Definition: mtr0types.h:56
mtr_state_t
Definition: mtr0types.h:337
@ MTR_STATE_COMMITTING
Definition: mtr0types.h:340
@ MTR_STATE_ACTIVE
Definition: mtr0types.h:339
@ MTR_STATE_INIT
Definition: mtr0types.h:338
@ MTR_STATE_COMMITTED
Definition: mtr0types.h:341
mtr_memo_type_t
Types for the mlock objects to store in the mtr memo; NOTE that the first 3 values must be RW_S_LATCH...
Definition: mtr0types.h:287
@ MTR_MEMO_X_LOCK
Definition: mtr0types.h:302
@ MTR_MEMO_S_LOCK
Definition: mtr0types.h:300
@ MTR_MEMO_SX_LOCK
Definition: mtr0types.h:304
Type inc(Shards< COUNT > &shards, size_t id)
Increment the counter of a shard by 1.
Definition: ut0counter.h:293
Type dec(Shards< COUNT > &shards, size_t id)
Decrement the counter of a shard by 1.
Definition: ut0counter.h:302
Type total(const Shards< COUNT > &shards) noexcept
Get the total value of all shards.
Definition: ut0counter.h:333
void clear(Shards< COUNT > &shards) noexcept
Clear the counter - reset to 0.
Definition: ut0counter.h:344
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
Provides atomic access in shared-exclusive modes.
Definition: shared_spin_lock.h:79
mode
Definition: file_handle.h:61
std::unordered_set< Key, std::hash< Key >, std::equal_to< Key >, ut::allocator< Key > > unordered_set
Definition: ut0new.h:2737
required string type
Definition: replication_group_member_actions.proto:34
The server main program.
void set_order(std::memory_order memory_order)
Override default memory order.
Definition: ut0counter.h:256
The buffer control block structure.
Definition: buf0buf.h:1756
Mini-transaction memo stack slot.
Definition: mtr0mtr.h:152
bool is_lock() const
Check if the object stored in this slot is a lock (rw_lock_t).
Definition: mtr0mtr.h:161
ulint type
type of the stored object (MTR_MEMO_S_LOCK, ...)
Definition: mtr0mtr.h:157
std::ostream & print(std::ostream &out) const
Definition: mtr0mtr.cc:802
void * object
Pointer to the object - either buf_block_t or rw_lock_t.
Definition: mtr0mtr.h:154
State variables of the mtr.
Definition: mtr0mtr.h:176
Flush_observer * m_flush_observer
Flush Observer.
Definition: mtr0mtr.h:210
bool m_inside_ibuf
true if inside ibuf changes
Definition: mtr0mtr.h:184
mtr_log_t m_log_mode
specifies which operations should be logged; default value MTR_LOG_ALL
Definition: mtr0mtr.h:204
mtr_state_t m_state
State of the transaction.
Definition: mtr0mtr.h:207
mtr_t * m_mtr
Owning mini-transaction.
Definition: mtr0mtr.h:219
size_t m_shard_index
Shard index used for incrementing global counter at start.
Definition: mtr0mtr.h:196
ulint m_magic_n
For checking corruption.
Definition: mtr0mtr.h:214
mtr_buf_t m_log
mini-transaction log
Definition: mtr0mtr.h:181
bool m_modifications
true if the mini-transaction might have modified buffer pool pages
Definition: mtr0mtr.h:187
mtr_buf_t m_memo
memo stack for locks etc.
Definition: mtr0mtr.h:178
uint32_t m_n_log_recs
Count of how many page initial log records have been written to the mtr log.
Definition: mtr0mtr.h:200
bool m_marked_nolog
true if mtr is forced to NO_LOG mode because redo logging is disabled globally.
Definition: mtr0mtr.h:192
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:174
void check_nolog_and_unmark()
Check if the mtr has marked the global no log counter and unmark it.
Definition: mtr0mtr.cc:537
bool conflicts_with(const mtr_t *mtr2) const
Check if the changes done in this mtr conflicts with changes done in the given mtr.
Definition: mtr0mtr.cc:229
void sx_latch_at_savepoint(ulint savepoint, buf_block_t *block)
SX-latch a not yet latched block after a savepoint.
Definition: mtr0mtr.ic:82
void memo_modify_page(const byte *ptr)
Mark the given latched page as modified.
Definition: mtr0mtr.cc:1006
void release_block_at_savepoint(ulint savepoint, buf_block_t *block)
Release the block in an mtr memo after a savepoint.
Definition: mtr0mtr.ic:132
bool m_sync
true if it is synchronous mini-transaction
Definition: mtr0mtr.h:675
Impl m_impl
Definition: mtr0mtr.h:669
void x_lock_space(fil_space_t *space, ut::Location location)
Acquire a tablespace X-latch.
Definition: mtr0mtr.cc:626
Flush_observer * get_flush_observer() const
Get flush observer.
Definition: mtr0mtr.h:513
bool has_modifications() const
Checks if this mtr has modified any buffer pool page.
Definition: mtr0mtr.h:482
bool has_any_log_record()
Checks if this mtr has generated any redo log records which should be written to the redo log during ...
Definition: mtr0mtr.h:610
bool is_async() const
Definition: mtr0mtr.h:389
lsn_t m_commit_lsn
LSN at commit time.
Definition: mtr0mtr.h:672
void memo_push(void *object, mtr_memo_type_t type)
Push an object to an mtr memo stack.
Definition: mtr0mtr.ic:38
const mtr_buf_t * get_log() const
Get the buffered redo log of this mini-transaction.
Definition: mtr0mtr.h:614
static bool is_this_thread_inside_mtr()
This method is useful to detect if the thread is already inside an mtr.
Definition: mtr0mtr.h:646
bool is_active() const
Definition: mtr0mtr.h:507
uint32_t read_ulint(const byte *ptr, mlog_id_t type) const
Read 1 - 4 bytes from a file page buffered in the buffer pool.
Definition: mtr0mtr.ic:193
mtr_buf_t * get_log()
Get the buffered redo log of this mini-transaction.
Definition: mtr0mtr.h:622
mtr_log_t set_log_mode(mtr_log_t mode)
Change the logging mode.
Definition: mtr0mtr.cc:447
void exit_ibuf()
Note that we have exited from the change buffer code.
Definition: mtr0mtr.h:500
void x_latch_at_savepoint(ulint savepoint, buf_block_t *block)
X-latch a not yet latched block after a savepoint.
Definition: mtr0mtr.ic:107
void set_modified()
Note that the mini-transaction might have modified a buffer pool page.
Definition: mtr0mtr.h:475
size_t get_expected_log_size() const
Computes the number of bytes that would be written to the redo log if mtr was committed right now (ex...
Definition: mtr0mtr.h:590
size_t m_restart_count
Count the number of times the same mtr object has been committed and restarted.
Definition: mtr0mtr.h:660
void commit()
Commit the mini-transaction.
Definition: mtr0mtr.cc:577
mtr_log_t get_log_mode() const
Get the logging mode.
Definition: mtr0mtr.ic:153
static void check_my_thread_mtrs_are_not_latching()
Iterate all MTRs created in this thread to assure they are not latching any resources.
Definition: mtr0mtr.h:637
static bool memo_contains(const mtr_buf_t *memo, const void *object, ulint type)
Check if memo contains the given item.
Definition: mtr0mtr.cc:948
void wait_for_flush()
Definition: mtr0mtr.cc:1154
void set_sync()
Request a future commit to be synchronous.
Definition: mtr0mtr.h:392
void start(bool sync=true)
Start a mini-transaction.
Definition: mtr0mtr.cc:480
mtr_t()
Definition: mtr0mtr.h:347
buf_block_t * memo_contains_page_flagged(const byte *ptr, ulint flags) const
Check if memo contains the given page.
Definition: mtr0mtr.cc:995
void added_rec()
Note that a record has been added to the log.
Definition: mtr0mtr.h:598
bool is_inside_ibuf() const
Definition: mtr0mtr.h:503
bool is_committing() const
Definition: mtr0mtr.h:569
bool memo_contains_flagged(const void *ptr, ulint flags) const
Check if memo contains the given item.
Definition: mtr0mtr.cc:979
void release_s_latch_at_savepoint(ulint savepoint, rw_lock_t *lock)
Release the (index tree) s-latch stored in an mtr memo after a savepoint.
Definition: mtr0mtr.ic:57
void set_flush_observer(Flush_observer *observer)
Set flush observer.
Definition: mtr0mtr.h:519
mtr_buf_t * get_memo()
Definition: mtr0mtr.h:584
static thread_local ut::unordered_set< const mtr_t * > s_my_thread_active_mtrs
List of all non-committed MTR instances created in this thread.
Definition: mtr0mtr.h:680
void check_is_not_latching() const
Assure that there are no slots that are latching any resources.
Definition: mtr0mtr.cc:612
bool has_committed() const
Definition: mtr0mtr.h:564
ulint get_savepoint() const
Return current size of the buffer.
Definition: mtr0mtr.h:399
lsn_t commit_lsn() const
Get the LSN of commit().
Definition: mtr0mtr.h:490
void enter_ibuf()
Note that we are inside the change buffer code.
Definition: mtr0mtr.h:497
std::ostream & print_memos(std::ostream &out) const
Print the memo objects (mtr_memo_slot_t) of mtr_t to the given output stream.
Definition: mtr0mtr.cc:196
static Logging s_logging
Instance level logging information for all mtrs.
Definition: mtr0mtr.h:665
const mtr_buf_t * get_memo() const
Definition: mtr0mtr.h:581
void remove_from_debug_list() const
Removed the MTR from the s_my_thread_active_mtrs list.
Definition: mtr0mtr.cc:604
static bool s_mode_update[MTR_LOG_MODE_MAX][MTR_LOG_MODE_MAX]
Matrix to check if a mode update request should be ignored.
Definition: mtr0mtr.h:652
void memo_release(const void *object, ulint type)
Release an object in the memo stack.
Definition: mtr0mtr.cc:634
~mtr_t()
Definition: mtr0mtr.h:353
void s_lock(rw_lock_t *lock, ut::Location location)
Locks a rw-latch in S mode.
Definition: mtr0mtr.ic:164
void x_lock(rw_lock_t *lock, ut::Location location)
Locks a rw-latch in X mode.
Definition: mtr0mtr.ic:173
static bool s_mode_update_valid[MTR_LOG_MODE_MAX][MTR_LOG_MODE_MAX]
For checking invalid mode update requests.
Definition: mtr0mtr.h:656
void release_page(const void *ptr, mtr_memo_type_t type)
Release a page latch.
Definition: mtr0mtr.cc:653
void print() const
Print info of an mtr handle.
Definition: mtr0mtr.cc:1017
void sx_lock(rw_lock_t *lock, ut::Location location)
Locks a rw-latch in X mode.
Definition: mtr0mtr.ic:182
void check_nolog_and_mark()
Check if redo logging is disabled globally and mark the global counter till mtr ends.
Definition: mtr0mtr.cc:520
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:362
Definition: ut0core.h:36
Transaction system global type definitions.
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:403
#define ut_error
Abort execution.
Definition: ut0dbg.h:105
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:111