From cc9eb4d807acc868a714447942c69a20357dbac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 10 Feb 2015 18:36:48 +0000 Subject: [PATCH] Removed client_fd and server_fd from MySQL_Session --- include/mysql_session.h | 6 +++--- lib/MySQL_Session.cpp | 23 ++++++++++++++--------- lib/Standard_MySQL_Thread.cpp | 13 +++++++------ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/mysql_session.h b/include/mysql_session.h index b236e0c79..5ce3537ba 100644 --- a/include/mysql_session.h +++ b/include/mysql_session.h @@ -68,8 +68,8 @@ class MySQL_Session bool admin; bool stats; void (*admin_func) (MySQL_Session *arg, ProxySQL_Admin *, PtrSize_t *pkt); - int client_fd; - int server_fd; +// int client_fd; +// int server_fd; enum session_status status; int current_hostgroup; int default_hostgroup; @@ -97,7 +97,7 @@ class MySQL_Session PtrArray *mybes; MySQL_Session(); - MySQL_Session(int); +// MySQL_Session(int); ~MySQL_Session(); diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index df34ecb35..70b0eb235 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -104,8 +104,8 @@ MySQL_Session::MySQL_Session() { admin=false; stats=false; admin_func=NULL; - client_fd=0; - server_fd=0; + //client_fd=0; + //server_fd=0; client_myds=NULL; server_myds=NULL; to_process=0; @@ -122,10 +122,12 @@ MySQL_Session::MySQL_Session() { //myprot_server.init(&server_myds, NULL, this); } +/* MySQL_Session::MySQL_Session(int _fd) { MySQL_Session(); client_fd=_fd; } +*/ MySQL_Session::~MySQL_Session() { if (client_myds) { @@ -218,7 +220,8 @@ int MySQL_Session::handler() { unsigned int j; unsigned char c; - +/* + * FIXME: this code is obscure and needs improvements . Commenting for now if (pause>0 || (status==CONNECTING_SERVER && server_myds && ( server_myds->myds_type==MYDS_BACKEND_FAILED_CONNECT || server_myds->myds_type==MYDS_BACKEND_PAUSE_CONNECT ))) { server_myds->connect_tries++; if (server_myds->connect_tries<10) { @@ -260,6 +263,7 @@ int MySQL_Session::handler() { //assert(0); } } +*/ for (j=0; jPSarrayIN->len;) { client_myds->PSarrayIN->remove_index(0,&pkt); @@ -387,7 +391,7 @@ __get_a_backend: // FIXME : handle missing connection from connection pool // FIXME : perhaps is a goto __exit_DSS__STATE_NOT_INITIALIZED after setting time wait - thread->mypolls.add(POLLIN|POLLOUT, server_fd, server_myds, curtime); + thread->mypolls.add(POLLIN|POLLOUT, server_myds->fd, server_myds, curtime); if (server_myds->DSS!=STATE_READY) { server_myds->move_from_OUT_to_OUTpending(); @@ -513,12 +517,12 @@ __exit_DSS__STATE_NOT_INITIALIZED: MyHGM->destroy_MyConn_from_pool(mybe->myconn); mybe->myconn=NULL; } - if (server_fd) { + if (server_myds->fd) { shutdown(server_myds->fd,SHUT_RDWR); close(server_myds->fd); server_myds->fd=0; thread->mypolls.remove_index_fast(server_myds->poll_fds_idx); - server_fd=0; + //server_fd=0; } server_myds->net_failure=false; server_myds->active=1; @@ -967,8 +971,9 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED // we didn't get a valid connection, we need to create one proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Sess=%p -- MySQL Connection has no FD\n", this); server_myds->myconn=mybe->myconn; - server_fd=server_myds->myds_connect(mybe->myconn->parent->address, mybe->myconn->parent->port, &pending_connect); - server_myds->init((pending_connect==1 ? MYDS_BACKEND_NOT_CONNECTED : MYDS_BACKEND), this, server_fd); + int __fd; + __fd=server_myds->myds_connect(mybe->myconn->parent->address, mybe->myconn->parent->port, &pending_connect); + server_myds->init((pending_connect==1 ? MYDS_BACKEND_NOT_CONNECTED : MYDS_BACKEND), this, __fd); mybe->myconn=server_myds->myconn; mybe->myconn->reusable=true; server_myds->myconn->fd=server_myds->fd; @@ -978,7 +983,7 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED proxy_debug(PROXY_DEBUG_MYSQL_CONNECTION, 5, "Sess=%p -- MySQL Connection found = %p\n", this, mybe->myconn); server_myds->myconn=mybe->myconn; server_myds->assign_fd_from_mysql_conn(); - server_fd=server_myds->fd; + //server_fd=server_myds->fd; server_myds->myds_type=MYDS_BACKEND; server_myds->DSS=STATE_READY; } diff --git a/lib/Standard_MySQL_Thread.cpp b/lib/Standard_MySQL_Thread.cpp index be139f42c..9f932f57e 100644 --- a/lib/Standard_MySQL_Thread.cpp +++ b/lib/Standard_MySQL_Thread.cpp @@ -604,10 +604,11 @@ virtual MySQL_Session * create_new_session_and_client_data_stream(int _fd) { int arg_on=1; MySQL_Session *sess=new MySQL_Session; register_session(sess); // register session - sess->client_fd=_fd; - setsockopt(sess->client_fd, IPPROTO_TCP, TCP_NODELAY, (char *) &arg_on, sizeof(int)); + //sess->client_fd=_fd; sess->client_myds = new MySQL_Data_Stream(); - sess->client_myds->init(MYDS_FRONTEND, sess, sess->client_fd); + sess->client_myds->fd=_fd; + setsockopt(sess->client_myds->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &arg_on, sizeof(int)); + sess->client_myds->init(MYDS_FRONTEND, sess, sess->client_myds->fd); proxy_debug(PROXY_DEBUG_NET,1,"Thread=%p, Session=%p, DataStream=%p -- Created new client Data Stream\n", sess->thread, sess, sess->client_myds); //sess->prot.generate_server_handshake(sess->client_myds); #ifdef DEBUG @@ -875,9 +876,9 @@ void Standard_MySQL_Thread::listener_handle_new_connection(MySQL_Data_Stream *my //sess->myprot_client.generate_pkt_initial_handshake(sess->client_myds,true,NULL,NULL); //sess->myprot_client.generate_pkt_initial_handshake(true,NULL,NULL); sess->client_myds->myprot.generate_pkt_initial_handshake(true,NULL,NULL); - ioctl_FIONBIO(sess->client_fd, 1); - mypolls.add(POLLIN|POLLOUT, sess->client_fd, sess->client_myds, curtime); - proxy_debug(PROXY_DEBUG_NET,1,"Session=%p -- Adding client FD %d\n", sess, sess->client_fd); + ioctl_FIONBIO(sess->client_myds->fd, 1); + mypolls.add(POLLIN|POLLOUT, sess->client_myds->fd, sess->client_myds, curtime); + proxy_debug(PROXY_DEBUG_NET,1,"Session=%p -- Adding client FD %d\n", sess, sess->client_myds->fd); } else { // if we arrive here, accept() failed // because multiple threads try to handle the same incoming connection, this is OK