mirror of
https://gitee.com/wangbin579/cetus.git
synced 2024-12-03 12:27:42 +08:00
Merge branch 'master' into ssl-support
Conflicts: plugins/admin/admin-plugin.c
This commit is contained in:
commit
dad2fccd48
@ -43,6 +43,7 @@
|
||||
#include "server-session.h"
|
||||
#include "sys-pedantic.h"
|
||||
#include "network-ssl.h"
|
||||
#include "chassis-options-utils.h"
|
||||
|
||||
#ifndef PLUGIN_VERSION
|
||||
#ifdef CHASSIS_BUILD_TAG
|
||||
@ -1117,6 +1118,22 @@ admin_delete_deny_ip(network_mysqld_con *con, const char *sql)
|
||||
g_ptr_array_add(fields, field); \
|
||||
}while(0)
|
||||
|
||||
#define MAKE_FIELD_DEF_3_COL(fields, col1_name, col2_name, col3_name) \
|
||||
do {\
|
||||
MYSQL_FIELD *field = network_mysqld_proto_fielddef_new();\
|
||||
field->name = g_strdup((col1_name)); \
|
||||
field->type = FIELD_TYPE_VAR_STRING;\
|
||||
g_ptr_array_add(fields, field); \
|
||||
field = network_mysqld_proto_fielddef_new(); \
|
||||
field->name = g_strdup((col2_name)); \
|
||||
field->type = FIELD_TYPE_VAR_STRING;\
|
||||
g_ptr_array_add(fields, field); \
|
||||
field = network_mysqld_proto_fielddef_new(); \
|
||||
field->name = g_strdup((col3_name)); \
|
||||
field->type = FIELD_TYPE_VAR_STRING;\
|
||||
g_ptr_array_add(fields, field); \
|
||||
}while(0)
|
||||
|
||||
#define APPEND_ROW_1_COL(rows, row_data) \
|
||||
do {\
|
||||
GPtrArray *row = g_ptr_array_new();\
|
||||
@ -1132,6 +1149,15 @@ admin_delete_deny_ip(network_mysqld_con *con, const char *sql)
|
||||
g_ptr_array_add(rows, row);\
|
||||
}while(0)
|
||||
|
||||
#define APPEND_ROW_3_COL(rows, col1, col2, col3) \
|
||||
do {\
|
||||
GPtrArray *row = g_ptr_array_new();\
|
||||
g_ptr_array_add(row, (col1)); \
|
||||
g_ptr_array_add(row, (col2)); \
|
||||
g_ptr_array_add(row, (col3)); \
|
||||
g_ptr_array_add(rows, row);\
|
||||
}while(0)
|
||||
|
||||
static void
|
||||
strip_extra_spaces(char *str)
|
||||
{
|
||||
@ -1229,7 +1255,7 @@ admin_show_variables(network_mysqld_con *con, const char *sql)
|
||||
GList *options = admin_get_all_options(con->srv);
|
||||
|
||||
GPtrArray *fields = network_mysqld_proto_fielddefs_new();
|
||||
MAKE_FIELD_DEF_2_COL(fields, "Variable_name", "Value");
|
||||
MAKE_FIELD_DEF_3_COL(fields, "Variable_name", "Value", "Property");
|
||||
|
||||
GPtrArray *rows = g_ptr_array_new_with_free_func((void *)network_mysqld_mysql_field_row_free);
|
||||
|
||||
@ -1238,13 +1264,16 @@ admin_show_variables(network_mysqld_con *con, const char *sql)
|
||||
for (l = options; l; l = l->next) {
|
||||
chassis_option_t *opt = l->data;
|
||||
/* just support these for now */
|
||||
if (opt->arg != OPTION_ARG_INT && opt->arg != OPTION_ARG_INT64
|
||||
&& opt->arg != OPTION_ARG_DOUBLE && opt->arg != OPTION_ARG_STRING && opt->arg != OPTION_ARG_NONE)
|
||||
continue;
|
||||
if (sql_pattern_like(pattern, opt->long_name)) {
|
||||
char *value = chassis_option_get_value_str(opt);
|
||||
struct external_param param = {0};
|
||||
param.chas = con->srv;
|
||||
param.opt_type = opt->opt_property;
|
||||
char *value = opt->show_hook != NULL? opt->show_hook(¶m) : NULL;
|
||||
if(NULL == value) {
|
||||
continue;
|
||||
}
|
||||
freelist = g_list_append(freelist, value);
|
||||
APPEND_ROW_2_COL(rows, (char *)opt->long_name, value);
|
||||
APPEND_ROW_3_COL(rows, (char *)opt->long_name, value, (CAN_ASSIGN_OPTS_PROPERTY(opt->opt_property)? "Dynamic" : "Static"));
|
||||
}
|
||||
}
|
||||
network_mysqld_con_send_resultset(con->client, fields, rows);
|
||||
@ -1847,8 +1876,8 @@ admin_get_config(network_mysqld_con *con, const char *sql)
|
||||
0};
|
||||
if (strcasecmp(p, "common") == 0) {
|
||||
snprintf(buf1, 32, "%d", chas->check_slave_delay);
|
||||
snprintf(buf2, 32, "%f", chas->slave_delay_down_threshold_sec);
|
||||
snprintf(buf3, 32, "%f", chas->slave_delay_recover_threshold_sec);
|
||||
snprintf(buf2, 32, "%lf", chas->slave_delay_down_threshold_sec);
|
||||
snprintf(buf3, 32, "%lf", chas->slave_delay_recover_threshold_sec);
|
||||
snprintf(buf4, 32, "%d", chas->long_query_time);
|
||||
APPEND_ROW_2_COL(rows, "common.check_slave_delay", buf1);
|
||||
APPEND_ROW_2_COL(rows, "common.slave_delay_down_threshold_sec", buf2);
|
||||
@ -1877,39 +1906,41 @@ static int
|
||||
admin_set_config(network_mysqld_con *con, const char *sql)
|
||||
{
|
||||
char key[128] = { 0 };
|
||||
int val = -1;
|
||||
sscanf(sql, "config set %64[a-zA-Z0-9_.]=%d", key, &val);
|
||||
if (key[0] == '\0' || val == -1) {
|
||||
char val[128] = { 0 };
|
||||
sscanf(sql, "config set %64[a-zA-Z0-9_.-]=%64[a-zA-Z0-9_.-]", key, val);
|
||||
if (key[0] == '\0') {
|
||||
network_mysqld_con_send_ok_full(con->client, 0, 0, SERVER_STATUS_AUTOCOMMIT, 0);
|
||||
return PROXY_SEND_RESULT;
|
||||
}
|
||||
chassis *chas = con->srv;
|
||||
int affected_rows = 1;
|
||||
if (strcasecmp(key, "common.check_slave_delay") == 0) {
|
||||
chas->check_slave_delay = val;
|
||||
} else if (strcasecmp(key, "common.slave_delay_down_threshold_sec") == 0) {
|
||||
chas->slave_delay_down_threshold_sec = val;
|
||||
} else if (strcasecmp(key, "common.slave_delay_recover_threshold_sec") == 0) {
|
||||
chas->slave_delay_recover_threshold_sec = val;
|
||||
} else if (strcasecmp(key, "common.long_query_time") == 0) {
|
||||
chas->long_query_time = val;
|
||||
} else if (strcasecmp(key, "pool.default_pool_size") == 0) {
|
||||
chas->mid_idle_connections = val;
|
||||
} else if (strcasecmp(key, "pool.max_pool_size") == 0) {
|
||||
chas->max_idle_connections = val;
|
||||
} else if (strcasecmp(key, "pool.max_resp_len") == 0) {
|
||||
chas->max_resp_len = val;
|
||||
} else if (strcasecmp(key, "pool.max_alive_time") == 0) {
|
||||
if (val < 600) {
|
||||
val = 600;
|
||||
|
||||
int affected_rows = 0;
|
||||
int ret = 0;
|
||||
|
||||
GList *options = admin_get_all_options(con->srv);
|
||||
|
||||
GList *l = NULL;
|
||||
for (l = options; l; l = l->next) {
|
||||
chassis_option_t *opt = l->data;
|
||||
if (strcasecmp(key, opt->long_name) == 0) {
|
||||
struct external_param param = {0};
|
||||
param.chas = con->srv;
|
||||
param.opt_type = opt->opt_property;
|
||||
ret = opt->assign_hook != NULL? opt->assign_hook(val, ¶m) : ASSIGN_NOT_SUPPORT;
|
||||
affected_rows++;
|
||||
break;
|
||||
}
|
||||
chas->max_alive_time = val;
|
||||
} else if (strcasecmp(key, "pool.master_preferred") == 0) {
|
||||
chas->master_preferred = val;
|
||||
} else {
|
||||
affected_rows = 0;
|
||||
}
|
||||
network_mysqld_con_send_ok_full(con->client, affected_rows, 0, SERVER_STATUS_AUTOCOMMIT, 0);
|
||||
g_list_free(options);
|
||||
|
||||
if(0 == ret) {
|
||||
network_mysqld_con_send_ok_full(con->client, affected_rows, 0, SERVER_STATUS_AUTOCOMMIT, 0);
|
||||
} else if(ASSIGN_NOT_SUPPORT == ret){
|
||||
network_mysqld_con_send_error_full(con->client, C("Variable cannot be set dynamically"), 1065, "28000");
|
||||
} else if(ASSIGN_VALUE_INVALID == ret){
|
||||
network_mysqld_con_send_error_full(con->client, C("Value is illegal"), 1065, "28000");
|
||||
} else {
|
||||
network_mysqld_con_send_error_full(con->client, C("You have an error in your SQL syntax"), 1065, "28000");
|
||||
}
|
||||
return PROXY_SEND_RESULT;
|
||||
}
|
||||
|
||||
@ -1925,8 +1956,76 @@ admin_reset_stats(network_mysqld_con *con, const char *sql)
|
||||
static int
|
||||
admin_save_settings(network_mysqld_con *con, const char *sql)
|
||||
{
|
||||
/* TODO: */
|
||||
network_mysqld_con_send_ok_full(con->client, 1, 0, SERVER_STATUS_AUTOCOMMIT, 0);
|
||||
chassis *srv = con->srv;
|
||||
GKeyFile *keyfile = g_key_file_new();
|
||||
g_key_file_set_list_separator(keyfile, ',');
|
||||
GError *gerr = NULL;
|
||||
gint ret = 0;
|
||||
gint effected_rows = 0;
|
||||
GString *free_path = g_string_new(NULL);
|
||||
if(srv->default_file == NULL) {
|
||||
free_path = g_string_append(free_path, get_current_dir_name());
|
||||
free_path = g_string_append(free_path, "/default.conf");
|
||||
srv->default_file = g_strdup(free_path->str);
|
||||
}
|
||||
|
||||
if(!g_path_is_absolute(srv->default_file)) {
|
||||
free_path = g_string_append(free_path, get_current_dir_name());
|
||||
free_path = g_string_append(free_path, "/");
|
||||
free_path = g_string_append(free_path, srv->default_file);
|
||||
if(srv->default_file) {
|
||||
g_free(srv->default_file);
|
||||
}
|
||||
srv->default_file = g_strdup(free_path->str);
|
||||
}
|
||||
if(free_path) {
|
||||
g_string_free(free_path, TRUE);
|
||||
}
|
||||
//1 rename config file
|
||||
if(srv->default_file) {
|
||||
GString *new_file = g_string_new(NULL);
|
||||
new_file = g_string_append(new_file, srv->default_file);
|
||||
new_file = g_string_append(new_file, ".old");
|
||||
if(remove(new_file->str)) {
|
||||
ret = REMOVE_ERROR;
|
||||
}
|
||||
if(rename(srv->default_file, new_file->str)) {
|
||||
ret = RENAME_ERROR;
|
||||
}
|
||||
g_string_free(new_file, TRUE);
|
||||
}
|
||||
|
||||
if(0 == ret) {
|
||||
//2 save new config
|
||||
effected_rows = chassis_options_save(keyfile, srv->options, srv);
|
||||
gsize file_size = 0;
|
||||
gchar *file_buf = g_key_file_to_data(keyfile, &file_size, NULL);
|
||||
if (FALSE == g_file_set_contents(srv->default_file, file_buf, file_size, &gerr)) {
|
||||
ret = SAVE_ERROR;
|
||||
} else {
|
||||
if((ret = chmod(srv->default_file, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP))) {
|
||||
ret = CHMOD_ERROR;
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
ret = RENAME_ERROR;
|
||||
}
|
||||
|
||||
if(0 == ret) {
|
||||
network_mysqld_con_send_ok_full(con->client, effected_rows, 0, SERVER_STATUS_AUTOCOMMIT, 0);
|
||||
} else if(RENAME_ERROR == ret) {
|
||||
network_mysqld_con_send_error_full(con->client, C("rename file failed"), 1066, "28000");
|
||||
} else if(SAVE_ERROR == ret) {
|
||||
network_mysqld_con_send_error_full(con->client, C("save file failed"), 1066, "28000");
|
||||
} else if(REMOVE_ERROR == ret) {
|
||||
network_mysqld_con_send_error_full(con->client, C("remove old file failed"), 1066, "28000");
|
||||
} else if(CHMOD_ERROR == ret) {
|
||||
network_mysqld_con_send_error_full(con->client, C("chmod file failed"), 1066, "28000");
|
||||
} else {
|
||||
network_mysqld_con_send_error_full(con->client, C("unknown error happened"), 1066, "28000");
|
||||
}
|
||||
|
||||
return PROXY_SEND_RESULT;
|
||||
}
|
||||
|
||||
@ -2121,7 +2220,7 @@ static struct sql_handler_entry_t sql_handler_shard_map[] = {
|
||||
{"config get", admin_get_config, "config get [<item>]", "show config"},
|
||||
{"config set ", admin_set_config, "config set <key>=<value>","set config"},
|
||||
{"stats reset", admin_reset_stats, "stats reset", "reset query statistics"},
|
||||
{"save settings ", admin_save_settings, "save settings", "not implemented"},
|
||||
{"save settings", admin_save_settings, "save settings", "not implemented"},
|
||||
{"select * from help", admin_help, "select * from help", "show this help"},
|
||||
{"select help", admin_help, "select help", "show this help"},
|
||||
{"cetus", admin_send_status, "cetus", "show overall status of Cetus"},
|
||||
@ -2192,7 +2291,7 @@ static struct sql_handler_entry_t sql_handler_rw_map[] = {
|
||||
{"config get", admin_get_config, "config get [<item>]", "show config"},
|
||||
{"config set ", admin_set_config, "config set <key>=<value>","set config"},
|
||||
{"stats reset", admin_reset_stats, "stats reset", "reset query statistics"},
|
||||
{"save settings ", admin_save_settings, "save settings", "not implemented"},
|
||||
{"save settings", admin_save_settings, "save settings", "not implemented"},
|
||||
{"select * from help", admin_help, "select * from help", "show this help"},
|
||||
{"select help", admin_help, "select help", "show this help"},
|
||||
{"cetus", admin_send_status, "cetus", "show overall status of Cetus"},
|
||||
@ -2337,11 +2436,11 @@ network_mysqld_server_connection_init(network_mysqld_con *con)
|
||||
return 0;
|
||||
}
|
||||
|
||||
chassis_plugin_config *config;
|
||||
|
||||
static chassis_plugin_config *
|
||||
network_mysqld_admin_plugin_new(void)
|
||||
{
|
||||
chassis_plugin_config *config;
|
||||
|
||||
config = g_new0(chassis_plugin_config, 1);
|
||||
|
||||
return config;
|
||||
@ -2379,6 +2478,111 @@ network_mysqld_admin_plugin_free(chassis *chas, chassis_plugin_config *config)
|
||||
g_free(config);
|
||||
}
|
||||
|
||||
gchar*
|
||||
show_admin_address(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%s", config->address != NULL ? config->address: "NULL");
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
if(config->address != NULL) {
|
||||
return g_strdup_printf("%s", config->address);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar*
|
||||
show_admin_username(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%s", config->admin_username != NULL ? config->admin_username: "NULL");
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
if(config->admin_username != NULL) {
|
||||
return g_strdup_printf("%s", config->admin_username);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar*
|
||||
show_admin_password(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%s", config->admin_password != NULL ? config->admin_password: "NULL");
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
if(config->admin_password != NULL) {
|
||||
return g_strdup_printf("%s", config->admin_password);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gchar*
|
||||
show_admin_allow_ip(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gchar *ret = NULL;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
GList *free_list = NULL;
|
||||
if(config && config->allow_ip_table && g_hash_table_size(config->allow_ip_table)) {
|
||||
free_list = g_hash_table_get_keys(config->allow_ip_table);
|
||||
GList *it = NULL;
|
||||
for(it = free_list; it; it=it->next) {
|
||||
free_str = g_string_append(free_str, it->data);
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len - 1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
if(free_list) {
|
||||
g_list_free(free_list);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
gchar*
|
||||
show_admin_deny_ip(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gchar *ret = NULL;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
GList *free_list = NULL;
|
||||
if(config && config->deny_ip_table && g_hash_table_size(config->deny_ip_table)) {
|
||||
free_list = g_hash_table_get_keys(config->deny_ip_table);
|
||||
GList *it = NULL;
|
||||
for(it = free_list; it; it=it->next) {
|
||||
free_str = g_string_append(free_str, it->data);
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len - 1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
if(free_list) {
|
||||
g_list_free(free_list);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* add the proxy specific options to the cmdline interface
|
||||
*/
|
||||
@ -2389,20 +2593,25 @@ network_mysqld_admin_plugin_get_options(chassis_plugin_config *config)
|
||||
|
||||
chassis_options_add(&opts, "admin-address",
|
||||
0, 0, OPTION_ARG_STRING, &(config->address),
|
||||
"listening address:port of the admin-server (default: :4041)", "<host:port>");
|
||||
"listening address:port of the admin-server (default: :4041)", "<host:port>",
|
||||
NULL, show_admin_address, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "admin-username",
|
||||
0, 0, OPTION_ARG_STRING, &(config->admin_username), "username to allow to log in", "<string>");
|
||||
0, 0, OPTION_ARG_STRING, &(config->admin_username), "username to allow to log in", "<string>",
|
||||
NULL, show_admin_username, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "admin-password",
|
||||
0, 0, OPTION_ARG_STRING, &(config->admin_password), "password to allow to log in", "<string>");
|
||||
0, 0, OPTION_ARG_STRING, &(config->admin_password), "password to allow to log in", "<string>",
|
||||
NULL, show_admin_password, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "admin-allow-ip",
|
||||
0, 0, OPTION_ARG_STRING, &(config->allow_ip),
|
||||
"ip address allowed to connect to admin", "<string>");
|
||||
"ip address allowed to connect to admin", "<string>",
|
||||
NULL, show_admin_allow_ip, SAVE_OPTS_PROPERTY);
|
||||
chassis_options_add(&opts, "admin-deny-ip",
|
||||
0, 0, OPTION_ARG_STRING, &(config->deny_ip),
|
||||
"ip address denyed to connect to admin", "<string>");
|
||||
"ip address denyed to connect to admin", "<string>",
|
||||
NULL, show_admin_deny_ip, SAVE_OPTS_PROPERTY);
|
||||
|
||||
return opts.options;
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ typedef int socklen_t;
|
||||
#include "cetus-users.h"
|
||||
#include "plugin-common.h"
|
||||
#include "chassis-options.h"
|
||||
#include "chassis-options-utils.h"
|
||||
|
||||
#ifndef PLUGIN_VERSION
|
||||
#ifdef CHASSIS_BUILD_TAG
|
||||
@ -2181,6 +2182,8 @@ network_mysqld_proxy_free(network_mysqld_con G_GNUC_UNUSED *con)
|
||||
{
|
||||
}
|
||||
|
||||
chassis_plugin_config *config;
|
||||
|
||||
chassis_plugin_config *
|
||||
network_mysqld_proxy_plugin_new(void)
|
||||
{
|
||||
@ -2188,7 +2191,6 @@ network_mysqld_proxy_plugin_new(void)
|
||||
g_critical("try loading proxy-plugin.so from shard-edition, exit");
|
||||
exit(1);
|
||||
#endif
|
||||
chassis_plugin_config *config;
|
||||
|
||||
config = g_new0(chassis_plugin_config, 1);
|
||||
|
||||
@ -2218,6 +2220,307 @@ network_mysqld_proxy_plugin_free(chassis *chas, chassis_plugin_config *config)
|
||||
g_free(config);
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_address(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%s", config->address != NULL ? config->address: "NULL");
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
if(config->address) {
|
||||
return g_strdup_printf("%s", config->address);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_read_only_backend_address(gpointer param) {
|
||||
gchar *ret = NULL;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
chassis *srv = opt_param->chas;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
network_backends_t *bs = opt_param->chas->priv->backends;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
guint i;
|
||||
for (i = 0; i < bs->backends->len; i++) {
|
||||
network_backend_t *old_backend = g_ptr_array_index(bs->backends, i);
|
||||
if(old_backend && old_backend->type == BACKEND_TYPE_RO) {
|
||||
free_str = g_string_append(free_str, old_backend->address->str);
|
||||
if(old_backend->server_group && old_backend->server_group->len) {
|
||||
free_str = g_string_append(free_str, "@");
|
||||
free_str = g_string_append(free_str, old_backend->server_group->str);
|
||||
}
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len -1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_backend_addresses(gpointer param) {
|
||||
gchar *ret = NULL;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
chassis *srv = opt_param->chas;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
network_backends_t *bs = opt_param->chas->priv->backends;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
guint i;
|
||||
for (i = 0; i < bs->backends->len; i++) {
|
||||
network_backend_t *old_backend = g_ptr_array_index(bs->backends, i);
|
||||
if(old_backend && old_backend->type == BACKEND_TYPE_RW) {
|
||||
free_str = g_string_append(free_str, old_backend->address->str);
|
||||
if(old_backend->server_group && old_backend->server_group->len) {
|
||||
free_str = g_string_append(free_str, "@");
|
||||
free_str = g_string_append(free_str, old_backend->server_group->str);
|
||||
}
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len -1] = '\0';
|
||||
}
|
||||
//handle defaults
|
||||
if(!strcasecmp(free_str->str, "127.0.0.1:3306")) {
|
||||
ret = NULL;
|
||||
} else {
|
||||
if(free_str->len) {
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_connect_timeout(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%lf (s)", config->connect_timeout_dbl);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
//handle default
|
||||
if(config->connect_timeout_dbl == -1) {
|
||||
return NULL;
|
||||
}
|
||||
return g_strdup_printf("%lf", config->connect_timeout_dbl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
assign_proxy_connect_timeout(const gchar *newval, gpointer param) {
|
||||
gint ret = ASSIGN_ERROR;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_ASSIGN_OPTS_PROPERTY(opt_type)) {
|
||||
if(NULL != newval) {
|
||||
gdouble value = 0;
|
||||
if(try_get_double_value(newval, &value)) {
|
||||
config->connect_timeout_dbl = value;
|
||||
ret = ASSIGN_OK;
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_read_timeout(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%lf (s)", config->read_timeout_dbl);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
//handle default
|
||||
if(config->read_timeout_dbl == -1) {
|
||||
return NULL;
|
||||
}
|
||||
return g_strdup_printf("%lf", config->read_timeout_dbl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
assign_proxy_read_timeout(const gchar *newval, gpointer param) {
|
||||
gint ret = ASSIGN_ERROR;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_ASSIGN_OPTS_PROPERTY(opt_type)) {
|
||||
if(NULL != newval) {
|
||||
gdouble value = 0;
|
||||
if(try_get_double_value(newval, &value)) {
|
||||
config->read_timeout_dbl = value;
|
||||
ret = ASSIGN_OK;
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_write_timeout(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%lf (s)", config->write_timeout_dbl);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
if(config->write_timeout_dbl == -1) {
|
||||
return NULL;
|
||||
}
|
||||
return g_strdup_printf("%lf", config->write_timeout_dbl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
assign_proxy_write_timeout(const gchar *newval, gpointer param) {
|
||||
gint ret = ASSIGN_ERROR;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_ASSIGN_OPTS_PROPERTY(opt_type)) {
|
||||
if(NULL != newval) {
|
||||
gdouble value = 0;
|
||||
if(try_get_double_value(newval, &value)) {
|
||||
config->write_timeout_dbl = value;
|
||||
ret = ASSIGN_OK;
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_allow_ip(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gchar *ret = NULL;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
GList *free_list = NULL;
|
||||
if(config && config->allow_ip_table && g_hash_table_size(config->allow_ip_table)) {
|
||||
free_list = g_hash_table_get_keys(config->allow_ip_table);
|
||||
GList *it = NULL;
|
||||
for(it = free_list; it; it=it->next) {
|
||||
free_str = g_string_append(free_str, it->data);
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len - 1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
if(free_list) {
|
||||
g_list_free(free_list);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_deny_ip(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gchar *ret = NULL;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
GList *free_list = NULL;
|
||||
if(config && config->deny_ip_table && g_hash_table_size(config->deny_ip_table)) {
|
||||
free_list = g_hash_table_get_keys(config->deny_ip_table);
|
||||
GList *it = NULL;
|
||||
for(it = free_list; it; it=it->next) {
|
||||
free_str = g_string_append(free_str, it->data);
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len - 1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
if(free_list) {
|
||||
g_list_free(free_list);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_read_master_percentage(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%d", config->read_master_percentage);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
//handle default
|
||||
if(config->read_master_percentage == 0) {
|
||||
return NULL;
|
||||
}
|
||||
return g_strdup_printf("%d", config->read_master_percentage);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
assign_read_master_percentage(const gchar *newval, gpointer param) {
|
||||
gint ret = ASSIGN_ERROR;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_ASSIGN_OPTS_PROPERTY(opt_type)) {
|
||||
if(NULL != newval) {
|
||||
gint value = 0;
|
||||
if(try_get_int_value(newval, &value)) {
|
||||
if(value >= 0 || value <= 100) {
|
||||
config->read_master_percentage = value;
|
||||
ret = ASSIGN_OK;
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* plugin options
|
||||
*/
|
||||
@ -2228,36 +2531,45 @@ network_mysqld_proxy_plugin_get_options(chassis_plugin_config *config)
|
||||
|
||||
chassis_options_add(&opts, "proxy-address",
|
||||
'P', 0, OPTION_ARG_STRING, &(config->address),
|
||||
"listening address:port of the proxy-server (default: :4040)", "<host:port>");
|
||||
"listening address:port of the proxy-server (default: :4040)", "<host:port>",
|
||||
NULL, show_proxy_address, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-read-only-backend-addresses",
|
||||
'r', 0, OPTION_ARG_STRING_ARRAY, &(config->read_only_backend_addresses),
|
||||
"address:port of the remote slave-server (default: not set)", "<host:port>");
|
||||
"address:port of the remote slave-server (default: not set)", "<host:port>",
|
||||
NULL, show_proxy_read_only_backend_address, SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-backend-addresses",
|
||||
'b', 0, OPTION_ARG_STRING_ARRAY, &(config->backend_addresses),
|
||||
"address:port of the remote backend-servers (default: 127.0.0.1:3306)", "<host:port>");
|
||||
"address:port of the remote backend-servers (default: 127.0.0.1:3306)", "<host:port>",
|
||||
NULL, show_proxy_backend_addresses, SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-connect-timeout",
|
||||
0, 0, OPTION_ARG_DOUBLE, &(config->connect_timeout_dbl),
|
||||
"connect timeout in seconds (default: 2.0 seconds)", NULL);
|
||||
"connect timeout in seconds (default: 2.0 seconds)", NULL,
|
||||
assign_proxy_connect_timeout, show_proxy_connect_timeout, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-read-timeout",
|
||||
0, 0, OPTION_ARG_DOUBLE, &(config->read_timeout_dbl),
|
||||
"read timeout in seconds (default: 10 minuates)", NULL);
|
||||
"read timeout in seconds (default: 10 minuates)", NULL,
|
||||
assign_proxy_read_timeout, show_proxy_read_timeout, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-write-timeout",
|
||||
0, 0, OPTION_ARG_DOUBLE, &(config->write_timeout_dbl),
|
||||
"write timeout in seconds (default: 10 minuates)", NULL);
|
||||
"write timeout in seconds (default: 10 minuates)", NULL,
|
||||
assign_proxy_write_timeout, show_proxy_write_timeout, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-allow-ip",
|
||||
0, 0, OPTION_ARG_STRING, &(config->allow_ip), "allow user@IP for proxy permission", NULL);
|
||||
0, 0, OPTION_ARG_STRING, &(config->allow_ip), "allow user@IP for proxy permission", NULL,
|
||||
NULL, show_proxy_allow_ip, SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-deny-ip",
|
||||
0, 0, OPTION_ARG_STRING, &(config->deny_ip), "deny user@IP for proxy permission", NULL);
|
||||
0, 0, OPTION_ARG_STRING, &(config->deny_ip), "deny user@IP for proxy permission", NULL,
|
||||
NULL, show_proxy_deny_ip, SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "read-master-percentage",
|
||||
0, 0, OPTION_ARG_INT, &(config->read_master_percentage), "range [0, 100]", NULL);
|
||||
0, 0, OPTION_ARG_INT, &(config->read_master_percentage), "range [0, 100]", NULL,
|
||||
assign_read_master_percentage, show_read_master_percentage, ALL_OPTS_PROPERTY);
|
||||
|
||||
return opts.options;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "sharding-query-plan.h"
|
||||
#include "sql-filter-variables.h"
|
||||
#include "cetus-log.h"
|
||||
#include "chassis-options-utils.h"
|
||||
|
||||
#ifdef NETWORK_DEBUG_TRACE_STATE_CHANGES
|
||||
#include "cetus-query-queue.h"
|
||||
@ -2034,6 +2035,8 @@ network_mysqld_shard_connection_init(network_mysqld_con *con)
|
||||
return 0;
|
||||
}
|
||||
|
||||
chassis_plugin_config *config;
|
||||
|
||||
static chassis_plugin_config *
|
||||
network_mysqld_shard_plugin_new(void)
|
||||
{
|
||||
@ -2041,7 +2044,6 @@ network_mysqld_shard_plugin_new(void)
|
||||
g_critical("try loading shard-plugin.so from rw-edition, exit");
|
||||
exit(1);
|
||||
#endif
|
||||
chassis_plugin_config *config;
|
||||
|
||||
config = g_new0(chassis_plugin_config, 1);
|
||||
|
||||
@ -2078,6 +2080,263 @@ network_mysqld_shard_plugin_free(chassis *chas, chassis_plugin_config *config)
|
||||
g_free(config);
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_address(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%s", config->address != NULL ? config->address: "NULL");
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
if(config->address) {
|
||||
return g_strdup_printf("%s", config->address);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_read_only_backend_address(gpointer param) {
|
||||
gchar *ret = NULL;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
chassis *srv = opt_param->chas;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
network_backends_t *bs = opt_param->chas->priv->backends;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
guint i;
|
||||
for (i = 0; i < bs->backends->len; i++) {
|
||||
network_backend_t *old_backend = g_ptr_array_index(bs->backends, i);
|
||||
if(old_backend && old_backend->type == BACKEND_TYPE_RO) {
|
||||
free_str = g_string_append(free_str, old_backend->address->str);
|
||||
if(old_backend->server_group && old_backend->server_group->len) {
|
||||
free_str = g_string_append(free_str, "@");
|
||||
free_str = g_string_append(free_str, old_backend->server_group->str);
|
||||
}
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len -1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_backend_addresses(gpointer param) {
|
||||
gchar *ret = NULL;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
chassis *srv = opt_param->chas;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
network_backends_t *bs = opt_param->chas->priv->backends;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
guint i;
|
||||
for (i = 0; i < bs->backends->len; i++) {
|
||||
network_backend_t *old_backend = g_ptr_array_index(bs->backends, i);
|
||||
if(old_backend && old_backend->type == BACKEND_TYPE_RW) {
|
||||
free_str = g_string_append(free_str, old_backend->address->str);
|
||||
if(old_backend->server_group && old_backend->server_group->len) {
|
||||
free_str = g_string_append(free_str, "@");
|
||||
free_str = g_string_append(free_str, old_backend->server_group->str);
|
||||
}
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len -1] = '\0';
|
||||
}
|
||||
if(!strcasecmp("127.0.0.1:3306", free_str->str)) {
|
||||
return NULL;
|
||||
} else {
|
||||
if(free_str->len) {
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_connect_timeout(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%lf (s)", config->connect_timeout_dbl);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
//handle default
|
||||
if(config->connect_timeout_dbl == -1) {
|
||||
return NULL;
|
||||
}
|
||||
return g_strdup_printf("%lf", config->connect_timeout_dbl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
assign_proxy_connect_timeout(const gchar *newval, gpointer param) {
|
||||
gint ret = ASSIGN_ERROR;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_ASSIGN_OPTS_PROPERTY(opt_type)) {
|
||||
if(NULL != newval) {
|
||||
gdouble value = 0;
|
||||
if(try_get_double_value(newval, &value)) {
|
||||
config->connect_timeout_dbl = value;
|
||||
ret = ASSIGN_OK;
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_read_timeout(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%lf (s)", config->read_timeout_dbl);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
if(config->read_timeout_dbl == -1) {
|
||||
return NULL;
|
||||
}
|
||||
return g_strdup_printf("%lf", config->read_timeout_dbl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
assign_proxy_read_timeout(const gchar *newval, gpointer param) {
|
||||
gint ret = ASSIGN_ERROR;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_ASSIGN_OPTS_PROPERTY(opt_type)) {
|
||||
if(NULL != newval) {
|
||||
gdouble value = 0;
|
||||
if(try_get_double_value(newval, &value)) {
|
||||
config->read_timeout_dbl = value;
|
||||
ret = ASSIGN_OK;
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_write_timeout(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
|
||||
return g_strdup_printf("%lf (s)", config->write_timeout_dbl);
|
||||
}
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
if(config->write_timeout_dbl == -1) {
|
||||
return NULL;
|
||||
}
|
||||
return g_strdup_printf("%lf", config->write_timeout_dbl);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gint
|
||||
assign_proxy_write_timeout(const gchar *newval, gpointer param) {
|
||||
gint ret = ASSIGN_ERROR;
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_ASSIGN_OPTS_PROPERTY(opt_type)) {
|
||||
if(NULL != newval) {
|
||||
gdouble value = 0;
|
||||
if(try_get_double_value(newval, &value)) {
|
||||
config->write_timeout_dbl = value;
|
||||
ret = ASSIGN_OK;
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
} else {
|
||||
ret = ASSIGN_VALUE_INVALID;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_allow_ip(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gchar *ret = NULL;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
GList *free_list = NULL;
|
||||
if(config && config->allow_ip_table && g_hash_table_size(config->allow_ip_table)) {
|
||||
free_list = g_hash_table_get_keys(config->allow_ip_table);
|
||||
GList *it = NULL;
|
||||
for(it = free_list; it; it=it->next) {
|
||||
free_str = g_string_append(free_str, it->data);
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len - 1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
if(free_list) {
|
||||
g_list_free(free_list);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static gchar*
|
||||
show_proxy_deny_ip(gpointer param) {
|
||||
struct external_param *opt_param = (struct external_param *)param;
|
||||
gchar *ret = NULL;
|
||||
gint opt_type = opt_param->opt_type;
|
||||
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
|
||||
GString *free_str = g_string_new(NULL);
|
||||
GList *free_list = NULL;
|
||||
if(config && config->deny_ip_table && g_hash_table_size(config->deny_ip_table)) {
|
||||
free_list = g_hash_table_get_keys(config->deny_ip_table);
|
||||
GList *it = NULL;
|
||||
for(it = free_list; it; it=it->next) {
|
||||
free_str = g_string_append(free_str, it->data);
|
||||
free_str = g_string_append(free_str, ",");
|
||||
}
|
||||
if(free_str->len) {
|
||||
free_str->str[free_str->len - 1] = '\0';
|
||||
ret = g_strdup(free_str->str);
|
||||
}
|
||||
}
|
||||
if(free_str) {
|
||||
g_string_free(free_str, TRUE);
|
||||
}
|
||||
if(free_list) {
|
||||
g_list_free(free_list);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* plugin options
|
||||
*/
|
||||
@ -2088,33 +2347,41 @@ network_mysqld_shard_plugin_get_options(chassis_plugin_config *config)
|
||||
|
||||
chassis_options_add(&opts, "proxy-address",
|
||||
'P', 0, OPTION_ARG_STRING, &(config->address),
|
||||
"listening address:port of the proxy-server (default: :4040)", "<host:port>");
|
||||
"listening address:port of the proxy-server (default: :4040)", "<host:port>",
|
||||
NULL, show_proxy_address, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-backend-addresses",
|
||||
'b', 0, OPTION_ARG_STRING_ARRAY, &(config->backend_addresses),
|
||||
"address:port of the remote backend-servers (default: 127.0.0.1:3306)", "<host:port>");
|
||||
"address:port of the remote backend-servers (default: 127.0.0.1:3306)", "<host:port>",
|
||||
NULL, show_proxy_backend_addresses, SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-read-only-backend-addresses",
|
||||
'r', 0, OPTION_ARG_STRING_ARRAY, &(config->read_only_backend_addresses),
|
||||
"address:port of the remote slave-server (default: not set)", "<host:port>");
|
||||
"address:port of the remote slave-server (default: not set)", "<host:port>",
|
||||
NULL, show_proxy_read_only_backend_address, SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-connect-timeout",
|
||||
0, 0, OPTION_ARG_DOUBLE, &(config->connect_timeout_dbl),
|
||||
"connect timeout in seconds (default: 2.0 seconds)", NULL);
|
||||
"connect timeout in seconds (default: 2.0 seconds)", NULL,
|
||||
assign_proxy_connect_timeout, show_proxy_connect_timeout, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-read-timeout",
|
||||
0, 0, OPTION_ARG_DOUBLE, &(config->read_timeout_dbl),
|
||||
"read timeout in seconds (default: 10 minuates)", NULL);
|
||||
"read timeout in seconds (default: 10 minuates)", NULL,
|
||||
assign_proxy_read_timeout, show_proxy_read_timeout, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-write-timeout",
|
||||
0, 0, OPTION_ARG_DOUBLE, &(config->write_timeout_dbl),
|
||||
"write timeout in seconds (default: 10 minuates)", NULL);
|
||||
"write timeout in seconds (default: 10 minuates)", NULL,
|
||||
assign_proxy_write_timeout, show_proxy_write_timeout, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-allow-ip",
|
||||
0, 0, OPTION_ARG_STRING, &(config->allow_ip), "allow user@IP for proxy permission", NULL);
|
||||
0, 0, OPTION_ARG_STRING, &(config->allow_ip), "allow user@IP for proxy permission", NULL,
|
||||
NULL, show_proxy_allow_ip, SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(&opts, "proxy-deny-ip",
|
||||
0, 0, OPTION_ARG_STRING, &(config->deny_ip), "deny user@IP for proxy permission", NULL);
|
||||
0, 0, OPTION_ARG_STRING, &(config->deny_ip), "deny user@IP for proxy permission", NULL,
|
||||
NULL, show_proxy_deny_ip, SAVE_OPTS_PROPERTY);
|
||||
|
||||
return opts.options;
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ SET(chassis_sources
|
||||
chassis-limits.c
|
||||
chassis-frontend.c
|
||||
chassis-options.c
|
||||
chassis-options-utils.c
|
||||
chassis-unix-daemon.c
|
||||
chassis-config.c
|
||||
cJSON.c
|
||||
|
@ -236,6 +236,7 @@ cetus_users_authenticate_client(cetus_users_t *users,
|
||||
|
||||
struct pwd_pair_t *pwd = g_hash_table_lookup(users->records, user_name);
|
||||
if (pwd == NULL) {
|
||||
g_debug("pwd is null for user:%s", user_name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -102,3 +102,26 @@ read_file_to_buffer(const char *filename, char **buffer)
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
try_get_int_value(const gchar *option_value, gint *return_value)
|
||||
{
|
||||
gint ret = sscanf(option_value, "%ld", return_value);
|
||||
if(1 == ret) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
try_get_double_value(const gchar *option_value, gdouble *return_value)
|
||||
{
|
||||
gint ret = sscanf(option_value, "%lf", return_value);
|
||||
if(1 == ret) {
|
||||
return TRUE;
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,7 @@ void cetus_string_dequote(char *z);
|
||||
|
||||
gboolean read_file_to_buffer(const char *filename, char **buffer);
|
||||
|
||||
gboolean try_get_int_value(const gchar *option_value, gint *return_value);
|
||||
gboolean try_get_double_value(const gchar *option_value, gdouble *return_value);
|
||||
|
||||
#endif
|
||||
|
@ -57,12 +57,16 @@ charset_get_number(const char *name)
|
||||
const char *
|
||||
charset_get_name(int number)
|
||||
{
|
||||
assert(number < 64);
|
||||
static const char *charset[64] = {
|
||||
0, "big5", 0, 0, 0, 0, 0, 0, "latin1", 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, "gb2312", 0, 0, 0, "gbk", 0, 0, 0,
|
||||
0, "utf8", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "utf8mb4", 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "binary"
|
||||
};
|
||||
|
||||
if (number >= (sizeof(charset) / sizeof(charset[0]))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return charset[number];
|
||||
}
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "chassis-filemode.h"
|
||||
#include "chassis-options.h"
|
||||
#include "cetus-util.h"
|
||||
#include "chassis-options-utils.h"
|
||||
|
||||
/**
|
||||
* initialize the basic components of the chassis
|
||||
@ -249,9 +250,9 @@ int
|
||||
chassis_options_set_cmdline_only_options(chassis_options_t *opts, int *print_version, char **config_file)
|
||||
{
|
||||
|
||||
chassis_options_add(opts, "version", 'V', 0, OPTION_ARG_NONE, print_version, "Show version", NULL);
|
||||
chassis_options_add(opts, "version", 'V', 0, OPTION_ARG_NONE, print_version, "Show version", NULL, NULL, NULL, 0);
|
||||
|
||||
chassis_options_add(opts, "defaults-file", 0, 0, OPTION_ARG_STRING, config_file, "configuration file", "<file>");
|
||||
chassis_options_add(opts, "defaults-file", 0, 0, OPTION_ARG_STRING, config_file, "configuration file", "<file>", NULL, NULL, 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -104,6 +104,12 @@ chassis_new()
|
||||
|
||||
chas->startup_time = time(0);
|
||||
|
||||
chas->pid_file = NULL;
|
||||
chas->log_level = NULL;
|
||||
chas->log_xa_filename = NULL;
|
||||
chas->remote_config_url = NULL;
|
||||
chas->default_file = NULL;
|
||||
|
||||
return chas;
|
||||
}
|
||||
|
||||
@ -209,6 +215,30 @@ chassis_free(chassis *chas)
|
||||
if (chas->config_manager)
|
||||
chassis_config_free(chas->config_manager);
|
||||
|
||||
if(chas->pid_file) {
|
||||
g_free(chas->pid_file);
|
||||
}
|
||||
|
||||
if(chas->log_level) {
|
||||
g_free(chas->log_level);
|
||||
}
|
||||
|
||||
if (chas->plugin_names) {
|
||||
g_strfreev(chas->plugin_names);
|
||||
}
|
||||
|
||||
if(chas->log_xa_filename) {
|
||||
g_free(chas->log_xa_filename);
|
||||
}
|
||||
|
||||
if(chas->remote_config_url) {
|
||||
g_free(chas->remote_config_url);
|
||||
}
|
||||
|
||||
if(chas->default_file) {
|
||||
g_free(chas->default_file);
|
||||
}
|
||||
|
||||
g_free(chas);
|
||||
}
|
||||
|
||||
|
@ -176,6 +176,19 @@ struct chassis {
|
||||
GQueue *cache_index;
|
||||
unsigned long long last_cache_purge_time;
|
||||
gboolean allow_new_conns;
|
||||
|
||||
gint verbose_shutdown;
|
||||
gint daemon_mode;
|
||||
gchar *pid_file;
|
||||
gchar *log_level;
|
||||
gchar **plugin_names;
|
||||
gchar *log_xa_filename;
|
||||
guint invoke_dbg_on_crash;
|
||||
guint auto_restart;
|
||||
gint max_files_number;
|
||||
char *remote_config_url;
|
||||
gchar *default_file;
|
||||
gint print_version;
|
||||
};
|
||||
|
||||
CHASSIS_API chassis *chassis_new(void);
|
||||
|
1035
src/chassis-options-utils.c
Normal file
1035
src/chassis-options-utils.c
Normal file
File diff suppressed because it is too large
Load Diff
112
src/chassis-options-utils.h
Normal file
112
src/chassis-options-utils.h
Normal file
@ -0,0 +1,112 @@
|
||||
/* $%BEGINLICENSE%$
|
||||
Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; version 2 of the
|
||||
License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
||||
02110-1301 USA
|
||||
|
||||
$%ENDLICENSE%$ */
|
||||
|
||||
#ifndef _CHASSIS_OPTIONS_UTILS_H_
|
||||
#define _CHASSIS_OPTIONS_UTILS_H_
|
||||
|
||||
#include <glib.h>
|
||||
#include "chassis-exports.h"
|
||||
#include "chassis-options.h"
|
||||
#include "chassis-mainloop.h"
|
||||
|
||||
#define ASSIGN_OPTS_PROPERTY 0x01
|
||||
#define SHOW_OPTS_PROPERTY 0x02
|
||||
#define SAVE_OPTS_PROPERTY 0x04
|
||||
|
||||
#define SHOW_SAVE_OPTS_PROPERTY (SHOW_OPTS_PROsPERTY|SAVE_OPTS_PROPERTY)
|
||||
#define ALL_OPTS_PROPERTY (ASSIGN_OPTS_PROPERTY|SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY)
|
||||
|
||||
#define CAN_ASSIGN_OPTS_PROPERTY(opt_property) ((opt_property) & ASSIGN_OPTS_PROPERTY)
|
||||
#define CAN_SHOW_OPTS_PROPERTY(opt_property) ((opt_property) & SHOW_OPTS_PROPERTY)
|
||||
#define CAN_SAVE_OPTS_PROPERTY(opt_property) ((opt_property) & SAVE_OPTS_PROPERTY)
|
||||
|
||||
#define ASSIGN_OK 0
|
||||
#define ASSIGN_ERROR -1
|
||||
#define ASSIGN_NOT_SUPPORT -2
|
||||
#define ASSIGN_VALUE_INVALID -3
|
||||
#define SAVE_ERROR -10
|
||||
#define RENAME_ERROR -11
|
||||
#define CHMOD_ERROR -12
|
||||
#define REMOVE_ERROR -13
|
||||
#define NOT_EXIST -14
|
||||
|
||||
/* show utils */
|
||||
CHASSIS_API gchar* show_verbose_shutdown(gpointer param);
|
||||
CHASSIS_API gchar* show_daemon_mode(gpointer param);
|
||||
CHASSIS_API gchar* show_user(gpointer param);
|
||||
CHASSIS_API gchar* show_basedir(gpointer param);
|
||||
CHASSIS_API gchar* show_confdir(gpointer param);
|
||||
CHASSIS_API gchar* show_pidfile(gpointer param);
|
||||
CHASSIS_API gchar* show_plugindir(gpointer param);
|
||||
CHASSIS_API gchar* show_plugins(gpointer param);
|
||||
CHASSIS_API gchar* show_log_level(gpointer param);
|
||||
CHASSIS_API gchar* show_log_file(gpointer param);
|
||||
CHASSIS_API gchar* show_log_xa_file(gpointer param);
|
||||
CHASSIS_API gchar* show_log_backtrace_on_crash(gpointer param);
|
||||
CHASSIS_API gchar* show_keepalive(gpointer param);
|
||||
CHASSIS_API gchar* show_max_open_files(gpointer param);
|
||||
CHASSIS_API gchar* show_default_charset(gpointer param);
|
||||
CHASSIS_API gchar* show_default_username(gpointer param);
|
||||
CHASSIS_API gchar* show_default_db(gpointer param);
|
||||
CHASSIS_API gchar* show_default_pool_size(gpointer param);
|
||||
CHASSIS_API gchar* show_max_pool_size(gpointer param);
|
||||
CHASSIS_API gchar* show_max_resp_len(gpointer param);
|
||||
CHASSIS_API gchar* show_max_alive_time(gpointer param);
|
||||
CHASSIS_API gchar* show_merged_output_size(gpointer param);
|
||||
CHASSIS_API gchar* show_max_header_size(gpointer param);
|
||||
CHASSIS_API gchar* show_worker_id(gpointer param);
|
||||
CHASSIS_API gchar* show_disable_threads(gpointer param);
|
||||
CHASSIS_API gchar* show_enable_back_compress(gpointer param);
|
||||
CHASSIS_API gchar* show_enable_client_compress(gpointer param);
|
||||
CHASSIS_API gchar* show_check_slave_delay(gpointer param);
|
||||
CHASSIS_API gchar* show_slave_delay_down(gpointer param);
|
||||
CHASSIS_API gchar* show_slave_delay_recover(gpointer param);
|
||||
CHASSIS_API gchar* show_default_query_cache_timeout(gpointer param);
|
||||
CHASSIS_API gchar* show_long_query_time(gpointer param);
|
||||
CHASSIS_API gchar* show_enable_client_found_rows(gpointer param);
|
||||
CHASSIS_API gchar* show_reduce_connections(gpointer param);
|
||||
CHASSIS_API gchar* show_enable_query_cache(gpointer param);
|
||||
CHASSIS_API gchar* show_enable_tcp_stream(gpointer param);
|
||||
CHASSIS_API gchar* show_log_xa_in_detail(gpointer param);
|
||||
CHASSIS_API gchar* show_disable_dns_cache(gpointer param);
|
||||
CHASSIS_API gchar* show_master_preferred(gpointer param);
|
||||
CHASSIS_API gchar* show_max_allowed_packet(gpointer param);
|
||||
CHASSIS_API gchar* show_remote_conf_url(gpointer param);
|
||||
|
||||
/* assign utils */
|
||||
CHASSIS_API gint assign_log_level(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_default_charset(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_default_username(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_default_db(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_default_pool_size(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_max_pool_size(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_max_resp_len(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_max_alive_time(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_merged_output_size(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_max_header_size(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_slave_delay_recover(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_slave_delay_down(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_default_query_cache_timeout(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_long_query_time(const gchar *newval, gpointer param);
|
||||
CHASSIS_API gint assign_max_allowed_packet(const gchar *newval, gpointer param);
|
||||
|
||||
CHASSIS_API gint chassis_options_save(GKeyFile *keyfile, chassis_options_t *opts, chassis *chas);
|
||||
|
||||
#endif
|
@ -67,7 +67,12 @@ int
|
||||
chassis_option_set(chassis_option_t *opt,
|
||||
const char *long_name,
|
||||
gchar short_name,
|
||||
gint flags, enum option_type arg, gpointer arg_data, const char *description, const char *arg_desc)
|
||||
gint flags,
|
||||
enum option_type arg,
|
||||
gpointer arg_data,
|
||||
const char *description,
|
||||
const char *arg_desc,
|
||||
chas_opt_assign_hook assign_hook, chas_opt_show_hook show_hook, gint opt_property)
|
||||
{
|
||||
opt->long_name = long_name;
|
||||
opt->short_name = short_name;
|
||||
@ -76,6 +81,9 @@ chassis_option_set(chassis_option_t *opt,
|
||||
opt->arg_data = arg_data;
|
||||
opt->description = description;
|
||||
opt->arg_description = arg_desc;
|
||||
opt->assign_hook = assign_hook;
|
||||
opt->show_hook = show_hook;
|
||||
opt->opt_property = opt_property;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -181,14 +189,22 @@ int
|
||||
chassis_options_add(chassis_options_t *opts,
|
||||
const char *long_name,
|
||||
gchar short_name,
|
||||
int flags, enum option_type arg, gpointer arg_data, const char *description, const char *arg_desc)
|
||||
int flags,
|
||||
enum option_type arg,
|
||||
gpointer arg_data,
|
||||
const char *description,
|
||||
const char *arg_desc,
|
||||
chas_opt_assign_hook assign_hook, chas_opt_show_hook show_hook, gint opt_property)
|
||||
{
|
||||
chassis_option_t *opt = chassis_option_new();
|
||||
if (0 != chassis_option_set(opt,
|
||||
long_name,
|
||||
short_name,
|
||||
flags,
|
||||
arg, arg_data, description, arg_desc) || 0 != chassis_options_add_option(opts, opt)) {
|
||||
arg,
|
||||
arg_data,
|
||||
description,
|
||||
arg_desc, assign_hook, show_hook, opt_property) || 0 != chassis_options_add_option(opts, opt)) {
|
||||
chassis_option_free(opt);
|
||||
return -1;
|
||||
} else {
|
||||
|
@ -23,6 +23,14 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
struct external_param {
|
||||
struct chassis *chas;
|
||||
gint opt_type;
|
||||
};
|
||||
|
||||
typedef gint (*chas_opt_assign_hook)(const gchar *newval, gpointer param);
|
||||
typedef gchar* (*chas_opt_show_hook)(gpointer param);
|
||||
|
||||
enum option_type { // arg_data type
|
||||
OPTION_ARG_NONE, // bool *
|
||||
OPTION_ARG_INT, // int *
|
||||
@ -56,6 +64,10 @@ typedef struct {
|
||||
enum option_type arg;
|
||||
enum option_flags flags;
|
||||
gchar short_name;
|
||||
|
||||
chas_opt_assign_hook assign_hook;
|
||||
chas_opt_show_hook show_hook;
|
||||
gint opt_property;
|
||||
} chassis_option_t;
|
||||
|
||||
/**
|
||||
@ -67,7 +79,11 @@ int chassis_option_set(chassis_option_t *opt,
|
||||
const char *long_name,
|
||||
gchar short_name,
|
||||
gint flags,
|
||||
enum option_type arg, gpointer arg_data, const char *description, const char *arg_desc);
|
||||
enum option_type arg,
|
||||
gpointer arg_data,
|
||||
const char *description,
|
||||
const char *arg_desc,
|
||||
chas_opt_assign_hook assign_hook, chas_opt_show_hook show_hook, gint opt_property);
|
||||
/**
|
||||
* @return newly allocated string, need to be freed
|
||||
*/
|
||||
@ -98,7 +114,11 @@ int chassis_options_add(chassis_options_t *opts,
|
||||
const char *long_name,
|
||||
gchar short_name,
|
||||
int flags,
|
||||
enum option_type arg, gpointer arg_data, const char *description, const char *arg_desc);
|
||||
enum option_type arg,
|
||||
gpointer arg_data,
|
||||
const char *description,
|
||||
const char *arg_desc,
|
||||
chas_opt_assign_hook assign_hook, chas_opt_show_hook show_hook, gint opt_property);
|
||||
|
||||
chassis_option_t *chassis_options_get(GList *opts, const char *long_name);
|
||||
|
||||
|
@ -48,6 +48,8 @@
|
||||
#include <glib.h>
|
||||
#include <gmodule.h>
|
||||
|
||||
#include "chassis-options-utils.h"
|
||||
|
||||
#ifdef HAVE_VALGRIND_VALGRIND_H
|
||||
#include <valgrind/valgrind.h>
|
||||
#endif
|
||||
@ -216,184 +218,225 @@ chassis_frontend_set_chassis_options(struct chassis_frontend_t *frontend, chassi
|
||||
chassis_options_add(opts,
|
||||
"verbose-shutdown",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->verbose_shutdown),
|
||||
"Always log the exit code when shutting down", NULL);
|
||||
"Always log the exit code when shutting down", NULL,
|
||||
NULL, show_verbose_shutdown, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts, "daemon", 0, 0, OPTION_ARG_NONE, &(frontend->daemon_mode), "Start in daemon-mode", NULL);
|
||||
chassis_options_add(opts, "daemon", 0, 0, OPTION_ARG_NONE, &(frontend->daemon_mode), "Start in daemon-mode", NULL,
|
||||
NULL, show_daemon_mode, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts, "user", 0, 0, OPTION_ARG_STRING, &(frontend->user), "Run cetus as user", "<user>");
|
||||
chassis_options_add(opts, "user", 0, 0, OPTION_ARG_STRING, &(frontend->user), "Run cetus as user", "<user>",
|
||||
NULL, show_user, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"basedir",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->base_dir),
|
||||
"Base directory to prepend to relative paths in the config", "<absolute path>");
|
||||
"Base directory to prepend to relative paths in the config", "<absolute path>",
|
||||
NULL, show_basedir, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"conf-dir",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->conf_dir), "Configuration directory", "<absolute path>");
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->conf_dir), "Configuration directory", "<absolute path>",
|
||||
NULL, show_confdir, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"pid-file",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->pid_file),
|
||||
"PID file in case we are started as daemon", "<file>");
|
||||
"PID file in case we are started as daemon", "<file>",
|
||||
NULL, show_pidfile, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"plugin-dir",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->plugin_dir), "Path to the plugins", "<path>");
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->plugin_dir), "Path to the plugins", "<path>",
|
||||
NULL, show_plugindir, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"plugins",
|
||||
0, 0, OPTION_ARG_STRING_ARRAY, &(frontend->plugin_names), "Plugins to load", "<name>");
|
||||
0, 0, OPTION_ARG_STRING_ARRAY, &(frontend->plugin_names), "Plugins to load", "<name>",
|
||||
NULL, show_plugins, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"log-level",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->log_level),
|
||||
"Log all messages of level ... or higher", "(error|warning|info|message|debug)");
|
||||
"Log all messages of level ... or higher", "(error|warning|info|message|debug)",
|
||||
assign_log_level, show_log_level, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"log-file",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->log_filename), "Log all messages in a file", "<file>");
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->log_filename), "Log all messages in a file", "<file>",
|
||||
NULL, show_log_file, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"log-xa-file",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->log_xa_filename),
|
||||
"Log all xa messages in a file", "<file>");
|
||||
"Log all xa messages in a file", "<file>",
|
||||
NULL, show_log_xa_file, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"log-backtrace-on-crash",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->invoke_dbg_on_crash),
|
||||
"Try to invoke debugger on crash", NULL);
|
||||
"Try to invoke debugger on crash", NULL,
|
||||
NULL, show_log_backtrace_on_crash, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"keepalive",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->auto_restart),
|
||||
"Try to restart the proxy if it crashed", NULL);
|
||||
"Try to restart the proxy if it crashed", NULL,
|
||||
NULL, show_keepalive, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"max-open-files",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->max_files_number),
|
||||
"Maximum number of open files (ulimit -n)", NULL);
|
||||
"Maximum number of open files (ulimit -n)", NULL,
|
||||
NULL, show_max_open_files, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"default-charset",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->default_charset),
|
||||
"Set the default character set for backends", "<string>");
|
||||
"Set the default character set for backends", "<string>",
|
||||
assign_default_charset, show_default_charset, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"default-username",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->default_username),
|
||||
"Set the default username for visiting backends", "<string>");
|
||||
"Set the default username for visiting backends", "<string>",
|
||||
assign_default_username, show_default_username, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"default-db",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->default_db),
|
||||
"Set the default db for visiting backends", "<string>");
|
||||
"Set the default db for visiting backends", "<string>",
|
||||
assign_default_db, show_default_db, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"default-pool-size",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->default_pool_size),
|
||||
"Set the default pool szie for visiting backends", "<integer>");
|
||||
"Set the default pool szie for visiting backends", "<integer>",
|
||||
assign_default_pool_size, show_default_pool_size, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"max-pool-size",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->max_pool_size),
|
||||
"Set the max pool szie for visiting backends", "<integer>");
|
||||
"Set the max pool szie for visiting backends", "<integer>",
|
||||
assign_max_pool_size, show_max_pool_size, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"max-resp-size",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->max_resp_len),
|
||||
"Set the max response size for one backend", "<integer>");
|
||||
"Set the max response size for one backend", "<integer>",
|
||||
assign_max_resp_len, show_max_resp_len, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"max-alive-time",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->max_alive_time),
|
||||
"Set the max alive time for server connection", "<integer>");
|
||||
"Set the max alive time for server connection", "<integer>",
|
||||
assign_max_alive_time, show_max_alive_time, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"merged-output-size",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->merged_output_size),
|
||||
"set the merged output size for tcp streaming", "<integer>");
|
||||
"set the merged output size for tcp streaming", "<integer>",
|
||||
assign_merged_output_size, show_merged_output_size, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"max-header-size",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->max_header_size),
|
||||
"set the max header size for tcp streaming", "<integer>");
|
||||
"set the max header size for tcp streaming", "<integer>",
|
||||
assign_max_header_size, show_max_header_size, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"worker_id",
|
||||
"worker-id",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->worker_id),
|
||||
"Set the worker id and the maximum value allowed is 63 and the min value is 1", "<integer>");
|
||||
"Set the worker id and the maximum value allowed is 63 and the min value is 1", "<integer>",
|
||||
NULL, show_worker_id, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"disable-threads",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->disable_threads), "Disable all threads creation", NULL);
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->disable_threads), "Disable all threads creation", NULL,
|
||||
NULL, show_disable_threads, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"enable-back-compress",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->is_back_compressed),
|
||||
"enable compression for backend interactions", NULL);
|
||||
"enable compression for backend interactions", NULL,
|
||||
NULL, show_enable_back_compress, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"enable-client-compress",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->is_client_compress_support),
|
||||
"enable compression for client interactions", NULL);
|
||||
"enable compression for client interactions", NULL,
|
||||
NULL, show_enable_client_compress, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"check-slave-delay",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->check_slave_delay),
|
||||
"Check ro backends with heartbeat", NULL);
|
||||
"Check ro backends with heartbeat", NULL,
|
||||
NULL, show_check_slave_delay, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"slave-delay-down",
|
||||
0, 0, OPTION_ARG_DOUBLE, &(frontend->slave_delay_down_threshold_sec),
|
||||
"Slave will be set down after reach this delay secondes", "<double>");
|
||||
"Slave will be set down after reach this delay secondes", "<double>",
|
||||
assign_slave_delay_down, show_slave_delay_down, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"slave-delay-recover",
|
||||
0, 0, OPTION_ARG_DOUBLE, &(frontend->slave_delay_recover_threshold_sec),
|
||||
"Slave will recover after below this delay secondes", "<double>");
|
||||
"Slave will recover after below this delay secondes", "<double>",
|
||||
assign_slave_delay_recover, show_slave_delay_recover, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"default-query-cache-timeout",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->default_query_cache_timeout),
|
||||
"default query cache timeout in ms", "<integer>");
|
||||
"default query cache timeout in ms", "<integer>",
|
||||
assign_default_query_cache_timeout, show_default_query_cache_timeout, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"long-query-time",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->long_query_time), "Long query time in ms", "<integer>");
|
||||
0, 0, OPTION_ARG_INT, &(frontend->long_query_time), "Long query time in ms", "<integer>",
|
||||
assign_long_query_time, show_long_query_time, ALL_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"enable-client-found-rows",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->set_client_found_rows), "Set client found rows flag", NULL);
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->set_client_found_rows), "Set client found rows flag", NULL,
|
||||
NULL, show_enable_client_found_rows, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"reduce-connections",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->is_reduce_conns),
|
||||
"Reduce connections when idle connection num is too high", NULL);
|
||||
"Reduce connections when idle connection num is too high", NULL,
|
||||
NULL, show_reduce_connections, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts, "enable-query-cache", 0, 0, OPTION_ARG_NONE, &(frontend->query_cache_enabled), "", NULL);
|
||||
chassis_options_add(opts, "enable-query-cache", 0, 0, OPTION_ARG_NONE, &(frontend->query_cache_enabled), "", NULL,
|
||||
NULL, show_enable_query_cache, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts, "enable-tcp-stream", 0, 0, OPTION_ARG_NONE, &(frontend->is_tcp_stream_enabled), "", NULL);
|
||||
chassis_options_add(opts, "enable-tcp-stream", 0, 0, OPTION_ARG_NONE, &(frontend->is_tcp_stream_enabled), "", NULL,
|
||||
NULL, show_enable_tcp_stream, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"log-xa-in-detail",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->xa_log_detailed), "log xa in detail", NULL);
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->xa_log_detailed), "log xa in detail", NULL,
|
||||
NULL, show_log_xa_in_detail, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"disable-dns-cache",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->disable_dns_cache),
|
||||
"Every new connection to backends will resolve domain name", NULL);
|
||||
"Every new connection to backends will resolve domain name", NULL,
|
||||
NULL, show_disable_dns_cache, SHOW_OPTS_PROPERTY);
|
||||
|
||||
chassis_options_add(opts,
|
||||
"master-preferred",
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->master_preferred), "Access to master preferentially", NULL);
|
||||
0, 0, OPTION_ARG_NONE, &(frontend->master_preferred), "Access to master preferentially", NULL,
|
||||
NULL, show_master_preferred, SHOW_OPTS_PROPERTY);
|
||||
chassis_options_add(opts,
|
||||
"max-allowed-packet",
|
||||
0, 0, OPTION_ARG_INT, &(frontend->cetus_max_allowed_packet),
|
||||
"Max allowed packet as in mysql", "<int>");
|
||||
"Max allowed packet as in mysql", "<int>",
|
||||
assign_max_allowed_packet, show_max_allowed_packet, ALL_OPTS_PROPERTY);
|
||||
chassis_options_add(opts,
|
||||
"remote-conf-url",
|
||||
0, 0, OPTION_ARG_STRING, &(frontend->remote_config_url),
|
||||
"Remote config url, mysql://xx", "<string>");
|
||||
"Remote config url, mysql://xx", "<string>",
|
||||
NULL, show_remote_conf_url, SHOW_OPTS_PROPERTY);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -527,7 +570,7 @@ init_parameters(struct chassis_frontend_t *frontend, chassis *srv)
|
||||
srv->disable_dns_cache = frontend->disable_dns_cache;
|
||||
if (frontend->slave_delay_recover_threshold_sec > 0) {
|
||||
srv->slave_delay_recover_threshold_sec = frontend->slave_delay_recover_threshold_sec;
|
||||
if (frontend->slave_delay_recover_threshold_sec > srv->slave_delay_down_threshold_sec) {
|
||||
if (srv->slave_delay_recover_threshold_sec > srv->slave_delay_down_threshold_sec) {
|
||||
srv->slave_delay_recover_threshold_sec = srv->slave_delay_down_threshold_sec;
|
||||
g_warning("`slave-delay-recover` should be lower than `slave-delay-down`.");
|
||||
g_warning("Set slave-delay-recover=%.3f", srv->slave_delay_down_threshold_sec);
|
||||
@ -581,6 +624,7 @@ resolve_path(chassis *srv, struct chassis_frontend_t *frontend)
|
||||
g_free(frontend->pid_file);
|
||||
frontend->pid_file = new_path;
|
||||
}
|
||||
srv->pid_file = g_strdup(frontend->pid_file);
|
||||
|
||||
new_path = chassis_resolve_path(srv->base_dir, frontend->plugin_dir);
|
||||
if (new_path && new_path != frontend->plugin_dir) {
|
||||
@ -687,14 +731,17 @@ main_cmdline(int argc, char **argv)
|
||||
*
|
||||
* leave the unknown options in the list
|
||||
*/
|
||||
|
||||
if (chassis_frontend_init_base_options(&argc, &argv, &(frontend->print_version), &(frontend->default_file), &gerr)) {
|
||||
g_critical("%s: %s", G_STRLOC, gerr->message);
|
||||
g_clear_error(&gerr);
|
||||
|
||||
GOTO_EXIT(EXIT_FAILURE);
|
||||
}
|
||||
srv->print_version = frontend->print_version;
|
||||
|
||||
if (frontend->default_file) {
|
||||
srv->default_file = g_strdup(frontend->default_file);
|
||||
if (!(frontend->keyfile = chassis_frontend_open_config_file(frontend->default_file, &gerr))) {
|
||||
g_critical("%s: loading config from '%s' failed: %s", G_STRLOC, frontend->default_file, gerr->message);
|
||||
g_clear_error(&gerr);
|
||||
@ -722,6 +769,10 @@ main_cmdline(int argc, char **argv)
|
||||
GOTO_EXIT(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
srv->verbose_shutdown = frontend->verbose_shutdown;
|
||||
|
||||
srv->is_reduce_conns = frontend->is_reduce_conns;
|
||||
|
||||
if (frontend->keyfile) {
|
||||
if (FALSE == chassis_keyfile_to_options_with_error(frontend->keyfile, "cetus", opts->options, &gerr)) {
|
||||
g_critical("%s", gerr->message);
|
||||
@ -730,7 +781,8 @@ main_cmdline(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (frontend->remote_config_url) {
|
||||
srv->config_manager = chassis_config_from_url(frontend->remote_config_url);
|
||||
srv->remote_config_url = g_strdup(frontend->remote_config_url);
|
||||
srv->config_manager = chassis_config_from_url(srv->remote_config_url);
|
||||
if (!srv->config_manager) {
|
||||
g_critical("remote config init error");
|
||||
GOTO_EXIT(EXIT_FAILURE);
|
||||
@ -752,7 +804,9 @@ main_cmdline(int argc, char **argv)
|
||||
sigemptyset(&sigsegv_sa.sa_mask);
|
||||
|
||||
frontend->invoke_dbg_on_crash = 1;
|
||||
if (frontend->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
|
||||
srv->invoke_dbg_on_crash = frontend->invoke_dbg_on_crash;
|
||||
|
||||
if (srv->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
|
||||
sigaction(SIGSEGV, &sigsegv_sa, NULL);
|
||||
}
|
||||
#endif
|
||||
@ -794,15 +848,17 @@ main_cmdline(int argc, char **argv)
|
||||
* just in case it is specified in the file
|
||||
*/
|
||||
if (frontend->log_level) {
|
||||
if (0 != chassis_log_set_level(log, frontend->log_level)) {
|
||||
g_critical("--log-level=... failed, level '%s' is unknown ", frontend->log_level);
|
||||
|
||||
GOTO_EXIT(EXIT_FAILURE);
|
||||
}
|
||||
srv->log_level = g_strdup(frontend->log_level);
|
||||
} else {
|
||||
/* if it is not set, use "critical" as default */
|
||||
log->min_lvl = G_LOG_LEVEL_CRITICAL;
|
||||
srv->log_level = g_strdup("critical");
|
||||
}
|
||||
if (0 != chassis_log_set_level(log, srv->log_level)) {
|
||||
g_critical("--log-level=... failed, level '%s' is unknown ", srv->log_level);
|
||||
|
||||
GOTO_EXIT(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
g_message("starting " PACKAGE_STRING);
|
||||
#ifdef CHASSIS_BUILD_TAG
|
||||
g_message("build revision: " CHASSIS_BUILD_TAG);
|
||||
@ -831,6 +887,19 @@ main_cmdline(int argc, char **argv)
|
||||
GOTO_EXIT(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
{
|
||||
gint i = 0;
|
||||
srv->plugin_names = g_new(char *, (srv->modules->len + 1));
|
||||
for (i = 0; frontend->plugin_names && frontend->plugin_names[i]; i++) {
|
||||
if (!g_strcmp0("", frontend->plugin_names[i])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
srv->plugin_names[i] = g_strdup(frontend->plugin_names[i]);
|
||||
}
|
||||
srv->plugin_names[i] = NULL;
|
||||
}
|
||||
|
||||
if (chassis_frontend_init_plugins(srv->modules,
|
||||
opts, srv->config_manager, &argc, &argv, frontend->keyfile, "cetus", &gerr)) {
|
||||
g_critical("%s: %s", G_STRLOC, gerr->message);
|
||||
@ -871,11 +940,14 @@ main_cmdline(int argc, char **argv)
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
if (frontend->daemon_mode) {
|
||||
srv->daemon_mode = frontend->daemon_mode;
|
||||
|
||||
if (srv->daemon_mode) {
|
||||
chassis_unix_daemonize();
|
||||
}
|
||||
|
||||
if (frontend->auto_restart) {
|
||||
srv->auto_restart = frontend->auto_restart;
|
||||
if (srv->auto_restart) {
|
||||
int child_exit_status = EXIT_SUCCESS; /* forward the exit-status of the child */
|
||||
int ret = chassis_unix_proc_keepalive(&child_exit_status);
|
||||
|
||||
@ -890,8 +962,8 @@ main_cmdline(int argc, char **argv)
|
||||
/* we are the child, go on */
|
||||
}
|
||||
}
|
||||
if (frontend->pid_file) {
|
||||
if (0 != chassis_frontend_write_pidfile(frontend->pid_file, &gerr)) {
|
||||
if (srv->pid_file) {
|
||||
if (0 != chassis_frontend_write_pidfile(srv->pid_file, &gerr)) {
|
||||
g_critical("%s", gerr->message);
|
||||
g_clear_error(&gerr);
|
||||
|
||||
@ -925,15 +997,16 @@ main_cmdline(int argc, char **argv)
|
||||
if (!frontend->log_xa_filename)
|
||||
frontend->log_xa_filename = g_strdup("logs/xa.log");
|
||||
|
||||
char *new_path = chassis_resolve_path(srv->base_dir, frontend->log_xa_filename);
|
||||
if (new_path && new_path != frontend->log_xa_filename) {
|
||||
g_free(frontend->log_xa_filename);
|
||||
frontend->log_xa_filename = new_path;
|
||||
srv->log_xa_filename = g_strdup(frontend->log_xa_filename);
|
||||
char *new_path = chassis_resolve_path(srv->base_dir, srv->log_xa_filename);
|
||||
if (new_path && new_path != srv->log_xa_filename) {
|
||||
g_free(srv->log_xa_filename);
|
||||
srv->log_xa_filename = new_path;
|
||||
}
|
||||
|
||||
g_message("XA log file: %s", frontend->log_xa_filename);
|
||||
g_message("XA log file: %s", srv->log_xa_filename);
|
||||
|
||||
if (tc_log_init(frontend->log_xa_filename) == -1) {
|
||||
if (tc_log_init(srv->log_xa_filename) == -1) {
|
||||
GOTO_EXIT(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
@ -944,10 +1017,11 @@ main_cmdline(int argc, char **argv)
|
||||
GOTO_EXIT(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (frontend->max_files_number) {
|
||||
if (0 != chassis_fdlimit_set(frontend->max_files_number)) {
|
||||
srv->max_files_number = frontend->max_files_number;
|
||||
if (srv->max_files_number) {
|
||||
if (0 != chassis_fdlimit_set(srv->max_files_number)) {
|
||||
g_critical("%s: setting fdlimit = %d failed: %s (%d)",
|
||||
G_STRLOC, frontend->max_files_number, g_strerror(errno), errno);
|
||||
G_STRLOC, srv->max_files_number, g_strerror(errno), errno);
|
||||
GOTO_EXIT(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@ -982,13 +1056,13 @@ main_cmdline(int argc, char **argv)
|
||||
if (frontend && !frontend->print_version) {
|
||||
/* add a tag to the logfile */
|
||||
g_log(G_LOG_DOMAIN,
|
||||
(frontend->verbose_shutdown ? G_LOG_LEVEL_CRITICAL : G_LOG_LEVEL_MESSAGE),
|
||||
(srv->verbose_shutdown ? G_LOG_LEVEL_CRITICAL : G_LOG_LEVEL_MESSAGE),
|
||||
"shutting down normally, exit code is: %d", exit_code);
|
||||
}
|
||||
#ifdef HAVE_SIGACTION
|
||||
/* reset the handler */
|
||||
sigsegv_sa.sa_handler = SIG_DFL;
|
||||
if (frontend && frontend->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
|
||||
if (frontend && srv->invoke_dbg_on_crash && !(RUNNING_ON_VALGRIND)) {
|
||||
sigaction(SIGSEGV, &sigsegv_sa, NULL);
|
||||
}
|
||||
#endif
|
||||
|
@ -4365,6 +4365,8 @@ proxy_self_create_auth(chassis *srv, server_connection_state_t *con)
|
||||
auth->client_capabilities &= ~CLIENT_FOUND_ROWS;
|
||||
}
|
||||
|
||||
auth->client_capabilities &= ~CLIENT_PLUGIN_AUTH;
|
||||
|
||||
auth->max_packet_size = 0x01000000;
|
||||
auth->charset = con->charset_code;
|
||||
con->is_multi_stmt_set = 1;
|
||||
|
@ -172,7 +172,6 @@ do_read_auth(network_mysqld_con *con, GHashTable *allow_ip_table, GHashTable *de
|
||||
g_hash_table_lookup(deny_ip_table, client_ip_with_username)) {
|
||||
check_ip = TRUE;
|
||||
ip_err_msg = g_strdup_printf("Access denied for user '%s'@'%s'", client_username, client_ip);
|
||||
//g_debug("Allow IP check failed: '%s'@'%s'", client_username, client_ip);
|
||||
} else {
|
||||
check_ip = FALSE;
|
||||
}
|
||||
@ -187,6 +186,11 @@ do_read_auth(network_mysqld_con *con, GHashTable *allow_ip_table, GHashTable *de
|
||||
}
|
||||
|
||||
const char *client_charset = charset_get_name(auth->charset);
|
||||
if (client_charset == NULL) {
|
||||
client_charset = con->srv->default_charset;
|
||||
auth->charset = charset_get_number(client_charset);
|
||||
}
|
||||
|
||||
recv_sock->charset_code = auth->charset;
|
||||
g_string_assign(recv_sock->charset, client_charset);
|
||||
g_string_assign(recv_sock->charset_client, client_charset);
|
||||
|
Loading…
Reference in New Issue
Block a user