Fix multi insert related problems

This commit is contained in:
lazio579 2019-04-26 09:33:49 +08:00
parent ee159ebf32
commit 89b2ac92be
3 changed files with 44 additions and 0 deletions

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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);