Merge branch 'master' into multi-processes

This commit is contained in:
wangbin579 2018-08-14 17:08:46 +08:00
commit ffa21bc963
9 changed files with 77 additions and 28 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@ tests/
TAGS
edeProject.el
core
.cquery_cached_index/
# gtags file
GTAGS

View File

@ -60,11 +60,11 @@ Cetus增加了全量日志的功能即可以按需要输出经由Cetus的所
- sql-log-path
该参数可以指定全量日志输出的路径该值默认与basedir路径相同该参数不能动态配置。
该参数可以指定全量日志输出的路径该值默认与basedir/logs/路径相同,如果路径不存在,尝试创建该目录,该参数不能动态配置。
- sql-log-maxsize
该值控制每个全量日志的最大容量,默认值为0表示不限制文件大小单位是B该参数不能动态配置。如果当前日志量超过该值则会rotate成历史日志文件。
该值控制每个全量日志的最大容量,默认值为10240表示不限制文件大小单位是M该参数不能动态配置。如果当前日志量超过该值则会rotate成历史日志文件。
- sql-log-mode
@ -76,7 +76,7 @@ Cetus增加了全量日志的功能即可以按需要输出经由Cetus的所
- sql-log-maxnum
保留的历史文件的个数默认为0表示不限制文件个数。
保留的历史文件的个数,默认为30表示不限制文件个数。
#### 2.3 统计信息

View File

@ -2036,7 +2036,7 @@ void admin_sql_log_status(network_mysqld_con* con) {
cached = g_strdup("NULL");
}
APPEND_ROW_3_COL(rows, "sql-log-cached", cached, "Internal");
gchar *cursize = g_strdup_printf("%u", con->srv->sql_mgr->sql_log_cursize);
gchar *cursize = g_strdup_printf("%lu", con->srv->sql_mgr->sql_log_cursize);
APPEND_ROW_3_COL(rows, "sql-log-cursize", cursize, "Internal");
network_mysqld_con_send_resultset(con->client, fields, rows);

View File

@ -1670,6 +1670,9 @@ select_check_HAVING_column(sql_select_t *select)
gboolean found = FALSE; /* found having cond in columns */
int num_aggregate = 0;
const char *having_func = having->left->token_text;
if (!having_func) {
return FALSE;
}
sql_expr_list_t *columns = select->columns;
int i;
for (i = 0; columns && i < columns->len; ++i) {

View File

@ -23,6 +23,7 @@
#include "chassis-plugin.h"
#include "cetus-util.h"
#include "chassis-sql-log.h"
#include "network-backend.h"
#include <glib-ext.h>
#include <errno.h>
@ -414,6 +415,15 @@ assign_default_pool_size(const gchar *newval, gpointer param) {
value = 10;
}
srv->mid_idle_connections = value;
network_backends_t *bs = srv->priv->backends;
int back_num = network_backends_count(srv->priv->backends);
int loop = 0;
for (loop = 0; loop < back_num; loop++) {
network_backend_t *backend = network_backends_get(bs, loop);
network_connection_pool *pool = backend->pool;
pool->mid_idle_connections = srv->mid_idle_connections;
}
ret = ASSIGN_OK;
} else {
ret = ASSIGN_VALUE_INVALID;
@ -460,6 +470,15 @@ assign_max_pool_size(const gchar *newval, gpointer param) {
} else {
srv->max_idle_connections = srv->mid_idle_connections << 1;
}
network_backends_t *bs = srv->priv->backends;
int back_num = network_backends_count(srv->priv->backends);
int loop = 0;
for (loop = 0; loop < back_num; loop++) {
network_backend_t *backend = network_backends_get(bs, loop);
network_connection_pool *pool = backend->pool;
pool->max_idle_connections = srv->max_idle_connections;
}
ret = ASSIGN_OK;
} else {
ret = ASSIGN_VALUE_INVALID;
@ -1325,7 +1344,7 @@ gchar* show_sql_log_maxsize(gpointer param) {
chassis *srv = opt_param->chas;
gint opt_type = opt_param->opt_type;
if (CAN_SHOW_OPTS_PROPERTY(opt_type) || CAN_SAVE_OPTS_PROPERTY(opt_type)) {
return g_strdup_printf("%u", srv->sql_mgr->sql_log_maxsize);
return g_strdup_printf("%u M", srv->sql_mgr->sql_log_maxsize);
}
return NULL;
}
@ -1423,7 +1442,7 @@ show_sql_log_maxnum(gpointer param) {
return g_strdup_printf("%u", srv->sql_mgr->sql_log_maxnum);
}
if (CAN_SAVE_OPTS_PROPERTY(opt_type)) {
if (srv->sql_mgr->sql_log_idletime == 0) return NULL;
if (srv->sql_mgr->sql_log_maxnum == 3) return NULL;
return g_strdup_printf("%u", srv->sql_mgr->sql_log_maxnum);
}
return NULL;
@ -1437,10 +1456,14 @@ assign_sql_log_maxnum(const gchar *newval, gpointer param) {
gint opt_type = opt_param->opt_type;
if (CAN_ASSIGN_OPTS_PROPERTY(opt_type)) {
if (NULL != newval) {
guint value = 0;
gint value = 0;
if (try_get_int_value(newval, &value)) {
srv->sql_mgr->sql_log_maxnum = value;
ret = ASSIGN_OK;
if (value < 0) {
ret = ASSIGN_VALUE_INVALID;
} else {
srv->sql_mgr->sql_log_maxnum = value;
ret = ASSIGN_OK;
}
} else {
ret = ASSIGN_VALUE_INVALID;
}

View File

@ -2,6 +2,7 @@
#include "network-mysqld-packet.h"
#include <sys/stat.h>
#include <sys/types.h>
#include<unistd.h>
const COM_STRING com_command_name[]={
{ C("Sleep") },
@ -162,13 +163,13 @@ struct sql_log_mgr *sql_log_alloc() {
mgr->sql_log_mode = BACKEND;
mgr->sql_log_switch = OFF;
mgr->sql_log_cursize = 0;
mgr->sql_log_maxsize = 0;
mgr->sql_log_maxsize = 1024;
mgr->sql_log_fullname = NULL;
mgr->sql_log_idletime = SQL_LOG_DEF_IDLETIME;
mgr->sql_log_action = SQL_LOG_STOP;
mgr->fifo = NULL;
mgr->sql_log_filelist = NULL;
mgr->sql_log_maxnum = 0;
mgr->sql_log_maxnum = 3;
return mgr;
}
@ -236,7 +237,7 @@ static void sql_log_check_filenum(struct sql_log_mgr *mgr, gchar *filename) {
static void sql_log_check_rotate(struct sql_log_mgr *mgr) {
if (!mgr) return ;
if (mgr->sql_log_maxsize == 0) return;
if (mgr->sql_log_cursize < mgr->sql_log_maxsize) return ;
if (mgr->sql_log_cursize < ((gulong)mgr->sql_log_maxsize) * MEGABYTES) return ;
time_t t = time(NULL);
struct tm cur_tm;
@ -341,6 +342,14 @@ sql_log_thread_start(struct sql_log_mgr *mgr) {
if (mgr->sql_log_path == NULL) {
mgr->sql_log_path = g_strdup(SQL_LOG_DEF_PATH);
}
int result = access(mgr->sql_log_path, F_OK);
if (result != 0) {
g_message("sql log path is not exist, try to mkdir");
result = mkdir(mgr->sql_log_path, 0660);
if (result != 0) {
g_message("mkdir(%s) failed", mgr->sql_log_path);
}
}
if (mgr->sql_log_fullname == NULL) {
mgr->sql_log_fullname = g_strdup_printf("%s/%s.%s", mgr->sql_log_path, mgr->sql_log_filename, SQL_LOG_DEF_SUFFIX);
}

View File

@ -12,6 +12,7 @@
#define SQL_LOG_DEF_SUFFIX "sql"
#define SQL_LOG_DEF_PATH "/var/log/"
#define SQL_LOG_DEF_IDLETIME 500
#define MEGABYTES 1024*1024
#define min(a, b) ((a) < (b) ? (a) : (b))
@ -52,20 +53,21 @@ struct rfifo {
};
struct sql_log_mgr {
gchar *sql_log_filename;
guint sql_log_bufsize;
SQL_LOG_SWITCH sql_log_switch;
SQL_LOG_MODE sql_log_mode;
gchar *sql_log_path;
guint sql_log_maxsize;
gulong sql_log_cursize;
volatile guint sql_log_action;
volatile SQL_LOG_ACTION sql_log_idletime;
volatile guint sql_log_maxnum;
gchar *sql_log_filename;
gchar *sql_log_path;
GThread *thread;
FILE *sql_log_fp;
guint sql_log_cursize;
gchar *sql_log_fullname;
volatile guint sql_log_action;
struct rfifo *fifo;
GQueue *sql_log_filelist;
};

View File

@ -156,10 +156,10 @@ struct chassis_frontend_t {
gchar *sql_log_switch;
gchar *sql_log_filename;
gchar *sql_log_path;
guint sql_log_maxsize;
gint sql_log_maxsize;
gchar *sql_log_mode;
guint sql_log_idletime;
guint sql_log_maxnum;
gint sql_log_maxnum;
};
/**
@ -198,9 +198,10 @@ chassis_frontend_new(void)
frontend->sql_log_switch = NULL;
frontend->sql_log_filename = NULL;
frontend->sql_log_path = NULL;
frontend->sql_log_maxsize = 0;
frontend->sql_log_maxsize = -1;
frontend->sql_log_mode = NULL;
frontend->sql_log_idletime = 0;
frontend->sql_log_maxnum = -1;
return frontend;
}
@ -517,7 +518,7 @@ chassis_frontend_set_chassis_options(struct chassis_frontend_t *frontend, chassi
chassis_options_add(opts,
"sql-log-maxsize",
0, 0, OPTION_ARG_INT, &(frontend->sql_log_maxsize),
"the maxsize of sql file","<int>",
"the maxsize of sql file, units is M","<int>",
NULL, show_sql_log_maxsize, SHOW_OPTS_PROPERTY|SAVE_OPTS_PROPERTY);
chassis_options_add(opts,
"sql-log-mode",
@ -1164,9 +1165,12 @@ main_cmdline(int argc, char **argv)
if (frontend->sql_log_path) {
srv->sql_mgr->sql_log_path = g_strdup(frontend->sql_log_path);
} else if(frontend->base_dir) {
srv->sql_mgr->sql_log_path = g_strdup(frontend->base_dir);
srv->sql_mgr->sql_log_path = g_strdup_printf("%s/logs", frontend->base_dir);
}
srv->sql_mgr->sql_log_maxsize = frontend->sql_log_maxsize;
if (frontend->sql_log_maxsize >= 0) {
srv->sql_mgr->sql_log_maxsize = frontend->sql_log_maxsize;
}
if (frontend->sql_log_mode) {
if (strcasecmp(frontend->sql_log_mode, "CLIENT") == 0) {
srv->sql_mgr->sql_log_mode = CLIENT;
@ -1186,7 +1190,7 @@ main_cmdline(int argc, char **argv)
if (frontend->sql_log_idletime) {
srv->sql_mgr->sql_log_idletime = frontend->sql_log_idletime;
}
if (frontend->sql_log_maxnum) {
if (frontend->sql_log_maxnum >= 0) {
srv->sql_mgr->sql_log_maxnum = frontend->sql_log_maxnum;
}
}

View File

@ -1876,8 +1876,8 @@ disp_xa_abnormal_resultset(network_mysqld_con *con, server_session_t *ss,
} else if (con->dist_tran_state <= NEXT_ST_XA_ROLLBACK) {
if (ss->dist_tran_state < con->dist_tran_state) {
ss->dist_tran_state = con->dist_tran_state;
g_message("%s:adjust ss dist state:%d to %d", G_STRLOC, ss->dist_tran_state, con->dist_tran_state);
ss->dist_tran_state = con->dist_tran_state;
}
if (*is_xa_cmd_met) {
@ -2828,7 +2828,7 @@ shard_read_response(network_mysqld_con *con, server_session_t *ss)
break;
case NETWORK_SOCKET_ERROR:
default:
g_critical("%s:network_mysqld_read_mul_packets error", G_STRLOC);
g_critical("%s:network_mysqld_read_mul_packets error for con:%p", G_STRLOC, con);
con->num_read_pending--;
con->state = ST_ERROR;
return DISP_CONTINUE;
@ -2995,12 +2995,14 @@ check_server_status(network_mysqld_con *con, int *srv_down_count, int *srv_respo
server_session_t *ss = g_ptr_array_index(con->servers, i);
if (!ss->participated) {
g_debug("%s: server not participated", G_STRLOC);
g_debug("%s: server:%d is not participated for con:%p",
G_STRLOC, i, con);
continue;
}
network_socket *server = ss->server;
if (server->unavailable) {
g_debug("%s: server:%d is unavailable for con:%p", G_STRLOC, i, con);
(*srv_down_count)++;
continue;
}
@ -3079,9 +3081,13 @@ disp_resp_workers_not_matched(network_mysqld_con *con, int *disp_flag)
if (con->is_attr_adjust) {
g_critical("%s: attr adj met problems here for con:%p", G_STRLOC, con);
con->server_to_be_closed = 1;
} else if (con->is_timeout) {
g_critical("%s: server timeout for con:%p", G_STRLOC, con);
con->server_to_be_closed = 1;
} else {
if (con->dist_tran_state < NEXT_ST_XA_CANDIDATE_OVER) {
g_debug("%s: build xa stmt for failure, state:%d", G_STRLOC, con->state);
g_debug("%s: build xa stmt for failure, dist state:%d",
G_STRLOC, con->dist_tran_state);
build_xa_statements(con);
if (con->dist_tran_state != NEXT_ST_XA_OVER) {
*disp_flag = DISP_CONTINUE;
@ -3320,7 +3326,8 @@ disp_after_resp(network_mysqld_con *con, int srv_down_count, int srv_response_co
static int
handle_read_mul_servers_resp(network_mysqld_con *con)
{
g_debug("%s: visit handle_read_mul_servers_resp for con:%p", G_STRLOC, con);
g_debug("%s: visit handle_read_mul_servers_resp for con:%p, num pending:%d",
G_STRLOC, con, con->num_read_pending);
int disp_flag = 0;
int srv_down_count = 0, srv_response_count = 0;