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