Store transaction type bit on transaction end
When the transaction ends, it's good to know what type of a transaction just ended. Currently, this will be used by readwritesplit to detect when a read-only transaction ends.
This commit is contained in:
@ -58,14 +58,17 @@ typedef enum
|
|||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
/*< There is no on-going transaction. */
|
/*< There is no on-going transaction. */
|
||||||
SESSION_TRX_INACTIVE = SESSION_TRX_INACTIVE_BIT,
|
SESSION_TRX_INACTIVE = SESSION_TRX_INACTIVE_BIT,
|
||||||
/*< A transaction is active. */
|
/*< A transaction is active. */
|
||||||
SESSION_TRX_ACTIVE = SESSION_TRX_ACTIVE_BIT,
|
SESSION_TRX_ACTIVE = SESSION_TRX_ACTIVE_BIT,
|
||||||
/*< An explicit READ ONLY transaction is active. */
|
/*< An explicit READ ONLY transaction is active. */
|
||||||
SESSION_TRX_READ_ONLY = (SESSION_TRX_ACTIVE_BIT | SESSION_TRX_READ_ONLY_BIT),
|
SESSION_TRX_READ_ONLY = (SESSION_TRX_ACTIVE_BIT | SESSION_TRX_READ_ONLY_BIT),
|
||||||
/*< An explicit READ WRITE transaction is active. */
|
/*< An explicit READ WRITE transaction is active. */
|
||||||
SESSION_TRX_READ_WRITE = (SESSION_TRX_ACTIVE_BIT | SESSION_TRX_READ_WRITE_BIT),
|
SESSION_TRX_READ_WRITE = (SESSION_TRX_ACTIVE_BIT | SESSION_TRX_READ_WRITE_BIT),
|
||||||
SESSION_TRX_ENDING = SESSION_TRX_ENDING_BIT,
|
/*< An explicit READ ONLY transaction is ending. */
|
||||||
|
SESSION_TRX_READ_ONLY_ENDING = (SESSION_TRX_ENDING_BIT | SESSION_TRX_READ_ONLY_BIT),
|
||||||
|
/*< An explicit READ WRITE transaction is ending. */
|
||||||
|
SESSION_TRX_READ_WRITE_ENDING = (SESSION_TRX_ENDING_BIT | SESSION_TRX_READ_WRITE_BIT),
|
||||||
} mxs_session_trx_state_t;
|
} mxs_session_trx_state_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -248,7 +251,7 @@ static inline bool session_trx_is_read_write(const MXS_SESSION* ses)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells whether a transaction is ending.
|
* Tells whether a transaction is ending.
|
||||||
*
|
*
|
||||||
* @see session_get_trx_state
|
* @see session_get_trx_state
|
||||||
*
|
*
|
||||||
@ -259,7 +262,39 @@ static inline bool session_trx_is_read_write(const MXS_SESSION* ses)
|
|||||||
*/
|
*/
|
||||||
static inline bool session_trx_is_ending(const MXS_SESSION* ses)
|
static inline bool session_trx_is_ending(const MXS_SESSION* ses)
|
||||||
{
|
{
|
||||||
return ses->trx_state == SESSION_TRX_ENDING;
|
return ses->trx_state & SESSION_TRX_ENDING_BIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether a read-only transaction is ending.
|
||||||
|
*
|
||||||
|
* @see session_get_trx_state
|
||||||
|
*
|
||||||
|
* @note The return value is valid only if either a router or a filter
|
||||||
|
* has declared that it needs RCAP_TYPE_TRANSACTION_TRACKING.
|
||||||
|
*
|
||||||
|
* @return True if a transaction that was active is ending either via COMMIT or
|
||||||
|
* ROLLBACK and it was a read-only transaction.
|
||||||
|
*/
|
||||||
|
static inline bool session_read_only_trx_is_ending(const MXS_SESSION* ses)
|
||||||
|
{
|
||||||
|
return ses->trx_state == SESSION_TRX_READ_ONLY_ENDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tells whether a read-write transaction is ending.
|
||||||
|
*
|
||||||
|
* @see session_get_trx_state
|
||||||
|
*
|
||||||
|
* @note The return value is valid only if either a router or a filter
|
||||||
|
* has declared that it needs RCAP_TYPE_TRANSACTION_TRACKING.
|
||||||
|
*
|
||||||
|
* @return True if a transaction that was active is ending either via COMMIT or
|
||||||
|
* ROLLBACK and it was a read-write transaction.
|
||||||
|
*/
|
||||||
|
static inline bool session_read_write_trx_is_ending(const MXS_SESSION* ses)
|
||||||
|
{
|
||||||
|
return ses->trx_state == SESSION_TRX_READ_WRITE_ENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -897,8 +897,10 @@ const char* session_trx_state_to_string(mxs_session_trx_state_t state)
|
|||||||
return "SESSION_TRX_READ_ONLY";
|
return "SESSION_TRX_READ_ONLY";
|
||||||
case SESSION_TRX_READ_WRITE:
|
case SESSION_TRX_READ_WRITE:
|
||||||
return "SESSION_TRX_READ_WRITE";
|
return "SESSION_TRX_READ_WRITE";
|
||||||
case SESSION_TRX_ENDING:
|
case SESSION_TRX_READ_ONLY_ENDING:
|
||||||
return "SESSION_TRX_ENDING";
|
return "SESSION_TRX_READ_ONLY_ENDING";
|
||||||
|
case SESSION_TRX_READ_WRITE_ENDING:
|
||||||
|
return "SESSION_TRX_READ_WRITE_ENDING";
|
||||||
}
|
}
|
||||||
|
|
||||||
MXS_ERROR("Unknown session_trx_state_t value: %d", (int)state);
|
MXS_ERROR("Unknown session_trx_state_t value: %d", (int)state);
|
||||||
|
@ -1520,7 +1520,14 @@ static int route_by_statement(MXS_SESSION* session, uint64_t capabilities, GWBUF
|
|||||||
}
|
}
|
||||||
else if ((type & QUERY_TYPE_COMMIT) || (type & QUERY_TYPE_ROLLBACK))
|
else if ((type & QUERY_TYPE_COMMIT) || (type & QUERY_TYPE_ROLLBACK))
|
||||||
{
|
{
|
||||||
session_set_trx_state(session, SESSION_TRX_ENDING);
|
mxs_session_trx_state_t trx_state = session_get_trx_state(session);
|
||||||
|
|
||||||
|
/** Remove the active transaction bit and set the end
|
||||||
|
* of transaction bit */
|
||||||
|
trx_state &= ~SESSION_TRX_ACTIVE_BIT;
|
||||||
|
trx_state |= SESSION_TRX_ENDING_BIT;
|
||||||
|
|
||||||
|
session_set_trx_state(session, trx_state);
|
||||||
|
|
||||||
if (type & QUERY_TYPE_ENABLE_AUTOCOMMIT)
|
if (type & QUERY_TYPE_ENABLE_AUTOCOMMIT)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user