Spring Batch: java.sql.SQLRecoverableException: IO Error: Socket read timed out - spring-batch

In Spring Batch, Reading from and writing to database does up to 31 000 records. After 31 000 records, getting the below exception:
java.sql.SQLRecoverableException:
Encountered an error executing the step
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.sql.SQLRecoverableException: IO Error: Socket read timed out
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:240)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:127)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:264)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
at org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate$ExecutingRunnable.run(TaskExecutorRepeatTemplate.java:258)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLRecoverableException: IO Error: Socket read timed out
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:458)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:157)
at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:202)
... 8 more
Caused by: oracle.net.ns.NetException: Socket read timed out
at oracle.net.ns.Packet.receive(Packet.java:339)
at oracle.net.ns.NSProtocol.connect(NSProtocol.java:296)
at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1102)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:320)
... 16 more
DataSource:
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource"
destroy-method="close">
<property name="explicitCachingEnabled" value="true" />
<property name="URL" value="${batch.jdbc.url}"></property>
<property name="password" value="${batch.jdbc.password}"></property>
<property name="user" value="${batch.jdbc.user}"></property>
<property name="connectionCachingEnabled" value="true" />
<property name="connectionCacheName" value="ImplicitCache01" />
<property name="maxStatements" value="2000000" />
<property name="connectionCacheProperties">
<props merge="default">
<!-- <prop key="MinLimit">5</prop> -->
<!-- <prop key="MaxLimit">50</prop> -->
<prop key="InitialLimit">1</prop>
<prop key="MinLimit">1</prop>
<prop key="MaxLimit">2000</prop>
<prop key="ConnectionWaitTimeout">11800000</prop>
<prop key="InactivityTimeout">11800000</prop>
<prop key="TimeToLiveConnectionTimeout">18000</prop>
<prop key="ValidateConnection">true</prop>
<prop key="PropertyCheckInterval">300000</prop>
</props>
</property>
</bean>
Even though I raised the timeout in Connection Properties, Still I am getting the same exception.
I have raised the TimeToLiveConnectionTimeout. Still facing same issue.
Query:
select e.id, e.tpin, e.res_blob.getClobVal() clobvalue from ecrnt e where e.id >= 688370 AND e.id <= 788370
I am querying xmltype in oracle db.
The batch job runs successfully for 100k records when I query without xmlType.
I am facing the below exception when I try to query xmltype.
- org.springframework.dao.DataAccessResourceFailureException: Attempt
to process next row failed; SQL [select e.id, e.tpin, e.res_blob.getClobVal()
clobvalue from ecrnt e where e.id >= 688370 AND e.id <= 788370];
**ORA-00028: your session has been killed ORA-00028: your session has
been killed ORA-00028: your session has been killed ORA-04036: PGA
memory used by the instance exceeds PGA_AGGREGATE_LIMIT ORA-06512: at
"SYS.XMLTYPE", line 138 ;**
Nested exception:
nested exception is java.sql.SQLRecoverableException: ORA-00028: your session has been killed ORA-00028: your session has been killed ORA-00028: your session has been killed ORA-04036: PGA memory used by the instance exceeds PGA_AGGREGATE_LIMIT ORA-06512: at "SYS.XMLTYPE", line 138 at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) at org.springframework.batch.item.database.AbstractCursorItemReader.doRead(AbstractCursorItemReader.java:450) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:85) at sun.reflect.GeneratedMethodAccessor962.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:131) at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:119) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at com.sun.proxy.$Proxy467.read(Unknown Source) at org.springframework.batch.core.step.item.Simpl

Increasing the timeout would not solve the issue since there is actually no timeout. You need to set the connection time-to-live to a high value so that oracle db server does not close your connection. See here: https://docs.oracle.com/cd/B28359_01/java.111/e10788/optimize.htm#CFHBJBCI

Implement JPA for avoiding this error

Related

Server Tomcat v8.0 Server at localhost failed to start. This is error snapshot

