Merge branch 'v1.2.2-644' into v1.2.2

pull/679/head
René Cannaò 10 years ago
commit 7f652375b5

@ -154,7 +154,8 @@ class MySQL_HostGroups_Manager {
int get_multiple_idle_connections(int, unsigned long long, MySQL_Connection **, int);
SQLite3_result * SQL3_Connection_Pool();
void push_MyConn_to_pool(MySQL_Connection *);
void push_MyConn_to_pool(MySQL_Connection *, bool _lock=true);
void push_MyConn_to_pool_array(MySQL_Connection **);
void destroy_MyConn_from_pool(MySQL_Connection *);
void replication_lag_action(int, char*, unsigned int, int);

@ -143,6 +143,7 @@ class MySQL_Thread
bool processing_idles;
bool maintenance_loop;
PtrArray *cached_connections;
protected:
int nfds;
@ -195,6 +196,9 @@ class MySQL_Thread
//void myds_backend_first_packet_after_connect(MySQL_Data_Stream *myds, unsigned int n);
void listener_handle_new_connection(MySQL_Data_Stream *myds, unsigned int n);
void Get_Memory_Stats();
MySQL_Connection * get_MyConn_local(unsigned int);
void push_MyConn_local(MySQL_Connection *);
void return_local_connections();
};

@ -613,7 +613,7 @@ MySrvC * MyHGC::MySrvC_lookup_with_coordinates(MySQL_Connection *c) {
*/
//MyHGC * MySQL_HostGroups_Manager::MyConn_add_to_pool(MySQL_Connection *c, int _hid) {
void MySQL_HostGroups_Manager::push_MyConn_to_pool(MySQL_Connection *c) {
void MySQL_HostGroups_Manager::push_MyConn_to_pool(MySQL_Connection *c, bool _lock) {
assert(c->parent);
MySrvC *mysrvc=NULL;
// if (c->parent) {
@ -622,7 +622,8 @@ void MySQL_HostGroups_Manager::push_MyConn_to_pool(MySQL_Connection *c) {
// MyHGC=MyHGC_lookup(_hid);
// MySrvC=MyHGC->MySrvC_lookup_with_coordinates(c);
// }
wrlock();
if (_lock)
wrlock();
status.myconnpoll_push++;
mysrvc=(MySrvC *)c->parent;
proxy_debug(PROXY_DEBUG_MYSQL_CONNPOOL, 7, "Returning MySQL_Connection %p, server %s:%d with status %d\n", c, mysrvc->address, mysrvc->port, mysrvc->status);
@ -645,10 +646,22 @@ void MySQL_HostGroups_Manager::push_MyConn_to_pool(MySQL_Connection *c) {
delete c;
}
__exit_push_MyConn_to_pool:
wrunlock();
if (_lock)
wrunlock();
}
void MySQL_HostGroups_Manager::push_MyConn_to_pool_array(MySQL_Connection **ca) {
unsigned int i=0;
MySQL_Connection *c=NULL;
c=ca[i];
wrlock();
while (c) {
push_MyConn_to_pool(c,false);
i++;
c=ca[i];
}
wrunlock();
}
MySrvC *MyHGC::get_random_MySrvC() {
MySrvC *mysrvc=NULL;

@ -170,6 +170,7 @@ void MySQL_Logger::wrunlock() {
};
void MySQL_Logger::flush_log() {
if (enabled==false) return;
wrlock();
flush_log_unlocked();
wrunlock();

@ -2124,7 +2124,11 @@ void MySQL_Session::handler___client_DSS_QUERY_SENT___server_DSS_NOT_INITIALIZED
// Get a MySQL Connection
// if (rand()%3==0) {
MySQL_Connection *mc=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id);
MySQL_Connection *mc=NULL;
mc=thread->get_MyConn_local(mybe->hostgroup_id); // experimental , #644
if (mc==NULL) {
mc=MyHGM->get_MyConn_from_pool(mybe->hostgroup_id);
}
if (mc) {
mybe->server_myds->attach_connection(mc);
}

@ -1521,6 +1521,15 @@ MySQL_Thread::~MySQL_Thread() {
}
delete mysql_sessions;
}
if (cached_connections) {
while(cached_connections->len) {
MySQL_Connection *c=(MySQL_Connection *)cached_connections->remove_index_fast(0);
delete c;
}
delete cached_connections;
}
unsigned int i;
for (i=0;i<mypolls.len;i++) {
if (
@ -1585,6 +1594,7 @@ MySQL_Session * MySQL_Thread::create_new_session_and_client_data_stream(int _fd)
bool MySQL_Thread::init() {
int i;
mysql_sessions = new PtrArray();
cached_connections = new PtrArray();
assert(mysql_sessions);
shutdown=0;
my_idle_conns=(MySQL_Connection **)malloc(sizeof(MySQL_Connection *)*SESSIONS_FOR_CONNECTIONS_HANDLER);
@ -1874,7 +1884,7 @@ void MySQL_Thread::run() {
// iterate through all sessions and process the session logic
process_all_sessions();
return_local_connections();
}
}
@ -2731,3 +2741,44 @@ void MySQL_Thread::Get_Memory_Stats() {
}
}
}
MySQL_Connection * MySQL_Thread::get_MyConn_local(unsigned int _hid) {
unsigned int i;
MySQL_Connection *c=NULL;
for (i=0; i<cached_connections->len; i++) {
c=(MySQL_Connection *)cached_connections->index(i);
if (c->parent->myhgc->hid==_hid) {
c=(MySQL_Connection *)cached_connections->remove_index_fast(i);
return c;
}
}
return NULL;
}
void MySQL_Thread::push_MyConn_local(MySQL_Connection *c) {
MySrvC *mysrvc=NULL;
mysrvc=(MySrvC *)c->parent;
if (mysrvc->status==MYSQL_SERVER_STATUS_ONLINE) {
if (c->async_state_machine==ASYNC_IDLE) {
cached_connections->add(c);
return; // all went well
}
}
MyHGM->push_MyConn_to_pool(c);
}
void MySQL_Thread::return_local_connections() {
if (cached_connections->len==0) {
return;
}
MySQL_Connection **ca=(MySQL_Connection **)malloc(sizeof(MySQL_Connection *)*(cached_connections->len+1));
unsigned int i=0;
while (cached_connections->len) {
ca[i]=(MySQL_Connection *)cached_connections->remove_index_fast(0);
i++;
}
ca[i]=NULL;
MyHGM->push_MyConn_to_pool_array(ca);
free(ca);
}

@ -969,7 +969,8 @@ void MySQL_Data_Stream::return_MySQL_Connection_To_Pool() {
detach_connection();
unplug_backend();
//mc->async_state_machine=ASYNC_IDLE;
MyHGM->push_MyConn_to_pool(mc);
sess->thread->push_MyConn_local(mc);
//MyHGM->push_MyConn_to_pool(mc); // #644
}
}

Loading…
Cancel
Save