Merge branch 'master' into multi-process

This commit is contained in:
wangbin579 2018-07-19 11:01:27 +08:00
commit 21bb21e5e6
9 changed files with 119 additions and 20 deletions

View File

@ -406,7 +406,7 @@ mysql> select * from services;
Default: false
禁用辅助线程,包括: 配置变更检测、后端存活检测和只读库延迟检测等
禁用辅助线程,包括: 后端存活检测、只读库延迟检测、MGR节点状态和角色检测等
> disable-threads = true

View File

@ -1359,8 +1359,13 @@ void admin_set_config(network_mysqld_con* con, char* key, char* value)
static void admin_reload_settings(network_mysqld_con* con)
{
GList *options = admin_get_all_options(con->srv);
if (!chassis_config_reload_options(con->srv->config_manager)) {
gint ret = chassis_config_reload_options(con->srv->config_manager);
if (ret == -1) {
network_mysqld_con_send_error(con->client,
C("Can't connect to remote or can't get config"));
return;
}
if (ret == -2) {
network_mysqld_con_send_error(con->client,
C("Can't load options, only support remote config"));
return;
@ -1525,10 +1530,12 @@ static struct sql_help_entry_t {
{"select * from help", "show this help", ALL_HELP},
{"select help", "show this help", ALL_HELP},
{"cetus", "Show overall status of Cetus", ALL_HELP},
{"create vdb <id> (groupA:xx, groupB:xx) using <method>", "method example: hash(int,4) range(str)", SHARD_HELP},
{"create sharded table <schema>.<table> vdb <id> shardkey <key>", "create sharded table", SHARD_HELP},
{"select * from vdb", "show all vdb", SHARD_HELP},
{"select sharded table", "show all sharded table", SHARD_HELP},
{"create vdb <id> (groupA:xx, groupB:xx) using <method>", "Method example: hash(int,4) range(str)", SHARD_HELP},
{"create sharded table <schema>.<table> vdb <id> shardkey <key>", "Create sharded table", SHARD_HELP},
{"select * from vdb", "Show all vdb", SHARD_HELP},
{"select sharded table", "Show all sharded table", SHARD_HELP},
{"create single table <schema>.<table> on <group>", "Create single-node table", SHARD_HELP},
{"select single table", "Show single tables", SHARD_HELP},
{NULL, NULL, 0}
};
@ -1785,6 +1792,7 @@ void admin_select_sharded_table(network_mysqld_con* con)
network_mysqld_proto_fielddefs_free(fields);
g_ptr_array_free(rows, TRUE);
g_list_free_full(freelist, g_free);
g_list_free(tables);
}
void admin_save_settings(network_mysqld_con *con)
@ -1894,3 +1902,35 @@ void admin_show_databases(network_mysqld_con* con)
network_mysqld_proto_fielddefs_free(fields);
g_ptr_array_free(rows, TRUE);
}
void admin_create_single_table(network_mysqld_con* con, const char* schema,
const char* table, const char* group)
{
gboolean ok = shard_conf_add_single_table(schema, table, group);
if (ok) {
shard_conf_write_json(con->srv->config_manager);
network_mysqld_con_send_ok_full(con->client, 1, 0, SERVER_STATUS_AUTOCOMMIT, 0);
} else {
network_mysqld_con_send_error(con->client, C("failed to add single table"));
}
}
void admin_select_single_table(network_mysqld_con* con)
{
GList* tables = shard_conf_get_single_tables();
GPtrArray* fields = network_mysqld_proto_fielddefs_new();
MAKE_FIELD_DEF_2_COL(fields, "Table", "Group");
GPtrArray *rows = g_ptr_array_new_with_free_func((void *)network_mysqld_mysql_field_row_free);
GList* freelist = NULL;
GList* l = NULL;
for (l = tables; l; l = l->next) {
struct single_table_t* t = l->data;
char* name = g_strdup_printf("%s.%s", t->schema->str, t->name->str);
freelist = g_list_append(freelist, name);
APPEND_ROW_2_COL(rows, name, t->group->str);
}
network_mysqld_con_send_resultset(con->client, fields, rows);
network_mysqld_proto_fielddefs_free(fields);
g_ptr_array_free(rows, TRUE);
g_list_free_full(freelist, g_free);
}

View File

@ -54,4 +54,7 @@ void admin_select_sharded_table(network_mysqld_con* con);
void admin_save_settings(network_mysqld_con* con);
void admin_compatible_cmd(network_mysqld_con* con);
void admin_show_databases(network_mysqld_con* con);
void admin_create_single_table(network_mysqld_con*, const char* schema, const char* table,
const char* group);
void admin_select_single_table(network_mysqld_con*);
#endif // ADMIN_COMMANDS_H

View File

@ -112,7 +112,7 @@ input ::= cmd.
%fallback ID
CONN_DETAILS BACKENDS AT_SIGN REDUCE_CONNS ADD MAINTAIN STATUS
CONN_NUM BACKEND_NDX RESET CETUS VDB HASH RANGE SHARDKEY RELOAD
SAVE SETTINGS.
SAVE SETTINGS SINGLE.
%wildcard ANY.
@ -436,3 +436,16 @@ cmd ::= SELECT STAR FROM VDB SEMI. {
cmd ::= SELECT SHARDED TABLE SEMI. {
admin_select_sharded_table(con);
}
cmd ::= CREATE SINGLE TABLE ids(X) DOT ids(Y) ON ids(Z) SEMI. {
char* schema = token_strdup(X);
char* table = token_strdup(Y);
char* group = token_strdup(Z);
admin_create_single_table(con, schema, table, group);
g_free(schema);
g_free(table);
g_free(group);
}
cmd ::= SELECT SINGLE TABLE SEMI. {
admin_select_single_table(con);
}

View File

@ -93,6 +93,8 @@
"settings" return TK_SETTINGS;
"NAMES" return TK_NAMES;
"DATABASES" return TK_DATABASES;
"SINGLE" return TK_SINGLE;
"ON" return TK_ON;
[0-9]+ return TK_INTEGER; /*sign symbol is handled in parser*/

View File

@ -326,14 +326,18 @@ chassis_config_load_options_mysql(chassis_config_t *conf)
return FALSE;
}
gboolean chassis_config_reload_options(chassis_config_t *conf)
gint chassis_config_reload_options(chassis_config_t *conf)
{
switch (conf->type) {
case CHASSIS_CONF_MYSQL:
return chassis_config_load_options_mysql(conf);
if(chassis_config_load_options_mysql(conf)) {
return 0;
} else {
return -1;
}
default:
/* TODO g_critical(G_STRLOC " not implemented"); */
return FALSE;
return -2;
}
}

View File

@ -36,7 +36,7 @@ chassis_config_t *chassis_config_from_local_dir(char *dir, char *conf_file);
void chassis_config_free(chassis_config_t *);
gboolean chassis_config_reload_options(chassis_config_t *conf);
gint chassis_config_reload_options(chassis_config_t *conf);
GHashTable *chassis_config_get_options(chassis_config_t *);

View File

@ -394,12 +394,6 @@ shard_conf_get_fixed_group(GPtrArray *groups, guint32 fixture)
return groups;
}
struct single_table_t { /* single table only resides on 1 group */
GString *name;
GString *schema;
GString *group;
};
void
single_table_free(struct single_table_t *t)
{
@ -451,6 +445,11 @@ GList* shard_conf_get_tables()
return tables;
}
GList* shard_conf_get_single_tables()
{
return shard_conf_single_tables;
}
static void
shard_conf_set_single_tables(GList *tables)
{
@ -1057,3 +1056,31 @@ gboolean shard_conf_write_json(chassis_config_t* conf_manager)
g_free(json_str);
return TRUE;
}
gboolean shard_conf_add_single_table(const char* schema,
const char* table, const char* group)
{
g_assert(schema && table && group);
if (shard_conf_is_single_table(schema, table)) {
g_critical("try adding duplicate single table %s.%s", schema, table);
return FALSE;
}
gboolean found = FALSE;
GList* l;
for (l = shard_conf_all_groups; l; l = l->next) {
GString* gp = l->data;
if (strcmp(gp->str, group) == 0) {
found = TRUE;
}
}
if (!found) {
g_critical("try adding single table to non-existed group: %s", group);
return FALSE;
}
struct single_table_t *st = g_new0(struct single_table_t, 1);
st->group = g_string_new(group);
st->schema = g_string_new(schema);
st->name = g_string_new(table);
shard_conf_single_tables = g_list_append(shard_conf_single_tables, st);
return TRUE;
}

View File

@ -85,6 +85,13 @@ struct sharding_table_t {
int vdb_id;
struct sharding_vdb_t *vdb_ref;
};
struct single_table_t { /* single table only resides on 1 group */
GString *name;
GString *schema;
GString *group;
};
int sharding_key_type(const char *str);
const char* sharding_key_type_str(int type);
GPtrArray *shard_conf_get_any_group(GPtrArray *groups, const char *db, const char *table);
@ -130,8 +137,11 @@ void sharding_vdb_free(sharding_vdb_t *vdb);
gboolean shard_conf_add_sharded_table(sharding_table_t* t);
GList* shard_conf_get_vdb_list();
GList* shard_conf_get_tables();
GList* shard_conf_get_tables(); /* ! g_list_free() after use */
GList* shard_conf_get_single_tables();
gboolean shard_conf_write_json(chassis_config_t* conf_manager);
gboolean shard_conf_add_single_table(const char* schema,
const char* table, const char* group);
#endif /* __SHARDING_CONFIG_H__ */