Merge branch '2.3' into develop
This commit is contained in:
@ -109,12 +109,14 @@ This feature is disabled by default.
|
|||||||
|
|
||||||
max_slave_replication_lag=<allowed lag in seconds>
|
max_slave_replication_lag=<allowed lag in seconds>
|
||||||
|
|
||||||
This applies to Master/Slave replication with MySQL monitor and
|
The Readwritesplit-router does not detect the replication lag itself. A monitor
|
||||||
`detect_replication_lag=1` options set. max_slave_replication_lag must be
|
such as the MariaDB-monitor for a Master/Slave-cluster is required. This option
|
||||||
greater than the monitor interval.
|
only affects Master-Slave clusters. Galera clusters do not have a concept of
|
||||||
|
slave lag even if the application of write sets might have lag. When a server is
|
||||||
This option only affects Master-Slave clusters. Galera clusters do not have a
|
disqualified from routing because of replication lag, a warning is logged. Similarly,
|
||||||
concept of slave lag even if the application of write sets might have lag.
|
when the server has caught up enough to be a valid routing target, another warning
|
||||||
|
is logged. These messages are only logged when a query is being routed and the
|
||||||
|
replication state changes.
|
||||||
|
|
||||||
### `use_sql_variables_in`
|
### `use_sql_variables_in`
|
||||||
|
|
||||||
|
@ -134,6 +134,15 @@ public:
|
|||||||
|
|
||||||
// Controlled by the session
|
// Controlled by the session
|
||||||
ResponseStat& response_stat();
|
ResponseStat& response_stat();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change server replication lag state and log warning when state changes.
|
||||||
|
*
|
||||||
|
* @param new_state New replication lag state
|
||||||
|
* @param max_rlag Maximum allowed lag. Used for the log message.
|
||||||
|
*/
|
||||||
|
void change_rlag_state(SERVER::RLagState new_state, int max_rlag);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
reply_state_t m_reply_state;
|
reply_state_t m_reply_state;
|
||||||
BackendHandleMap m_ps_handles; /**< Internal ID to backend PS handle mapping */
|
BackendHandleMap m_ps_handles; /**< Internal ID to backend PS handle mapping */
|
||||||
|
@ -142,6 +142,13 @@ public:
|
|||||||
CLUSTRIX
|
CLUSTRIX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class RLagState
|
||||||
|
{
|
||||||
|
NONE,
|
||||||
|
BELOW_LIMIT,
|
||||||
|
ABOVE_LIMIT
|
||||||
|
};
|
||||||
|
|
||||||
struct Version
|
struct Version
|
||||||
{
|
{
|
||||||
uint64_t total = 0; /**< The version number received from server */
|
uint64_t total = 0; /**< The version number received from server */
|
||||||
@ -196,6 +203,7 @@ public:
|
|||||||
bool master_err_is_logged = false; /**< If node failed, this indicates whether it is logged. Only
|
bool master_err_is_logged = false; /**< If node failed, this indicates whether it is logged. Only
|
||||||
* used by rwsplit. TODO: Move to rwsplit */
|
* used by rwsplit. TODO: Move to rwsplit */
|
||||||
bool warn_ssl_not_enabled = true; /**< SSL not used for an SSL enabled server */
|
bool warn_ssl_not_enabled = true; /**< SSL not used for an SSL enabled server */
|
||||||
|
RLagState rlag_state = RLagState::NONE; /**< Is replication lag above or under limit? Used by rwsplit. */
|
||||||
|
|
||||||
virtual ~SERVER() = default;
|
virtual ~SERVER() = default;
|
||||||
|
|
||||||
|
@ -256,6 +256,31 @@ ResponseStat& RWBackend::response_stat()
|
|||||||
return m_response_stat;
|
return m_response_stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RWBackend::change_rlag_state(SERVER::RLagState new_state, int max_rlag)
|
||||||
|
{
|
||||||
|
mxb_assert(new_state == SERVER::RLagState::BELOW_LIMIT || new_state == SERVER::RLagState::ABOVE_LIMIT);
|
||||||
|
namespace atom = maxbase::atomic;
|
||||||
|
auto srv = server();
|
||||||
|
auto old_state = atom::load(&srv->rlag_state, atom::RELAXED);
|
||||||
|
if (new_state != old_state)
|
||||||
|
{
|
||||||
|
atom::store(&srv->rlag_state, new_state, atom::RELAXED);
|
||||||
|
// State has just changed, log warning. Don't log catchup if old state was RLAG_NONE.
|
||||||
|
if (new_state == SERVER::RLagState::ABOVE_LIMIT)
|
||||||
|
{
|
||||||
|
MXS_WARNING("Replication lag of '%s' is %is, which is above the configured limit %is. "
|
||||||
|
"'%s' is excluded from query routing.",
|
||||||
|
srv->name(), srv->rlag, max_rlag, srv->name());
|
||||||
|
}
|
||||||
|
else if (old_state == SERVER::RLagState::ABOVE_LIMIT)
|
||||||
|
{
|
||||||
|
MXS_WARNING("Replication lag of '%s' is %is, which is below the configured limit %is. "
|
||||||
|
"'%s' is returned to query routing.",
|
||||||
|
srv->name(), srv->rlag, max_rlag, srv->name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mxs::SRWBackends RWBackend::from_servers(SERVER_REF* servers)
|
mxs::SRWBackends RWBackend::from_servers(SERVER_REF* servers)
|
||||||
{
|
{
|
||||||
SRWBackends backends;
|
SRWBackends backends;
|
||||||
|
@ -605,14 +605,25 @@ RWBackend* RWSplitSession::get_slave_backend(int max_rlag)
|
|||||||
&& counts.second < m_router->max_slave_count();
|
&& counts.second < m_router->max_slave_count();
|
||||||
|
|
||||||
bool master_or_slave = backend->is_master() || backend->is_slave();
|
bool master_or_slave = backend->is_master() || backend->is_slave();
|
||||||
bool is_useable = backend->in_use() || can_take_slave_into_use;
|
bool is_usable = backend->in_use() || can_take_slave_into_use;
|
||||||
bool not_a_slacker = rpl_lag_is_ok(backend, max_rlag);
|
bool rlag_ok = rpl_lag_is_ok(backend, max_rlag);
|
||||||
|
|
||||||
bool server_is_candidate = master_or_slave && is_useable && not_a_slacker;
|
if (master_or_slave && is_usable)
|
||||||
|
{
|
||||||
if (server_is_candidate)
|
if (rlag_ok)
|
||||||
{
|
{
|
||||||
candidates.push_back(backend);
|
candidates.push_back(backend);
|
||||||
|
if (max_rlag > 0)
|
||||||
|
{
|
||||||
|
// Replication lag discrimination is on and the server passed.
|
||||||
|
backend->change_rlag_state(SERVER::RLagState::BELOW_LIMIT, max_rlag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// The server is otherwise usable except it's lagging too much.
|
||||||
|
backend->change_rlag_state(SERVER::RLagState::ABOVE_LIMIT, max_rlag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user