Fix several issues related to groups

This commit is contained in:
lazio579 2019-01-15 13:54:53 +08:00
parent 3fa5bc437e
commit b11da73cb6
8 changed files with 42 additions and 20 deletions

View File

@ -2265,7 +2265,7 @@ void admin_create_vdb(network_mysqld_con* con, int id, GPtrArray* partitions,
}
}
chassis_private *g = con->srv->priv;
gboolean ok = sharding_vdb_is_valid(vdb, g->backends->groups->len)
gboolean ok = sharding_vdb_is_valid(con->srv->is_partition_mode, vdb, g->backends->groups->len)
&& shard_conf_add_vdb(vdb);
if (ok) {
g_message("Admin: %s", con->orig_sql->str);

View File

@ -2670,7 +2670,7 @@ network_mysqld_shard_plugin_apply_config(chassis *chas, chassis_plugin_config *c
char *shard_json = NULL;
gboolean ok = chassis_config_query_object(chas->config_manager,
"sharding", &shard_json, 0);
if (!ok || !shard_json || !shard_conf_load(shard_json, g->backends->groups->len)) {
if (!ok || !shard_json || !shard_conf_load(chas->is_partition_mode, shard_json, g->backends->groups->len)) {
g_critical("sharding configuration load error, exit program.");
exit(0);
}

View File

@ -1107,6 +1107,9 @@ main_cmdline(int argc, char **argv)
srv->ssl = frontend->ssl;
init_parameters(frontend, srv);
printf("partition mode here before init:%d\n", srv->is_partition_mode);
if (network_mysqld_init(srv) == -1) {
g_print("network_mysqld_init failed\n");
GOTO_EXIT(EXIT_FAILURE);
@ -1213,7 +1216,6 @@ main_cmdline(int argc, char **argv)
GOTO_EXIT(EXIT_FAILURE);
}
init_parameters(frontend, srv);
#ifndef SIMPLE_PARSER
if (!frontend->log_xa_filename)

View File

@ -208,6 +208,9 @@ network_backends_add(network_backends_t *bs, const gchar *address,
g_string_assign(new_backend->server_group, group_p + 1);
g_string_assign_len(new_backend->address, address, group_p - address);
} else {
if (bs->is_partition_mode) {
network_backends_add_group(bs, NULL);
}
g_string_assign(new_backend->address, address);
}
@ -423,8 +426,14 @@ network_backends_get_group(network_backends_t *bs, const GString *name)
int i = 0;
for (i = 0; i < bs->groups->len; ++i) {
network_group_t *group = g_ptr_array_index(bs->groups, i);
if (g_string_equal(group->name, name)) {
return group;
if (bs->is_partition_mode) {
if (strcmp(group->name->str, "super") == 0) {
return group;
}
} else {
if (g_string_equal(group->name, name)) {
return group;
}
}
}
return NULL;
@ -433,7 +442,13 @@ network_backends_get_group(network_backends_t *bs, const GString *name)
static void
network_backends_add_group(network_backends_t *bs, const char *name)
{
GString *gp_name = g_string_new(name);
GString *gp_name;
if (bs->is_partition_mode) {
gp_name = g_string_new("super");
} else {
gp_name = g_string_new(name);
}
if (!network_backends_get_group(bs, gp_name)) { /* dup check */
network_group_t *gp = network_group_new(gp_name);
g_ptr_array_add(bs->groups, gp);

View File

@ -95,6 +95,7 @@ NETWORK_API int network_backend_conns_count(network_backend_t *b);
NETWORK_API int network_backend_init_extra(network_backend_t *b, chassis *chas);
typedef struct {
int is_partition_mode;
unsigned int ro_server_num;
unsigned int read_count;
GPtrArray *backends;

View File

@ -192,7 +192,7 @@ plugin_call_timeout(chassis *srv, network_mysqld_con *con)
}
chassis_private *
network_mysqld_priv_init(void)
network_mysqld_priv_init(int is_partition_mode)
{
chassis_private *priv;
@ -200,6 +200,7 @@ network_mysqld_priv_init(void)
priv->cons = g_ptr_array_new();
priv->backends = network_backends_new();
priv->backends->is_partition_mode = is_partition_mode;
priv->users = cetus_users_new();
priv->monitor = cetus_monitor_new();
priv->acl = cetus_acl_new();
@ -265,7 +266,7 @@ network_mysqld_init(chassis *srv)
srv->priv_free = network_mysqld_priv_free;
srv->priv_shutdown = network_mysqld_priv_shutdown;
srv->priv_finally_free_shared = network_mysqld_priv_finally_free_shared;
srv->priv = network_mysqld_priv_init();
srv->priv = network_mysqld_priv_init(srv->is_partition_mode);
cetus_users_read_json(srv->priv->users, srv->config_manager, 0);
cetus_variables_init_stats(&srv->priv->stats_variables, srv);
@ -2342,7 +2343,7 @@ disp_query_after_consistant_attr(network_mysqld_con *con)
}
}
void log_slowquery(int interval_ms, char*ip, char* domain, char* user, char* sql)
void log_slowquery(int interval_ms, char* ip, char* domain, char* user, char* sql)
{
uint64_t usec;
struct timeval t;

View File

@ -239,11 +239,14 @@ void sharding_vdb_free(sharding_vdb_t *vdb)
g_free(vdb);
}
gboolean sharding_vdb_is_valid(sharding_vdb_t *vdb, int num_groups)
gboolean sharding_vdb_is_valid(int is_partition_mode, sharding_vdb_t *vdb, int num_groups)
{
if (vdb->partitions->len != num_groups) {
g_critical("vdb-%d partition count not equal to number of groups", vdb->id);
return FALSE;
if (!is_partition_mode) {
if (vdb->partitions->len != num_groups) {
g_critical("vdb-%d partition count not equal to number of groups, vdb partition len:%d, groups:%d",
vdb->id, vdb->partitions->len, num_groups);
return FALSE;
}
}
if (vdb->method == SHARD_METHOD_HASH) {
if (vdb->logic_shard_num <= 0 || vdb->logic_shard_num > MAX_HASH_VALUE_COUNT) {
@ -488,7 +491,7 @@ string_list_distinct_append(GList *strlist, const GString *str)
* setup index & validate configurations
*/
static gboolean
shard_conf_try_setup(GList *vdbs, GList *tables, GList *single_tables, int num_groups)
shard_conf_try_setup(int is_partition_mode, GList *vdbs, GList *tables, GList *single_tables, int num_groups)
{
if (!vdbs || !tables) {
g_critical("empty vdb/table list");
@ -497,7 +500,7 @@ shard_conf_try_setup(GList *vdbs, GList *tables, GList *single_tables, int num_g
GList *l = vdbs;
for (; l != NULL; l = l->next) {
sharding_vdb_t *vdb = l->data;
if (!sharding_vdb_is_valid(vdb, num_groups)) {
if (!sharding_vdb_is_valid(is_partition_mode, vdb, num_groups)) {
g_warning("invalid vdb config");
return FALSE;
}
@ -559,7 +562,7 @@ shard_conf_destroy(void)
static GHashTable *load_shard_from_json(gchar *json_str);
gboolean
shard_conf_load(char *json_str, int num_groups)
shard_conf_load(int partition_mode, char *json_str, int num_groups)
{
GHashTable *ht = load_shard_from_json(json_str);
if (!ht)
@ -568,7 +571,7 @@ shard_conf_load(char *json_str, int num_groups)
GList *tables = g_hash_table_lookup(ht, "table_list");
GList *vdbs = g_hash_table_lookup(ht, "vdb_list");
GList *single_tables = g_hash_table_lookup(ht, "single_tables");
gboolean success = shard_conf_try_setup(vdbs, tables, single_tables, num_groups);
gboolean success = shard_conf_try_setup(partition_mode, vdbs, tables, single_tables, num_groups);
if (!success) {
g_list_free_full(vdbs, (GDestroyNotify) sharding_vdb_free);
g_list_free_full(tables, (GDestroyNotify) sharding_table_free);
@ -923,7 +926,7 @@ load_shard_from_json(gchar *json_str)
{
cJSON *root = cJSON_Parse(json_str);
if (!root) {
g_critical("JSON format is not correct!");
g_critical("JSON format is not correct:%s", json_str);
return NULL;
}

View File

@ -124,14 +124,14 @@ GPtrArray *shard_conf_table_partitions(GPtrArray *partitions, const char *db, co
*/
void shard_conf_find_groups(GPtrArray *groups, const char *match);
gboolean shard_conf_load(char *, int);
gboolean shard_conf_load(int, char *, int);
void shard_conf_destroy(void);
gboolean shard_conf_add_vdb(sharding_vdb_t* vdb);
sharding_vdb_t *sharding_vdb_new();
gboolean sharding_vdb_is_valid(sharding_vdb_t *vdb, int num_groups);
gboolean sharding_vdb_is_valid(int is_partition_mode, sharding_vdb_t *vdb, int num_groups);
void sharding_vdb_free(sharding_vdb_t *vdb);
gboolean shard_conf_add_sharded_table(sharding_table_t* t);