MXS-1549: Prevent optimistic transaction with no slaves
If the router session does not have an already open slave connection, optimistic transactions are not attempted.
This commit is contained in:
@ -151,13 +151,27 @@ void replace_binary_ps_id(GWBUF* buffer, uint32_t id)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RWSplitSession::have_connected_slaves() const
|
||||||
|
{
|
||||||
|
for (const auto& b: m_backends)
|
||||||
|
{
|
||||||
|
if (b->is_slave() && b->in_use())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool RWSplitSession::should_try_trx_on_slave(route_target_t route_target) const
|
bool RWSplitSession::should_try_trx_on_slave(route_target_t route_target) const
|
||||||
{
|
{
|
||||||
return m_config.optimistic_trx && // Optimistic transactions are enabled
|
return m_config.optimistic_trx && // Optimistic transactions are enabled
|
||||||
!is_locked_to_master() && // Not locked to master
|
!is_locked_to_master() && // Not locked to master
|
||||||
!m_is_replay_active && // Not replaying a transaction
|
!m_is_replay_active && // Not replaying a transaction
|
||||||
m_otrx_state == OTRX_INACTIVE && // Not yet in optimistic mode
|
m_otrx_state == OTRX_INACTIVE && // Not yet in optimistic mode
|
||||||
TARGET_IS_MASTER(route_target); // The target type is master
|
TARGET_IS_MASTER(route_target) && // The target type is master
|
||||||
|
have_connected_slaves(); // At least one connected slave
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RWSplitSession::track_optimistic_trx(GWBUF** buffer)
|
bool RWSplitSession::track_optimistic_trx(GWBUF** buffer)
|
||||||
|
|||||||
@ -204,6 +204,9 @@ private:
|
|||||||
|
|
||||||
void handle_trx_replay();
|
void handle_trx_replay();
|
||||||
|
|
||||||
|
// Do we have at least one open slave connection
|
||||||
|
bool have_connected_slaves() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the replaying of the latest transaction
|
* Start the replaying of the latest transaction
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user