Merge branch 'master' into master

This commit is contained in:
tsthght 2018-09-06 11:08:13 +08:00 committed by GitHub
commit 9768282755
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 156 additions and 31 deletions

View File

@ -76,3 +76,50 @@ bin/cetus --defaults-file=conf/shard.conf [--conf-dir/home/user/cetus_install
其中Cetus启动时可以添加命令行选项--defaults-file选项用来加载启动配置文件proxy.conf或者shard.conf且在启动前保证启动配置文件的权限为660--conf-dir是可选项用来加载其他配置文件(.json文件)默认为当前目录下conf文件夹。
Cetus可起动守护进程后台运行也可在进程意外终止自动启动一个新进程可通过启动配置选项进行设置。
## 注意事项
发现在某些最新版本的操作系统上例如centos:7.5.1804虽然成功安装了tcmalloc库但是有可能cetus仍然没有正确的链接该库。以下方法可以检测cetus是否已经成功链接了tcmalloc库
- cmake阶段
```
## cmake结束后如果检测到系统安装有tcmalloc会打印以下信息
-- Looking for malloc in tcmalloc
-- Looking for malloc in tcmalloc - found
## 如果检测不到tcmalloc则会打印以下信此时需要检测tcmalloc安装是否正确
-- Looking for malloc in tcmalloc
-- Looking for malloc in tcmalloc - not found
```
- make install 阶段
```
## make install命令执行之后编译出cetus可执行文件会被拷贝到安装目录可以检测该执行文件的动态库是否动态链接了tcmalloc库
ldd ${cetus_install_path}/libexec/cetus|grep tcmalloc
```
如果发现已经安装过了tcmalloc相应的发行包但是cetus却没有正确链接tcmalloc库极大可能是没有找到libtcmalloc.so动态库此时应该手动建立软链接。建立方法
```
## 以64位 centos7.5 为例
cd ls -alh /usr/lib64/|grep tcmalloc
lrwxrwxrwx 1 root root 20 Sep 4 00:58 libtcmalloc.so.4 -> libtcmalloc.so.4.4.5
-rwxr-xr-x 1 root root 295K Apr 11 01:41 libtcmalloc.so.4.4.5
lrwxrwxrwx 1 root root 33 Sep 4 00:58 libtcmalloc_and_profiler.so.4 -> libtcmalloc_and_profiler.so.4.4.5
-rwxr-xr-x 1 root root 315K Apr 11 01:41 libtcmalloc_and_profiler.so.4.4.5
lrwxrwxrwx 1 root root 26 Sep 4 00:58 libtcmalloc_debug.so.4 -> libtcmalloc_debug.so.4.4.5
-rwxr-xr-x 1 root root 351K Apr 11 01:41 libtcmalloc_debug.so.4.4.5
lrwxrwxrwx 1 root root 28 Sep 4 00:58 libtcmalloc_minimal.so.4 -> libtcmalloc_minimal.so.4.4.5
-rwxr-xr-x 1 root root 152K Apr 11 01:41 libtcmalloc_minimal.so.4.4.5
lrwxrwxrwx 1 root root 34 Sep 4 00:58 libtcmalloc_minimal_debug.so.4 -> libtcmalloc_minimal_debug.so.4.4.5
-rwxr-xr-x 1 root root 208K Apr 11 01:41 libtcmalloc_minimal_debug.so.4.4.5
## 发现没有 libtcmalloc.so建立软链接
ln -s /usr/lib64/libtcmalloc.so.4.4.5 /usr/lib64/libtcmalloc.so
## 重新cmake
rm -rf CMakeCache.txt
根据所需的cetus版本执行对应cmake命令
```

View File

@ -857,17 +857,6 @@ void admin_select_connection_stat(network_mysqld_con* con, int backend_ndx, char
g_free(numstr);
}
static void bytes_to_hex_str(char* pin, int len, char* pout)
{
const char* hex = "0123456789ABCDEF";
int i = 0;
for(; i < len; ++i){
*pout++ = hex[(*pin>>4)&0xF];
*pout++ = hex[(*pin++)&0xF];
}
*pout = 0;
}
static enum cetus_pwd_type password_type(char* table)
{
if (strcmp(table, "user_pwd")==0) {
@ -985,16 +974,33 @@ static backend_state_t backend_state(const char* str)
void admin_insert_backend(network_mysqld_con* con, char *addr, char *type, char *state)
{
chassis_private *g = con->srv->priv;
int affected = (network_backends_add(g->backends, addr,
int ret = network_backends_add(g->backends, addr,
backend_type(type),
backend_state(state), con->srv)==0)?1:0;
gint ret = CHANGE_SAVE_ERROR;
chassis *srv = con->srv;
network_socket *client = con->client;
gint effected_rows = 0;
if (affected)
ret = save_setting(srv, &effected_rows);
send_result(client, ret, affected);
backend_state(state), con->srv);
switch (ret) {
case BACKEND_OPERATE_SUCCESS:
{
network_mysqld_con_send_ok_full(con->client, 1, 0,
SERVER_STATUS_AUTOCOMMIT, 0);
break;
}
case BACKEND_OPERATE_NETERR:
{
network_mysqld_con_send_error(con->client, C("get network address failed"));
break;
}
case BACKEND_OPERATE_DUPLICATE:
{
network_mysqld_con_send_error(con->client, C("backend is already known"));
break;
}
case BACKEND_OPERATE_2MASTER:
{
network_mysqld_con_send_error(con->client, C("rw node is already existsonly one rw node is allowed"));
break;
}
}
}
void admin_update_backend(network_mysqld_con* con, GList* equations,
@ -1034,6 +1040,17 @@ void admin_update_backend(network_mysqld_con* con, GList* equations,
network_mysqld_con_send_error(con->client, C("no such backend"));
return;
}
if (type_str && backend_type(type_str) == BACKEND_TYPE_RW && network_backend_check_available_rw(g->backends, bk->server_group)) {
if (backend_type(type_str) == bk->type) {
network_mysqld_con_send_ok_full(con->client, 0, 0,
SERVER_STATUS_AUTOCOMMIT, 0);
} else {
network_mysqld_con_send_error(con->client, C("rw node is already existsonly one rw node is allowed"));
}
return;
}
int type = type_str ? backend_type(type_str) : bk->type;
int state = state_str ? backend_state(state_str) : bk->state;
if (type == ERROR_PARAM || state == ERROR_PARAM) {

View File

@ -440,13 +440,18 @@ gchar*
show_admin_password(gpointer param) {
struct external_param *opt_param = (struct external_param *)param;
gint opt_type = opt_param->opt_type;
GString* hashed_pwd = g_string_new(0);
network_mysqld_proto_password_hash(hashed_pwd, L(config->admin_password));
char* pwdhex = g_malloc0(hashed_pwd->len * 2 + 10);
bytes_to_hex_str(hashed_pwd->str, hashed_pwd->len, pwdhex);
g_string_free(hashed_pwd, TRUE);
if(CAN_SHOW_OPTS_PROPERTY(opt_type)) {
return g_strdup_printf("%s", config->admin_password != NULL ? config->admin_password: "NULL");
return pwdhex;
}
if(CAN_SAVE_OPTS_PROPERTY(opt_type)) {
if(config->admin_password != NULL) {
return g_strdup_printf("%s", config->admin_password);
}
return pwdhex;
}
return NULL;
}

View File

@ -132,3 +132,14 @@ guint64 get_timer_microseconds() {
}
return last_value;
}
void bytes_to_hex_str(char* pin, int len, char* pout)
{
const char* hex = "0123456789ABCDEF";
int i = 0;
for(; i < len; ++i){
*pout++ = hex[(*pin>>4)&0xF];
*pout++ = hex[(*pin++)&0xF];
}
*pout = 0;
}

View File

@ -50,4 +50,6 @@ gboolean try_get_double_value(const gchar *option_value, gdouble *return_value);
int make_iso8601_timestamp(char *buf, uint64_t utime);
guint64 get_timer_microseconds();
void bytes_to_hex_str(char* pin, int len, char* pout);
#endif

View File

@ -215,7 +215,7 @@ network_backends_add(network_backends_t *bs, const gchar *address,
if (0 != network_address_set_address(new_backend->addr, new_backend->address->str)) {
network_backend_free(new_backend);
return -1;
return BACKEND_OPERATE_NETERR;
}
guint i;
@ -227,10 +227,14 @@ network_backends_add(network_backends_t *bs, const gchar *address,
network_backend_free(new_backend);
g_critical("backend %s is already known!", address);
return -1;
return BACKEND_OPERATE_DUPLICATE;
}
}
if (type == BACKEND_TYPE_RW && network_backend_check_available_rw(bs, new_backend->server_group)) {
return BACKEND_OPERATE_2MASTER;
}
g_ptr_array_add(bs->backends, new_backend);
if (type == BACKEND_TYPE_RO) {
bs->ro_server_num += 1;
@ -241,7 +245,7 @@ network_backends_add(network_backends_t *bs, const gchar *address,
network_backends_into_group(bs, new_backend);
g_message("added %s backend: %s, state: %s", backend_type_t_str[type], address, backend_state_t_str[state]);
return 0;
return BACKEND_OPERATE_SUCCESS;
}
/**
@ -643,3 +647,31 @@ network_backends_used_conns(network_backends_t *bs)
}
return sum;
}
int
network_backend_check_available_rw(network_backends_t *bs, GString *name)
{
if (!name || name->len == 0) {
int i = 0;
int count = network_backends_count(bs);
for (i = 0; i < count; i++) {
network_backend_t *backend = network_backends_get(bs, i);
if ((BACKEND_TYPE_RW == backend->type) &&
backend->state != BACKEND_STATE_MAINTAINING && backend->state != BACKEND_STATE_DELETED) {
break;
}
}
return i < count ? 1 : 0;
} else {
network_group_t *group = network_backends_get_group(bs, name);
if (group == NULL) {
return 0;
}
network_backend_t *rw = group->master;
if (rw && rw->state != BACKEND_STATE_MAINTAINING && rw->state != BACKEND_STATE_DELETED) {
return 1;
} else {
return 0;
}
}
}

View File

@ -48,6 +48,13 @@ typedef enum {
BACKEND_TYPE_RO,
} backend_type_t;
typedef enum {
BACKEND_OPERATE_SUCCESS,
BACKEND_OPERATE_NETERR,
BACKEND_OPERATE_DUPLICATE,
BACKEND_OPERATE_2MASTER
} backend_operate_t;
typedef struct backend_config {
GString *default_username;
GString *default_db;
@ -144,4 +151,6 @@ int network_backends_get_rw_ndx(network_backends_t *);
int network_backends_idle_conns(network_backends_t *);
int network_backends_used_conns(network_backends_t *);
int network_backend_check_available_rw(network_backends_t *, GString *);
#endif /* _BACKEND_H_ */

View File

@ -446,16 +446,18 @@ plugin_add_backends(chassis *chas, gchar **backend_addresses, gchar **read_only_
GPtrArray *backends_arr = g->backends->backends;
for (i = 0; backend_addresses[i]; i++) {
if (-1 == network_backends_add(g->backends, backend_addresses[i], BACKEND_TYPE_RW, BACKEND_STATE_UNKNOWN, chas)) {
return -1;
if (BACKEND_OPERATE_SUCCESS != network_backends_add(g->backends, backend_addresses[i], BACKEND_TYPE_RW, BACKEND_STATE_UNKNOWN, chas)) {
g_critical("add rw node: %s failed.", backend_addresses[i]);
continue;
}
network_backend_init_extra(backends_arr->pdata[backends_arr->len - 1], chas);
}
for (i = 0; read_only_backend_addresses && read_only_backend_addresses[i]; i++) {
if (-1 == network_backends_add(g->backends,
if (BACKEND_OPERATE_SUCCESS != network_backends_add(g->backends,
read_only_backend_addresses[i], BACKEND_TYPE_RO, BACKEND_STATE_UNKNOWN, chas)) {
return -1;
g_critical("add ro node: %s failed.", read_only_backend_addresses[i]);
continue;
}
/* set conn-pool config */
network_backend_init_extra(backends_arr->pdata[backends_arr->len - 1], chas);