| 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 it under |
| 6 |
the terms of the GNU General Public License, version 2.0, as published by the |
| 7 |
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, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/**************************************************/ /** |
| 29 |
@file include/log0consumer.h |
| 30 |
|
| 31 |
Redo log functions and types related to the log consumption. |
| 32 |
|
| 33 |
*******************************************************/ |
| 34 |
|
| 35 |
#ifndef log0consumer_h |
| 36 |
#define log0consumer_h |
| 37 |
|
| 38 |
#include "log0types.h" /* lsn_t, log_t& */ |
| 39 |
|
| 40 |
class Log_consumer { |
| 41 |
public: |
| 42 |
virtual ~Log_consumer() {} |
| 43 |
|
| 44 |
/** @return Name of this consumer. */ |
| 45 |
virtual const std::string &get_name() const = 0; |
| 46 |
|
| 47 |
/** @return Maximum LSN up to which this consumer has consumed redo. |
| 48 |
The caller should acquire log.files_mutex. */ |
| 49 |
virtual lsn_t get_consumed_lsn() const = 0; |
| 50 |
|
| 51 |
/** Request the log consumer to consume faster. |
| 52 |
@remarks This is called whenever the redo log consumer is the most lagging one |
| 53 |
and it is critical to consume up to the request_lsn. The caller has to hold |
| 54 |
log.files_mutex and log.limits_mutex. */ |
| 55 |
virtual void consumption_requested(lsn_t request_lsn) = 0; |
| 56 |
}; |
| 57 |
|
| 58 |
class Log_user_consumer : public Log_consumer { |
| 59 |
public: |
| 60 |
explicit Log_user_consumer(const std::string &name); |
| 61 |
|
| 62 |
const std::string &get_name() const override; |
| 63 |
|
| 64 |
/** Set the lsn reported by get_consumed_lsn() to the given value. |
| 65 |
It is required that the given value is greater or equal to the value |
| 66 |
currently reported by the get_consumed_lsn(). |
| 67 |
@param[in] consumed_lsn the given lsn to report */ |
| 68 |
void set_consumed_lsn(lsn_t consumed_lsn); |
| 69 |
|
| 70 |
lsn_t get_consumed_lsn() const override; |
| 71 |
|
| 72 |
void consumption_requested(lsn_t request_lsn) override; |
| 73 |
|
| 74 |
private: |
| 75 |
/** Name of this consumer (saved value from ctor). */ |
| 76 |
const std::string m_name; |
| 77 |
|
| 78 |
/** Value reported by get_consumed_lsn(). |
| 79 |
Set by set_consumed_lsn(lsn). */ |
| 80 |
lsn_t m_consumed_lsn{}; |
| 81 |
}; |
| 82 |
|
| 83 |
class Log_checkpoint_consumer : public Log_consumer { |
| 84 |
public: |
| 85 |
explicit Log_checkpoint_consumer(log_t &log); |
| 86 |
|
| 87 |
const std::string &get_name() const override; |
| 88 |
|
| 89 |
lsn_t get_consumed_lsn() const override; |
| 90 |
|
| 91 |
void consumption_requested(lsn_t request_lsn) override; |
| 92 |
|
| 93 |
private: |
| 94 |
log_t &m_log; |
| 95 |
}; |
| 96 |
|
| 97 |
/** Register the given redo log consumer. |
| 98 |
@param[in,out] log redo log |
| 99 |
@param[in] log_consumer redo log consumer to register */ |
| 100 |
void log_consumer_register(log_t &log, Log_consumer *log_consumer); |
| 101 |
|
| 102 |
/** Unregister the given redo log consumer. |
| 103 |
@param[in,out] log redo log |
| 104 |
@param[in] log_consumer redo log consumer to unregister */ |
| 105 |
void log_consumer_unregister(log_t &log, Log_consumer *log_consumer); |
| 106 |
|
| 107 |
/** Find the registered redo log consumer which has the smallest value |
| 108 |
reported by get_consumed_lsn() - ie. the most lagging consumer. When |
| 109 |
multiple consumers have the same value, any of them might be returned. |
| 110 |
@param[in] log the redo log |
| 111 |
@param[out] oldest_needed_lsn the oldest lsn needed by the most lagging consumer |
| 112 |
@return the most lagging consumer */ |
| 113 |
Log_consumer *log_consumer_get_oldest(const log_t &log, |
| 114 |
lsn_t &oldest_needed_lsn); |
| 115 |
|
| 116 |
#endif /* !log0consumer_h */ |