Inline backend related functions
Inlined the getter/setter type functions that are often used. Profiling shows that inlining the RWBackend get/set functions for the reply state manipulation reduces the relative cost of the function to acceptable levels. Inlining the Backend state function did not have as large an effect but it appears contribute a slight performance boost.
This commit is contained in:
parent
9ece996466
commit
8bcd30ea7c
@ -112,21 +112,32 @@ public:
|
||||
*
|
||||
* @return Pointer to server reference
|
||||
*/
|
||||
SERVER_REF* backend() const;
|
||||
inline SERVER_REF* backend() const
|
||||
{
|
||||
ss_dassert(m_backend);
|
||||
return m_backend;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get pointer to server
|
||||
*
|
||||
* @return Pointer to server
|
||||
*/
|
||||
SERVER* server() const;
|
||||
inline SERVER* server() const
|
||||
{
|
||||
ss_dassert(m_backend);
|
||||
return m_backend->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if a connection to this backend can be made
|
||||
*
|
||||
* @return True if the backend has not failed and a connection can be attempted
|
||||
*/
|
||||
bool can_connect() const;
|
||||
inline bool can_connect() const
|
||||
{
|
||||
return !has_failed() && SERVER_IS_RUNNING(m_backend->server);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a new connection
|
||||
@ -149,7 +160,10 @@ public:
|
||||
*
|
||||
* @return Pointer to internal DCB
|
||||
*/
|
||||
DCB* dcb() const;
|
||||
inline DCB* dcb() const
|
||||
{
|
||||
return m_dcb;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write data to the backend server
|
||||
@ -197,49 +211,70 @@ public:
|
||||
*
|
||||
* @return True if backend is in use
|
||||
*/
|
||||
bool in_use() const;
|
||||
inline bool in_use() const
|
||||
{
|
||||
return m_state & IN_USE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the backend server reference is active
|
||||
*
|
||||
* @return True if the server reference is active
|
||||
*/
|
||||
bool is_active() const;
|
||||
inline bool is_active() const
|
||||
{
|
||||
return SERVER_REF_IS_ACTIVE(m_backend);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if backend is waiting for a result
|
||||
*
|
||||
* @return True if backend is waiting for a result
|
||||
*/
|
||||
bool is_waiting_result() const;
|
||||
inline bool is_waiting_result() const
|
||||
{
|
||||
return m_state & WAITING_RESULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the backend is closed
|
||||
*
|
||||
* @return True if the backend is closed
|
||||
*/
|
||||
bool is_closed() const;
|
||||
inline bool is_closed() const
|
||||
{
|
||||
return m_closed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the server is a master
|
||||
*
|
||||
* @return True if server is a master
|
||||
*/
|
||||
bool is_master() const;
|
||||
inline bool is_master() const
|
||||
{
|
||||
return SERVER_IS_MASTER(m_backend->server);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the server is a slave
|
||||
*
|
||||
* @return True if the server is a slave
|
||||
*/
|
||||
bool is_slave() const;
|
||||
inline bool is_slave() const
|
||||
{
|
||||
return SERVER_IS_SLAVE(m_backend->server);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the server is a relay server
|
||||
*
|
||||
* @return True if the server is a relay server
|
||||
*/
|
||||
bool is_relay() const;
|
||||
inline bool is_relay() const
|
||||
{
|
||||
return SERVER_IS_RELAY_SERVER(m_backend->server);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the backend has failed fatally
|
||||
@ -250,7 +285,10 @@ public:
|
||||
*
|
||||
* @return True if a fatal failure has occurred in the backend server
|
||||
*/
|
||||
bool has_failed() const;
|
||||
inline bool has_failed() const
|
||||
{
|
||||
return m_state & FATAL_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -258,14 +296,20 @@ public:
|
||||
*
|
||||
* @return The unique object name of this server
|
||||
*/
|
||||
const char* name() const;
|
||||
inline const char* name() const
|
||||
{
|
||||
return m_backend->server->unique_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the address and port as a string
|
||||
*
|
||||
* @return The address and port combined into one string
|
||||
*/
|
||||
const char* uri() const;
|
||||
inline const char* uri() const
|
||||
{
|
||||
return m_uri.c_str();
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
|
@ -173,23 +173,6 @@ void Backend::set_state(backend_state state)
|
||||
m_state |= state;
|
||||
}
|
||||
|
||||
SERVER_REF* Backend::backend() const
|
||||
{
|
||||
ss_dassert(m_backend);
|
||||
return m_backend;
|
||||
}
|
||||
|
||||
SERVER* Backend::server() const
|
||||
{
|
||||
ss_dassert(m_backend);
|
||||
return m_backend->server;
|
||||
}
|
||||
|
||||
bool Backend::can_connect() const
|
||||
{
|
||||
return !has_failed() && SERVER_IS_RUNNING(m_backend->server);
|
||||
}
|
||||
|
||||
bool Backend::connect(MXS_SESSION* session)
|
||||
{
|
||||
bool rval = false;
|
||||
@ -209,11 +192,6 @@ bool Backend::connect(MXS_SESSION* session)
|
||||
return rval;
|
||||
}
|
||||
|
||||
DCB* Backend::dcb() const
|
||||
{
|
||||
return m_dcb;
|
||||
}
|
||||
|
||||
bool Backend::write(GWBUF* buffer, response_type type)
|
||||
{
|
||||
bool rval = m_dcb->func.write(m_dcb, buffer) != 0;
|
||||
@ -266,53 +244,3 @@ bool Backend::write_stored_command()
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool Backend::in_use() const
|
||||
{
|
||||
return m_state & IN_USE;
|
||||
}
|
||||
|
||||
bool Backend::is_active() const
|
||||
{
|
||||
return SERVER_REF_IS_ACTIVE(m_backend);
|
||||
}
|
||||
|
||||
bool Backend::is_waiting_result() const
|
||||
{
|
||||
return m_state & WAITING_RESULT;
|
||||
}
|
||||
|
||||
bool Backend::is_closed() const
|
||||
{
|
||||
return m_closed;
|
||||
}
|
||||
|
||||
bool Backend::is_master() const
|
||||
{
|
||||
return SERVER_IS_MASTER(m_backend->server);
|
||||
}
|
||||
|
||||
bool Backend::is_slave() const
|
||||
{
|
||||
return SERVER_IS_SLAVE(m_backend->server);
|
||||
}
|
||||
|
||||
bool Backend::is_relay() const
|
||||
{
|
||||
return SERVER_IS_RELAY_SERVER(m_backend->server);
|
||||
}
|
||||
|
||||
bool Backend::has_failed() const
|
||||
{
|
||||
return m_state & FATAL_FAILURE;
|
||||
}
|
||||
|
||||
const char* Backend::name() const
|
||||
{
|
||||
return m_backend->server->unique_name;
|
||||
}
|
||||
|
||||
const char* Backend::uri() const
|
||||
{
|
||||
return m_uri.c_str();
|
||||
}
|
||||
|
@ -508,26 +508,26 @@ static bool route_stored_query(RWSplitSession *rses)
|
||||
return rval;
|
||||
}
|
||||
|
||||
static bool is_eof(GWBUF* buffer)
|
||||
static inline bool is_eof(GWBUF* buffer)
|
||||
{
|
||||
uint8_t* data = GWBUF_DATA(buffer);
|
||||
return data[MYSQL_HEADER_LEN] == MYSQL_REPLY_EOF &&
|
||||
gw_mysql_get_byte3(data) + MYSQL_HEADER_LEN == MYSQL_EOF_PACKET_LEN;
|
||||
}
|
||||
|
||||
static bool is_large(GWBUF* buffer)
|
||||
static inline bool is_large(GWBUF* buffer)
|
||||
{
|
||||
return gw_mysql_get_byte3(GWBUF_DATA(buffer)) == GW_MYSQL_MAX_PACKET_LEN;
|
||||
}
|
||||
|
||||
static bool more_results_exist(GWBUF* buffer)
|
||||
static inline bool more_results_exist(GWBUF* buffer)
|
||||
{
|
||||
ss_dassert(is_eof(buffer) || mxs_mysql_is_ok_packet(buffer));
|
||||
uint16_t status = gw_mysql_get_byte2(GWBUF_DATA(buffer) + MYSQL_HEADER_LEN + 1 + 2);
|
||||
return status & SERVER_MORE_RESULTS_EXIST;
|
||||
}
|
||||
|
||||
static bool is_result_set(GWBUF *buffer)
|
||||
static inline bool is_result_set(GWBUF *buffer)
|
||||
{
|
||||
bool rval = false;
|
||||
|
||||
@ -549,6 +549,11 @@ static bool is_result_set(GWBUF *buffer)
|
||||
return rval;
|
||||
}
|
||||
|
||||
static inline uint8_t get_cmd(SRWBackend& backend)
|
||||
{
|
||||
return mxs_mysql_current_command(backend->dcb()->session);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if we have received a complete reply from the backend
|
||||
*
|
||||
@ -559,11 +564,9 @@ static bool is_result_set(GWBUF *buffer)
|
||||
*/
|
||||
bool reply_is_complete(SRWBackend backend, GWBUF *buffer)
|
||||
{
|
||||
mxs_mysql_cmd_t cmd = mxs_mysql_current_command(backend->dcb()->session);
|
||||
|
||||
if (backend->get_reply_state() == REPLY_STATE_START && !is_result_set(buffer))
|
||||
{
|
||||
if (cmd == MXS_COM_STMT_PREPARE || !more_results_exist(buffer))
|
||||
if (!more_results_exist(buffer) || get_cmd(backend) == MXS_COM_STMT_PREPARE)
|
||||
{
|
||||
/** Not a result set, we have the complete response */
|
||||
LOG_RS(backend, REPLY_STATE_DONE);
|
||||
@ -596,7 +599,7 @@ bool reply_is_complete(SRWBackend backend, GWBUF *buffer)
|
||||
LOG_RS(backend, REPLY_STATE_RSET_COLDEF);
|
||||
backend->set_reply_state(REPLY_STATE_RSET_COLDEF);
|
||||
}
|
||||
else if (n_eof == 1 && cmd != MXS_COM_FIELD_LIST)
|
||||
else if (n_eof == 1 && get_cmd(backend) != MXS_COM_FIELD_LIST)
|
||||
{
|
||||
/** Waiting for the EOF packet after the rows */
|
||||
LOG_RS(backend, REPLY_STATE_RSET_ROWS);
|
||||
@ -606,7 +609,7 @@ bool reply_is_complete(SRWBackend backend, GWBUF *buffer)
|
||||
{
|
||||
/** We either have a complete result set or a response to
|
||||
* a COM_FIELD_LIST command */
|
||||
ss_dassert(n_eof == 2 || (n_eof == 1 && cmd == MXS_COM_FIELD_LIST));
|
||||
ss_dassert(n_eof == 2 || (n_eof == 1 && get_cmd(backend) == MXS_COM_FIELD_LIST));
|
||||
LOG_RS(backend, REPLY_STATE_DONE);
|
||||
backend->set_reply_state(REPLY_STATE_DONE);
|
||||
|
||||
|
@ -25,26 +25,6 @@ RWBackend::~RWBackend()
|
||||
{
|
||||
}
|
||||
|
||||
reply_state_t RWBackend::get_reply_state() const
|
||||
{
|
||||
return m_reply_state;
|
||||
}
|
||||
|
||||
void RWBackend::set_reply_state(reply_state_t state)
|
||||
{
|
||||
m_reply_state = state;
|
||||
}
|
||||
|
||||
void RWBackend::set_large_packet(bool value)
|
||||
{
|
||||
m_large_packet = value;
|
||||
}
|
||||
|
||||
bool RWBackend::is_large_packet() const
|
||||
{
|
||||
return m_large_packet;
|
||||
}
|
||||
|
||||
bool RWBackend::execute_session_command()
|
||||
{
|
||||
bool expect_response = mxs_mysql_command_will_respond(next_session_command()->get_command());
|
||||
|
@ -43,8 +43,15 @@ public:
|
||||
RWBackend(SERVER_REF* ref);
|
||||
~RWBackend();
|
||||
|
||||
reply_state_t get_reply_state() const;
|
||||
void set_reply_state(reply_state_t state);
|
||||
inline reply_state_t get_reply_state() const
|
||||
{
|
||||
return m_reply_state;
|
||||
}
|
||||
|
||||
inline void set_reply_state(reply_state_t state)
|
||||
{
|
||||
m_reply_state = state;
|
||||
}
|
||||
|
||||
void add_ps_handle(uint32_t id, uint32_t handle);
|
||||
uint32_t get_ps_handle(uint32_t id) const;
|
||||
@ -52,8 +59,15 @@ public:
|
||||
bool execute_session_command();
|
||||
bool write(GWBUF* buffer, response_type type = EXPECT_RESPONSE);
|
||||
|
||||
bool is_large_packet() const;
|
||||
void set_large_packet(bool value);
|
||||
inline void set_large_packet(bool value)
|
||||
{
|
||||
m_large_packet = value;
|
||||
}
|
||||
|
||||
inline bool is_large_packet() const
|
||||
{
|
||||
return m_large_packet;
|
||||
}
|
||||
|
||||
private:
|
||||
reply_state_t m_reply_state;
|
||||
|
Loading…
x
Reference in New Issue
Block a user