Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Barkov committed Sep 28, 2017
2 parents 139441d + de7c2e5 commit 7131a0a
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 118 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MYSQL_VERSION_MAJOR=10
MYSQL_VERSION_MINOR=2
MYSQL_VERSION_PATCH=9
MYSQL_VERSION_PATCH=10
97 changes: 57 additions & 40 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,47 @@ void revert_properties();
static void handle_no_active_connection(struct st_command* command,
struct st_connection *cn, DYNAMIC_STRING *ds);


/* Wrapper for fgets.Strips \r off newlines on Windows.
Should be used with together with my_popen().
*/
static char *my_fgets(char * s, int n, FILE * stream, int *len)
{
char *buf = fgets(s, n, stream);
if (!buf)
{
*len= 0;
return buf;
}

*len = (int)strlen(buf);
#ifdef _WIN32
/* Strip '\r' off newlines. */
if (*len > 1 && buf[*len - 2] == '\r' && buf[*len - 1] == '\n')
{
buf[*len - 2]= '\n';
buf[*len - 1]= 0;
(*len)--;
}
#endif
return buf;
}

/*
Wrapper for popen().
On Windows, uses binary mode to workaround
C runtime bug mentioned in MDEV-9409
*/
static FILE* my_popen(const char *cmd, const char *mode)
{
FILE *f= popen(cmd, mode);
#ifdef _WIN32
if (f)
_setmode(fileno(f), O_BINARY);
#endif
return f;
}

#ifdef EMBEDDED_LIBRARY

#define EMB_SEND_QUERY 1
Expand Down Expand Up @@ -1785,19 +1826,20 @@ static int run_command(char* cmd,
DBUG_ENTER("run_command");
DBUG_PRINT("enter", ("cmd: %s", cmd));

if (!(res_file= popen(cmd, "r")))
if (!(res_file= my_popen(cmd, "r")))
{
report_or_die("popen(\"%s\", \"r\") failed", cmd);
DBUG_RETURN(-1);
}

while (fgets(buf, sizeof(buf), res_file))
int len;
while (my_fgets(buf, sizeof(buf), res_file, &len))
{
DBUG_PRINT("info", ("buf: %s", buf));
if(ds_res)
{
/* Save the output of this command in the supplied string */
dynstr_append(ds_res, buf);
dynstr_append_mem(ds_res, buf,len);
}
else
{
Expand Down Expand Up @@ -1886,14 +1928,15 @@ static int diff_check(const char *diff_name)

my_snprintf(buf, sizeof(buf), "%s -v", diff_name);

if (!(res_file= popen(buf, "r")))
if (!(res_file= my_popen(buf, "r")))
die("popen(\"%s\", \"r\") failed", buf);

/*
if diff is not present, nothing will be in stdout to increment
have_diff
*/
if (fgets(buf, sizeof(buf), res_file))
int len;
if (my_fgets(buf, sizeof(buf), res_file, &len))
have_diff= 1;

pclose(res_file);
Expand Down Expand Up @@ -3246,18 +3289,6 @@ void free_tmp_sh_file()
#endif


FILE* my_popen(DYNAMIC_STRING *ds_cmd, const char *mode)
{
#if defined _WIN32 && defined USE_CYGWIN
/* Dump the command into a sh script file and execute with popen */
str_to_file(tmp_sh_name, ds_cmd->str, ds_cmd->length);
return popen(tmp_sh_cmd, mode);
#else
return popen(ds_cmd->str, mode);
#endif
}


static void init_builtin_echo(void)
{
#ifdef _WIN32
Expand Down Expand Up @@ -3392,7 +3423,7 @@ void do_exec(struct st_command *command)
DBUG_PRINT("info", ("Executing '%s' as '%s'",
command->first_argument, ds_cmd.str));

if (!(res_file= my_popen(&ds_cmd, "r")))
if (!(res_file= my_popen(ds_cmd.str, "r")))
{
dynstr_free(&ds_cmd);
if (command->abort_on_error)
Expand All @@ -3406,24 +3437,9 @@ void do_exec(struct st_command *command)
init_dynamic_string(&ds_sorted, "", 1024, 1024);
ds_result= &ds_sorted;
}

#ifdef _WIN32
/* Workaround for CRT bug, MDEV-9409 */
_setmode(fileno(res_file), O_BINARY);
#endif

while (fgets(buf, sizeof(buf), res_file))
int len;
while (my_fgets(buf, sizeof(buf), res_file,&len))
{
int len = (int)strlen(buf);
#ifdef _WIN32
/* Strip '\r' off newlines. */
if (len > 1 && buf[len-2] == '\r' && buf[len-1] == '\n')
{
buf[len-2] = '\n';
buf[len-1] = 0;
len--;
}
#endif
replace_dynstr_append_mem(ds_result, buf, len);
}
error= pclose(res_file);
Expand Down Expand Up @@ -4685,24 +4701,25 @@ void do_perl(struct st_command *command)
/* Format the "perl <filename>" command */
my_snprintf(buf, sizeof(buf), "perl %s", temp_file_path);

if (!(res_file= popen(buf, "r")))
if (!(res_file= my_popen(buf, "r")))
{
if (command->abort_on_error)
die("popen(\"%s\", \"r\") failed", buf);
dynstr_free(&ds_delimiter);
DBUG_VOID_RETURN;
}

while (fgets(buf, sizeof(buf), res_file))
int len;
while (my_fgets(buf, sizeof(buf), res_file,&len))
{
if (disable_result_log)
{
buf[strlen(buf)-1]=0;
DBUG_PRINT("exec_result",("%s", buf));
buf[len - 1] = 0;
DBUG_PRINT("exec_result", ("%s", buf));
}
else
{
replace_dynstr_append(&ds_res, buf);
replace_dynstr_append_mem(&ds_res, buf, len);
}
}
error= pclose(res_file);
Expand Down
6 changes: 3 additions & 3 deletions mysql-test/r/mysqld--help,win.rdiff
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
--net-buffer-length=#
Buffer length for TCP/IP and socket communication
--net-read-timeout=#
@@ -956,6 +956,9 @@
@@ -957,6 +957,9 @@
characteristics (isolation level, read only/read
write,snapshot - but not any work done / data modified
within the transaction).
Expand All @@ -26,7 +26,7 @@
--show-slave-auth-info
Show user and password in SHOW SLAVE HOSTS on this
master.
@@ -1068,6 +1071,10 @@
@@ -1069,6 +1072,10 @@
Log slow queries to given log file. Defaults logging to
'hostname'-slow.log. Must be enabled to activate other
slow log options
Expand All @@ -37,7 +37,7 @@
--socket=name Socket file to use for connection
--sort-buffer-size=#
Each thread that needs to do a sort allocates a buffer of
@@ -1086,6 +1093,7 @@
@@ -1087,6 +1094,7 @@
NO_ENGINE_SUBSTITUTION, PAD_CHAR_TO_FULL_LENGTH
--stack-trace Print a symbolic stack trace on failure
(Defaults to on; use --skip-stack-trace to disable.)
Expand Down
7 changes: 4 additions & 3 deletions mysql-test/r/mysqld--help.result
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,10 @@ The following options may be given as the first argument:
--open-files-limit=#
If this is not 0, then mysqld will use this value to
reserve file descriptors to use with setrlimit(). If this
value is 0 then mysqld will reserve max_connections*5 or
max_connections + table_cache*2 (whichever is larger)
number of file descriptors
value is 0 or autoset then mysqld will reserve
max_connections*5 or max_connections + table_cache*2
(whichever is larger) number of file descriptors
(Automatically configured unless set explicitly)
--optimizer-prune-level=#
Controls the heuristic(s) applied during query
optimization to prune less-promising partial plans from
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/suite/sys_vars/r/host_cache_size_auto.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
select @@global.host_cache_size;
@@global.host_cache_size
653
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@
VARIABLE_SCOPE GLOBAL
-VARIABLE_TYPE BIGINT UNSIGNED
+VARIABLE_TYPE INT UNSIGNED
VARIABLE_COMMENT If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors
VARIABLE_COMMENT If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 or autoset then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 4294967295
@@ -4346,7 +4346,7 @@
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/sys_vars/r/sysvars_server_embedded.result
Original file line number Diff line number Diff line change
Expand Up @@ -4336,7 +4336,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME OPEN_FILES_LIMIT
VARIABLE_SCOPE GLOBAL
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors
VARIABLE_COMMENT If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 or autoset then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@
VARIABLE_SCOPE GLOBAL
-VARIABLE_TYPE BIGINT UNSIGNED
+VARIABLE_TYPE INT UNSIGNED
VARIABLE_COMMENT If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors
VARIABLE_COMMENT If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 or autoset then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 4294967295
@@ -5228,7 +5228,7 @@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5218,7 +5218,7 @@ COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME OPEN_FILES_LIMIT
VARIABLE_SCOPE GLOBAL
VARIABLE_TYPE BIGINT UNSIGNED
VARIABLE_COMMENT If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors
VARIABLE_COMMENT If this is not 0, then mysqld will use this value to reserve file descriptors to use with setrlimit(). If this value is 0 or autoset then mysqld will reserve max_connections*5 or max_connections + table_cache*2 (whichever is larger) number of file descriptors
NUMERIC_MIN_VALUE 0
NUMERIC_MAX_VALUE 4294967295
NUMERIC_BLOCK_SIZE 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--max_connections=1000 --open-files-limit=1000 --autoset-host-cache-size
1 change: 1 addition & 0 deletions mysql-test/suite/sys_vars/t/host_cache_size_auto.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select @@global.host_cache_size;
47 changes: 31 additions & 16 deletions sql/mysqld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4407,21 +4407,6 @@ static int init_common_variables()
SYSVAR_AUTOSIZE(threadpool_size, my_getncpus());
#endif

/* Fix host_cache_size. */
if (IS_SYSVAR_AUTOSIZE(&host_cache_size))
{
if (max_connections <= 628 - 128)
SYSVAR_AUTOSIZE(host_cache_size, 128 + max_connections);
else if (max_connections <= ((ulong)(2000 - 628)) * 20 + 500)
SYSVAR_AUTOSIZE(host_cache_size, 628 + ((max_connections - 500) / 20));
else
SYSVAR_AUTOSIZE(host_cache_size, 2000);
}

/* Fix back_log (back_log == 0 added for MySQL compatibility) */
if (back_log == 0 || IS_SYSVAR_AUTOSIZE(&back_log))
SYSVAR_AUTOSIZE(back_log, MY_MIN(900, (50 + max_connections / 5)));

/* connections and databases needs lots of files */
{
uint files, wanted_files, max_open_files;
Expand All @@ -4446,7 +4431,7 @@ static int init_common_variables()

if (files < wanted_files)
{
if (!open_files_limit)
if (!open_files_limit || IS_SYSVAR_AUTOSIZE(&open_files_limit))
{
/*
If we have requested too much file handles than we bring
Expand Down Expand Up @@ -4475,6 +4460,36 @@ static int init_common_variables()
}
SYSVAR_AUTOSIZE(open_files_limit, files);
}

/*
Max_connections is now set.
Now we can fix other variables depending on this variable.
*/

/* Fix host_cache_size */
if (IS_SYSVAR_AUTOSIZE(&host_cache_size))
{
/*
The default value is 128.
The autoset value is 128, plus 1 for a value of max_connections
up to 500, plus 1 for every increment of 20 over 500 in the
max_connections value, capped at 2000.
*/
uint size= (HOST_CACHE_SIZE + MY_MIN(max_connections, 500) +
MY_MAX(((long) max_connections)-500,0)/20);
SYSVAR_AUTOSIZE(host_cache_size, size);
}

/* Fix back_log (back_log == 0 added for MySQL compatibility) */
if (back_log == 0 || IS_SYSVAR_AUTOSIZE(&back_log))
{
/*
The default value is 150.
The autoset value is 50 + max_connections / 5 capped at 900
*/
SYSVAR_AUTOSIZE(back_log, MY_MIN(900, (50 + max_connections / 5)));
}

unireg_init(opt_specialflag); /* Set up extern variabels */
if (!(my_default_lc_messages=
my_locale_by_name(lc_messages)))
Expand Down
8 changes: 4 additions & 4 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2311,10 +2311,10 @@ export sys_var *Sys_old_passwords_ptr= &Sys_old_passwords; // for sql_acl.cc
static Sys_var_ulong Sys_open_files_limit(
"open_files_limit",
"If this is not 0, then mysqld will use this value to reserve file "
"descriptors to use with setrlimit(). If this value is 0 then mysqld "
"will reserve max_connections*5 or max_connections + table_cache*2 "
"(whichever is larger) number of file descriptors",
READ_ONLY GLOBAL_VAR(open_files_limit), CMD_LINE(REQUIRED_ARG),
"descriptors to use with setrlimit(). If this value is 0 or autoset "
"then mysqld will reserve max_connections*5 or max_connections + "
"table_cache*2 (whichever is larger) number of file descriptors",
AUTO_SET READ_ONLY GLOBAL_VAR(open_files_limit), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(0, OS_FILE_LIMIT), DEFAULT(0), BLOCK_SIZE(1));

/// @todo change to enum
Expand Down
2 changes: 1 addition & 1 deletion storage/innobase/page/page0page.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1569,7 +1569,7 @@ page_dir_balance_slot(
/* The last directory slot cannot be balanced with the upper
neighbor, as there is none. */

if (UNIV_UNLIKELY(slot_no == page_dir_get_n_slots(page) - 1)) {
if (UNIV_UNLIKELY(slot_no + 1 == page_dir_get_n_slots(page))) {

return;
}
Expand Down
Loading

0 comments on commit 7131a0a

Please sign in to comment.