Results 1 to 3 of 3

Thread: How to retry failing StoredProcedureItemReader connections?

  1. #1
    Join Date
    Aug 2008
    Posts
    26

    Default How to retry failing StoredProcedureItemReader connections?

    When a StoredProcedureItemReader fails due to a non existing connection, connection time out or similiar, the basic

    Code:
    <b:chunk reader="storedProcedureItemReader"  writer="itemWriter" retry-limit="50">
      <b:retryable-exception-classes>
        <b:include class="java.lang.Exception"/>
      </b:retryable-exception-classes>
    </b:chunk>
    Won't work, since the error is not a read error, but an initialization error:

    Code:
    DEBUG 04.05.2010 14:40:06: -- org.springframework.batch.core.repository.dao.JdbcStepExecutionDao - Truncating long message before update of StepExecution, original message is: org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139)
    	at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:98)
    	at org.springframework.batch.core.step.item.ChunkMonitor.open(ChunkMonitor.java:110)
    	at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:98)
    	at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:288)
    	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:193)
    	at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:115)
    	at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
    	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
    	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
    	at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:83)
    	at org.springframework.batch.core.job.flow.support.state.SplitState$1.call(SplitState.java:81)
    	at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    	at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    	at java.lang.Thread.run(Thread.java:619)
    Caused by: org.springframework.jdbc.UncategorizedSQLException: Executing query; uncategorized SQLException for SQL [PROCEDURE NAME: MYPROCEDURE]; SQL state [null]; error code [0]; Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection); nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection)
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83)
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80)
    	at org.springframework.batch.item.database.AbstractCursorItemReader.initializeConnection(AbstractCursorItemReader.java:425)
    	at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:400)
    	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:137)
    	... 15 more
    Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not establish the connection)
    	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
    	at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
    	at org.springframework.batch.item.database.AbstractCursorItemReader.initializeConnection(AbstractCursorItemReader.java:420)
    	... 17 more
    Caused by: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection
    	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    	at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:334)
    	at oracle.jdbc.ttc7.TTC7Protocol.handleIOException(TTC7Protocol.java:3668)
    	at oracle.jdbc.ttc7.TTC7Protocol.logon(TTC7Protocol.java:353)
    	at oracle.jdbc.driver.OracleConnection.<init>(OracleConnection.java:371)
    	at oracle.jdbc.driver.OracleDriver.getConnectionInstance(OracleDriver.java:551)
    	at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:351)
    	at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    	at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
    	at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
    	at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
    	... 19 more
    So, how do I retry this in case of connection issues?

  2. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    You could use a RetryOperationsInterceptor to wrap the open() method in the reader. I'd be pretty concerned that there was some other problem to solve in the database if this was happening though. Are you sure a retry will succeed?

  3. #3
    Join Date
    Aug 2008
    Posts
    26

    Default

    Quote Originally Posted by Dave Syer View Post
    You could use a RetryOperationsInterceptor to wrap the open() method in the reader. I'd be pretty concerned that there was some other problem to solve in the database if this was happening though. Are you sure a retry will succeed?
    Well as this will be an bi-hourly batch job over a vpn, I would prefer if it would retry a couple times in 5minute intervals so we can avoid getting notified about errors that might have been temporary.

    But I'll try the interceptor way, I'm just a bit baffled about the fact that this is a initialization exception instead of an read exception, but I guess there are reasons for that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •