Configure GlassFish JDBC connection pool to handle Amazon RDS Multi-AZ disaster recovery

I have a Java EE application running on GlassFish on EC2, with a MySQL database on Amazon RDS. I am trying to configure the JDBC connection pool in order to minimize downtime in the event of a database failure.

My current configuration does not work correctly when redirecting to Multi-AZ, since the backup database instance is available after a couple of minutes (according to the AWS console), while the GlassFish instance remains stuck for a long time (about 15 minutes) before resume work.

The connection pool is configured as follows:

asadmin create-jdbc-connection-pool --restype javax.sql.ConnectionPoolDataSource \
--datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource \
--isconnectvalidatereq=true --validateatmostonceperiod=60 --validationmethod=auto-commit \
--property user=$DBUSER:password=$DBPASS:databaseName=$DBNAME:serverName=$DBHOST:port=$DBPORT \
MyPool

If I use an instance of Single-AZ db.m1.small and reload the database from the console, GlassFish will invalidate the connections, throw some exceptions, and then reconnect as soon as the database is available. In this setup, I get less than 1 minute of downtime.

If I use Multi-AZ db.m1.small and reboot with failover from the AWS console , I see no exception at all. The server stops completely, while all incoming requests fail. After 15 minutes, I finally get the following:

Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 940,715 milliseconds ago.  The last packet sent successfully to the server was 935,598 milliseconds ago.

It seems that every HTTP stream is blocked on an invalid connection without receiving an exception and therefore there is no way to perform a connection check.

Multi-AZ 15 16 , -, .

, :

  • /
  • timeout/reclaim
  • MysqlDataSource MysqlConnectionPoolDataSource

- , , ? GlassFish ?

+4
1

, , , , , , , - , , , 30 .

, - JDBC / JDNI COnnection socketTimeout .

, , , , ( , , ).

, , connectTimeout autoReconnect.

JDBC:

jdbc:(...)&connectTimeout=15000&socketTimeout=60000&autoReconnect=true 

DNS DNS,

 java.security.Security.setProperty("networkaddress.cache.ttl" , "0"); 
 java.security.Security.setProperty("networkaddress.cache.negative.ttl" , "0"); 

, Java TTL, , DNS , IP .

, DNS JVM -Dnet, .

+4

All Articles