Announcement Announcement Module
Collapse
No announcement yet.
Restart when there is an error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Restart when there is an error

    Hi,

    I use the rc1 version and I test the restart when there is an error.

    I test an extraction from database into a flat file.
    I have only one step with JdbcCursorItemReader and with a FaltFileItemWriter (ShouldDeleteIfExist = true).

    If saveState of JdbcCursorItemReader = true then after the error when I restart, I have an exception:
    ERROR - BatchMain.start(165) | Job Terminated in error:
    java.lang.IllegalArgumentException: Value: [ nullmust be serializable.Object of class [null] must be an instance of interface java.io.Serializable
    at org.springframework.util.Assert.isInstanceOf(Asser t.java:337)
    at org.springframework.batch.item.ExecutionContext.pu t(ExecutionContext.java:67)
    at org.springframework.batch.item.ExecutionContext.pu tString(ExecutionContext.java:53)
    at org.springframework.batch.core.repository.dao.Jdbc StepExecutionDao$1.processRow(JdbcStepExecutionDao .java:101)
    at org.springframework.jdbc.core.JdbcTemplate$RowCall backHandlerResultSetExtractor.extractData(JdbcTemp late.java:1336)
    at org.springframework.jdbc.core.JdbcTemplate$1.doInP reparedStatement(JdbcTemplate.java:650)
    at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:588)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:638)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:667)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:683)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:691)
    at org.springframework.batch.core.repository.dao.Jdbc StepExecutionDao.findExecutionContext(JdbcStepExec utionDao.java:119)
    at org.springframework.batch.core.repository.dao.Jdbc StepExecutionDao$StepExecutionRowMapper.mapRow(Jdb cStepExecutionDao.java:359)
    at org.springframework.jdbc.core.RowMapperResultSetEx tractor.extractData(RowMapperResultSetExtractor.ja va:92)
    at org.springframework.jdbc.core.JdbcTemplate$1.doInP reparedStatement(JdbcTemplate.java:650)
    at org.springframework.jdbc.core.JdbcTemplate.execute (JdbcTemplate.java:588)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:638)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:667)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:675)
    at org.springframework.jdbc.core.JdbcTemplate.query(J dbcTemplate.java:707)
    at org.springframework.batch.core.repository.dao.Jdbc StepExecutionDao.getStepExecution(JdbcStepExecutio nDao.java:412)
    at org.springframework.batch.core.repository.support. SimpleJobRepository.getStepExecutionCount(SimpleJo bRepository.java:285)
    at com.natixis.sphinx.batch.advice.SimpleStepLogAdvic e.doRepriseLogging(SimpleStepLogAdvice.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:79)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:618)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethodWithGivenArgs(AbstractAspect JAdvice.java:627)
    at org.springframework.aop.aspectj.AbstractAspectJAdv ice.invokeAdviceMethod(AbstractAspectJAdvice.java: 609)
    at org.springframework.aop.aspectj.AspectJAfterAdvice .invoke(AspectJAfterAdvice.java:45)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :160)
    at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:106)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.interceptor.ExposeInvocati onInterceptor.invoke(ExposeInvocationInterceptor.j ava:90)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy0.getLastStepExecution(Unknown Source)
    at org.springframework.batch.core.job.SimpleJob.shoul dStart(SimpleJob.java:175)
    at org.springframework.batch.core.job.SimpleJob.execu te(SimpleJob.java:103)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:90)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:85)
    at com.natixis.sphinx.batch.BatchMain.start(BatchMain .java:156)
    at com.natixis.sphinx.batch.BatchMain.main(BatchMain. java:206)
    If saveState of JdbcCrusorItemReader = false, then after the error when I restart the job, the file isn't delete before write and then I have the old line written before the error + all the line written after restart and so I have the front line in double.

    It seems to be a bug, no?

    More, FlatFileItemWriter.restart.count is always = 0. Is this normal?

  • #2
    I think this is the same bug that you reported in http://forum.springframework.org/showthread.php?t=50984. The JIRA issue has been re-opened.

    Comment


    • #3
      I think this is the same bug that you reported in http://forum.springframework.org/showthread.php?t=50984
      Yes you are right, I have created this thread to regroup all the problems I can have with restart.

      the file isn't delete before write and then I have the old line written before the error + all the line written after restart and so I have the front line in double.
      I have seen that if the flat file has an outputState with restart=true, the property shouldDeleteIfExist is not read.
      private void initializeBufferedWriter() {
      File file;

      try {
      file = resource.getFile();

      // If the output source was restarted, keep existing file.
      // If the output source was not restarted, check following:
      // - if the file should be deleted, delete it if it was exiting
      // and create blank file,
      // - if the file should not be deleted, if it already exists,
      // throw an exception,
      // - if the file was not existing, create new.
      if (!restarted) {
      if (file.exists()) {
      if (shouldDeleteIfExists) {
      file.delete();
      } else {
      throw new ItemStreamException("Resource already exists: " + resource);
      }
      }
      String parent = file.getParent();
      if (parent != null) {
      new File(parent).mkdirs();
      }
      file.createNewFile();
      }

      } catch (IOException ioe) {
      throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]",
      ioe);
      }
      I understand why but my problem is if my reader doesn't restore data, it reads the first record one second time when I restart my job that is not complete and then the flat file has the front lines in double.

      Have all the readers to be able to restore data since the last commit?

      What's happened if saveState of JdbcCursorItemReader = false?

      would the use of RESTART_COUNT_STATISTICS_NAME be able to answer to this problem?

      Thanks in advance for your help.

      Comment


      • #4
        I think there is an inconsistency in the framework (it allows you to setSaveState in the JdbcCursorItemReader but not in the FlatFileOutputWriter). This could possibly be fixed - please raise an issue in JIRA. The workaround is to put a step in your job (or a listener in the same step) that delets the output file for you.

        But why do you want to set saveState="false" in the reader?

        Comment


        • #5
          Thank you.

          http://jira.springframework.org/browse/BATCH-493 is created.

          I have forgotten to give the affect version : rc1.0 and I don't know how to modify this issue.

          Comment


          • #6
            Hi,

            I use a stepListener now. It deletes the created file when there is an error in the step using my reader which is not restartable.
            Thanks for the advice, it works well.

            Comment

            Working...
            X