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