From 89b2ac92bec9b3e46cc2cb898048e441d23a4eef Mon Sep 17 00:00:00 2001 From: lazio579 Date: Fri, 26 Apr 2019 09:33:49 +0800 Subject: [PATCH] Fix multi insert related problems --- plugins/shard/shard-plugin.c | 26 ++++++++++++++++++++++++++ src/sharding-query-plan.c | 17 +++++++++++++++++ src/sharding-query-plan.h | 1 + 3 files changed, 44 insertions(+) diff --git a/plugins/shard/shard-plugin.c b/plugins/shard/shard-plugin.c index 9e7db93..0346a5f 100644 --- a/plugins/shard/shard-plugin.c +++ b/plugins/shard/shard-plugin.c @@ -988,6 +988,18 @@ before_get_server_list(network_mysqld_con *con) } con->dist_tran_xa_start_generated = 0; } + + if (con->sharding_plan) { + if (con->servers == NULL || con->servers->len == 0) { + if (con->sharding_plan) { + sharding_plan_free(con->sharding_plan); + g_debug("%s: call sharding_plan_free here:%p", G_STRLOC, con); + con->sharding_plan = NULL; + } + } else { + sharding_plan_free_map(con->sharding_plan); + } + } } static void @@ -1162,6 +1174,13 @@ make_first_decision(network_mysqld_con *con, sharding_plan_t *plan, int *rv, int return 0; case USE_PREVIOUS_WARNING_CONN: + if (con->sharding_plan == NULL) { + con->client->is_server_conn_reserved = 0; + *disp_flag = PROXY_SEND_RESULT; + network_mysqld_con_send_ok_full(con->client, 0, 0, 0, 0); + g_warning("%s: origin has no sharding plan yet", G_STRLOC); + return 0; + } sharding_plan_free(plan); if (con->last_warning_met) { con->use_all_prev_servers = 1; @@ -1184,6 +1203,13 @@ make_first_decision(network_mysqld_con *con, sharding_plan_t *plan, int *rv, int } break; case USE_PREVIOUS_TRAN_CONNS: + if (con->sharding_plan == NULL) { + con->client->is_server_conn_reserved = 0; + *disp_flag = PROXY_SEND_RESULT; + network_mysqld_con_send_ok_full(con->client, 0, 0, 0, 0); + g_warning("%s: origin has no sharding plan yet", G_STRLOC); + return 0; + } if (!process_rv_use_previous_tran_conns(con, plan, rv, disp_flag)) { return 0; } diff --git a/src/sharding-query-plan.c b/src/sharding-query-plan.c index ca9ee5b..c4fd100 100644 --- a/src/sharding-query-plan.c +++ b/src/sharding-query-plan.c @@ -49,6 +49,23 @@ sharding_plan_free(sharding_plan_t *plan) g_free(plan); } +void +sharding_plan_free_map(sharding_plan_t *plan) +{ + if (plan->sql_list) { + g_list_free_full(plan->sql_list, g_string_true_free); + plan->sql_list = NULL; + } + if (plan->mapping) { + GList *l = plan->mapping; + for (; l != NULL; l = l->next) { + g_free(l->data); + } + g_list_free(plan->mapping); + plan->mapping = NULL; + } +} + static struct _group_sql_pair * sharding_plan_get_mapping(sharding_plan_t *plan, const GString *gp) { diff --git a/src/sharding-query-plan.h b/src/sharding-query-plan.h index 4e090ce..f136a32 100644 --- a/src/sharding-query-plan.h +++ b/src/sharding-query-plan.h @@ -52,6 +52,7 @@ typedef struct sharding_plan_t { sharding_plan_t *sharding_plan_new(const GString *orig_sql); void sharding_plan_free(sharding_plan_t *); +void sharding_plan_free_map(sharding_plan_t *); void sharding_plan_set_modified_sql(sharding_plan_t *, GString *sql);