Merge branch '2.3' into develop

This commit is contained in:
Esa Korhonen 2019-01-21 13:51:50 +02:00
commit 7fb80c530b
5 changed files with 70 additions and 15 deletions

View File

@ -109,12 +109,14 @@ This feature is disabled by default.
max_slave_replication_lag=<allowed lag in seconds>
This applies to Master/Slave replication with MySQL monitor and
`detect_replication_lag=1` options set. max_slave_replication_lag must be
greater than the monitor interval.
This option 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.
The Readwritesplit-router does not detect the replication lag itself. A monitor
such as the MariaDB-monitor for a Master/Slave-cluster is required. This option
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
disqualified from routing because of replication lag, a warning is logged. Similarly,
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`

View File

@ -134,6 +134,15 @@ public:
// Controlled by the session
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:
reply_state_t m_reply_state;
BackendHandleMap m_ps_handles; /**< Internal ID to backend PS handle mapping */

View File

@ -142,6 +142,13 @@ public:
CLUSTRIX
};
enum class RLagState
{
NONE,
BELOW_LIMIT,
ABOVE_LIMIT
};
struct Version
{
uint64_t total = 0; /**< The version number received from server */
@ -193,9 +200,10 @@ public:
unsigned long node_ts = 0; /**< Last timestamp set from M/S monitor module */
// Misc fields
bool master_err_is_logged = false; /**< If node failed, this indicates whether it is logged. Only
* used by rwsplit. TODO: Move to rwsplit */
bool warn_ssl_not_enabled = true; /**< SSL not used for an SSL enabled server */
bool master_err_is_logged = false; /**< If node failed, this indicates whether it is logged. Only
* used by rwsplit. TODO: Move to rwsplit */
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;

View File

@ -256,6 +256,31 @@ ResponseStat& RWBackend::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)
{
SRWBackends backends;

View File

@ -605,14 +605,25 @@ RWBackend* RWSplitSession::get_slave_backend(int max_rlag)
&& counts.second < m_router->max_slave_count();
bool master_or_slave = backend->is_master() || backend->is_slave();
bool is_useable = backend->in_use() || can_take_slave_into_use;
bool not_a_slacker = rpl_lag_is_ok(backend, max_rlag);
bool is_usable = backend->in_use() || can_take_slave_into_use;
bool rlag_ok = rpl_lag_is_ok(backend, max_rlag);
bool server_is_candidate = master_or_slave && is_useable && not_a_slacker;
if (server_is_candidate)
if (master_or_slave && is_usable)
{
candidates.push_back(backend);
if (rlag_ok)
{
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);
}
}
}