Server Tomcat v8.0 Server at localhost failed to start. This is error snapshot
**I am unable to identify why this problem is occur. when i change something in xml files then this problem start.I send a small snapshot of my problem. Help me to resolve this issue.
After change in this file mentioned below i got error. I send a small snapshot of that file also.Advance thanks.
Project is in maven, spring , mysql**
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/shoot]]
at java.util.concurrent.FutureTask.report(FutureTask.java:122)
at java.util.concurrent.FutureTask.get(FutureTask.java:192)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:915)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:871)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/shoot]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:153)
... 6 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextException
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.apache.catalina.util.Introspection.getDeclaredFields(Introspection.java:106)
at org.apache.catalina.startup.WebAnnotationSet.loadFieldsAnnotation(WebAnnotationSet.java:256)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationListenerAnnotations(WebAnnotationSet.java:86)
at org.apache.catalina.startup.WebAnnotationSet.loadApplicationAnnotations(WebAnnotationSet.java:63)
at org.apache.catalina.startup.ContextConfig.applicationAnnotationsConfig(ContextConfig.java:335)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:782)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:306)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5202)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
... 6 more
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
... 20 more
</pre>
File :
<context:component-scan base-package="com.jwt" />
<!-- Getting Database properties -->
<mvc:annotation-driven />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- DataSource -->
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
id="dataSource">
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="packagesToScan" value="com.jwt"></property>
</bean>
<!-- Transaction -->
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager
">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
Probably, spring-context.jar is not inclded in your application. If you are using maven, please check dependency for spring-context jar file:
<dependency>
<groupid>org.springframework</groupid>
<artifactid>spring-context</artifactid>
<version>${org.springframework.version}</version>
</dependency>

postgres: Error querying database

Project run for some time after the database connection is not found, the error message is as follows:
2017-05-02 10:02:17,224 ERROR [main] (line:com.unis.license.agent.management.aop.ManagementServicesAop.afterThrowing(ManagementServicesAop.java:47)) - BeforeMethod:com.unis.license.agent.management.service.impl.LicenseServiceImpl.loadLicenseInfo Params: []
2017-05-02 10:02:17,225 ERROR [main] (line:com.unis.license.agent.management.aop.ManagementServicesAop.afterThrowing(ManagementServicesAop.java:50)) - methodException:com.unis.license.agent.management.service.impl.LicenseServiceImpl.loadLicenseInfo Exception:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (FATAL: the database system is starting up)
The error may exist in licenseAgent/orm/LicenseInfo.xml
The error may involve com.unis.license.agent.management.dao.ILicenseInfoOper.getAll
The error occurred while executing a query
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (FATAL: the database system is starting up)
2017-05-02 10:02:17,226 ERROR [main] (line:org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:318)) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.unis.license.agent.management.filter.Initialization#0' defined in class path resource [spring-context.xml]: Invocation of init method failed; nested exception is org.springframework.transaction.NoTransactionException: No transaction aspect-managed TransactionStatus in scope
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:381)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:799)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:446)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:296)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1347)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:743)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:492)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:117)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:99)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:154)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
My DataSource configuration information is as follows:
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver"></property>
<property name="url" value="jdbc:postgresql://127.0.0.1:5432/ucsm"></property>
<property name="username" value="uqdm"></property>
<property name="password" value="unis123"></property>
<property name="maxActive" value="100"></property>
<property name="maxIdle" value="30"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="configLocation" value="classpath:licenseAgent/mybatiscfg.xml"></property>
<property name="dataSource" ref="dataSource" />
</bean>
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.unis.license.agent.management.dao" />
</bean>
This is the key part of your stack trace:
FATAL: the database system is starting up
It means that the PostgreSQL server is starting or restarting and not ready to accept connections yet.
You should check the PostgreSQL server log to find the cause of this unexpected start.
Chances are that it is a restart caused by a crashing PostgreSQL server process. Such crashes can be caused (in rough order of likelihood) by buggy server extensions, buggy hardware or PostgreSQL bugs.

