Use shared configurations in readwritesplit
By using a shared pointer instead of a plain object, we can replace the router configuration without it affecting existing sessions. This is a change that is required to enable runtime reconfiguration of readwritesplit.
This commit is contained in:
@ -38,17 +38,17 @@ RWSplitSession::RWSplitSession(RWSplit* instance, MXS_SESSION* session,
|
||||
m_gtid_pos(""),
|
||||
m_wait_gtid(NONE),
|
||||
m_next_seq(0),
|
||||
m_qc(this, session, instance->config().use_sql_variables_in),
|
||||
m_qc(this, session, m_config->use_sql_variables_in),
|
||||
m_retry_duration(0),
|
||||
m_is_replay_active(false),
|
||||
m_can_replay_trx(true)
|
||||
{
|
||||
if (m_config.rw_max_slave_conn_percent)
|
||||
if (m_config->rw_max_slave_conn_percent)
|
||||
{
|
||||
int n_conn = 0;
|
||||
double pct = (double)m_config.rw_max_slave_conn_percent / 100.0;
|
||||
double pct = (double)m_config->rw_max_slave_conn_percent / 100.0;
|
||||
n_conn = MXS_MAX(floor((double)m_nbackends * pct), 1);
|
||||
m_config.max_slave_connections = n_conn;
|
||||
m_config->max_slave_connections = n_conn;
|
||||
}
|
||||
}
|
||||
|
||||
@ -350,7 +350,7 @@ static void log_unexpected_response(SRWBackend& backend, GWBUF* buffer, GWBUF* c
|
||||
|
||||
GWBUF* RWSplitSession::handle_causal_read_reply(GWBUF *writebuf, SRWBackend& backend)
|
||||
{
|
||||
if (m_config.causal_reads)
|
||||
if (m_config->causal_reads)
|
||||
{
|
||||
if (GWBUF_IS_REPLY_OK(writebuf) && backend == m_current_master)
|
||||
{
|
||||
@ -473,7 +473,7 @@ void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb)
|
||||
poll_fake_hangup_event(backend_dcb);
|
||||
}
|
||||
}
|
||||
else if (m_config.transaction_replay && m_can_replay_trx &&
|
||||
else if (m_config->transaction_replay && m_can_replay_trx &&
|
||||
session_trx_is_active(m_client->session))
|
||||
{
|
||||
if (!backend->has_session_commands())
|
||||
@ -491,7 +491,7 @@ void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb)
|
||||
|
||||
size_t size{m_trx.size() + m_current_query.length()};
|
||||
// A transaction is open and it is eligible for replaying
|
||||
if (size < m_config.trx_max_size)
|
||||
if (size < m_config->trx_max_size)
|
||||
{
|
||||
/** Transaction size is OK, store the statement for replaying and
|
||||
* update the checksum of the result */
|
||||
@ -524,7 +524,7 @@ void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb)
|
||||
ss_dassert(backend->get_reply_state() == REPLY_STATE_DONE);
|
||||
MXS_INFO("Reply complete, last reply from %s", backend->name());
|
||||
|
||||
if (m_config.causal_reads)
|
||||
if (m_config->causal_reads)
|
||||
{
|
||||
// The reply should never be complete while we are still waiting for the header.
|
||||
ss_dassert(m_wait_gtid != WAITING_FOR_HEADER);
|
||||
@ -560,7 +560,7 @@ void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb)
|
||||
}
|
||||
else if (m_is_replay_active)
|
||||
{
|
||||
ss_dassert(m_config.transaction_replay);
|
||||
ss_dassert(m_config->transaction_replay);
|
||||
handle_trx_replay();
|
||||
|
||||
/**
|
||||
@ -582,7 +582,7 @@ void RWSplitSession::clientReply(GWBUF *writebuf, DCB *backend_dcb)
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (m_config.transaction_replay && session_trx_is_ending(m_client->session))
|
||||
else if (m_config->transaction_replay && session_trx_is_ending(m_client->session))
|
||||
{
|
||||
m_trx.close();
|
||||
m_can_replay_trx = true;
|
||||
@ -638,7 +638,7 @@ bool RWSplitSession::start_trx_replay()
|
||||
{
|
||||
bool rval = false;
|
||||
|
||||
if (!m_is_replay_active && m_config.transaction_replay && m_can_replay_trx)
|
||||
if (!m_is_replay_active && m_config->transaction_replay && m_can_replay_trx)
|
||||
{
|
||||
if (m_trx.have_stmts() || m_current_query.get())
|
||||
{
|
||||
@ -736,7 +736,7 @@ void RWSplitSession::handleError(GWBUF *errmsgbuf, DCB *problem_dcb,
|
||||
* can't be sure whether it was executed or not. In this
|
||||
* case the safest thing to do is to close the client
|
||||
* connection. */
|
||||
if (m_config.master_failure_mode != RW_FAIL_INSTANTLY)
|
||||
if (m_config->master_failure_mode != RW_FAIL_INSTANTLY)
|
||||
{
|
||||
can_continue = true;
|
||||
}
|
||||
@ -752,7 +752,7 @@ void RWSplitSession::handleError(GWBUF *errmsgbuf, DCB *problem_dcb,
|
||||
can_continue = true;
|
||||
retry_query(m_current_query.release());
|
||||
}
|
||||
else if (m_config.master_failure_mode == RW_ERROR_ON_WRITE)
|
||||
else if (m_config->master_failure_mode == RW_ERROR_ON_WRITE)
|
||||
{
|
||||
/** In error_on_write mode, the session can continue even
|
||||
* if the master is lost. Send a read-only error to
|
||||
@ -865,7 +865,7 @@ bool RWSplitSession::handle_error_new_connection(DCB *backend_dcb, GWBUF *errmsg
|
||||
*/
|
||||
GWBUF *stored = m_current_query.release();
|
||||
|
||||
if (stored && m_config.retry_failed_reads)
|
||||
if (stored && m_config->retry_failed_reads)
|
||||
{
|
||||
MXS_INFO("Re-routing failed read after server '%s' failed", backend->name());
|
||||
retry_query(stored, 0);
|
||||
@ -905,7 +905,7 @@ bool RWSplitSession::handle_error_new_connection(DCB *backend_dcb, GWBUF *errmsg
|
||||
* Try to get replacement slave or at least the minimum
|
||||
* number of slave connections for router session.
|
||||
*/
|
||||
if (m_recv_sescmd > 0 && m_config.disable_sescmd_history)
|
||||
if (m_recv_sescmd > 0 && m_config->disable_sescmd_history)
|
||||
{
|
||||
succp = m_router->have_enough_servers();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user