Fix group by without aggr fun problems and refactor SIMPLE_PARSER

This commit is contained in:
lazio579 2018-03-12 15:52:54 +08:00
parent 7fc21867bb
commit 0407ee84f2
8 changed files with 101 additions and 98 deletions

View File

@ -48,6 +48,7 @@ IF (ENABLE_GCOV AND NOT WIN32 AND NOT APPLE)
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage -lgcov")
ENDIF()
option(SIMPLE_PARSER "use the simple parser")
option(NETWORK_DEBUG_TRACE_IO "if NETWORK_DEBUG_TRACE_IO is defined, the network layer will log the raw MySQL packets as log-level debug")
option(NETWORK_DEBUG_TRACE_EVENT "if NETWORK_DEBUG_TRACE_EVENT is defined, cetus will log the abnormal event")

View File

@ -42,6 +42,7 @@
#cmakedefine HAVE_OPENSSL
#define SIZEOF_RLIM_T @SIZEOF_RLIM_T@
#cmakedefine SIMPLE_PARSER 1
#cmakedefine NETWORK_DEBUG_TRACE_IO 1
#cmakedefine NETWORK_DEBUG_TRACE_STATE_CHANGES 1
#cmakedefine USE_GLIB_DEBUG_LOG 1

View File

@ -34,7 +34,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ## for the packaged header file
#lemon bin
add_executable(lemon ${CETUS_TOOLS_DIR}/lemon.c)
option(SIMPLE_PARSER "use the simple parser")
#option(SIMPLE_PARSER "use the simple parser")
if(SIMPLE_PARSER)
message("** Using simple parser [-DSIMPLE_PARSER=ON]")
set(LEMON_GRAMMAR_FILE "${CMAKE_CURRENT_SOURCE_DIR}/simple-parser.y")

View File

