mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Port cleanups, trivial refactoring and code rearrangements from
Alik's patch for BUG#22306: STOP INSTANCE can not be applied for instances in Crashed, Failed and Abandoned" to ease review process. Evaluate global variable linuxthreads before starting threads to avoid a race.
This commit is contained in:
@ -29,6 +29,7 @@
|
||||
#include "buffer.h"
|
||||
#include "instance.h"
|
||||
#include "log.h"
|
||||
#include "options.h"
|
||||
#include "parse_output.h"
|
||||
#include "priv.h"
|
||||
|
||||
@ -82,8 +83,12 @@ bool Instance_options::is_option_im_specific(const char *option_name)
|
||||
|
||||
Instance_options::Instance_options()
|
||||
:mysqld_version(NULL), mysqld_socket(NULL), mysqld_datadir(NULL),
|
||||
mysqld_pid_file(NULL), mysqld_port(NULL), mysqld_port_val(0),
|
||||
nonguarded(NULL), shutdown_delay(NULL), shutdown_delay_val(0),
|
||||
mysqld_pid_file(NULL),
|
||||
nonguarded(NULL),
|
||||
mysqld_port(NULL),
|
||||
mysqld_port_val(0),
|
||||
shutdown_delay(NULL),
|
||||
shutdown_delay_val(0),
|
||||
filled_default_options(0)
|
||||
{
|
||||
mysqld_path.str= NULL;
|
||||
@ -99,7 +104,7 @@ Instance_options::Instance_options()
|
||||
/*
|
||||
Get compiled-in value of default_option
|
||||
|
||||
SYNOPSYS
|
||||
SYNOPSIS
|
||||
get_default_option()
|
||||
result buffer to put found value
|
||||
result_len buffer size
|
||||
@ -139,7 +144,7 @@ err:
|
||||
/*
|
||||
Fill mysqld_version option (used at initialization stage)
|
||||
|
||||
SYNOPSYS
|
||||
SYNOPSIS
|
||||
fill_instance_version()
|
||||
|
||||
DESCRIPTION
|
||||
@ -182,7 +187,7 @@ int Instance_options::fill_instance_version()
|
||||
err:
|
||||
if (rc)
|
||||
log_error("fill_instance_version: Failed to get version of '%s'",
|
||||
mysqld_path.str);
|
||||
(const char *) mysqld_path.str);
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -190,7 +195,7 @@ err:
|
||||
/*
|
||||
Fill mysqld_real_path
|
||||
|
||||
SYNOPSYS
|
||||
SYNOPSIS
|
||||
fill_mysqld_real_path()
|
||||
|
||||
DESCRIPTION
|
||||
@ -242,7 +247,7 @@ err:
|
||||
/*
|
||||
Fill various log options
|
||||
|
||||
SYNOPSYS
|
||||
SYNOPSIS
|
||||
fill_log_options()
|
||||
|
||||
DESCRIPTION
|
||||
@ -355,7 +360,7 @@ err:
|
||||
/*
|
||||
Get the full pid file name with path
|
||||
|
||||
SYNOPSYS
|
||||
SYNOPSIS
|
||||
get_pid_filaname()
|
||||
result buffer to sotre the pidfile value
|
||||
|
||||
@ -396,7 +401,7 @@ int Instance_options::unlink_pidfile()
|
||||
}
|
||||
|
||||
|
||||
pid_t Instance_options::get_pid()
|
||||
pid_t Instance_options::load_pid()
|
||||
{
|
||||
FILE *pid_file_stream;
|
||||
|
||||
@ -415,7 +420,7 @@ pid_t Instance_options::get_pid()
|
||||
}
|
||||
|
||||
|
||||
int Instance_options::complete_initialization(const char *default_path)
|
||||
bool Instance_options::complete_initialization()
|
||||
{
|
||||
int arg_idx;
|
||||
const char *tmp;
|
||||
@ -423,10 +428,14 @@ int Instance_options::complete_initialization(const char *default_path)
|
||||
|
||||
if (!mysqld_path.str)
|
||||
{
|
||||
// Need one extra byte, as convert_dirname() adds a slash at the end.
|
||||
if (!(mysqld_path.str= alloc_root(&alloc, strlen(default_path) + 2)))
|
||||
goto err;
|
||||
strcpy(mysqld_path.str, default_path);
|
||||
/* Need one extra byte, as convert_dirname() adds a slash at the end. */
|
||||
mysqld_path.str= alloc_root(&alloc,
|
||||
strlen(Options::Main::default_mysqld_path) + 2);
|
||||
|
||||
if (! mysqld_path.str)
|
||||
return TRUE;
|
||||
|
||||
strcpy(mysqld_path.str, Options::Main::default_mysqld_path);
|
||||
}
|
||||
|
||||
// it's safe to cast this to char* since this is a buffer we are allocating
|
||||
@ -442,7 +451,7 @@ int Instance_options::complete_initialization(const char *default_path)
|
||||
shutdown_delay_val= atoi(shutdown_delay);
|
||||
|
||||
if (!(tmp= strdup_root(&alloc, "--no-defaults")))
|
||||
goto err;
|
||||
return TRUE;
|
||||
|
||||
if (!mysqld_pid_file)
|
||||
{
|
||||
@ -477,21 +486,21 @@ int Instance_options::complete_initialization(const char *default_path)
|
||||
}
|
||||
|
||||
if (get_pid_filename(pid_file_with_path))
|
||||
goto err;
|
||||
return TRUE;
|
||||
|
||||
/* we need to reserve space for the final zero + possible default options */
|
||||
if (!(argv= (char**)
|
||||
alloc_root(&alloc, (get_num_options() + 1
|
||||
+ MAX_NUMBER_OF_DEFAULT_OPTIONS) * sizeof(char*))))
|
||||
goto err;
|
||||
return TRUE;
|
||||
filled_default_options= 0;
|
||||
|
||||
/* the path must be first in the argv */
|
||||
if (add_to_argv(mysqld_path.str))
|
||||
goto err;
|
||||
return TRUE;
|
||||
|
||||
if (add_to_argv(tmp))
|
||||
goto err;
|
||||
return TRUE;
|
||||
|
||||
arg_idx= filled_default_options;
|
||||
for (int opt_idx= 0; opt_idx < get_num_options(); ++opt_idx)
|
||||
@ -514,12 +523,9 @@ int Instance_options::complete_initialization(const char *default_path)
|
||||
argv[arg_idx]= 0;
|
||||
|
||||
if (fill_log_options() || fill_mysqld_real_path() || fill_instance_version())
|
||||
goto err;
|
||||
return TRUE;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
return 1;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@ -636,26 +642,26 @@ void Instance_options::print_argv()
|
||||
|
||||
/*
|
||||
We execute this function to initialize some options.
|
||||
Return value: 0 - ok. 1 - unable to allocate memory.
|
||||
|
||||
RETURN
|
||||
FALSE - ok
|
||||
TRUE - memory allocation error
|
||||
*/
|
||||
|
||||
int Instance_options::init(const LEX_STRING *instance_name_arg)
|
||||
bool Instance_options::init(const LEX_STRING *instance_name_arg)
|
||||
{
|
||||
instance_name.length= instance_name_arg->length;
|
||||
|
||||
init_alloc_root(&alloc, MEM_ROOT_BLOCK_SIZE, 0);
|
||||
|
||||
if (options.init())
|
||||
goto err;
|
||||
return TRUE;
|
||||
|
||||
if (!(instance_name.str= strmake_root(&alloc, instance_name_arg->str,
|
||||
instance_name_arg->length)))
|
||||
goto err;
|
||||
return TRUE;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
return 1;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
@ -663,3 +669,29 @@ Instance_options::~Instance_options()
|
||||
{
|
||||
free_root(&alloc, MYF(0));
|
||||
}
|
||||
|
||||
|
||||
uint Instance_options::get_shutdown_delay() const
|
||||
{
|
||||
static const uint DEFAULT_SHUTDOWN_DELAY= 35;
|
||||
|
||||
/*
|
||||
NOTE: it is important to check shutdown_delay here, but use
|
||||
shutdown_delay_val. The idea is that if the option is unset,
|
||||
shutdown_delay will be NULL, but shutdown_delay_val will not be reset.
|
||||
*/
|
||||
|
||||
return shutdown_delay ? shutdown_delay_val : DEFAULT_SHUTDOWN_DELAY;
|
||||
}
|
||||
|
||||
int Instance_options::get_mysqld_port() const
|
||||
{
|
||||
/*
|
||||
NOTE: it is important to check mysqld_port here, but use mysqld_port_val.
|
||||
The idea is that if the option is unset, mysqld_port will be NULL, but
|
||||
mysqld_port_val will not be reset.
|
||||
*/
|
||||
|
||||
return mysqld_port ? mysqld_port_val : 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user