mirror of
https://gitee.com/wangbin579/cetus.git
synced 2024-12-02 03:47:41 +08:00
Fix issue 157
This commit is contained in:
parent
a21b841034
commit
0c7a084cc8
@ -1347,8 +1347,8 @@ void admin_get_stats(network_mysqld_con* con, char* p)
|
||||
}
|
||||
} else if (strcasecmp(p, "server_query_details") == 0) {
|
||||
int i = 0;
|
||||
for (i; i < network_backends_count(chas->priv->backends)
|
||||
&& i < MAX_SERVER_NUM; ++i) {
|
||||
int backends_num = network_backends_count(chas->priv->backends);
|
||||
for (i; i < backends_num && i < MAX_SERVER_NUM; ++i) {
|
||||
GPtrArray* row = g_ptr_array_new_with_free_func(g_free);
|
||||
g_ptr_array_add(row, g_strdup(buffer));
|
||||
g_ptr_array_add(row, g_strdup_printf("server_query_details.%d.ro", i+1));
|
||||
|
@ -427,7 +427,8 @@ check_backend_alive(int fd, short what, void *arg)
|
||||
group_replication_detect(bs, monitor);
|
||||
}
|
||||
|
||||
for (i = 0; i < network_backends_count(bs); i++) {
|
||||
int backends_num = network_backends_count(bs);
|
||||
for (i = 0; i < backends_num; i++) {
|
||||
network_backend_t *backend = network_backends_get(bs, i);
|
||||
backend_state_t oldstate = backend->state;
|
||||
gint ret = 0;
|
||||
@ -503,7 +504,8 @@ update_master_timestamp(int fd, short what, void *arg)
|
||||
* PRIMARY KEY (`p_id`)
|
||||
* ) ENGINE = InnoDB DEFAULT CHARSET = utf8;
|
||||
*/
|
||||
for (i = 0; i < network_backends_count(bs); i++) {
|
||||
int backends_num = network_backends_count(bs);
|
||||
for (i = 0; i < backends_num; i++) {
|
||||
network_backend_t *backend = network_backends_get(bs, i);
|
||||
backend_state_t oldstate = backend->state;
|
||||
gint ret = 0;
|
||||
@ -565,7 +567,9 @@ check_slave_timestamp(int fd, short what, void *arg)
|
||||
network_backends_t *bs = chas->priv->backends;
|
||||
|
||||
/* Read delay sec and set slave UP/DOWN according to delay_secs */
|
||||
for (i = 0; i < network_backends_count(bs); i++) {
|
||||
|
||||
int backends_num = network_backends_count(bs);
|
||||
for (i = 0; i < backends_num; i++) {
|
||||
network_backend_t *backend = network_backends_get(bs, i);
|
||||
backend_state_t oldstate = backend->state;
|
||||
gint ret = 0;
|
||||
|
@ -192,6 +192,7 @@ struct chassis {
|
||||
time_t startup_time;
|
||||
time_t child_exit_time;
|
||||
time_t current_time;
|
||||
time_t server_conn_refresh_time;
|
||||
struct chassis_options_t *options;
|
||||
chassis_config_t *config_manager;
|
||||
GHashTable *query_cache_table;
|
||||
|
@ -777,15 +777,15 @@ init_parameters(struct chassis_frontend_t *frontend, chassis *srv)
|
||||
srv->internal_trx_isolation_level = TF_SERIALIZABLE;
|
||||
srv->trx_isolation_level = g_strdup("SERIALIZABLE");
|
||||
} else {
|
||||
srv->internal_trx_isolation_level = TF_REPEATABLE_READ;
|
||||
g_warning("trx isolation level:%s is not expected, use REPEATABLE READ instead",
|
||||
srv->internal_trx_isolation_level = TF_READ_COMMITTED;
|
||||
g_warning("trx isolation level:%s is not expected, use READ COMMITTED instead",
|
||||
frontend->trx_isolation_level);
|
||||
srv->trx_isolation_level = g_strdup("REPEATABLE READ");
|
||||
srv->trx_isolation_level = g_strdup("READ COMMITTED");
|
||||
}
|
||||
} else {
|
||||
g_message("trx isolation level is not set");
|
||||
srv->internal_trx_isolation_level = TF_REPEATABLE_READ;
|
||||
srv->trx_isolation_level = g_strdup("REPEATABLE READ");
|
||||
srv->internal_trx_isolation_level = TF_READ_COMMITTED;
|
||||
srv->trx_isolation_level = g_strdup("READ COMMITTED");
|
||||
}
|
||||
|
||||
g_message("trx isolation level value:%s", srv->trx_isolation_level);
|
||||
|
@ -407,7 +407,8 @@ network_backends_load_config(network_backends_t *bs, chassis *srv)
|
||||
return -1;
|
||||
}
|
||||
int i;
|
||||
for (i = 0; i < network_backends_count(bs); i++) {
|
||||
int count = network_backends_count(bs);
|
||||
for (i = 0; i < count; i++) {
|
||||
network_backend_t *backend = network_backends_get(bs, i);
|
||||
if (backend) {
|
||||
set_backend_config(backend, srv);
|
||||
|
@ -74,7 +74,7 @@ network_mysqld_con_idle_handle(int event_fd, short events, void *user_data)
|
||||
*
|
||||
* remove us from the connection pool and close the connection */
|
||||
|
||||
network_connection_pool_remove(pool, pool_entry);
|
||||
network_connection_pool_remove(pool_entry);
|
||||
if (pool->srv) {
|
||||
chassis *srv = pool->srv;
|
||||
srv->complement_conn_flag = 1;
|
||||
@ -87,7 +87,7 @@ network_mysqld_con_idle_handle(int event_fd, short events, void *user_data)
|
||||
chassis *srv = pool->srv;
|
||||
srv->complement_conn_flag = 1;
|
||||
}
|
||||
network_connection_pool_remove(pool, pool_entry);
|
||||
network_connection_pool_remove(pool_entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,20 +273,11 @@ network_connection_pool_add(network_connection_pool *pool, network_socket *sock)
|
||||
* remove the connection referenced by entry from the pool
|
||||
*/
|
||||
void
|
||||
network_connection_pool_remove(network_connection_pool *pool, network_connection_pool_entry *entry)
|
||||
network_connection_pool_remove(network_connection_pool_entry *entry)
|
||||
{
|
||||
network_socket *sock = entry->sock;
|
||||
GQueue *conns;
|
||||
|
||||
if (NULL == (conns = g_hash_table_lookup(pool->users, sock->response->username))) {
|
||||
return;
|
||||
}
|
||||
|
||||
entry->pool->cur_idle_connections--;
|
||||
g_queue_delete_link(entry->conns, entry->link);
|
||||
network_connection_pool_entry_free(entry, TRUE);
|
||||
|
||||
g_queue_remove(conns, entry);
|
||||
|
||||
pool->cur_idle_connections--;
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
@ -42,6 +42,8 @@ typedef struct {
|
||||
typedef struct {
|
||||
network_socket *sock; /** the idling socket */
|
||||
network_connection_pool *pool; /** a pointer back to the pool */
|
||||
GQueue *conns; /** a pointer back to the queue */
|
||||
GList *link; /** a pointer back to the link */
|
||||
} network_connection_pool_entry;
|
||||
|
||||
NETWORK_API network_socket *network_connection_pool_get(network_connection_pool *pool,
|
||||
@ -49,7 +51,7 @@ NETWORK_API network_socket *network_connection_pool_get(network_connection_pool
|
||||
|
||||
NETWORK_API network_connection_pool_entry *network_connection_pool_add(network_connection_pool *, network_socket *);
|
||||
|
||||
NETWORK_API void network_connection_pool_remove(network_connection_pool *pool, network_connection_pool_entry *entry);
|
||||
NETWORK_API void network_connection_pool_remove(network_connection_pool_entry *entry);
|
||||
NETWORK_API GQueue *network_connection_pool_get_conns(network_connection_pool *, GString *, int *);
|
||||
|
||||
NETWORK_API network_connection_pool *network_connection_pool_new(void);
|
||||
|
@ -4862,8 +4862,8 @@ network_connection_pool_create_conn(network_mysqld_con *con)
|
||||
|
||||
time_t cur = time(0);
|
||||
|
||||
int back_num = network_backends_count(g->backends);
|
||||
for (i = 0; i < back_num; i++) {
|
||||
int backends_count = network_backends_count(g->backends);
|
||||
for (i = 0; i < backends_count; i++) {
|
||||
network_backend_t *backend = network_backends_get(g->backends, i);
|
||||
if (backend != NULL) {
|
||||
|
||||
@ -5005,7 +5005,8 @@ network_connection_pool_create_conns(chassis *srv)
|
||||
int i, j;
|
||||
chassis_private *g = srv->priv;
|
||||
|
||||
for (i = 0; i < network_backends_count(g->backends); i++) {
|
||||
int backends_count = network_backends_count(g->backends);
|
||||
for (i = 0; i < backends_count; i++) {
|
||||
network_backend_t *backend = network_backends_get(g->backends, i);
|
||||
if (backend != NULL) {
|
||||
if (backend->state != BACKEND_STATE_UP && backend->state != BACKEND_STATE_UNKNOWN) {
|
||||
@ -5107,6 +5108,50 @@ update_time_func(int fd, short what, void *arg)
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
check_old_server_connection(gpointer data, gpointer user_data)
|
||||
{
|
||||
network_connection_pool_entry *entry = data;
|
||||
chassis *chas = user_data;
|
||||
|
||||
if (chas->server_conn_refresh_time > entry->sock->create_time) {
|
||||
chas->complement_conn_flag = 1;
|
||||
network_connection_pool_remove(entry);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
close_old_server_connetions(chassis *chas)
|
||||
{
|
||||
chas->server_conn_refresh_time = time(0);
|
||||
chassis_private *g = chas->priv;
|
||||
int i;
|
||||
int backends_count = network_backends_count(g->backends);
|
||||
for (i = 0; i < backends_count; i++) {
|
||||
network_backend_t *backend = network_backends_get(g->backends, i);
|
||||
if (backend != NULL) {
|
||||
if (backend->state != BACKEND_STATE_UP && backend->state != BACKEND_STATE_UNKNOWN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
network_connection_pool *pool = backend->pool;
|
||||
GHashTable *users = pool->users;
|
||||
int total = 0;
|
||||
if (users != NULL) {
|
||||
GHashTableIter iter;
|
||||
GString *key;
|
||||
GQueue *queue;
|
||||
g_hash_table_iter_init(&iter, users);
|
||||
/* count all users' pooled connections */
|
||||
while (g_hash_table_iter_next(&iter, (void **)&key, (void **)&queue)) {
|
||||
total += queue->length;
|
||||
g_queue_foreach(queue, check_old_server_connection, chas);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
check_and_create_conns_func(int fd, short what, void *arg)
|
||||
{
|
||||
|
@ -105,8 +105,8 @@ typedef struct network_ssl_connection_s network_ssl_connection_t;
|
||||
typedef struct {
|
||||
int socket_type; /**< SOCK_STREAM or SOCK_DGRAM for now */
|
||||
int fd; /**< socket-fd */
|
||||
guint32 create_time;
|
||||
guint32 update_time;
|
||||
time_t create_time;
|
||||
time_t update_time;
|
||||
|
||||
struct event event; /**< events for this fd */
|
||||
|
||||
|
@ -375,7 +375,8 @@ do_connect_cetus(network_mysqld_con *con, network_backend_t **backend, int *back
|
||||
*/
|
||||
|
||||
int min_connected_clients = 0x7FFFFFFF;
|
||||
for (i = 0; i < network_backends_count(g->backends); i++) {
|
||||
int backends_count = network_backends_count(g->backends);
|
||||
for (i = 0; i < backends_count; i++) {
|
||||
cur = network_backends_get(g->backends, i);
|
||||
|
||||
/**
|
||||
@ -550,6 +551,7 @@ try_to_get_resp_from_query_cache(network_mysqld_con *con)
|
||||
int i;
|
||||
int len = item->queue->chunks->length;
|
||||
for (i = 0; i < len; i++) {
|
||||
/* TODO g_queue_peek_nth is not efficient*/
|
||||
GString *packet = g_queue_peek_nth(item->queue->chunks, i);
|
||||
GString *dup_packet = g_string_new(NULL);
|
||||
g_string_append_len(dup_packet, S(packet));
|
||||
|
@ -1566,6 +1566,7 @@ cetus_result_parse_fielddefs(cetus_result_t *res_merge, GQueue *input)
|
||||
res_merge->fielddefs = network_mysqld_proto_fielddefs_new();
|
||||
int i;
|
||||
for (i = 0; i < res_merge->field_count; ++i) {
|
||||
/* TODO g_queue_peek_nth is not efficient*/
|
||||
packet.data = g_queue_peek_nth(input, i + 1);
|
||||
packet.offset = 0;
|
||||
network_mysqld_proto_skip_network_header(&packet);
|
||||
|
Loading…
Reference in New Issue
Block a user