Initial work on issue #78

Removed 127.0.0.1 from mysql_connection.cpp (issue #70)
pull/190/head
René Cannaò 11 years ago
parent f79a0c2a1f
commit 33421ca997

@ -244,6 +244,7 @@ class MySQL_Hostgroup {
}
return mshge;
};
MySQL_Hostgroup_Entry * get_random_hostgroup_entry();
};
class MySQL_HostGroups_Handler {
@ -385,6 +386,7 @@ class MySQL_HostGroups_Handler {
return MyHostGroups[hid]->set_HG_entry_status(msptr,_status);
};
*/
MySQL_Hostgroup_Entry * get_random_hostgroup_entry(unsigned int hid);
};

@ -92,6 +92,15 @@ void MySQL_HostGroups_Handler::insert_hostgroup(MySQL_Hostgroup *myhg) {
}
MySQL_Hostgroup_Entry * MySQL_HostGroups_Handler::get_random_hostgroup_entry(unsigned int hid) {
MySQL_Hostgroup_Entry *mshge=NULL;
rdlock();
MySQL_Hostgroup *mshg=(MySQL_Hostgroup *)MyHostGroups->index(hid);
mshge=mshg->get_random_hostgroup_entry();
rdunlock();
return mshge;
}
void * MySQL_Backend::operator new(size_t size) {
return l_alloc(size);
@ -190,3 +199,23 @@ size_t MySQL_Hostgroup::servers_in_hostgroup() {
return MSHGEs->len;
}
MySQL_Hostgroup_Entry * MySQL_Hostgroup::get_random_hostgroup_entry() {
unsigned int i;
unsigned int sum=0;
MySQL_Hostgroup_Entry *mshge;
for (i=0; i<MSHGEs->len; i++) {
mshge=(MySQL_Hostgroup_Entry *)MSHGEs->index(i);
sum+=mshge->weight;
}
unsigned int j=rand()%sum;
sum=0;
for (i=0; i<MSHGEs->len; i++) {
mshge=(MySQL_Hostgroup_Entry *)MSHGEs->index(i);
sum+=mshge->weight;
if (j<=sum) {
return mshge;
}
}
return NULL;
}

@ -59,7 +59,8 @@ int MySQL_Connection::assign_mshge(unsigned int hid) { // FIXME
*/
MyHGH->rdlock();
if (mshge) { free_mshge(); }
MySQL_Hostgroup_Entry *_mshge=MyHGH->MSHGE_find(hid,(char *)"127.0.0.1", 3306);
//MySQL_Hostgroup_Entry *_mshge=MyHGH->MSHGE_find(hid,(char *)"127.0.0.1", 3306);
MySQL_Hostgroup_Entry *_mshge=MyHGH->get_random_hostgroup_entry(hid);
assert(_mshge);
if (_mshge) {
set_mshge(_mshge);

Loading…
Cancel
Save