MySQL Forums
Forum List  »  Utilities

Fabric creates multiple DB connections
Posted by: Puneet Nahata
Date: August 30, 2016 12:20PM

I have setup of 1 global group, 3 HA groups and 1 fabric node

The below piece of code ends up creating thousands of physical DB connections. The code errors out once all the max connection on DB is reached. According to my understanding, 1 fabric connection will contain map of single database connections to each physical DB servers.
Then why is below code trying to create thousands of physical connection on my HA1 server?

The range grouping is setup as 1-33000 to HA1, 33001-66000 to HA2 and 66001 onwards to HA3

Connection rawConnection = DriverManager.getConnection("jdbc:mysql:fabric://<fabricServer>:<port>/employees?fabricUsername=<fabricUser>&fabricPassword=<fabricPassword>&fabricShardTable=employees.employees", "<db_user>", "<db_password>");

FabricMySQLConnection fabricConnection = (FabricMySQLConnection) rawConnection;

for(int emp_id=1; emp_id<100000; emp_id++) {
fabricConnection.setShardKey(emp_id);
PreparedStatement ps = fabricConnection.prepareStatement(INSERT_EMPLOYEE_SQL);
ps.setInt(1, emp_id);
ps.setString(2, "Name"+i);
ps.setString(3, "Surname"+i);
ps.executeUpdate();
ps.close();
ps == null;
}


PS: i am using PreparedStatement inside the loop and not outside because i want to simulate real world scenareo where multipl user requests will run in parallel and they will create their own PreparedStatements

Options: ReplyQuote


Subject
Views
Written By
Posted
Fabric creates multiple DB connections
1139
August 30, 2016 12:20PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.