Enhance connection fail-over with master/slave restriction and add load balancing of connections among multiple hosts. Based on work by chenhj@cn.fujitsu.com