MySQL 8.0.31
Source Code Documentation
mtr0mtr.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1995, 2022, 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/** Check if a mini-transaction is dirtying a clean page.
151@param b block being x-fixed
152@return true if the mtr is dirtying a clean page. */
153#define mtr_block_dirtied(b) mtr_t::is_block_dirtied((b))
154
155/** Forward declaration of a tablespace object */
156struct fil_space_t;
157
158/** Mini-transaction memo stack slot. */
160 /** Pointer to the object - either buf_block_t or rw_lock_t */
161 void *object;
162
163 /** type of the stored object (MTR_MEMO_S_LOCK, ...) */
165
166 /** Check if the object stored in this slot is a lock (rw_lock_t).
167 @return true if it is a lock object, false otherwise. */
168 bool is_lock() const {
169 return type == MTR_MEMO_S_LOCK || type == MTR_MEMO_X_LOCK ||
171 }
172
173 std::ostream &print(std::ostream &out) const;
174};
175
176inline std::ostream &operator<<(std::ostream &out, const mtr_memo_slot_t &obj) {
177 return obj.print(out);
178}
179
180/** Mini-transaction handle and buffer */
181struct mtr_t {
182 /** State variables of the mtr */
183 struct Impl {
184 /** memo stack for locks etc. */
186
187 /** mini-transaction log */
189
190 /** true if mtr has made at least one buffer pool page dirty */
192
193 /** true if inside ibuf changes */
195
196 /** true if the mini-transaction modified buffer pool pages */
198
199 /** true if mtr is forced to NO_LOG mode because redo logging is
200 disabled globally. In this case, mtr increments the global counter
201 at ::start and must decrement it back at ::commit. */
203
204 /** Shard index used for incrementing global counter at ::start. We need
205 to use the same shard while decrementing counter at ::commit. */
207
208 /** Count of how many page initial log records have been
209 written to the mtr log */
210 uint32_t m_n_log_recs;
211
212 /** specifies which operations should be logged; default
213 value MTR_LOG_ALL */
215
216 /** State of the transaction */
218
219 /** Flush Observer */
221
222#ifdef UNIV_DEBUG
223 /** For checking corruption. */
225
226#endif /* UNIV_DEBUG */
227
228 /** Owning mini-transaction */
230 };
231
232#ifndef UNIV_HOTBACKUP
233 /** mtr global logging */
234 class Logging {
235 public:
236 /** mtr global redo logging state.
237 Enable Logging :
238 [ENABLED] -> [ENABLED_RESTRICT] -> [DISABLED]
239
240 Disable Logging :
241 [DISABLED] -> [ENABLED_RESTRICT] -> [ENABLED_DBLWR] -> [ENABLED] */
242
243 enum State : uint32_t {
244 /* Redo Logging is enabled. Server is crash safe. */
246 /* Redo logging is enabled. All non-logging mtr are finished with the
247 pages flushed to disk. Double write is enabled. Some pages could be
248 still getting written to disk without double-write. Not safe to crash. */
250 /* Redo logging is enabled but there could be some mtrs still running
251 in no logging mode. Redo archiving and clone are not allowed to start.
252 No double-write */
254 /* Redo logging is disabled and all new mtrs would not generate any redo.
255 Redo archiving and clone are not allowed. */
257 };
258
259 /** Initialize logging state at server start up. */
260 void init() {
261 m_state.store(ENABLED);
262 /* We use sharded counter and force sequentially consistent counting
263 which is the general default for c++ atomic operation. If we try to
264 optimize it further specific to current operations, we could use
265 Release-Acquire ordering i.e. std::memory_order_release during counting
266 and std::memory_order_acquire while checking for the count. However,
267 sharding looks to be good enough for now and we should go for non default
268 memory ordering only with some visible proof for improvement. */
269 m_count_nologging_mtr.set_order(std::memory_order_seq_cst);
271 }
272
273 /** Disable mtr redo logging. Server is crash unsafe without logging.
274 @param[in] thd server connection THD
275 @return mysql error code. */
276 int disable(THD *thd);
277
278 /** Enable mtr redo logging. Ensure that the server is crash safe
279 before returning.
280 @param[in] thd server connection THD
281 @return mysql error code. */
282 int enable(THD *thd);
283
284 /** Mark a no-logging mtr to indicate that it would not generate redo log
285 and system is crash unsafe.
286 @return true iff logging is disabled and mtr is marked. */
287 bool mark_mtr(size_t index) {
288 /* Have initial check to avoid incrementing global counter for regular
289 case when redo logging is enabled. */
290 if (is_disabled()) {
291 /* Increment counter to restrict state change DISABLED to ENABLED. */
293
294 /* Check if the no-logging is still disabled. At this point, if we
295 find the state disabled, it is no longer possible for the state move
296 back to enabled till the mtr finishes and we unmark the mtr. */
297 if (is_disabled()) {
298 return (true);
299 }
301 }
302 return (false);
303 }
304
305 /** unmark a no logging mtr. */
306 void unmark_mtr(size_t index) {
307 ut_ad(!is_enabled());
310 }
311
312 /* @return flush loop count for faster response when logging is disabled. */
313 uint32_t get_nolog_flush_loop() const { return (NOLOG_MAX_FLUSH_LOOP); }
314
315 /** @return true iff redo logging is enabled and server is crash safe. */
316 bool is_enabled() const { return (m_state.load() == ENABLED); }
317
318 /** @return true iff redo logging is disabled and new mtrs are not going
319 to generate redo log. */
320 bool is_disabled() const { return (m_state.load() == DISABLED); }
321
322 /** @return true iff we can skip data page double write. */
323 bool dblwr_disabled() const {
324 auto state = m_state.load();
325 return (state == DISABLED || state == ENABLED_RESTRICT);
326 }
327
328 /* Force faster flush loop for quicker adaptive flush response when logging
329 is disabled. When redo logging is disabled the system operates faster with
330 dirty pages generated at much faster rate. */
331 static constexpr uint32_t NOLOG_MAX_FLUSH_LOOP = 5;
332
333 private:
334 /** Wait till all no-logging mtrs are finished.
335 @return mysql error code. */
336 int wait_no_log_mtr(THD *thd);
337
338 private:
339 /** Global redo logging state. */
340 std::atomic<State> m_state;
341
343
344 /** Number of no logging mtrs currently running. */
346 };
347
348 /** Check if redo logging is disabled globally and mark
349 the global counter till mtr ends. */
351
352 /** Check if the mtr has marked the global no log counter and
353 unmark it. */
355#endif /* !UNIV_HOTBACKUP */
356
359 m_impl.m_marked_nolog = false;
361 }
362
364#ifdef UNIV_DEBUG
365 switch (m_impl.m_state) {
366 case MTR_STATE_ACTIVE:
367 ut_ad(m_impl.m_memo.size() == 0);
369 break;
370 case MTR_STATE_INIT:
372 break;
374 ut_error;
375 }
376#endif /* UNIV_DEBUG */
377#ifndef UNIV_HOTBACKUP
378 /* Safety check in case mtr is not committed. */
381 }
382#endif /* !UNIV_HOTBACKUP */
383 }
384
385#ifdef UNIV_DEBUG
386 /** Removed the MTR from the s_my_thread_active_mtrs list. */
387 void remove_from_debug_list() const;
388
389 /** Assure that there are no slots that are latching any resources. Only
390 buffer fixing a page is allowed. */
391 void check_is_not_latching() const;
392#endif /* UNIV_DEBUG */
393
394 /** Start a mini-transaction.
395 @param sync true if it is a synchronous mini-transaction */
396 void start(bool sync = true);
397
398 /** @return whether this is an asynchronous mini-transaction. */
399 bool is_async() const { return (!m_sync); }
400
401 /** Request a future commit to be synchronous. */
402 void set_sync() { m_sync = true; }
403
404 /** Commit the mini-transaction. */
405 void commit();
406
407 /** Return current size of the buffer.
408 @return savepoint */
409 [[nodiscard]] ulint get_savepoint() const {
410 ut_ad(is_active());
412
413 return (m_impl.m_memo.size());
414 }
415
416 /** Release the (index tree) s-latch stored in an mtr memo after a
417 savepoint.
418 @param savepoint value returned by @see set_savepoint.
419 @param lock latch to release */
420 inline void release_s_latch_at_savepoint(ulint savepoint, rw_lock_t *lock);
421
422 /** Release the block in an mtr memo after a savepoint. */
423 inline void release_block_at_savepoint(ulint savepoint, buf_block_t *block);
424
425 /** SX-latch a not yet latched block after a savepoint. */
426 inline void sx_latch_at_savepoint(ulint savepoint, buf_block_t *block);
427
428 /** X-latch a not yet latched block after a savepoint. */
429 inline void x_latch_at_savepoint(ulint savepoint, buf_block_t *block);
430
431 /** Get the logging mode.
432 @return logging mode */
433 [[nodiscard]] inline mtr_log_t get_log_mode() const;
434
435 /** Change the logging mode.
436 @param mode logging mode
437 @return old mode */
439
440 /** Read 1 - 4 bytes from a file page buffered in the buffer pool.
441 @param ptr pointer from where to read
442 @param type MLOG_1BYTE, MLOG_2BYTES, MLOG_4BYTES
443 @return value read */
444 [[nodiscard]] inline uint32_t read_ulint(const byte *ptr,
445 mlog_id_t type) const;
446
447 /** Locks a rw-latch in S mode.
448 NOTE: use mtr_s_lock().
449 @param lock rw-lock
450 @param location location from where called */
451 inline void s_lock(rw_lock_t *lock, ut::Location location);
452
453 /** Locks a rw-latch in X mode.
454 NOTE: use mtr_x_lock().
455 @param lock rw-lock
456 @param location location where name from where called */
457 inline void x_lock(rw_lock_t *lock, ut::Location location);
458
459 /** Locks a rw-latch in X mode.
460 NOTE: use mtr_sx_lock().
461 @param lock rw-lock
462 @param location location from where called */
463 inline void sx_lock(rw_lock_t *lock, ut::Location location);
464
465 /** Acquire a tablespace X-latch.
466 NOTE: use mtr_x_lock_space().
467 @param[in] space tablespace instance
468 @param[in] location location from where called */
469 void x_lock_space(fil_space_t *space, ut::Location location);
470
471 /** Release an object in the memo stack.
472 @param object object
473 @param type object type: MTR_MEMO_S_LOCK, ... */
474 void memo_release(const void *object, ulint type);
475
476 /** Release a page latch.
477 @param[in] ptr pointer to within a page frame
478 @param[in] type object type: MTR_MEMO_PAGE_X_FIX, ... */
479 void release_page(const void *ptr, mtr_memo_type_t type);
480
481 /** Note that the mini-transaction has modified data. */
483
484 /** Set the state to not-modified. This will not log the
485 changes. This is only used during redo log apply, to avoid
486 logging the changes. */
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 /** @return true if mini-transaction contains modifications. */
577 [[nodiscard]] bool has_modifications() const {
578 return (m_impl.m_modifications);
579 }
580
581 /** Check if the changes done in this mtr conflicts with changes done
582 in the given mtr. Two mtrs are said to conflict with each other, if
583 they modify the same buffer block.
584 @param[in] mtr2 the given mtr.
585 @return true if there is conflict, false otherwise. */
586 [[nodiscard]] bool conflicts_with(const mtr_t *mtr2) const;
587
588 /** @return the memo stack */
589 [[nodiscard]] const mtr_buf_t *get_memo() const { return (&m_impl.m_memo); }
590
591 /** @return the memo stack */
592 [[nodiscard]] mtr_buf_t *get_memo() { return (&m_impl.m_memo); }
593
594 /** Computes the number of bytes that would be written to the redo
595 log if mtr was committed right now (excluding headers of log blocks).
596 @return number of bytes of the collected log records increased
597 by 1 if MLOG_MULTI_REC_END would already be required */
598 size_t get_expected_log_size() const {
599 return (m_impl.m_log.size() + (m_impl.m_n_log_recs > 1 ? 1 : 0));
600 }
601
602 void wait_for_flush();
603#endif /* UNIV_DEBUG */
604
605 /** @return true if a record was added to the mini-transaction */
606 [[nodiscard]] bool is_dirty() const { return (m_impl.m_made_dirty); }
607
608 /** Note that a record has been added to the log */
610
611 /** Get the buffered redo log of this mini-transaction.
612 @return redo log */
613 [[nodiscard]] const mtr_buf_t *get_log() const {
615
616 return (&m_impl.m_log);
617 }
618
619 /** Get the buffered redo log of this mini-transaction.
620 @return redo log */
621 [[nodiscard]] mtr_buf_t *get_log() {
623
624 return (&m_impl.m_log);
625 }
626
627 /** Push an object to an mtr memo stack.
628 @param object object
629 @param type object type: MTR_MEMO_S_LOCK, ... */
630 inline void memo_push(void *object, mtr_memo_type_t type);
631
632#ifdef UNIV_DEBUG
633 /** Iterate all MTRs created in this thread to assure they are not latching
634 any resources. Violating this could lead to deadlocks under
635 log_free_check(). */
637 for (auto &it : s_my_thread_active_mtrs) {
638 it->check_is_not_latching();
639 }
640 }
641#endif
642
643 /** Check if this mini-transaction is dirtying a clean page.
644 @param block block being x-fixed
645 @return true if the mtr is dirtying a clean page. */
646 [[nodiscard]] static bool is_block_dirtied(const buf_block_t *block);
647
648 /** Matrix to check if a mode update request should be ignored. */
650
651#ifdef UNIV_DEBUG
652 /** For checking invalid mode update requests. */
654
655 /** Count the number of times the same mtr object has been committed and
656 restarted. */
658#endif /* UNIV_DEBUG */
659
660#ifndef UNIV_HOTBACKUP
661 /** Instance level logging information for all mtrs. */
663#endif /* !UNIV_HOTBACKUP */
664
665 private:
667
668 /** LSN at commit time */
670
671 /** true if it is synchronous mini-transaction */
672 bool m_sync;
673
674#ifdef UNIV_DEBUG
675 /** List of all non-committed MTR instances created in this thread. Used for
676 debug purposes in the log_free_check(). */
678#endif
679
680 class Command;
681
682 friend class Command;
683};
684
685#ifndef UNIV_HOTBACKUP
686#ifdef UNIV_DEBUG
687
688/** Reserves space in the log buffer and writes a single MLOG_TEST.
689@param[in] payload number of extra bytes within the record,
690 not greater than 1024
691@return end_lsn pointing to the first byte after the written record */
692lsn_t mtr_commit_mlog_test(size_t payload = 0);
693
694/** Reserves space in the log buffer and writes a single MLOG_TEST.
695Adjusts size of the payload in the record, in order to fill the current
696block up to its boundary. If nothing else is happening in parallel,
697we could expect to see afterwards:
698(cur_lsn + space_left) % OS_FILE_LOG_BLOCK_SIZE == LOG_BLOCK_HDR_SIZE,
699where cur_lsn = log_get_lsn(log).
700@param[in,out] log redo log
701@param[in] space_left extra bytes left to the boundary of block,
702 must be not greater than 496 */
703void mtr_commit_mlog_test_filling_block(log_t &log, size_t space_left = 0);
704
705#endif /* UNIV_DEBUG */
706#endif /* !UNIV_HOTBACKUP */
707
708#include "mtr0mtr.ic"
709
710#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:268
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_class.h:922
ulint size() const
Returns the size of the total stored data.
Definition: dyn0buf.h:279
Definition: mtr0mtr.cc:384
mtr global logging
Definition: mtr0mtr.h:234
bool dblwr_disabled() const
Definition: mtr0mtr.h:323
State
mtr global redo logging state.
Definition: mtr0mtr.h:243
@ ENABLED
Definition: mtr0mtr.h:245
@ ENABLED_RESTRICT
Definition: mtr0mtr.h:253
@ ENABLED_DBLWR
Definition: mtr0mtr.h:249
@ DISABLED
Definition: mtr0mtr.h:256
void unmark_mtr(size_t index)
unmark a no logging mtr.
Definition: mtr0mtr.h:306
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:287
int disable(THD *thd)
Disable mtr redo logging.
Definition: mtr0mtr.cc:960
uint32_t get_nolog_flush_loop() const
Definition: mtr0mtr.h:313
int wait_no_log_mtr(THD *thd)
Wait till all no-logging mtrs are finished.
Definition: mtr0mtr.cc:1006
static constexpr uint32_t NOLOG_MAX_FLUSH_LOOP
Definition: mtr0mtr.h:331
bool is_disabled() const
Definition: mtr0mtr.h:320
int enable(THD *thd)
Enable mtr redo logging.
Definition: mtr0mtr.cc:914
std::atomic< State > m_state
Global redo logging state.
Definition: mtr0mtr.h:340
void init()
Initialize logging state at server start up.
Definition: mtr0mtr.h:260
bool is_enabled() const
Definition: mtr0mtr.h:316
Shards m_count_nologging_mtr
Number of no logging mtrs currently running.
Definition: mtr0mtr.h:345
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:176
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:1120
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:1249
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:2868
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:1664
Tablespace or log data space.
Definition: fil0fil.h:230
Redo log - single data structure with state of the redo log system.
Definition: log0sys.h:74
Mini-transaction memo stack slot.
Definition: mtr0mtr.h:159
bool is_lock() const
Check if the object stored in this slot is a lock (rw_lock_t).
Definition: mtr0mtr.h:168
ulint type
type of the stored object (MTR_MEMO_S_LOCK, ...)
Definition: mtr0mtr.h:164
std::ostream & print(std::ostream &out) const
Definition: mtr0mtr.cc:900
void * object
Pointer to the object - either buf_block_t or rw_lock_t.
Definition: mtr0mtr.h:161
State variables of the mtr.
Definition: mtr0mtr.h:183
Flush_observer * m_flush_observer
Flush Observer.
Definition: mtr0mtr.h:220
bool m_made_dirty
true if mtr has made at least one buffer pool page dirty
Definition: mtr0mtr.h:191
bool m_inside_ibuf
true if inside ibuf changes
Definition: mtr0mtr.h:194
mtr_log_t m_log_mode
specifies which operations should be logged; default value MTR_LOG_ALL
Definition: mtr0mtr.h:214
mtr_state_t m_state
State of the transaction.
Definition: mtr0mtr.h:217
mtr_t * m_mtr
Owning mini-transaction.
Definition: mtr0mtr.h:229
size_t m_shard_index
Shard index used for incrementing global counter at start.
Definition: mtr0mtr.h:206
ulint m_magic_n
For checking corruption.
Definition: mtr0mtr.h:224
mtr_buf_t m_log
mini-transaction log
Definition: mtr0mtr.h:188
bool m_modifications
true if the mini-transaction modified buffer pool pages
Definition: mtr0mtr.h:197
mtr_buf_t m_memo
memo stack for locks etc.
Definition: mtr0mtr.h:185
uint32_t m_n_log_recs
Count of how many page initial log records have been written to the mtr log.
Definition: mtr0mtr.h:210
bool m_marked_nolog
true if mtr is forced to NO_LOG mode because redo logging is disabled globally.
Definition: mtr0mtr.h:202
Mini-transaction handle and buffer.
Definition: mtr0mtr.h:181
void check_nolog_and_unmark()
Check if the mtr has marked the global no log counter and unmark it.
Definition: mtr0mtr.cc:634
void discard_modifications()
Set the state to not-modified.
Definition: mtr0mtr.h:487
bool is_dirty() const
Definition: mtr0mtr.h:606
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:96
static bool is_block_dirtied(const buf_block_t *block)
Check if this mini-transaction is dirtying a clean page.
Definition: mtr0mtr.cc:501
void memo_modify_page(const byte *ptr)
Mark the given latched page as modified.
Definition: mtr0mtr.cc:1103
void release_block_at_savepoint(ulint savepoint, buf_block_t *block)
Release the block in an mtr memo after a savepoint.
Definition: mtr0mtr.ic:154
bool m_sync
true if it is synchronous mini-transaction
Definition: mtr0mtr.h:672
Impl m_impl
Definition: mtr0mtr.h:666
void x_lock_space(fil_space_t *space, ut::Location location)
Acquire a tablespace X-latch.
Definition: mtr0mtr.cc:723
Flush_observer * get_flush_observer() const
Get flush observer.
Definition: mtr0mtr.h:516
bool has_modifications() const
Definition: mtr0mtr.h:577
bool is_async() const
Definition: mtr0mtr.h:399
lsn_t m_commit_lsn
LSN at commit time.
Definition: mtr0mtr.h:669
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:613
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:215
mtr_buf_t * get_log()
Get the buffered redo log of this mini-transaction.
Definition: mtr0mtr.h:621
mtr_log_t set_log_mode(mtr_log_t mode)
Change the logging mode.
Definition: mtr0mtr.cc:470
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:125
void set_modified()
Note that the mini-transaction has modified data.
Definition: mtr0mtr.h:482
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:598
size_t m_restart_count
Count the number of times the same mtr object has been committed and restarted.
Definition: mtr0mtr.h:657
void commit()
Commit the mini-transaction.
Definition: mtr0mtr.cc:674
mtr_log_t get_log_mode() const
Get the logging mode.
Definition: mtr0mtr.ic:175
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:636
static bool memo_contains(const mtr_buf_t *memo, const void *object, ulint type)
Check if memo contains the given item.
Definition: mtr0mtr.cc:1045
void wait_for_flush()
Definition: mtr0mtr.cc:1253
void set_sync()
Request a future commit to be synchronous.
Definition: mtr0mtr.h:402
void start(bool sync=true)
Start a mini-transaction.
Definition: mtr0mtr.cc:576
mtr_t()
Definition: mtr0mtr.h:357
buf_block_t * memo_contains_page_flagged(const byte *ptr, ulint flags) const
Check if memo contains the given page.
Definition: mtr0mtr.cc:1092
void added_rec()
Note that a record has been added to the log.
Definition: mtr0mtr.h:609
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:1076
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:71
void set_flush_observer(Flush_observer *observer)
Set flush observer.
Definition: mtr0mtr.h:522
mtr_buf_t * get_memo()
Definition: mtr0mtr.h:592
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:677
void check_is_not_latching() const
Assure that there are no slots that are latching any resources.
Definition: mtr0mtr.cc:709
bool has_committed() const
Definition: mtr0mtr.h:567
ulint get_savepoint() const
Return current size of the buffer.
Definition: mtr0mtr.h:409
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:189
static Logging s_logging
Instance level logging information for all mtrs.
Definition: mtr0mtr.h:662
const mtr_buf_t * get_memo() const
Definition: mtr0mtr.h:589
void remove_from_debug_list() const
Removed the MTR from the s_my_thread_active_mtrs list.
Definition: mtr0mtr.cc:701
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:649
void memo_release(const void *object, ulint type)
Release an object in the memo stack.
Definition: mtr0mtr.cc:731
~mtr_t()
Definition: mtr0mtr.h:363
void s_lock(rw_lock_t *lock, ut::Location location)
Locks a rw-latch in S mode.
Definition: mtr0mtr.ic:186
void x_lock(rw_lock_t *lock, ut::Location location)
Locks a rw-latch in X mode.
Definition: mtr0mtr.ic:195
static bool s_mode_update_valid[MTR_LOG_MODE_MAX][MTR_LOG_MODE_MAX]
For checking invalid mode update requests.
Definition: mtr0mtr.h:653
void release_page(const void *ptr, mtr_memo_type_t type)
Release a page latch.
Definition: mtr0mtr.cc:750
void print() const
Print info of an mtr handle.
Definition: mtr0mtr.cc:1114
void sx_lock(rw_lock_t *lock, ut::Location location)
Locks a rw-latch in X mode.
Definition: mtr0mtr.ic:204
void check_nolog_and_mark()
Check if redo logging is disabled globally and mark the global counter till mtr ends.
Definition: mtr0mtr.cc:617
The structure used in the spin lock implementation of a read-write lock.
Definition: sync0rw.h:361
Definition: ut0core.h:32
Transaction system global type definitions.
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:407
#define ut_error
Abort execution.
Definition: ut0dbg.h:64
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:68
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:70