@ -401,77 +401,76 @@ static int admin_send_backend_detail_info(network_mysqld_con *admin_con, const c
continue;
}
if (chas->sharding_mode) {
if (con->servers == NULL) {
#ifndef SIMPLE_PARSER
if (con->servers == NULL) {
continue;
}
for (j = 0; j < con->servers->len; j++) {
server_session_t *pmd = g_ptr_array_index(con->servers, j);
GHashTable *table = g_hash_table_lookup(back_user_conn_hash_table,
pmd->backend->addr->name->str);
if (table == NULL) {
g_warning("%s: table is null for backend:%s", G_STRLOC,
pmd->backend->addr->name->str);
continue;
}
for (j = 0; j < con->servers->len; j++) {
server_session_t *pmd = g_ptr_array_index(con->servers, j);
GHashTable *table = g_hash_table_lookup(back_user_conn_hash_table,
pmd->backend->addr->name->str);
if (table == NULL) {
g_warning("%s: table is null for backend:%s", G_STRLOC,
pmd->backend->addr->name->str);
continue;
}
used_conns_t *total_used = g_hash_table_lookup(table,
con->client->response->username->str);
if (total_used == NULL) {
total_used = g_new0(used_conns_t, 1);
g_hash_table_insert(table,
g_strdup(con->client->response->username->str), total_used);
}
total_used->num++;
}
} else {
if (con->servers != NULL) {
for (j = 0; j < con->servers->len; j++) {
network_socket *sock = g_ptr_array_index(con->servers, j);
GHashTable *table = g_hash_table_lookup(back_user_conn_hash_table,
sock->dst->name->str);
if (table == NULL) {
g_warning("%s: table is null for backend:%s", G_STRLOC,
sock->dst->name->str);
continue;
}
used_conns_t *total_used = g_hash_table_lookup(table,
con->client->response->username->str);
if (total_used == NULL) {
total_used = g_new0(used_conns_t, 1);
g_hash_table_insert(table,
g_strdup(con->client->response->username->str), total_used);
}
total_used->num++;
}
} else {
if (con->server == NULL) {
continue;
}
GHashTable *table = g_hash_table_lookup(back_user_conn_hash_table,
con->server->dst->name->str);
if (table == NULL) {
g_warning("%s: table is null for backend:%s", G_STRLOC,
con->server->dst->name->str);
continue;
}
used_conns_t *total_used = g_hash_table_lookup(table,
con->client->response->username->str);
if (total_used == NULL) {
total_used = g_new0(used_conns_t, 1);
g_hash_table_insert(table,
g_strdup(con->client->response->username->str), total_used);
}
total_used->num++;
used_conns_t *total_used = g_hash_table_lookup(table,
con->client->response->username->str);
if (total_used == NULL) {
total_used = g_new0(used_conns_t, 1);
g_hash_table_insert(table,
g_strdup(con->client->response->username->str), total_used);
}
total_used->num++;
}
#else
if (con->servers != NULL) {
for (j = 0; j < con->servers->len; j++) {
network_socket *sock = g_ptr_array_index(con->servers, j);
GHashTable *table = g_hash_table_lookup(back_user_conn_hash_table,
sock->dst->name->str);
if (table == NULL) {
g_warning("%s: table is null for backend:%s", G_STRLOC,
sock->dst->name->str);
continue;
}
used_conns_t *total_used = g_hash_table_lookup(table,
con->client->response->username->str);
if (total_used == NULL) {
total_used = g_new0(used_conns_t, 1);
g_hash_table_insert(table,
g_strdup(con->client->response->username->str), total_used);
}
total_used->num++;
}
} else {
if (con->server == NULL) {
continue;
}
GHashTable *table = g_hash_table_lookup(back_user_conn_hash_table,
con->server->dst->name->str);
if (table == NULL) {
g_warning("%s: table is null for backend:%s", G_STRLOC,
con->server->dst->name->str);
continue;
}
used_conns_t *total_used = g_hash_table_lookup(table,
con->client->response->username->str);
if (total_used == NULL) {
total_used = g_new0(used_conns_t, 1);
g_hash_table_insert(table,
g_strdup(con->client->response->username->str), total_used);
}
total_used->num++;
}
#endif
}

View File

@ -109,7 +109,6 @@ struct chassis {
unsigned int auto_key;
unsigned int sess_key;
unsigned int maintain_close_mode;
unsigned int sharding_mode;
unsigned int config_remote;
unsigned int disable_threads;
unsigned int is_tcp_stream_enabled;

View File

@ -424,12 +424,12 @@ static void sigsegv_handler(int G_GNUC_UNUSED signum) {
static gboolean check_plugin_mode_valid(chassis_frontend_t *frontend, chassis *srv)
{
int i, proxy_mode = 0;
int i, proxy_mode = 0, sharding_mode = 0;
for (i = 0; frontend->plugin_names[i]; ++i) {
char *name = frontend->plugin_names[i];
if (strcmp(name, "shard") == 0) {
srv->sharding_mode = 1;
sharding_mode = 1;
g_message("set sharding mode true");
}
if (strcmp(name, "proxy") == 0) {
@ -437,7 +437,7 @@ static gboolean check_plugin_mode_valid(chassis_frontend_t *frontend, chassis *s
}
}
if (srv->sharding_mode && proxy_mode) {
if (sharding_mode && proxy_mode) {
g_critical("shard & proxy is mutual exclusive");
return FALSE;
}
@ -939,23 +939,23 @@ int main_cmdline(int argc, char **argv) {
init_parameters(frontend, srv);
if (srv->sharding_mode) {
if (!frontend->log_xa_filename)
frontend->log_xa_filename = g_strdup("logs/xa.log");
#ifndef SIMPLE_PARSER
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;
}
g_message("XA log file: %s", frontend->log_xa_filename);
if (tc_log_init(frontend->log_xa_filename) == -1) {
GOTO_EXIT(EXIT_FAILURE);
}
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;
}
g_message("XA log file: %s", frontend->log_xa_filename);
if (tc_log_init(frontend->log_xa_filename) == -1) {
GOTO_EXIT(EXIT_FAILURE);
}
#endif
if (frontend->max_files_number) {
if (0 != chassis_fdlimit_set(frontend->max_files_number)) {
g_critical("%s: setting fdlimit = %d failed: %s (%d)",

View File

@ -2563,17 +2563,19 @@ handle_send_query_to_servers(network_mysqld_con *con,
* this state will loop until all the packets
* from the send-queue are flushed
*/
if (con->srv->sharding_mode && con->servers != NULL) {
#ifndef SIMPLE_PARSER
g_message("%s: SIMPLE_PARSER true for con:%p", G_STRLOC, con);
if (con->servers != NULL) {
if (!process_shard_write(con, &disp_flag)) {
return disp_flag;
}
} else {/* RW-edition */
if (!process_rw_write(con, ostate, &disp_flag)) {
return disp_flag;
}
}
#else
g_message("%s: SIMPLE_PARSER false for con:%p", G_STRLOC, con);
if (!process_rw_write(con, ostate, &disp_flag)) {
return disp_flag;
}
#endif
return DISP_CONTINUE;
}
@ -4321,12 +4323,12 @@ static retval_t proxy_self_read_handshake(chassis *srv, server_connection_state_
return RET_ERROR;
}
if (con->srv->sharding_mode) {
if (challenge->server_version < 50707) {
g_warning("%s: for xa, server:%s, mysql version:%s is lower than 5.7.7",
G_STRLOC, recv_sock->dst->name->str, challenge->server_version_str);
}
#ifndef SIMPLE_PARSER
if (challenge->server_version < 50707) {
g_warning("%s: for xa, server:%s, mysql version:%s is lower than 5.7.7",
G_STRLOC, recv_sock->dst->name->str, challenge->server_version_str);
}
#endif
if (!con->srv->client_found_rows) {
challenge->capabilities &= ~(CLIENT_FOUND_ROWS);

View File

@ -1336,6 +1336,7 @@ static int
compare_records_from_column(char *str1, char *str2,
int com_type, int desc, int *result)
{
g_debug("%s: str1:%s, str2:%s", G_STRLOC, str1, str2);
int ret = 0;
if (str1[0] == '\0' && str2[0] != '\0') {
ret = -1;
@ -2983,7 +2984,7 @@ merge_for_select(sql_context_t *context, network_queue *send_queue, GPtrArray *r
con->data = data;
if (select->flags & SF_DISTINCT) {
if ((select->flags & SF_DISTINCT) || field_count == group_array_size) {
data->is_distinct = 1;
}