Readwritesplit: Graceful maintenance mode

By allowing transactions to the master to end even if the server is in
maintenance mode makes it possible to terminate connections at a known
point. This helps prevent interrupted transactions which can help reduce
errors that are visible to the clients.
This commit is contained in:
Markus Mäkelä
2019-04-02 10:18:33 +03:00
parent 319d9fa1c5
commit 5242cd5ebf
4 changed files with 33 additions and 5 deletions

View File

@ -386,6 +386,25 @@ static inline const char* failure_mode_to_str(enum failure_mode type)
void closed_session_reply(GWBUF* querybuf);
bool send_readonly_error(DCB* dcb);
/**
* See if the current master is still a valid TARGET_MASTER candidate
*
* The master is valid if it's in `Master, Running` state or if it is still in but in maintenance mode while a
* transaction is open. If a transaction is open to a master in maintenance mode, the connection is closed on
* the next COMMIT or ROLLBACK.
*
* @see RWSplitSession::close_stale_connections()
*/
inline bool can_continue_using_master(const mxs::RWBackend* current_master)
{
constexpr uint64_t bits = SERVER_MASTER | SERVER_RUNNING | SERVER_MAINT;
auto server = current_master->server();
return server->is_master() || (current_master->in_use()
&& (server->status & bits) == bits
&& session_trx_is_active(current_master->dcb()->session));
}
mxs::RWBackend* get_root_master(const mxs::PRWBackends& backends, mxs::RWBackend* current_master,
const BackendSelectFunction& func);