Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
MXS-3613: Add support for metadata skip
The MARIADB_CLIENT_CACHE_METADATA flag is now advertised by MaxScale and
understood by the result parsing code. Added the
RCAP_TYPE_NO_METADATA_CACHE routing flag to allow the feature to be
disabled for modules that don't support the caching of metadata. Currently
cache, masking and smartrouter modules do not support it as they use
different code for processing the result metadata.
  • Loading branch information
markus456 committed Jun 16, 2021
1 parent 08b46a8 commit 305b17d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
15 changes: 10 additions & 5 deletions include/maxscale/protocol/mariadb/mysql.hh
Expand Up @@ -298,14 +298,19 @@ enum gw_mysql_capabilities_t
* Since we only use these in the non-shifted form, the definitions declared here
* are right shifted by 32 bytes and can be directly copied into the extra capabilities.
*/
#define MXS_MARIA_CAP_PROGRESS (1 << 0)
#define MXS_MARIA_CAP_COM_MULTI (1 << 1)
#define MXS_MARIA_CAP_STMT_BULK_OPERATIONS (1 << 2)
#define MXS_MARIA_CAP_PROGRESS (1UL << 0)
#define MXS_MARIA_CAP_COM_MULTI (1UL << 1)
#define MXS_MARIA_CAP_STMT_BULK_OPERATIONS (1UL << 2)
#define MXS_MARIA_CAP_EXTENDED_TYPES (1UL << 3) // Added in 10.5
#define MXS_MARIA_CAP_CACHE_METADATA (1UL << 4) // Added in 10.6

// Default extended flags that MaxScale supports
constexpr const uint32_t MXS_EXTRA_CAPABILITIES_SERVER = MXS_MARIA_CAP_STMT_BULK_OPERATIONS;
constexpr const uint32_t MXS_EXTRA_CAPABILITIES_SERVER =
MXS_MARIA_CAP_STMT_BULK_OPERATIONS
| MXS_MARIA_CAP_CACHE_METADATA;

// Same as above, for uint64.
constexpr const uint64_t MXS_EXTRA_CAPS_SERVER64 = (1ul << 34u);
constexpr const uint64_t MXS_EXTRA_CAPS_SERVER64 = ((uint64_t)MXS_EXTRA_CAPABILITIES_SERVER << 32);

enum mxs_mysql_cmd_t
{
Expand Down
7 changes: 7 additions & 0 deletions include/maxscale/routing.hh
Expand Up @@ -137,6 +137,13 @@ enum mxs_routing_capability_t
* Binary: 0b0000000100000000
*/
RCAP_TYPE_SESCMD_HISTORY = (1 << 8),

/**
* Disables the metadata caching extension that was added to MariaDB in 10.6.
*
* Binary: 0b0000001000000000
*/
RCAP_TYPE_NO_METADATA_CACHE = (1 << 9),
};

#define RCAP_TYPE_NONE 0
Expand Down
3 changes: 2 additions & 1 deletion server/modules/filter/cache/cachefilter.cc
Expand Up @@ -31,7 +31,8 @@ namespace
{

static char VERSION_STRING[] = "V1.0.0";
constexpr uint64_t CAPABILITIES = RCAP_TYPE_TRANSACTION_TRACKING | RCAP_TYPE_REQUEST_TRACKING;
constexpr uint64_t CAPABILITIES = RCAP_TYPE_TRANSACTION_TRACKING | RCAP_TYPE_REQUEST_TRACKING
| RCAP_TYPE_NO_METADATA_CACHE;

/**
* Implement "call command cache show ..."
Expand Down
4 changes: 2 additions & 2 deletions server/modules/filter/masking/maskingfilter.cc
Expand Up @@ -86,7 +86,7 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
MXS_FILTER_VERSION,
"A masking filter that is capable of masking/obfuscating returned column values.",
"V1.0.0",
RCAP_TYPE_STMT_INPUT | RCAP_TYPE_STMT_OUTPUT,
RCAP_TYPE_STMT_INPUT | RCAP_TYPE_STMT_OUTPUT | RCAP_TYPE_NO_METADATA_CACHE,
&mxs::FilterApi<MaskingFilter>::s_api,
NULL, /* Process init. */
NULL, /* Process finish. */
Expand Down Expand Up @@ -169,7 +169,7 @@ json_t* MaskingFilter::diagnostics() const
// static
uint64_t MaskingFilter::getCapabilities() const
{
return RCAP_TYPE_STMT_INPUT | RCAP_TYPE_STMT_OUTPUT;
return RCAP_TYPE_STMT_INPUT | RCAP_TYPE_STMT_OUTPUT | RCAP_TYPE_NO_METADATA_CACHE;
}

std::shared_ptr<MaskingRules> MaskingFilter::rules() const
Expand Down
11 changes: 10 additions & 1 deletion server/modules/protocol/MariaDB/mariadb_backend.cc
Expand Up @@ -2231,6 +2231,7 @@ void MariaDBBackendConnection::process_reply_start(Iter it, Iter end)
void MariaDBBackendConnection::process_result_start(Iter it, Iter end)
{
uint8_t cmd = *it;
MYSQL_session* data = static_cast<MYSQL_session*>(m_session->protocol_data());

switch (cmd)
{
Expand Down Expand Up @@ -2279,7 +2280,15 @@ void MariaDBBackendConnection::process_result_start(Iter it, Iter end)
// Start of a result set
m_num_coldefs = get_encoded_int(it);
m_reply.add_field_count(m_num_coldefs);
set_reply_state(ReplyState::RSET_COLDEF);

if ((data->extra_capabilitites() & MXS_MARIA_CAP_CACHE_METADATA) && *it == 0)
{
set_reply_state(ReplyState::RSET_COLDEF_EOF);
}
else
{
set_reply_state(ReplyState::RSET_COLDEF);
}
break;
}
}
Expand Down
6 changes: 6 additions & 0 deletions server/modules/protocol/MariaDB/mariadb_client.cc
Expand Up @@ -388,6 +388,12 @@ bool MariaDBClientConnection::send_server_handshake()
// extended capabilities.
caps &= ~GW_MYSQL_CAPABILITIES_CLIENT_MYSQL;
caps |= MXS_EXTRA_CAPS_SERVER64;

if (service->capabilities() & RCAP_TYPE_NO_METADATA_CACHE)
{
caps &= ~(MXS_MARIA_CAP_CACHE_METADATA << 32);
mxb_assert((caps & MXS_EXTRA_CAPS_SERVER64) == (MXS_MARIA_CAP_STMT_BULK_OPERATIONS << 32));
}
}

if (require_ssl())
Expand Down
2 changes: 1 addition & 1 deletion server/modules/routing/smartrouter/smartrouter.cc
Expand Up @@ -56,7 +56,7 @@ extern "C" MXS_MODULE* MXS_CREATE_MODULE()
MXS_ROUTER_VERSION,
"Provides routing for the Smart Query feature",
"V1.0.0",
RCAP_TYPE_TRANSACTION_TRACKING | RCAP_TYPE_STMT_INPUT | RCAP_TYPE_STMT_OUTPUT,
RCAP_TYPE_TRANSACTION_TRACKING | RCAP_TYPE_STMT_INPUT | RCAP_TYPE_STMT_OUTPUT | RCAP_TYPE_NO_METADATA_CACHE,
&mxs::RouterApi<SmartRouter>::s_api,
nullptr, /* Process init. */
nullptr, /* Process finish. */
Expand Down

0 comments on commit 305b17d

Please sign in to comment.