In IBM liberty server I have configured the datasource with oracle connection details like below.
<dataSource id="auditLogDatasource" jndiName="jdbc/audit_log" type="javax.sql.DataSource" validationTimeout="10s">
<jdbcDriver libraryRef="OracleLib"/> <properties.oracle description="main db pipe" URL="jdbc:oracle:thin://@localhost:1686/mkapp" password="test" user="test"/>
<connectionManager id="ConnectionManager" maxPoolSize="30" minPoolSize="1" purgePolicy="FailingConnectionOnly" />
</dataSource>
Java code
@Resource(lookup = "jdbc/audit_log")
public void setDataSource(DataSource dataSource)
{
if (this.dataSource == null) { this.dataSource = dataSource; }
}
public void store(@Observes AuditRecord auditRecord) {
Connection con = null;
PreparedStatement preparedStatement = null;
try {
log.info("DB connection requested");
con = this.dataSource.getConnection();
preparedStatement = con.prepareStatement(INSERT_QUERY);
int index = 1;
preparedStatement.setString(index++, auditRecord.getAction());
preparedStatement.setString(index++, auditRecord.getUserInitiating());
preparedStatement.setString(index++, auditRecord.getUserAffected());
preparedStatement.setString(index++, auditRecord.getAdditionalInfo());
preparedStatement.setTimestamp(index++, new Timestamp(auditRecord.getCreateTime().getTime()));
preparedStatement.setString(index++, auditRecord.getServer());
preparedStatement.executeUpdate();
log.info("DB record added");
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
if (preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
}
if (con != null) {
try {
con.close();
} catch (SQLException e) {
log.error(e.getMessage(), e);
}
}
}
}
Initially everything working fine mostly I am seeing only 1 Free connection count.
But once I trigger AWS RDS failover (Reboot with failover) server taking too much time to discard the invalid connection from pool & creating new connection.
2019/11/15 17:31:28.571 [Default Executor-thread-60] INFO dao.AuditDao : DB connection requested
2019/11/15 17:47:03.741 [Default Executor-thread-60] INFO dao.AuditDao : DB record added
error in message.log after 16 min
[ERROR ] J2CA0081E: Method destroy failed while trying to execute method destroy on ManagedConnection WSRdbManagedConnectionImpl@10e0477e
from resource No longer available. Caught exception: com.ibm.ws.rsadapter.exceptions.DataStoreAdapterException:
DSRA0080E: An exception was received by the Data Store Adapter. See original exception message: {0}. with SQL State : 08000 SQL Code : 17410
at com.ibm.ws.rsadapter.impl.WSRdbManagedConnectionImpl.destroy(WSRdbManagedConnectionImpl.java:2513)
at [internal classes]
at com.test.auth.dao.AuditDao.store(AuditDao.java: