Commit 49a4bbe1 authored by Kentoku SHIBA's avatar Kentoku SHIBA

Add spider_general_log and spider_log_result_errors feature.

parent e1fc2f4d
......@@ -77,6 +77,8 @@ struct hstcpcli : public hstcpcli_i, private noncopyable {
virtual size_t get_response_end_offset() { return response_end_offset; }
virtual const char *get_readbuf_begin() { return readbuf.begin(); }
virtual const char *get_readbuf_end() { return readbuf.end(); }
virtual const char *get_writebuf_begin() { return writebuf.begin(); }
virtual size_t get_writebuf_size() { return writebuf.size(); }
virtual void write_error_to_log(const char *func_name, const char *file_name,
ulong line_no);
private:
......
......@@ -82,6 +82,8 @@ struct hstcpcli_i {
virtual size_t get_response_end_offset() = 0;
virtual const char *get_readbuf_begin() = 0;
virtual const char *get_readbuf_end() = 0;
virtual const char *get_writebuf_begin() = 0;
virtual size_t get_writebuf_size() = 0;
virtual void write_error_to_log(const char *func_name, const char *file_name,
ulong line_no) = 0;
static hstcpcli_ptr create(const socket_args& args);
......
......@@ -682,6 +682,17 @@ int spider_db_errorno(
) {
push_warning(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
error_num, conn->db_conn->get_error());
if (spider_param_log_result_errors() >= 3)
{
time_t cur_time = (time_t) time((time_t*) 0);
struct tm lt;
struct tm *l_time = localtime_r(&cur_time, &lt);
fprintf(stderr, "%04d%02d%02d %02d:%02d:%02d [WARN SPIDER RESULT] "
"to %ld: %d %s\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
current_thd->thread_id, error_num, conn->db_conn->get_error());
}
if (!conn->mta_conn_mutex_unlock_later)
{
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
......@@ -691,6 +702,17 @@ int spider_db_errorno(
}
*conn->need_mon = error_num;
my_message(error_num, conn->db_conn->get_error(), MYF(0));
if (spider_param_log_result_errors() >= 1)
{
time_t cur_time = (time_t) time((time_t*) 0);
struct tm lt;
struct tm *l_time = localtime_r(&cur_time, &lt);
fprintf(stderr, "%04d%02d%02d %02d:%02d:%02d [ERROR SPIDER RESULT] "
"to %ld: %d %s\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
current_thd->thread_id, error_num, conn->db_conn->get_error());
}
if (!conn->mta_conn_mutex_unlock_later)
{
SPIDER_CLEAR_FILE_POS(&conn->mta_conn_mutex_file_pos);
......@@ -725,6 +747,18 @@ int spider_db_errorno(
}
my_printf_error(ER_SPIDER_HS_NUM, ER_SPIDER_HS_STR, MYF(0),
conn->db_conn->get_errno(), conn->db_conn->get_error());
if (spider_param_log_result_errors() >= 1)
{
time_t cur_time = (time_t) time((time_t*) 0);
struct tm lt;
struct tm *l_time = localtime_r(&cur_time, &lt);
fprintf(stderr, "%04d%02d%02d %02d:%02d:%02d [ERROR SPIDER RESULT] "
"to %ld: %d %s\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
current_thd->thread_id, conn->db_conn->get_errno(),
conn->db_conn->get_error());
}
*conn->need_mon = ER_SPIDER_HS_NUM;
if (!conn->mta_conn_mutex_unlock_later)
{
......
......@@ -1061,6 +1061,24 @@ int spider_db_handlersocket::exec_query(
(*hs_conn_p)->get_num_req_rcvd()));
DBUG_PRINT("info",("spider hs response_end_offset=%zu",
(*hs_conn_p)->get_response_end_offset()));
if (spider_param_general_log())
{
const char *tgt_str = conn->hs_sock ? conn->hs_sock : conn->tgt_host;
uint32 tgt_len = strlen(tgt_str);
spider_string tmp_query_str((*hs_conn_p)->get_writebuf_size() +
conn->tgt_wrapper_length +
tgt_len + (SPIDER_SQL_SPACE_LEN * 2));
tmp_query_str.init_calc_mem(231);
tmp_query_str.length(0);
tmp_query_str.q_append(conn->tgt_wrapper, conn->tgt_wrapper_length);
tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
tmp_query_str.q_append(tgt_str, tgt_len);
tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
tmp_query_str.q_append((*hs_conn_p)->get_writebuf_begin(),
(*hs_conn_p)->get_writebuf_size());
general_log_write(current_thd, COM_QUERY, tmp_query_str.ptr(),
tmp_query_str.length());
}
if ((*hs_conn_p)->request_send() < 0)
{
DBUG_PRINT("info",("spider hs num_req_bufd=%zu",
......
......@@ -1475,9 +1475,54 @@ int spider_db_mysql::exec_query(
uint length,
int quick_mode
) {
int error_num;
DBUG_ENTER("spider_db_mysql::exec_query");
DBUG_PRINT("info",("spider this=%p", this));
DBUG_RETURN(mysql_real_query(db_conn, query, length));
if (spider_param_general_log())
{
const char *tgt_str = conn->tgt_host;
uint32 tgt_len = conn->tgt_host_length;
spider_string tmp_query_str(length + conn->tgt_wrapper_length +
tgt_len + (SPIDER_SQL_SPACE_LEN * 2));
tmp_query_str.init_calc_mem(230);
tmp_query_str.length(0);
tmp_query_str.q_append(conn->tgt_wrapper, conn->tgt_wrapper_length);
tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
tmp_query_str.q_append(tgt_str, tgt_len);
tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
tmp_query_str.q_append(query, length);
general_log_write(current_thd, COM_QUERY, tmp_query_str.ptr(),
tmp_query_str.length());
}
error_num = mysql_real_query(db_conn, query, length);
if (spider_param_log_result_errors() >= 2 && db_conn->warning_count > 0)
{
time_t cur_time = (time_t) time((time_t*) 0);
struct tm lt;
struct tm *l_time = localtime_r(&cur_time, &lt);
fprintf(stderr, "%04d%02d%02d %02d:%02d:%02d [WARN SPIDER RESULT] "
"from [%s] %ld to %ld: "
"affected_rows: %llu id: %llu status: %u warning_count: %u\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
conn->tgt_host, db_conn->thread_id, current_thd->thread_id,
db_conn->affected_rows, db_conn->insert_id,
db_conn->server_status, db_conn->warning_count);
} else if (spider_param_log_result_errors() >= 4)
{
time_t cur_time = (time_t) time((time_t*) 0);
struct tm lt;
struct tm *l_time = localtime_r(&cur_time, &lt);
fprintf(stderr, "%04d%02d%02d %02d:%02d:%02d [INFO SPIDER RESULT] "
"from [%s] %ld to %ld: "
"affected_rows: %llu id: %llu status: %u warning_count: %u\n",
l_time->tm_year + 1900, l_time->tm_mon + 1, l_time->tm_mday,
l_time->tm_hour, l_time->tm_min, l_time->tm_sec,
conn->tgt_host, db_conn->thread_id, current_thd->thread_id,
db_conn->affected_rows, db_conn->insert_id,
db_conn->server_status, db_conn->warning_count);
}
DBUG_RETURN(error_num);
}
int spider_db_mysql::get_errno()
......
......@@ -1403,6 +1403,22 @@ int spider_db_oracle::exec_query(
int error_num;
DBUG_ENTER("spider_db_oracle::exec_query");
DBUG_PRINT("info",("spider this=%p", this));
if (spider_param_general_log())
{
const char *tgt_str = conn->tgt_host;
uint32 tgt_len = conn->tgt_host_length;
spider_string tmp_query_str(length + conn->tgt_wrapper_length +
tgt_len + (SPIDER_SQL_SPACE_LEN * 2));
tmp_query_str.init_calc_mem(232);
tmp_query_str.length(0);
tmp_query_str.q_append(conn->tgt_wrapper, conn->tgt_wrapper_length);
tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
tmp_query_str.q_append(tgt_str, tgt_len);
tmp_query_str.q_append(SPIDER_SQL_SPACE_STR, SPIDER_SQL_SPACE_LEN);
tmp_query_str.q_append(query, length);
general_log_write(current_thd, COM_QUERY, tmp_query_str.ptr(),
tmp_query_str.length());
}
stored_error_num = 0;
if (table_lock_mode && !conn->in_before_query)
{
......
......@@ -86,7 +86,7 @@
#define SPIDER_TMP_SHARE_LONG_COUNT 15
#define SPIDER_TMP_SHARE_LONGLONG_COUNT 3
#define SPIDER_MEM_CALC_LIST_NUM 230
#define SPIDER_MEM_CALC_LIST_NUM 233
#define SPIDER_BACKUP_DASTATUS \
bool da_status; if (thd) da_status = thd->is_error(); else da_status = FALSE;
......
......@@ -2783,6 +2783,50 @@ int spider_param_udf_ds_use_real_table(
}
#endif
static my_bool spider_general_log;
static MYSQL_SYSVAR_BOOL(
general_log,
spider_general_log,
PLUGIN_VAR_OPCMDARG,
"Log query to remote server in general log",
NULL,
NULL,
FALSE
);
my_bool spider_param_general_log()
{
DBUG_ENTER("spider_param_general_log");
DBUG_RETURN(spider_general_log);
}
static uint spider_log_result_errors;
/*
0: no log
1: log error
2: log warning summary
3: log warning
4: log info
*/
static MYSQL_SYSVAR_UINT(
log_result_errors,
spider_log_result_errors,
PLUGIN_VAR_RQCMDARG,
"Log error from remote server in error log",
NULL,
NULL,
0,
0,
4,
0
);
uint spider_param_log_result_errors()
{
DBUG_ENTER("spider_param_log_result_errors");
DBUG_RETURN(spider_log_result_errors);
}
static struct st_mysql_storage_engine spider_storage_engine =
{ MYSQL_HANDLERTON_INTERFACE_VERSION };
......@@ -2908,6 +2952,8 @@ static struct st_mysql_sys_var* spider_system_variables[] = {
#else
MYSQL_SYSVAR(udf_ds_use_real_table),
#endif
MYSQL_SYSVAR(general_log),
MYSQL_SYSVAR(log_result_errors),
NULL
};
......
......@@ -368,3 +368,5 @@ int spider_param_udf_ds_use_real_table(
int udf_ds_use_real_table
);
#endif
my_bool spider_param_general_log();
uint spider_param_log_result_errors();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment