dbproxy-id生成器

时间:2022-08-31 16:02:21

id生成器使用的是snowflake, 需要执行 snowflake_init(region_id, worker_id); 而region_id和worker_id是在配置文件中配置的

network_mysqld_proxy_plugin_apply_config
位置plugins/proxy/proxy-plugin.c

int network_mysqld_proxy_plugin_apply_config(chassis *chas, chassis_plugin_config *oldconfig) {
...
int region_id = ;
int worker_id = ;
gboolean is_complete = FALSE;
gchar *id_generate = g_strdup(config->id_generate); if ( (region_id = strtoll(strsep(&id_generate, ":"), NULL, )) != NULL) {
g_log_dbproxy(g_message, "##### is %s", id_generate);
if ( (worker_id = strtoll(strsep(&id_generate, ":"), NULL, )) != NULL) {
is_complete = TRUE;
}
}
if (is_complete) {
snowflake_init(region_id, worker_id);
g_log_dbproxy(g_message, "id_generate is %s, region_id is %d, worker_id is %d", config->id_generate, region_id, worker_id);
} else {
g_log_dbproxy(g_critical, "id_generate is %s, region_id is %d, worker_id is %d", config->id_generate, region_id, worker_id);
}
...
}