MXS-1828: Simplify LOAD DATA LOCAL INFILE handling

By relying on the server to tell us that it is requesting the loading of a
local infile, we can remove one state from the state machine that governs
the loading of local files. It also removes the need to handle error and
success cases separately.

A side-effect of this change is that execution of multi-statement LOAD
DATA LOCAL INFILE no longer hangs. This is done by checking whether the
completion of one command initiates a new load.

The current code recursively checks the reply state and clones the
buffers. Neither of these are required nor should they be done but
refactoring the code is to be done in a separate commit.

Added two helper functions that are used to detect requests for local
infiles and to extract the total packet length from a non-contiguous
GWBUF.
This commit is contained in:
Markus Mäkelä
2018-05-16 17:41:55 +03:00
parent 35f2382263
commit 91cc5b1e89
8 changed files with 67 additions and 27 deletions

View File

@ -563,6 +563,15 @@ bool mxs_mysql_is_err_packet(GWBUF *buffer);
*/
bool mxs_mysql_is_result_set(GWBUF *buffer);
/**
* @brief Check if the buffer contains a LOCAL INFILE request
*
* @param buffer Buffer containing a complete MySQL packet
*
* @return True if the buffer contains a LOCAL INFILE request
*/
bool mxs_mysql_is_local_infile(GWBUF *buffer);
/**
* @brief Check if the buffer contains a prepared statement OK packet
*
@ -643,6 +652,23 @@ static inline uint8_t mxs_mysql_get_command(GWBUF* buffer)
}
}
/**
* @brief Get the total size of the first packet
*
* The size includes the payload and the header
*
* @param buffer Buffer to inspect
*
* @return The total packet size in bytes
*/
static inline uint32_t mxs_mysql_get_packet_len(GWBUF* buffer)
{
// The first three bytes of the packet header contain its length
uint8_t buf[3];
gwbuf_copy_data(buffer, 0, 3, buf);
return gw_mysql_get_byte3(buf) + MYSQL_HEADER_LEN;
}
/**
* @brief Extract PS response values
*