@ -71,13 +71,13 @@ MySQL_Hostgroup_Entry * MySQL_HostGroups_Handler::MSHGE_find(unsigned int hid, M
proxy_debug ( PROXY_DEBUG_MYSQL_CONNPOOL , 4 , " Searching MSHGE for MySQL_Server %p into HID %d \n " , srv , hid ) ;
MySQL_Hostgroup * myhg = ( MySQL_Hostgroup * ) MyHostGroups - > index ( hid ) ;
return myhg - > MSHGE_find ( srv ) ;
} ;
}
MySQL_Hostgroup_Entry * MySQL_HostGroups_Handler : : MSHGE_find ( unsigned int hid , char * add , uint16_t p ) {
proxy_debug ( PROXY_DEBUG_MYSQL_CONNPOOL , 4 , " Searching MSHGE for MySQL server %s:%d into HID %d \n " , add , p , hid ) ;
MySQL_Server * srv = server_find ( add , p ) ;
if ( srv = = NULL ) return NULL ; // server not found
return MSHGE_find ( hid , srv ) ;
} ;
}
void MySQL_HostGroups_Handler : : insert_hostgroup ( MySQL_Hostgroup * myhg ) {
@ -89,17 +89,17 @@ void MySQL_HostGroups_Handler::insert_hostgroup(MySQL_Hostgroup *myhg) {
//MyHostGroups.insert(MyHostGroups.begin()+p,myhg);
//MyHostGroups[p]=myhg;
MyHostGroups - > pdata [ p ] = myhg ;
} ;
}
void * MySQL_Backend : : operator new ( size_t size ) {
return l_alloc ( size ) ;
} ;
}
void MySQL_Backend : : operator delete ( void * ptr ) {
l_free ( sizeof ( MySQL_Backend ) , ptr ) ;
} ;
}
MySQL_Backend : : MySQL_Backend ( ) {
hostgroup_id = - 1 ;
@ -107,10 +107,10 @@ MySQL_Backend::MySQL_Backend() {
myconn = NULL ;
server_bytes_at_cmd . bytes_recv = 0 ;
server_bytes_at_cmd . bytes_sent = 0 ;
} ;
}
MySQL_Backend : : ~ MySQL_Backend ( ) {
} ;
}
void MySQL_Backend : : reset ( ) {
if ( server_myds ) {
@ -126,5 +126,67 @@ void MySQL_Backend::reset() {
}
} ;
myconn = NULL ;
} ;
}
void MySQL_Hostgroup : : add ( MySQL_Hostgroup_Entry * mshge ) {
proxy_debug ( PROXY_DEBUG_MYSQL_CONNPOOL , 4 , " Adding MySQL_Hostgroup_Entry %p to Hostgroup %p with HID %d \n " , mshge , this , hostgroup_id ) ;
MSHGEs - > add ( mshge ) ;
}
void MySQL_Hostgroup : : add ( MySQL_Server * msptr , unsigned int _weight ) {
MySQL_Hostgroup_Entry * mshge = new MySQL_Hostgroup_Entry ( hostgroup_id , msptr , _weight ) ;
this - > add ( mshge ) ;
}
bool MySQL_Hostgroup : : del ( MySQL_Hostgroup_Entry * mshge ) {
proxy_debug ( PROXY_DEBUG_MYSQL_CONNPOOL , 4 , " Deleting MySQL_Hostgroup_Entry %p from Hostgroup %p with HID %d \n " , mshge , this , hostgroup_id ) ;
MySQL_Hostgroup_Entry * it = NULL ;
unsigned int i ;
for ( i = 0 ; i < MSHGEs - > len ; i + + ) {
it = ( MySQL_Hostgroup_Entry * ) MSHGEs - > index ( i ) ;
if ( it = = mshge ) {
it = ( MySQL_Hostgroup_Entry * ) MSHGEs - > remove_index_fast ( i ) ;
delete it ;
return true ;
}
}
return false ;
}
bool MySQL_Hostgroup : : del ( MySQL_Server * msptr ) {
proxy_debug ( PROXY_DEBUG_MYSQL_CONNPOOL , 4 , " Deleting MySQL_Hostgroup_Entry with MySQL_Server %p from Hostgroup %p with HID %d \n " , msptr , this , hostgroup_id ) ;
MySQL_Hostgroup_Entry * it = NULL ;
unsigned int i ;
for ( i = 0 ; i < MSHGEs - > len ; i + + ) {
it = ( MySQL_Hostgroup_Entry * ) MSHGEs - > index ( i ) ;
if ( it - > MSptr = = msptr ) {
it = ( MySQL_Hostgroup_Entry * ) MSHGEs - > remove_index_fast ( i ) ;
delete it ;
return true ;
}
}
return false ;
}
MySQL_Hostgroup_Entry * MySQL_Hostgroup : : MSHGE_find ( MySQL_Server * msptr ) {
proxy_debug ( PROXY_DEBUG_MYSQL_CONNPOOL , 4 , " Searching MySQL_Hostgroup_Entry for MySQL_Server %p from Hostgroup %p with HID %d \n " , msptr , this , hostgroup_id ) ;
MySQL_Hostgroup_Entry * it = NULL ;
unsigned int i ;
for ( i = 0 ; i < MSHGEs - > len ; i + + ) {
it = ( MySQL_Hostgroup_Entry * ) MSHGEs - > index ( i ) ;
if ( it - > MSptr = = msptr ) {
return it ;
}
}
proxy_debug ( PROXY_DEBUG_MYSQL_CONNPOOL , 4 , " MySQL_Hostgroup_Entry not found \n " ) ;
return NULL ;
}
size_t MySQL_Hostgroup : : servers_in_hostgroup ( ) {
return MSHGEs - > len ;
}