MXS-1549: Implement optimistic transaction execution
When the `optimistic_trx` mode is enabled, all transactions are started on a slave server. If the client executes a query inside the transaction that is not of a read-only nature, the transaction is rolled back and replayed on the master.
This commit is contained in:
@ -59,6 +59,14 @@ public:
|
||||
TARGET_RLAG_MAX = maxscale::QueryClassifier::TARGET_RLAG_MAX,
|
||||
};
|
||||
|
||||
enum otrx_state
|
||||
{
|
||||
OTRX_INACTIVE, // No open transactions
|
||||
OTRX_STARTING, // Transaction starting on slave
|
||||
OTRX_ACTIVE, // Transaction open on a slave server
|
||||
OTRX_ROLLBACK // Transaction being rolled back on the slave server
|
||||
};
|
||||
|
||||
enum wait_gtid_state
|
||||
{
|
||||
NONE,
|
||||
@ -149,6 +157,7 @@ public:
|
||||
bool m_can_replay_trx; /**< Whether the transaction can be replayed */
|
||||
Trx m_replayed_trx; /**< The transaction we are replaying */
|
||||
mxs::Buffer m_interrupted_query; /**< Query that was interrupted mid-transaction. */
|
||||
otrx_state m_otrx_state = OTRX_INACTIVE; /**< Optimistic trx state*/
|
||||
|
||||
private:
|
||||
RWSplitSession(RWSplit* instance, MXS_SESSION* session,
|
||||
@ -202,6 +211,27 @@ private:
|
||||
*/
|
||||
bool start_trx_replay();
|
||||
|
||||
/**
|
||||
* See if the transaction could be done on a slave
|
||||
*
|
||||
* @param route_target Target where the query is routed
|
||||
*
|
||||
* @return True if the query can be attempted on a slave
|
||||
*/
|
||||
bool should_try_trx_on_slave(route_target_t route_target) const;
|
||||
|
||||
/**
|
||||
* Track optimistic transaction status
|
||||
*
|
||||
* Tracks the progress of the optimistic transaction and starts the rollback
|
||||
* procedure if the transaction turns out to be one that modifies data.
|
||||
*
|
||||
* @param buffer Current query
|
||||
*
|
||||
* @return Whether the current statement should be stored for the duration of the query
|
||||
*/
|
||||
bool track_optimistic_trx(GWBUF** buffer);
|
||||
|
||||
private:
|
||||
// QueryClassifier::Handler
|
||||
bool lock_to_master();
|
||||
|
||||
Reference in New Issue
Block a user