Skip to content

Commit

Permalink
Bug#20821550 : ADD MYSQL_GET_PARAMETERS FUNCTIONALITY TO MYSQL_GET_OP…
Browse files Browse the repository at this point in the history
…TION()

Description : 1> Removed mysql_get_parameters() and st_mysql_parameters
              2> Updated mysql_get_options() and mysql_options() to get
                 and set value for max_allowed_packet and net_buffer_length.

Reviewed-By : Georgi Kodinov <[email protected]>
              V S Murthy Sidgam <[email protected]>
  • Loading branch information
harinvadodaria committed Jul 29, 2015
1 parent 0dfd969 commit 57dab49
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 58 deletions.
15 changes: 10 additions & 5 deletions client/mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2098,7 +2098,6 @@ static int get_options(int argc, char **argv)
{
char *tmp, *pagpoint;
int ho_error;
MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();

tmp= (char *) getenv("MYSQL_HOST");
if (tmp)
Expand All @@ -2115,14 +2114,20 @@ static int get_options(int argc, char **argv)
my_stpcpy(pager, pagpoint);
my_stpcpy(default_pager, pager);

opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
opt_net_buffer_length= *mysql_params->p_net_buffer_length;
if (mysql_get_option(NULL, MYSQL_OPT_MAX_ALLOWED_PACKET, &opt_max_allowed_packet) ||
mysql_get_option(NULL, MYSQL_OPT_NET_BUFFER_LENGTH, &opt_max_allowed_packet))
{
exit(1);
}

if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);

*mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
*mysql_params->p_net_buffer_length= opt_net_buffer_length;
if (mysql_options(NULL, MYSQL_OPT_MAX_ALLOWED_PACKET, &opt_max_allowed_packet) ||
mysql_options(NULL, MYSQL_OPT_NET_BUFFER_LENGTH, &opt_net_buffer_length))
{
exit(1);
}

