MDEV-9117: Client Server capability negotiation for MariaDB specific functionality

New capability flags space.
Removed old progress flag, added new one.
This commit is contained in:
Oleksandr Byelkin 2016-01-17 21:21:39 +01:00
parent 36eccebd6f
commit d4b3a199ac
10 changed files with 49 additions and 26 deletions

View File

@ -1921,7 +1921,7 @@ static int get_options(int argc, char **argv)
connect_flag|= CLIENT_IGNORE_SPACE; connect_flag|= CLIENT_IGNORE_SPACE;
if (opt_progress_reports) if (opt_progress_reports)
connect_flag|= CLIENT_PROGRESS; connect_flag|= CLIENT_PROGRESS_OBSOLETE;
return(0); return(0);
} }
@ -4638,10 +4638,10 @@ sql_real_connect(char *host,char *database,char *user,char *password,
mysql.reconnect= debug_info_flag; // We want to know if this happens mysql.reconnect= debug_info_flag; // We want to know if this happens
/* /*
CLIENT_PROGRESS is set only if we requsted it in mysql_real_connect() CLIENT_PROGRESS_OBSOLETE is set only if we requested it in
and the server also supports it mysql_real_connect() and the server also supports it
*/ */
if (mysql.client_flag & CLIENT_PROGRESS) if (mysql.client_flag & CLIENT_PROGRESS_OBSOLETE)
mysql_options(&mysql, MYSQL_PROGRESS_CALLBACK, (void*) report_progress); mysql_options(&mysql, MYSQL_PROGRESS_CALLBACK, (void*) report_progress);
#else #else
mysql.reconnect= 1; mysql.reconnect= 1;

View File

@ -188,7 +188,8 @@ enum enum_server_command
#define REFRESH_GENERIC (1ULL << 30) #define REFRESH_GENERIC (1ULL << 30)
#define REFRESH_FAST (1ULL << 31) /* Intern flag */ #define REFRESH_FAST (1ULL << 31) /* Intern flag */
#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */ #define CLIENT_LONG_PASSWORD 0 /* obsolete flag */
#define CLIENT_MYSQL 1 /* mysql/old mariadb server/client */
#define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ #define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */
#define CLIENT_LONG_FLAG 4 /* Get all column flags */ #define CLIENT_LONG_FLAG 4 /* Get all column flags */
#define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */ #define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */
@ -215,7 +216,7 @@ enum enum_server_command
/* Don't close the connection for a connection with expired password. */ /* Don't close the connection for a connection with expired password. */
#define CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS (1UL << 22) #define CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS (1UL << 22)
#define CLIENT_PROGRESS (1UL << 29) /* Client support progress indicator */ #define CLIENT_PROGRESS_OBSOLETE (1UL << 29)
#define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30) #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30)
/* /*
It used to be that if mysql_real_connect() failed, it would delete any It used to be that if mysql_real_connect() failed, it would delete any
@ -228,14 +229,23 @@ enum enum_server_command
*/ */
#define CLIENT_REMEMBER_OPTIONS (1UL << 31) #define CLIENT_REMEMBER_OPTIONS (1UL << 31)
/* MariaDB extended capability flags */
#define MARIADB_CLIENT_FLAGS_MASK 0xffffffff00000000ULL
/* Client support progress indicator */
#define MARIADB_CLIENT_PROGRESS (1ULL << 32)
#ifdef HAVE_COMPRESS #ifdef HAVE_COMPRESS
#define CAN_CLIENT_COMPRESS CLIENT_COMPRESS #define CAN_CLIENT_COMPRESS CLIENT_COMPRESS
#else #else
#define CAN_CLIENT_COMPRESS 0 #define CAN_CLIENT_COMPRESS 0
#endif #endif
/* Gather all possible capabilites (flags) supported by the server */ /*
#define CLIENT_ALL_FLAGS (CLIENT_LONG_PASSWORD | \ Gather all possible capabilites (flags) supported by the server
MARIADB_* flags supported only by MariaDB connector(s).
*/
#define CLIENT_ALL_FLAGS (\
CLIENT_FOUND_ROWS | \ CLIENT_FOUND_ROWS | \
CLIENT_LONG_FLAG | \ CLIENT_LONG_FLAG | \
CLIENT_CONNECT_WITH_DB | \ CLIENT_CONNECT_WITH_DB | \
@ -256,7 +266,7 @@ enum enum_server_command
CLIENT_PS_MULTI_RESULTS | \ CLIENT_PS_MULTI_RESULTS | \
CLIENT_SSL_VERIFY_SERVER_CERT | \ CLIENT_SSL_VERIFY_SERVER_CERT | \
CLIENT_REMEMBER_OPTIONS | \ CLIENT_REMEMBER_OPTIONS | \
CLIENT_PROGRESS | \ MARIADB_CLIENT_PROGRESS | \
CLIENT_PLUGIN_AUTH | \ CLIENT_PLUGIN_AUTH | \
CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA | \ CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA | \
CLIENT_CONNECT_ATTRS) CLIENT_CONNECT_ATTRS)

