Reconnect to oracle db after restart from Wildfly datasource - java

I have a product that uses Wildfly datasource to connect to Oracle DB.
Our Database servers have a scheduled weekly cold backup and for this reason the DB will shutdown every week for approx 10 mins. Then i am forced to restart the application after the DB is started.
How do i configure my Wildfly datasource to check and reconnect after the db is started ?
Wildfly version: wildfly-8.2.0.Final
Data source configuration -
<datasource jndi-name="java:/REQUESTDS" pool-name="REQUESTDS" enabled="true">
<connection-url>jdbc:oracle:thin:#localhost:1521:MYDB</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<connection-property name="selectMethod">
direct
</connection-property>
<connection-property name="sendStringParametersAsUnicode">
true
</connection-property>
<driver>oracle-thin</driver>
<new-connection-sql>SELECT 1 FROM DUAL</new-connection-sql>
<pool>
<min-pool-size>20</min-pool-size>
<max-pool-size>80</max-pool-size>
<prefill>true</prefill>
<use-strict-min>true</use-strict-min>
</pool>
<security>
<security-domain>CompanySecureDataSource</security-domain>
</security>
<validation>
<validate-on-match>true</validate-on-match>
</validation>
<timeout>
<blocking-timeout-millis>90000</blocking-timeout-millis>
<allocation-retry>40</allocation-retry>
<allocation-retry-wait-millis>30000</allocation-retry-wait-millis>
</timeout>
</datasource>
I have checked my threads here and tried most of them. But in vain.
What is the correct setting that will check and reconnect to oracle db

Using background-validation and the pool will try to create new connections if any one of them dies.
<validation>
<check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<background-validation-millis>20000</background-validation-millis>
</validation>

Related

How to fix the "tables are already present using metadata" camunda process engine exception?

I am using wildfly 14.0.1 Application server and Camunda V 7.11.0. I have configured mysql db instead of the default camunda h2 db and added the below data-sources to the standalone.xml file. But I get the below exception at deployment. How do I get this exception fixed?
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://127.0.0.1:3306/camunda11?jdbcCompliantTruncation=false</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>password</password>
</security>
</datasource>
<datasource jta="true" jndi-name="java:jboss/datasources/ProcessEngine" pool-name="ProcessEngine" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://127.0.0.1:3306/camunda11?sessionVariables=sql_mode='NO_ENGINE_SUBSTITUTION'&jdbcCompliantTruncation=false</connection-url>
<driver>mysql</driver>
<security>
<user-name>root</user-name>
<password>password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
11:47:10,206 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 72) MSC000001: Failed to start service org.camunda.bpm.platform.process-engine.default: org.jboss.msc.service.StartException in service org.camunda.bpm.platform.process-engine.default: org.camunda.bpm.engine.ProcessEngineException: ENGINE-03018 Could not check if tables are already present using metadata.
at org.camunda.bpm.wildfly.camunda-wildfly-subsystem#7.11.0//org.camunda.bpm.container.impl.jboss.service.MscManagedProcessEngineController$1.run(MscManagedProcessEngineController.java:98)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.jboss.threads#2.3.2.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads#2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads#2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads#2.3.2.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1349)
at java.base/java.lang.Thread.run(Thread.java:834)
at org.jboss.threads#2.3.2.Final//org.jboss.threads.JBossThread.run(JBossThread.java:485)
Caused by: org.camunda.bpm.engine.ProcessEngineException: ENGINE-03018 Could not check if tables are already present using metadata.
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.checkDatabaseTableException(EnginePersistenceLogger.java:241)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.db.sql.DbSqlSession.isTablePresent(DbSqlSession.java:494)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.db.sql.DbSqlSession.isEngineTablePresent(DbSqlSession.java:434)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.db.AbstractPersistenceSession.dbSchemaUpdate(AbstractPersistenceSession.java:218)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:56)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:34)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:28)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:107)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.ProcessEngineImpl.executeSchemaOperations(ProcessEngineImpl.java:120)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:93)
at org.camunda.bpm.camunda-engine#7.11.0//org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:798)
at org.camunda.bpm.wildfly.camunda-wildfly-subsystem#7.11.0//org.camunda.bpm.container.impl.jboss.service.MscManagedProcessEngineController.startProcessEngine(MscManagedProcessEngineController.java:178)
at org.camunda.bpm.wildfly.camunda-wildfly-subsystem#7.11.0//org.camunda.bpm.container.impl.jboss.service.MscManagedProcessEngineController$2.run(MscManagedProcessEngineController.java:132)
at org.camunda.bpm.wildfly.camunda-wildfly-subsystem#7.11.0//org.camunda.bpm.container.impl.jboss.service.MscManagedProcessEngineController$2.run(MscManagedProcessEngineController.java:130)
at org.camunda.bpm.wildfly.camunda-wildfly-subsystem#7.11.0//org.camunda.bpm.container.impl.jboss.util.Tccl.runWithTccl(Tccl.java:54)
at org.camunda.bpm.wildfly.camunda-wildfly-subsystem#7.11.0//org.camunda.bpm.container.impl.jboss.util.Tccl.runUnderClassloader(Tccl.java:46)
at org.camunda.bpm.wildfly.camunda-wildfly-subsystem#7.11.0//org.camunda.bpm.container.impl.jboss.service.MscManagedProcessEngineController.startInternal(MscManagedProcessEngineController.java:130)
at org.camunda.bpm.wildfly.camunda-wildfly-subsystem#7.11.0//org.camunda.bpm.container.impl.jboss.service.MscManagedProcessEngineController$1.run(MscManagedProcessEngineController.java:91)
... 8 more
Caused by: org.apache.ibatis.exceptions.PersistenceException:
I used the mysql-connector-java-5.1.44.jar instead of the 5.1.6 version to fix the exception.

Deploying WAR-Application in JBoss Wildfly with unavailable DataSource?

I have a web application which uses JPA persistence under wildfly 8.2.
The persistence.xml is connected to <jta-data-source>java:/jdbc/myDS</jta-data-source> which generally works fine.
BUT if I start the JBoss-Server before the Database-Server is ready, the web application doesn't get deployed with the following error:
BAS011411: Unexpected problem gathering statistics: java.lang.IllegalStateException: JBAS011477: Persistence unit 'my.war#myPU' is not available
My wish is that the application DOES get deployed (and throws an exception when is accessed) even when the DB-server is not available.
Is that possible?
My datasource-definition:
<datasource jndi-name="java:/jdbc/myDS" pool-name="myDS" enabled="true" use-java-context="true">
<connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
<driver>mysql</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>15</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>myuser</user-name>
<password>mypwd</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"/>
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"/>
</validation>
</datasource>
Steps to reproduce:
Deploy an app with a "valid" datasource definition but keep the database server offline

Auto recover Connections in Wildfly 8.2 for Oracle without using validate-on-match

I am using wildfly 8.2 and oracle 11g and I have my connection pool flushing an invalid connection and creating a new one if possible. I'm using Spring and Hibernate at the back-end too (we are looking up the connection via JNDI)
I could not find a concise example of pool configuration for oracle on the net that I could get to work, so I cribbed bits and bobs from various sources and managed to get it working.
My question is this. I am setting "Validate On Match" equal to true, but the Jboss documention (https://docs.jboss.org/jbossas/docs/Server_Configuration_Guide/beta500/html/ch13s13.html) states that
<validate-on-match> - Prior to JBoss 4.0.5, connection validation occurred when the JCA layer attempted to match a managed connection. With the addition of <background-validation> this is no longer required. Specifying <validate-on-match> forces the old behavior. NOTE: this is typically NOT used in conjunction with <background-validation>
I would not like to use "old behaviour" if I can avoid it. Does anyone have an example of auto recovering connection pools with Oracle 11g Wildfly 8.2. and using the ojdbc6 driver.
Thanks
Btw my current set up for the pool is as below (nb I know I have the pool size set to 1, it was so I could easily kill the session and know the pool recovers).
<datasource jta="true" jndi-name="java:/jboss/datasources/mydatabase" pool-name="mydatabase" enabled="true" use-ccm="true">
<connection-url>jdbc:oracle:thin:#localhost:1521:mydatabase</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>ojdbc6-11.1.0.7.0.jar</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>1</max-pool-size>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>mydatabase</user-name>
<password>mydatabase</password>
</security>
<validation>
<check-valid-connection-sql>SELECT 1 FROM DUAL</check-valid-connection-sql>
<validate-on-match>true</validate-on-match>
<background-validation>false</background-validation>
</validation>
<timeout>
<set-tx-query-timeout>false</set-tx-query-timeout>
<blocking-timeout-millis>0</blocking-timeout-millis>
<idle-timeout-minutes>0</idle-timeout-minutes>
<query-timeout>0</query-timeout>
<use-try-lock>0</use-try-lock>
<allocation-retry>0</allocation-retry>
<allocation-retry-wait-millis>0</allocation-retry-wait-millis>
</timeout>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
</datasources>
Cheer to anyone that can help
Try this validation node:
<validation>
<background-validation>true</background-validation>
<background-validation-millis>200000</background-validation-millis>
<check-valid-connection-sql>select 1 from dual</check-valid-connection-sql>
</validation>
Remember to adjust the value of background-validation-millis.

How to know the number of connection pools created in JBOSS application server

I am using jboss 7.0 for web application. In standalone.xml file, I have defined datasource as ,
<datasource jndi-name="java:jboss/datasources/finacpacds" pool-name="ltmscompanyadmindspool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>
jdbc:mysql://localhost:3306/finacpac?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
</connection-url>
<driver>
mysqldriver
</driver>
<transaction-isolation>
TRANSACTION_READ_COMMITTED
</transaction-isolation>
<pool>
<min-pool-size>
10
</min-pool-size>
<max-pool-size>
50
</max-pool-size>
<prefill>
true
</prefill>
<use-strict-min>
false
</use-strict-min>
<flush-strategy>
FailingConnectionOnly
</flush-strategy>
</pool>
<security>
<user-name>
root
</user-name>
<password>
</password>
</security>
<validation>
<validate-on-match>
false
</validate-on-match>
<background-validation>
false
</background-validation>
<useFastFail>
false
</useFastFail>
</validation>
<statement>
<prepared-statement-cache-size>
100
</prepared-statement-cache-size>
<share-prepared-statements/>
</statement>
</datasource>
Now my question is can i see the number of connection pools created when jboss is running by system.out.print statement. Is there any way to do this.
You cannot print out that info to System.out. You can read datasource statistics via CLI:
/subsystem=datasources/data-source=ltmscompanyadmindspool/statistics=pool:read-resource(include-runtime=true)
/subsystem=datasources/data-source=ltmscompanyadmindspool/statistics=jdbc:read-resource(include-runtime=true)
You can read more about statistics here.
On a side note, your datasource configuration is a bit concerning. Why would you have the validations disabled? If you do this then when there is an outage or a restart of the database server JBoss won't be able to validate/refresh the connections without a restart of the JBoss server.

java.sql.SQLRecoverableException:Closed Connection

I am using jboss7.0.2 final with Oracle 11. Currently I am facing one issue which happens randomly. But during heavy load this error trace keeps growing. Tried so many approaches couldn't succeed.
MyDatasource Config:
<?xml version="1.0" encoding="UTF-8"?>
<datasource jndi-name="sportPool" pool-name="sportPool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:oracle:thin:#10.11.252.200:1521:sportsdb</connection-url>
<driver>oracleDriver</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>75</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>mportal</user-name>
<password>mobile</password>
</security>
<timeout>
<idle-timeout-minutes>60000</idle-timeout-minutes>
</timeout>
</datasource>
StackTrace:
nested exception is java.sql.SQLRecoverableException: Closed Connection
at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.translate(SQLExceptionSubclassTranslator.java:82)
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:237)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:604)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:638)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:667)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:683)
... 50 more
Caused by: java.sql.SQLRecoverableException: Closed Connection
at oracle.jdbc.driver.OracleStatement.ensureOpen(OracleStatement.java:4051)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3563)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493)
at org.jboss.jca.adapters.jdbc.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:111)
at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462)
at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:645)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:588)
... 56 more
Take a look at your database settings - it's possible, that the timeout set in database is shorter than the timeout set in datasource deployment descriptor, and the database closes the connections.
Check your network - it's possible that there is something wrong with your firewall / routing settings, and the connections are closed/dropped somewhere in the middle of the route.
Take a look at this link JBoss 7 Datasource Configuration. There is a way of configuring a datasource descriptor, forcing the JBoss to check the connection when checking it out from the pool. Use the valid-connection-checker (faster) or check-valid-connection-sql (slower) setting and set the
<valid-connection-checker>
org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker
</valid-connection-checker>
or
<check-valid-connection-sql>
SELECT 1 FROM DUAL
</check-valid-connection-sql>
A quick update on how I fixed this issue.
I've done following changes outside of the application i.e in JBOSS
**ironjacamar-jdbc**
Updateed ironjacamar-jdbc jar from 1.0.3 to 1.1.0 at this location "{JBOSS_HOME_7.0.2}/modules/org/jboss/ironjacamar/jdbcadapters/main/"
Stanalone.xml
As suggested by npe added <check-valid-connection-sql>.
<datasource jndi-name="sportPool" pool-name="sptPool" enabled="true" jta="true" use-java-context="true" use-ccm="true">
<connection-url>
jdbc:oracle:thin:#10.11.252.200:1521:sprtsdb
</connection-url>
<driver>
oracleDriver
</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>90</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>mtal</user-name>
<password>mle</password>
</security>
<validation>
<check-valid-connection-sql>SELECT 1 FROM DUAL</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<use-fast-fail>false</use-fast-fail>
</validation>
<timeout>
<idle-timeout-minutes>15</idle-timeout-minutes>
</timeout>
</datasource>
This solved the problem. But jboss prints warning message "IJ000612" in console which I think should be ok as long as application is getting valid connection object from jboss.
Seems like your are losing connection, in most cases this happens when there network problems. The configuration you are using is a bit strange;
idle-timeout-minutes = 41 days , default is 15 minutes
min-pool-size = 1
probably the idle-timeout-minutes causing your SQLRecoverableExceptions, I would use a config like;
idle-timeout-minutes = 15 minutes
min-pool-size = 10
max-pool-size = 50 or even less You are using 150MB memory for 75 connections
if you don't have long blocking connection to the database 20 max pool size should be enough.

Categories