How to use JBossTS (Narayana) with Spring Data JPA

I am investigating the use of a JTA transaction manager with Spring Data JPA. I have successfully configured Atomikos and Bitronix and am trying to configure JBossTS (Arjuna/Narayana).
I followed the instructions for configuring JBossTS for Spring and came up with the following configuration:
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
<property name="jpaProperties">
<props>
<prop key="hibernate.format_sql">true"</prop>
<prop key="hibernate.hbm2ddl.auto">create-drop</prop>
<prop key="hibernate.id.new_generator_mappings">false</prop>
<prop key="hibernate.transaction.jta.platform">org.hibernate.engine.transaction.jta.platform.internal.JBossStandAloneJtaPlatform</prop>
<prop key="hibernate.use_sql_comments">true</prop>
</props>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.H2Dialect"/>
<property name="generateDdl" value="true"/>
<property name="showSql" value="true"/>
</bean>
</property>
<property name="jtaDataSource">
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="connectionProperties">
<props>
<prop key="dynamicClass">com.arjuna.ats.internal.jdbc.drivers.PropertyFileDynamicClass</prop>
<prop key="password"></prop>
<prop key="user">sa</prop>
</props>
</property>
<property name="driverClassName" value="com.arjuna.ats.jdbc.TransactionalDriver"/>
<property name="url" value="jdbc:arjuna:database.properties"/>
</bean>
</property>
<property name="packagesToScan" value="org.example.domain"/>
</bean>
<bean class="org.springframework.transaction.jta.JtaTransactionManager" id="transactionManager">
<property name="transactionManager">
<bean class="com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple"/>
</property>
<property name="userTransaction">
<bean class="com.arjuna.ats.jta.UserTransaction" factory-method="userTransaction"/>
</property>
</bean>
<transaction:annotation-driven/>
However, attempting to run the application throws the following error:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
Caused by: org.hibernate.exception.GenericJDBCException: Unable to open JDBC Connection for DDL execution
Caused by: java.sql.SQLException: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.createDataSource(IndirectRecoverableConnection.java:361)
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.<init>(IndirectRecoverableConnection.java:109)
at com.arjuna.ats.internal.jdbc.ConnectionImple.<init>(ConnectionImple.java:107)
at com.arjuna.ats.internal.jdbc.ConnectionManager.create(ConnectionManager.java:110)
at com.arjuna.ats.jdbc.TransactionalDriver.connect(TransactionalDriver.java:87)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:196)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:159)
at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180)
at org.hibernate.resource.transaction.backend.jta.internal.DdlTransactionIsolatorJtaImpl.prepare(DdlTransactionIsolatorJtaImpl.java:49)
... 60 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at com.arjuna.ats.internal.jdbc.IndirectRecoverableConnection.createDataSource(IndirectRecoverableConnection.java:346)
There does not seem to be any documentation on whether JNDI is mandatory to run JBossTS and if yes, how it can be configured in a standalone application that does not use a JavaEE container.
A sample application is available on Github in case the full configuration and source code is required. The problem can be seen by running Maven tests as mvn test -D"spring.profiles.active=jbossts".
Replace the <prop key="dynamicClass"> with <prop key="DYNAMIC_CLASS">
Specify the properties file with target/classes
Use the H2 file database instead of the memory
For more information you can see narayana.io

Unable to connect to Cassandra db through Kundera in Play! framework

I am getting the following error when I run my application through SBT Console in Intellij IDEA.
[info] play - Application started (Dev)
[error] c.i.c.c.t.ThriftClientFactory - Error during pool creation: caused by
org.apache.thrift.TException: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at net.dataforte.cassandra.pool.ConnectionPool.init(ConnectionPool.java:345) ~[cassandra-connection-pool-0.7.1.jar:na]
at net.dataforte.cassandra.pool.ConnectionPool.<init>(ConnectionPool.java:127) ~[cassandra-connection-pool-0.7.1.jar:na]
at com.impetus.client.cassandra.thrift.ThriftClientFactory.createPoolOrConnection(ThriftClientFactory.java:146) ~[kundera-cassandra-2.5.jar:na]
at com.impetus.kundera.loader.GenericClientFactory.load(GenericClientFactory.java:95) [kundera-core-2.5.jar:na]
at com.impetus.kundera.configure.ClientFactoryConfiguraton.configure(ClientFactoryConfiguraton.java:67) [kundera-core-2.5.jar:na]
Caused by: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at org.apache.thrift.transport.TFastFramedTransport.readFrame(TFastFramedTransport.java:144) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.transport.TFastFramedTransport.read(TFastFramedTransport.java:134) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297) ~[libthrift-0.7.0.jar:0.7.0]
[error] application -
! Internal server error, for (GET) [/] ->
java.lang.ExceptionInInitializerError: null
at models.process.EmployeeProcessImpl$.<init>(EmployeeProcess.scala:82) ~[myEntities.jar:na]
at models.process.EmployeeProcessImpl$.<clinit>(EmployeeProcess.scala) ~[myEntities.jar:na]
at controllers.Application$.<init>(Application.scala:168) ~[na:na]
at controllers.Application$.<clinit>(Application.scala) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:107) ~[na:na]
Caused by: com.impetus.kundera.loader.ClientLoaderException: org.apache.thrift.TException: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at com.impetus.client.cassandra.thrift.ThriftClientFactory.createPoolOrConnection(ThriftClientFactory.java:151) ~[kundera-cassandra-2.5.jar:na]
at com.impetus.kundera.loader.GenericClientFactory.load(GenericClientFactory.java:95) ~[kundera-core-2.5.jar:na]
at com.impetus.kundera.configure.ClientFactoryConfiguraton.configure(ClientFactoryConfiguraton.java:67) ~[kundera-core-2.5.jar:na]
at com.impetus.kundera.configure.Configurator.configure(Configurator.java:65) ~[kundera-core-2.5.jar:na]
at com.impetus.kundera.KunderaPersistence.initializeKundera(KunderaPersistence.java:109) ~[kundera-core-2.5.jar:na]
Caused by: org.apache.thrift.TException: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at net.dataforte.cassandra.pool.ConnectionPool.init(ConnectionPool.java:345) ~[cassandra-connection-pool-0.7.1.jar:na]
at net.dataforte.cassandra.pool.ConnectionPool.<init>(ConnectionPool.java:127) ~[cassandra-connection-pool-0.7.1.jar:na]
at com.impetus.client.cassandra.thrift.ThriftClientFactory.createPoolOrConnection(ThriftClientFactory.java:146) ~[kundera-cassandra-2.5.jar:na]
at com.impetus.kundera.loader.GenericClientFactory.load(GenericClientFactory.java:95) ~[kundera-core-2.5.jar:na]
at com.impetus.kundera.configure.ClientFactoryConfiguraton.configure(ClientFactoryConfiguraton.java:67) ~[kundera-core-2.5.jar:na]
Caused by: org.apache.thrift.transport.TTransportException: Read a negative frame size (-2080374784)!
at org.apache.thrift.transport.TFastFramedTransport.readFrame(TFastFramedTransport.java:144) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.transport.TFastFramedTransport.read(TFastFramedTransport.java:134) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.transport.TTransport.readAll(TTransport.java:84) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.protocol.TBinaryProtocol.readAll(TBinaryProtocol.java:378) ~[libthrift-0.7.0.jar:0.7.0]
at org.apache.thrift.protocol.TBinaryProtocol.readI32(TBinaryProtocol.java:297) ~[libthrift-0.7.0.jar:0.7.0]
[error] application - Error while rendering default error page
scala.MatchError: java.lang.ExceptionInInitializerError (of class java.lang.ExceptionInInitializerError)
at play.api.GlobalSettings$class.onError(GlobalSettings.scala:148) ~[play_2.11-2.3.0.jar:2.3.0]
at play.api.DefaultGlobal$.onError(GlobalSettings.scala:206) [play_2.11-2.3.0.jar:2.3.0]
at play.core.server.Server$class.logExceptionAndGetResult$1(Server.scala:76) [play_2.11-2.3.0.jar:2.3.0]
at play.core.server.Server$$anonfun$getHandlerFor$4.apply(Server.scala:86) [play_2.11-2.3.0.jar:2.3.0]
at play.core.server.Server$$anonfun$getHandlerFor$4.apply(Server.scala:84) [play_2.11-2.3.0.jar:2.3.0]
The example I am working with is taken from :
http://blog.knoldus.com/2014/06/22/playing-kundera-cassandra/
I am having Play! 2.4.6 framework with Cassandra 2.2. What could be wrong with the project which is not allowing to connect to the database ? Do I need to make some change regarding CQL or Kundera version so that my database can get connected ? My persistence.xml file is as under:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
https://raw.github.com/impetus-opensource/Kundera/Kundera-2.0.4/kundera-core/src/test/resources/META-INF/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="cassandra_employees">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<class>models.domains.Employee</class>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="9042" />
<property name="kundera.keyspace" value="EmployeeExample" />
<property name="kundera.dialect" value="cassandra" />
<property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
<property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider" />
<property name="kundera.cache.config.resource" value="/ehcache-test.xml" />
</properties>
</persistence-unit>
</persistence>
Please tell me if I have to make some version related change for Cassandra or CQL and that too in which file ?
used below config and it works fine on my system..
updated cassandra.yaml:
FROM:
start_rpc: false
TO:
start_rpc: true
Persistence.xml:
unit name mentioned below is random which will be used to access this particular persistence.
keyspace name is the name of the table created in cassandra.
<persistence-unit name="persistence">
<provider>com.impetus.kundera.KunderaPersistence</provider>
<properties>
<property name="kundera.nodes" value="localhost" />
<property name="kundera.port" value="9160" />
<property name="kundera.keyspace" value="trial1" />
<property name="kundera.dialect" value="cassandra" />
<property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.thrift.ThriftClientFactory" />
<property name="kundera.pool.size.max.active" value="500" />
<property name="kundera.pool.size.max.total" value="500" />
</properties>

