int network_connection_pool_python_add_connection(network_mysqld_con *con) { network_connection_pool_entry *pool_entry = NULL; network_mysqld_con_python_t *st = con->plugin_con_state; /* con-server is already disconnected, got out */ if (!con->server) return 0; /* the server connection is still authed */ con->server->is_authed = 1; /* insert the server socket into the connection pool */ pool_entry = network_connection_pool_add(st->backend->pool, con->server); event_set(&(con->server->event), con->server->fd, EV_READ, network_mysqld_con_idle_handle, pool_entry); /* add a event, but stay in the same thread */ chassis_event_add_local(con->srv, &(con->server->event)); st->backend->connected_clients--; st->backend = NULL; st->backend_ndx = -1; con->server = NULL; return 0; }
/** * move the con->server into connection pool and disconnect the * proxy from its backend */ int network_connection_pool_lua_add_connection(network_mysqld_con *con, int is_write_sql) { network_connection_pool_entry *pool_entry = NULL; network_mysqld_con_lua_t *st = con->plugin_con_state; guint thread_id; /* con-server is already disconnected, got out */ if (!con->server) return 0; /* TODO bug fix */ /* when mysql return unkonw packet, response is null, insert the socket into pool cause segment fault. */ /* ? should init socket->challenge ? */ /* if response is null, conn has not been authed, use an invalid username. */ if(!con->server->response) { g_warning("%s: (remove) remove socket from pool, response is NULL, src is %s, dst is %s", G_STRLOC, con->server->src->name->str, con->server->dst->name->str); con->server->response = network_mysqld_auth_response_new(); g_string_assign_len(con->server->response->username, C("mysql_proxy_invalid_user")); } /* the server connection is still authed */ con->server->is_authed = 1; /* insert the server socket into the connection pool */ if(is_write_sql == 0) { network_connection_pool* pool = chassis_event_thread_pool(st->backend); pool_entry = network_connection_pool_add(pool, con->server); }else { network_connection_pool* pool = chassis_event_thread_secondpool(st->backend); pool_entry = network_connection_pool_time_add(pool, con->server, con); } if (pool_entry) { event_set(&(con->server->event), con->server->fd, EV_READ, network_mysqld_con_idle_handle, pool_entry); chassis_event_add_local(con->srv, &(con->server->event)); /* add a event, but stay in the same thread */ } g_atomic_int_dec_and_test(&(st->backend->connected_clients)); st->backend = NULL; st->backend_ndx = -1; con->server = NULL; thread_id = chassis_event_thread_index_get(); chassis_event_thread_t *thread = g_ptr_array_index(con->srv->threads, thread_id); if(thread->block_con_queue->length) { if (write(thread->con_write_fd, "", 1) != 1) g_message("%s:pipes - write error: %s", G_STRLOC, g_strerror(errno)); } return 0; }
/** * move the con->server into connection pool and disconnect the * proxy from its backend */ int network_connection_pool_lua_add_connection(network_mysqld_con *con) { network_connection_pool_entry *pool_entry = NULL; network_mysqld_con_lua_t *st = con->plugin_con_state; /* con-server is already disconnected, got out */ if (!con->server) return 0; /* TODO bug fix */ /* when mysql return unkonw packet, response is null, insert the socket into pool cause segment fault. */ /* ? should init socket->challenge ? */ /* if response is null, conn has not been authed, use an invalid username. */ if(!con->server->response) { g_warning("%s: (remove) remove socket from pool, response is NULL, src is %s, dst is %s", G_STRLOC, con->server->src->name->str, con->server->dst->name->str); con->server->response = network_mysqld_auth_response_new(); g_string_assign_len(con->server->response->username, C("mysql_proxy_invalid_user")); } /* the server connection is still authed */ con->server->is_authed = 1; /* insert the server socket into the connection pool */ network_connection_pool* pool = chassis_event_thread_pool(st->backend); pool_entry = network_connection_pool_add(pool, con->server); if (pool_entry) { event_set(&(con->server->event), con->server->fd, EV_READ, network_mysqld_con_idle_handle, pool_entry); chassis_event_add_local(con->srv, &(con->server->event)); /* add a event, but stay in the same thread */ } if (!g_atomic_int_compare_and_exchange(&st->backend->connected_clients, 0, 0)) { g_atomic_int_dec_and_test(&st->backend->connected_clients); //g_critical("add_connection: %08x's connected_clients is %d\n", backend, backend->connected_clients); } // st->backend->connected_clients--; st->backend = NULL; st->backend_ndx = -1; con->server = NULL; return 0; }