Debian Codegraph @

storage/innobase/log/log0consumer.cc

raw
1 /*****************************************************************************
2
3 Copyright (c) 2021, 2026, Oracle and/or its affiliates.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8
9 This program is designed to work with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation. The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have either included with
15 the program or referenced in the documentation.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License, version 2.0, for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26 *****************************************************************************/
27
28 /**************************************************/ /**
29 @file log/log0consumer.cc
30
31 *******************************************************/
32
33 #include "log0consumer.h" /* Log_consumer */
34 #include "arch0arch.h"
35 #include "arch0log.h"
36 #include "log0chkp.h"
37 #include "log0files_governor.h" /* log_files_mutex_own() */
38 #include "log0log.h" /* log_get_lsn */
39 #include "srv0shutdown.h" /* srv_shutdown_state, ... */
40 #include "srv0start.h" /* srv_is_being_started */
41
42 Log_user_consumer::Log_user_consumer(const std::string &name) : m_name{name} {}
43
44 const std::string &Log_user_consumer::get_name() const { return m_name; }
45
46 void Log_user_consumer::set_consumed_lsn(lsn_t consumed_lsn) {
47 if (consumed_lsn % OS_FILE_LOG_BLOCK_SIZE == 0) {
48 consumed_lsn += LOG_BLOCK_HDR_SIZE;
49 }
50 ut_a(m_consumed_lsn <= consumed_lsn);
51 m_consumed_lsn = consumed_lsn;
52 }
53
54 lsn_t Log_user_consumer::get_consumed_lsn() const { return m_consumed_lsn; }
55
56 void Log_user_consumer::consumption_requested(lsn_t /*request_lsn*/) {}
57
58 Log_checkpoint_consumer::Log_checkpoint_consumer(log_t &log) : m_log{log} {}
59
60 const std::string &Log_checkpoint_consumer::get_name() const {
61 static std::string name{"log_checkpointer"};
62 return name;
63 }
64
65 lsn_t Log_checkpoint_consumer::get_consumed_lsn() const {
66 return log_get_checkpoint_lsn(m_log);
67 }
68
69 void Log_checkpoint_consumer::consumption_requested(lsn_t request_lsn) {
70 log_t &log = *log_sys;
71 ut_a(log_is_data_lsn(request_lsn));
72 const lsn_t current_lsn = log_get_lsn(log);
73 ut_a(request_lsn <= current_lsn);
74 log_request_checkpoint_low(log, request_lsn);
75 }
76
77 void log_consumer_register(log_t &log, Log_consumer *log_consumer) {
78 ut_ad(log_files_mutex_own(log) || srv_is_being_started);
79
80 log.m_consumers.insert(log_consumer);
81 }
82
83 void log_consumer_unregister(log_t &log, Log_consumer *log_consumer) {
84 ut_ad(log_files_mutex_own(log) || srv_is_being_started ||
85 srv_shutdown_state.load() != SRV_SHUTDOWN_NONE);
86
87 log.m_consumers.erase(log_consumer);
88 }
89
90 Log_consumer *log_consumer_get_oldest(const log_t &log,
91 lsn_t &oldest_needed_lsn) {
92 ut_ad(log_files_mutex_own(log) || srv_is_being_started ||
93 srv_shutdown_state.load() != SRV_SHUTDOWN_NONE);
94
95 Log_consumer *oldest_consumer{nullptr};
96 oldest_needed_lsn = LSN_MAX;
97
98 for (auto consumer : log.m_consumers) {
99 const lsn_t oldest_lsn = consumer->get_consumed_lsn();
100
101 if (oldest_lsn < oldest_needed_lsn) {
102 oldest_consumer = consumer;
103 oldest_needed_lsn = oldest_lsn;
104 }
105 }
106
107 const lsn_t current_lsn = log_get_lsn(log);
108 ut_a(oldest_needed_lsn <= current_lsn);
109
110 return oldest_consumer;
111 }