Spring Batch: Getting step context in processor for partitioned step

I'm developing a Spring Batch job that processes multiple input files in parallel using a MultiResourcePartitioner. In the ItemProcessor I need to get the number of records in the current input file. I get the current file name from the step context and read the number of lines in the file:
StepSynchronizationManager.register(stepExecution);
StepContext stepContext = StepSynchronizationManager.getContext();
StepSynchronizationManager.close();
log.trace("stepContext: " + stepContext.getStepExecution().getExecutionContext().entrySet().toString());
...
UrlResource currentFile = new UrlResource(stepContext.getStepExecution().getExecutionContext().getString("fileName"));
This all seems to work but I'm getting exceptions when accessing the step context from the processor threads:
2013-05-15 11:44:35,178 DEBUG [org.springframework.batch.core.step.tasklet.TaskletStep] <taskExecutor-3> - Rollback for RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.processor': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
2013-05-15 11:44:35,194 DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] <taskExecutor-3> - Returning JDBC Connection to DataSource
2013-05-15 11:44:35,194 DEBUG [org.springframework.batch.repeat.support.RepeatTemplate] <taskExecutor-3> - Handling exception: org.springframework.beans.factory.BeanCreationException, caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.processor': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
2013-05-15 11:44:35,194 DEBUG [org.springframework.batch.repeat.support.RepeatTemplate] <taskExecutor-3> - Handling fatal exception explicitly (rethrowing first of 1): org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.processor': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
2013-05-15 11:44:35,210 ERROR [org.springframework.batch.core.step.AbstractStep] <taskExecutor-3> - Encountered an error executing the step
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.processor': Scope 'step' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No context holder available for step scope
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:341)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:33)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:182)
at $Proxy14.process(Unknown Source)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:125)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:291)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:190)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:74)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:386)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:264)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:250)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:120)
at org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler$1.call(TaskExecutorPartitionHandler.java:118)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.IllegalStateException: No context holder available for step scope
at org.springframework.batch.core.scope.StepScope.getContext(StepScope.java:197)
at org.springframework.batch.core.scope.StepScope.get(StepScope.java:139)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:327)
... 24 more
Is there a way to get the current input file name from the processor of a partitioned job?
Here is the relevant config:
<batch:job id="acct">
<batch:step id="init" parent="abstractStep" next="processStep">
<batch:tasklet ref="fileDeleteTasklet" />
</batch:step>
<batch:step id="processStep">
<batch:partition step="processInput" partitioner="partitioner">
<batch:handler grid-size="2" task-executor="taskExecutor" />
</batch:partition>
</batch:step>
</batch:job>
<batch:step id="processInput">
<batch:tasklet>
<batch:chunk reader="reader" processor="processor" writer="writer" commit-interval="3">
<batch:streams>
<batch:stream ref="reader"/>
<batch:stream ref="flatFileItemWriter"/>
</batch:streams>
</batch:chunk>
</batch:tasklet>
</batch:step>
<bean id="partitioner" class="org.springframework.batch.core.partition.support.MultiResourcePartitioner" scope="step">
<property name="keyName" value="fileName"/>
<property name="resources" value="file:#{jobParameters['inputFilePattern']}"/>
</bean>
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="5"/>
<property name="maxPoolSize" value="5"/>
</bean>
<bean id="reader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<property name="resource" value="#{stepExecutionContext[fileName]}" />
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="lineTokenizer">
<bean class="org.springframework.batch.item.file.transform.FixedLengthTokenizer">
<property name="names" value="recordType,reserved,aCode,bCode,acctNumber,idType,cCode" />
<property name="columns" value="1,2,3-6,7-9,10-15,16,17-19" />
<property name="strict" value="false" />
</bean>
</property>
<property name="fieldSetMapper">
<bean class="com.example.batch.acct.AcctInputFieldSetMapper" />
</property>
</bean>
</property>
</bean>
<bean id="processor" class="com.example.batch.acct.AcctProcessor" scope="step">
<property name="soapClient" ref="soapClient" />
<property name="maxNumIds" value="${batch.soap.numberOfIds}" />
<aop:scoped-proxy />
</bean>
Answered on the Spring Batch forum:
The ItemProcessor interface does not expose a way to access the
StepContext, so you need to inject it yourself:
<bean id="itemProcessor" class="com.myApp.MyItemProcessor" scope="step">
<property name="stepContext" value="#{stepExecutionContext}"/>
</bean>
Assuming your processor class has an exposed property named
stepContext.
-- Michael Minella, Spring Batch Lead
<bean id="itemProcessor" class="com.myApp.MyItemProcessor" scope="step">
<property name="stepContext" value="#{stepExecutionContext}"/>
</bean>
In this case when stepContex is a type of org.springframework.batch.core.scope.context.StepContext, how suggests name of this property, I am getting exceptions:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name
'scopedTarget.itemProcessor' defined in
class path resource [META-INF/jobs/Job.xml]:
Initialization of bean failed; nested exception is
org.springframework.beans.ConversionNotSupportedException: Failed to
convert property value of type 'java.util.Collections$UnmodifiableMap'
to required type
'org.springframework.batch.core.scope.context.StepContext' for
property 'stepContext'; nested exception is
java.lang.IllegalStateException: Cannot convert value of type
'java.util.Collections$UnmodifiableMap' to required type
'org.springframework.batch.core.scope.context.StepContext' for
property 'stepContext': no matching editors or conversion strategy
found
I needed to access jobExecutionId inside ItemProcessor, so I have changed this configuration to:
<bean id="itemProcessor" class="com.myApp.MyItemProcessor" scope="step">
<property name="stepExecution" value="#{stepExecution}"/>
</bean>
Property "stepExecution" is a type org.springframework.batch.core.StepExecution