if (status.batch) /* disable pager and outfile in this case */
{
Expand Down
16 changes: 11 additions & 5 deletions client/mysqldump.c
Original file line number Diff line number Diff line change
Expand Up @@ -972,10 +972,12 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
static int get_options(int *argc, char ***argv)
{
int ho_error;
MYSQL_PARAMETERS *mysql_params= mysql_get_parameters();

opt_max_allowed_packet= *mysql_params->p_max_allowed_packet;
opt_net_buffer_length= *mysql_params->p_net_buffer_length;
if (mysql_get_option(NULL, MYSQL_OPT_MAX_ALLOWED_PACKET, &opt_max_allowed_packet) ||
mysql_get_option(NULL, MYSQL_OPT_NET_BUFFER_LENGTH, &opt_max_allowed_packet))
{
exit(1);
}

md_result_file= stdout;
my_getopt_use_args_separator= TRUE;
Expand Down Expand Up @@ -1007,8 +1009,12 @@ static int get_options(int *argc, char ***argv)
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
return(ho_error);

*mysql_params->p_max_allowed_packet= opt_max_allowed_packet;
*mysql_params->p_net_buffer_length= opt_net_buffer_length;
if (mysql_options(NULL, MYSQL_OPT_MAX_ALLOWED_PACKET, &opt_max_allowed_packet) ||
mysql_options(NULL, MYSQL_OPT_NET_BUFFER_LENGTH, &opt_net_buffer_length))
{
exit(1);
}

if (debug_info_flag)
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
if (debug_check_flag)
Expand Down
17 changes: 2 additions & 15 deletions include/mysql.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ enum mysql_option
MYSQL_SERVER_PUBLIC_KEY,
MYSQL_ENABLE_CLEARTEXT_PLUGIN,
MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
MYSQL_OPT_SSL_ENFORCE
MYSQL_OPT_SSL_ENFORCE,
MYSQL_OPT_MAX_ALLOWED_PACKET, MYSQL_OPT_NET_BUFFER_LENGTH
};

/**
Expand Down Expand Up @@ -315,19 +316,6 @@ typedef struct st_mysql_res {
#define MYSQL_CLIENT
#endif


typedef struct st_mysql_parameters
{
unsigned long *p_max_allowed_packet;
unsigned long *p_net_buffer_length;
void *extension;
} MYSQL_PARAMETERS;

#if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
#define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet)
#define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length)
#endif

/*
Set up and bring down the server; to ensure that applications will
work when linked against either the standard client library or the
Expand All @@ -348,7 +336,6 @@ void STDCALL mysql_server_end(void);
#define mysql_library_init mysql_server_init
#define mysql_library_end mysql_server_end

MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void);

/*
Set up and bring down a thread; these function should be called
Expand Down
10 changes: 2 additions & 8 deletions include/mysql.h.pp
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@
MYSQL_SERVER_PUBLIC_KEY,
MYSQL_ENABLE_CLEARTEXT_PLUGIN,
MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS,
MYSQL_OPT_SSL_ENFORCE
MYSQL_OPT_SSL_ENFORCE,
MYSQL_OPT_MAX_ALLOWED_PACKET, MYSQL_OPT_NET_BUFFER_LENGTH
};
struct st_mysql_options_extention;
struct st_mysql_options {
Expand Down Expand Up @@ -467,15 +468,8 @@
my_bool unbuffered_fetch_cancelled;
void *extension;
} MYSQL_RES;
typedef struct st_mysql_parameters
{
unsigned long *p_max_allowed_packet;
unsigned long *p_net_buffer_length;
void *extension;
} MYSQL_PARAMETERS;
int mysql_server_init(int argc, char **argv, char **groups);
void mysql_server_end(void);
MYSQL_PARAMETERS * mysql_get_parameters(void);
my_bool mysql_thread_init(void);
void mysql_thread_end(void);
my_ulonglong mysql_num_rows(MYSQL_RES *res);
Expand Down
1 change: 0 additions & 1 deletion libmysql/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ get_tty_password
# will have a FR to replace this for decent name/functionality and document it.
my_load_defaults
handle_options
mysql_get_parameters

CACHE INTERNAL "Undocumented Functions exported by client API"

Expand Down
25 changes: 10 additions & 15 deletions libmysql/libmysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@
#include "client_settings.h"
#include "mysql_trace.h"

#undef net_buffer_length
#undef max_allowed_packet

ulong net_buffer_length=8192;
ulong max_allowed_packet= 1024L*1024L*1024L;


#ifdef EMBEDDED_LIBRARY
Expand Down Expand Up @@ -215,14 +210,6 @@ void STDCALL mysql_server_end()
mysql_client_init= org_my_init_done= 0;
}

static MYSQL_PARAMETERS mysql_internal_parameters=
{&max_allowed_packet, &net_buffer_length, 0};

MYSQL_PARAMETERS *STDCALL mysql_get_parameters(void)
{
return &mysql_internal_parameters;
}

my_bool STDCALL mysql_thread_init()
{
return my_thread_init();
Expand Down Expand Up @@ -1100,11 +1087,19 @@ my_bool STDCALL mysql_embedded(void)

void my_net_local_init(NET *net)
{
net->max_packet= (uint) net_buffer_length;
ulong local_net_buffer_length;
ulong local_max_allowed_packet;

(void) mysql_get_option(NULL, MYSQL_OPT_MAX_ALLOWED_PACKET,
&local_max_allowed_packet);
(void) mysql_get_option(NULL, MYSQL_OPT_NET_BUFFER_LENGTH,
&local_net_buffer_length);

net->max_packet= (uint) local_net_buffer_length;
my_net_set_read_timeout(net, CLIENT_NET_READ_TIMEOUT);
my_net_set_write_timeout(net, CLIENT_NET_WRITE_TIMEOUT);
net->retry_count= 1;
net->max_packet_size= MY_MAX(net_buffer_length, max_allowed_packet);
net->max_packet_size= MY_MAX(local_net_buffer_length, local_max_allowed_packet);
}

/*
Expand Down
4 changes: 2 additions & 2 deletions libmysqld/libmysqld.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
#define INADDR_NONE -1
#endif

extern ulong net_buffer_length;
extern ulong max_allowed_packet;
ulong net_buffer_length;
ulong max_allowed_packet;

#if defined(_WIN32)
#define ERRNO WSAGetLastError()
Expand Down
29 changes: 25 additions & 4 deletions sql-common/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
#include "hash.h"
#include "mysql/client_authentication.h"

/* Remove client convenience wrappers */
#undef max_allowed_packet
#undef net_buffer_length

#ifdef EMBEDDED_LIBRARY

#undef MYSQL_SERVER
Expand Down Expand Up @@ -166,6 +162,9 @@ char *shared_memory_base_name= 0;
const char *def_shared_memory_base_name= default_shared_memory_base_name;
#endif

ulong g_net_buffer_length= 8192;
ulong g_max_allowed_packet= 1024L*1024L*1024L;

void mysql_close_free_options(MYSQL *mysql);
void mysql_close_free(MYSQL *mysql);
static void mysql_prune_stmt_list(MYSQL *mysql);
Expand Down Expand Up @@ -5494,6 +5493,17 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg)
mysql->options.client_flag&= ~CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS;
break;