View File

@ -27,7 +27,7 @@ extern char * mysql_unix_port;
When adding capabilities here, consider if they should be also added to When adding capabilities here, consider if they should be also added to
the server's version. the server's version.
*/ */
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | \ #define CLIENT_CAPABILITIES (CLIENT_MYSQL | \
CLIENT_LONG_FLAG | \ CLIENT_LONG_FLAG | \
CLIENT_TRANSACTIONS | \ CLIENT_TRANSACTIONS | \
CLIENT_PROTOCOL_41 | \ CLIENT_PROTOCOL_41 | \

View File

@ -601,7 +601,7 @@ restart:
uint last_errno=uint2korr(pos); uint last_errno=uint2korr(pos);
if (last_errno == 65535 && if (last_errno == 65535 &&
(mysql->server_capabilities & CLIENT_PROGRESS)) (mysql->server_capabilities & CLIENT_PROGRESS_OBSOLETE))
{ {
if (cli_report_progress(mysql, pos+2, (uint) (len-3))) if (cli_report_progress(mysql, pos+2, (uint) (len-3)))
{ {

View File

@ -28,7 +28,7 @@
When adding capabilities here, consider if they should be also added to When adding capabilities here, consider if they should be also added to
the libmysql version. the libmysql version.
*/ */
#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | \ #define CLIENT_CAPABILITIES (CLIENT_MYSQL | \
CLIENT_LONG_FLAG | \ CLIENT_LONG_FLAG | \
CLIENT_TRANSACTIONS | \ CLIENT_TRANSACTIONS | \
CLIENT_PROTOCOL_41 | \ CLIENT_PROTOCOL_41 | \

View File

@ -11314,7 +11314,8 @@ static bool send_server_handshake_packet(MPVIO_EXT *mpvio,
int2store(end+5, thd->client_capabilities >> 16); int2store(end+5, thd->client_capabilities >> 16);
end[7]= data_len; end[7]= data_len;
DBUG_EXECUTE_IF("poison_srv_handshake_scramble_len", end[7]= -100;); DBUG_EXECUTE_IF("poison_srv_handshake_scramble_len", end[7]= -100;);
bzero(end + 8, 10); bzero(end + 8, 6);
int4store(end + 14, thd->client_capabilities >> 32);
end+= 18; end+= 18;
/* write scramble tail */ /* write scramble tail */
end= (char*) memcpy(end, data + SCRAMBLE_LENGTH_323, end= (char*) memcpy(end, data + SCRAMBLE_LENGTH_323,
@ -11730,18 +11731,29 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio,
*/ */
DBUG_ASSERT(net->read_pos[pkt_len] == 0); DBUG_ASSERT(net->read_pos[pkt_len] == 0);
ulong client_capabilities= uint2korr(net->read_pos); ulonglong client_capabilities= uint2korr(net->read_pos);
compile_time_assert(sizeof(client_capabilities) >= 8);
if (client_capabilities & CLIENT_PROTOCOL_41) if (client_capabilities & CLIENT_PROTOCOL_41)
{ {
if (pkt_len < 4) if (pkt_len < 32)
return packet_error; return packet_error;
client_capabilities|= ((ulong) uint2korr(net->read_pos+2)) << 16; client_capabilities|= ((ulong) uint2korr(net->read_pos+2)) << 16;
if (!(client_capabilities & CLIENT_MYSQL))
{
// it is client with mariadb extensions
ulonglong ext_client_capabilities=
(((ulonglong)uint4korr(net->read_pos + 28)) << 32);
client_capabilities|= ext_client_capabilities;
}
else if (client_capabilities & CLIENT_PROGRESS_OBSOLETE)
client_capabilities|= MARIADB_CLIENT_PROGRESS;
} }
/* Disable those bits which are not supported by the client. */ /* Disable those bits which are not supported by the client. */
compile_time_assert(sizeof(thd->client_capabilities) >= 8);
thd->client_capabilities&= client_capabilities; thd->client_capabilities&= client_capabilities;
DBUG_PRINT("info", ("client capabilities: %lu", thd->client_capabilities)); DBUG_PRINT("info", ("client capabilities: %llu", thd->client_capabilities));
if (thd->client_capabilities & CLIENT_SSL) if (thd->client_capabilities & CLIENT_SSL)
{ {
unsigned long errptr __attribute__((unused)); unsigned long errptr __attribute__((unused));
@ -11769,8 +11781,6 @@ static ulong parse_client_handshake_packet(MPVIO_EXT *mpvio,
if (client_capabilities & CLIENT_PROTOCOL_41) if (client_capabilities & CLIENT_PROTOCOL_41)
{ {
if (pkt_len < 32)
return packet_error;
thd->max_client_packet_length= uint4korr(net->read_pos+4); thd->max_client_packet_length= uint4korr(net->read_pos+4);
DBUG_PRINT("info", ("client_character_set: %d", (uint) net->read_pos[8])); DBUG_PRINT("info", ("client_character_set: %d", (uint) net->read_pos[8]));
if (thd_init_client_charset(thd, (uint) net->read_pos[8])) if (thd_init_client_charset(thd, (uint) net->read_pos[8]))
@ -12547,7 +12557,7 @@ bool acl_authenticate(THD *thd, uint com_change_user_pkt_len)
} }
DBUG_PRINT("info", DBUG_PRINT("info",
("Capabilities: %lu packet_length: %ld Host: '%s' " ("Capabilities: %llu packet_length: %ld Host: '%s' "
"Login user: '%s' Priv_user: '%s' Using password: %s " "Login user: '%s' Priv_user: '%s' Using password: %s "
"Access: %lu db: '%s'", "Access: %lu db: '%s'",
thd->client_capabilities, thd->max_client_packet_length, thd->client_capabilities, thd->max_client_packet_length,

View File

@ -4329,7 +4329,7 @@ extern "C" void thd_progress_init(MYSQL_THD thd, uint max_stage)
is a high level command (like ALTER TABLE) and we are not in a is a high level command (like ALTER TABLE) and we are not in a
stored procedure stored procedure
*/ */
thd->progress.report= ((thd->client_capabilities & CLIENT_PROGRESS) && thd->progress.report= ((thd->client_capabilities & MARIADB_CLIENT_PROGRESS) &&
thd->progress.report_to_client && thd->progress.report_to_client &&
!thd->in_sub_stmt); !thd->in_sub_stmt);
thd->progress.next_report_time= 0; thd->progress.next_report_time= 0;

View File

@ -1411,7 +1411,7 @@ public:
Discrete_intervals_list auto_inc_intervals_forced; Discrete_intervals_list auto_inc_intervals_forced;
ulonglong limit_found_rows; ulonglong limit_found_rows;
ha_rows cuted_fields, sent_row_count, examined_row_count; ha_rows cuted_fields, sent_row_count, examined_row_count;
ulong client_capabilities; ulonglong client_capabilities;
ulong query_plan_flags; ulong query_plan_flags;
uint in_sub_stmt; uint in_sub_stmt;
bool enable_slow_log; bool enable_slow_log;
@ -2044,7 +2044,7 @@ public:
/* Needed by MariaDB semi sync replication */ /* Needed by MariaDB semi sync replication */
Trans_binlog_info *semisync_info; Trans_binlog_info *semisync_info;
ulong client_capabilities; /* What the client supports */ ulonglong client_capabilities; /* What the client supports */
ulong max_client_packet_length; ulong max_client_packet_length;
HASH handler_tables_hash; HASH handler_tables_hash;
@ -2086,7 +2086,7 @@ public:
bool report_to_client; bool report_to_client;
/* /*
true, if we will send progress report packets to a client true, if we will send progress report packets to a client
(client has requested them, see CLIENT_PROGRESS; report_to_client (client has requested them, see MARIADB_CLIENT_PROGRESS; report_to_client
is true; not in sub-statement) is true; not in sub-statement)
*/ */
bool report; bool report;

View File

@ -637,7 +637,7 @@ void execute_init_command(THD *thd, LEX_STRING *init_command,
mysql_rwlock_t *var_lock) mysql_rwlock_t *var_lock)
{ {
Vio* save_vio; Vio* save_vio;
ulong save_client_capabilities; ulonglong save_client_capabilities;
mysql_rwlock_rdlock(var_lock); mysql_rwlock_rdlock(var_lock);
if (!init_command->length) if (!init_command->length)

View File

@ -18699,8 +18699,11 @@ static void test_progress_reporting()
myheader("test_progress_reporting"); myheader("test_progress_reporting");
conn= client_connect(CLIENT_PROGRESS, MYSQL_PROTOCOL_TCP, 0);
DIE_UNLESS(conn->client_flag & CLIENT_PROGRESS); conn= client_connect(CLIENT_PROGRESS_OBSOLETE, MYSQL_PROTOCOL_TCP, 0);
if (!(conn->server_capabilities & CLIENT_PROGRESS_OBSOLETE))
return;
DIE_UNLESS(conn->client_flag & CLIENT_PROGRESS_OBSOLETE);
mysql_options(conn, MYSQL_PROGRESS_CALLBACK, (void*) report_progress); mysql_options(conn, MYSQL_PROGRESS_CALLBACK, (void*) report_progress);
rc= mysql_query(conn, "set @save=@@global.progress_report_time"); rc= mysql_query(conn, "set @save=@@global.progress_report_time");