Atlas icon indicating copy to clipboard operation
Atlas copied to clipboard

atlas sharding 多 个 shardrule 不启作用,求解

Open sixtool opened this issue 5 years ago • 2 comments

[shardrule-0] table = test.sid_1 type = hash shard-key = mod groups = 0,1

[shardrule-1] table = test.sid_2 type = hash shard-key = mod groups = 0,1

[group-0] proxy-backend-addresses=192.168.56.16:3306

[group-1] proxy-backend-addresses=192.168.56.17:3306

sixtool avatar Nov 09 '18 00:11 sixtool

/get the shard rule from GKeyFile, and insert the shard rule into a hashtable/ int proxy_plugin_get_shard_rules(GKeyFile *keyfile, chassis *chas, chassis_plugin_config *config) { GError *gerr = NULL; gchar **groups, **gname; gsize length; int i, j;

network_backends_t *bs = chas->backends;
groups = g_key_file_get_groups(keyfile, &length);
// must get config->db_groups firstly
for(i = 0; i < length; i++) {
    gname = g_strsplit(groups[i], "-", 2);
    if(gname == NULL || gname[0] == NULL || strcasecmp(gname[0], "mysql") == 0) continue;
    if(strcasecmp(gname[0], "group") == 0) {
        db_group_t *dg = keyfile_to_db_group(keyfile, groups[i], chas->event_thread_count);
        g_ptr_array_add(config->db_groups, dg);
    }
    g_strfreev(gname);
}

for(i = 0; i < length; i++) {
    gname = g_strsplit(groups[i], "-", 2);
    if(gname == NULL || gname[0] == NULL || strcasecmp(gname[0], "mysql") == 0) continue;
    if(strcasecmp(gname[0], "shardrule") == 0) {
        sharding_table_t *stable = keyfile_to_sharding_table(keyfile, groups[i], config->db_groups);
        if (stable != NULL) {
            g_hash_table_insert(config->table_shard_rules, g_strdup(stable->table_name->str), stable);
        }
    }      
    g_strfreev(gname);
}
g_strfreev(groups);
return 0;

}

sixtool avatar Nov 09 '18 02:11 sixtool

现在一个sharding不能再分表了吗? 我有200张分表,sid_1,sid_2........ sid_200这种,同一个数据库,那这个就不支持呢????

sixtool avatar Nov 09 '18 03:11 sixtool