case MYSQL_OPT_MAX_ALLOWED_PACKET:
if (mysql)
mysql->options.max_allowed_packet= (*(ulong *) arg);
else
g_max_allowed_packet= (*(ulong *) arg);
break;

case MYSQL_OPT_NET_BUFFER_LENGTH:
g_net_buffer_length= (*(ulong *) arg);
break;

default:
DBUG_RETURN(1);
}
Expand Down Expand Up @@ -5671,6 +5681,17 @@ mysql_get_option(MYSQL *mysql, enum mysql_option option, const void *arg)
CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS) ? TRUE : FALSE;
break;

case MYSQL_OPT_MAX_ALLOWED_PACKET:
if (mysql)
*((ulong*)arg)= mysql->options.max_allowed_packet;
else
*((ulong*)arg)= g_max_allowed_packet;
break;

case MYSQL_OPT_NET_BUFFER_LENGTH:
*((ulong*)arg)= g_net_buffer_length;
break;

case MYSQL_OPT_NAMED_PIPE: /* This option is depricated */
case MYSQL_INIT_COMMAND: /* Cumulative */
case MYSQL_OPT_CONNECT_ATTR_RESET: /* Cumulative */
Expand Down
10 changes: 7 additions & 3 deletions sql/log_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1303,13 +1303,17 @@ Log_event* Log_event::read_log_event(IO_CACHE* file,
char *buf= 0;
const char *error= 0;
Log_event *res= 0;
#ifndef max_allowed_packet
#if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY)
ulong log_max_allowed_packet;
mysql_get_option(NULL, MYSQL_OPT_MAX_ALLOWED_PACKET,
&log_max_allowed_packet);
#else
THD *thd=current_thd;
uint max_allowed_packet= thd ? slave_max_allowed_packet : ~0U;
uint log_max_allowed_packet= thd ? slave_max_allowed_packet : ~0U;
#endif

ulong const max_size=
max<ulong>(max_allowed_packet,
max<ulong>(log_max_allowed_packet,
opt_binlog_rows_event_max_size + MAX_LOG_EVENT_HEADER);
if (data_len > max_size)
{
Expand Down
5 changes: 5 additions & 0 deletions sql/mysqld.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ extern ulong log_error_verbosity;
/** System variable show_compatibility_56. */
extern my_bool show_compatibility_56;

#if defined(EMBEDDED_LIBRARY)
extern ulong max_allowed_packet;
extern ulong net_buffer_length;
#endif

extern LEX_CSTRING sql_statement_names[(uint) SQLCOM_END + 1];

/*
Expand Down
Loading

0 comments on commit 57dab49

Please sign in to comment.