How to use CacheJdbcBlobStore? Getting NotSerializableException

classic Classic list List threaded Threaded
2 messages Options
javamate javamate
Reply | Threaded
Open this post in threaded view
|

How to use CacheJdbcBlobStore? Getting NotSerializableException

I am trying to use CacheJdbcBlobStore with Ignite 1.0.6 but the grid will not start because of NotSerializableException from the CacheJdbcBlobStore on the CacheConfiguration.

I am using a slightly modified example-cache.xml:

  • Use the OptimizedMarshaller with requireSerializable=false
  • Added cacheStoreFactory property to CacheConfiguration to configure the CacheJdbcBlobStore
  • Use TcpDiscoveryVmIpFinder rather than TcpDiscoveryMulticastIpFinder (for convenience when working locally; not specifically relevant to this situation)

Here's the config file (with comments removed):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd">
 <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">

  <property name="marshaller">
   <bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
    <property name="requireSerializable" value="false" />
   </bean>
  </property>

  <property name="cacheConfiguration">
   <list>
    <bean class="org.apache.ignite.configuration.CacheConfiguration">
     <property name="atomicityMode" value="ATOMIC" />
     <property name="backups" value="1" />
     <property name="cacheStoreFactory">
      <bean class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
       <constructor-arg>
        <bean id="cache.jdbc.store"
         class="org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore" />
       </constructor-arg>
      </bean>
     </property>
    </bean>
   </list>
  </property>

  <property name="discoverySpi">
   <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
    <property name="ipFinder">
     <bean
      class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
      <property name="addresses">
       <list>
        <value>127.0.0.1:47500..47509</value>
       </list>
      </property>
     </bean>
    </property>
   </bean>
  </property>
 </bean>
</beans>

When I try to start the node, I get the following exception:

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
[10:31:01]    __________  ________________ 
[10:31:01]   /  _/ ___/ |/ /  _/_  __/ __/ 
[10:31:01]  _/ // (7 7    // /  / / / _/   
[10:31:01] /___/\___/_/|_/___/ /_/ /___/  
[10:31:01]  
[10:31:01] ver. 1.0.6#20150525-sha1:8977537d
[10:31:01] 2015 Copyright(C) Apache Software Foundation
[10:31:01] 
[10:31:01] Quiet mode.
[10:31:01]   ^-- Logging to file '/Users/eric/Downloads/gridgain-community-fabric-1.0.6/work/log/ignite-ce99056b.0.log'
[10:31:01]   ^-- To see **FULL** console log here add -DIGNITE_QUIET=false or "-v" to ignite.{sh|bat}
[10:31:01] 
[10:31:03] Configured plugins:
[10:31:03]   ^-- None
[10:31:03] 
[10:31:06,133][SEVERE][main][IgniteKernal] Got exception while starting (will rollback startup routine).
class org.apache.ignite.IgniteCheckedException: Failed to start processor: GridProcessorAdapter []
	at org.apache.ignite.internal.IgniteKernal.startProcessor(IgniteKernal.java:1386)
	at org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:769)
	at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:1599)
	at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1467)
	at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:993)
	at org.apache.ignite.internal.IgnitionEx.startConfigurations(IgnitionEx.java:920)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:833)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:737)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:691)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:531)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:501)
	at org.apache.ignite.Ignition.start(Ignition.java:332)
	at org.apache.ignite.startup.cmdline.CommandLineStartup.main(CommandLineStartup.java:288)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to validate cache configuration (make sure all objects in cache configuration are serializable): default
	at org.apache.ignite.internal.processors.cache.GridCacheProcessor.checkSerializable(GridCacheProcessor.java:2901)
	at org.apache.ignite.internal.processors.cache.GridCacheProcessor.start(GridCacheProcessor.java:576)
	at org.apache.ignite.internal.IgniteKernal.startProcessor(IgniteKernal.java:1383)
	... 12 more
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to serialize object: CacheConfiguration [name=null, rebalancePoolSize=2, rebalanceTimeout=10000, evictPlc=null, evictSync=false, evictKeyBufSize=1024, evictSyncConcurrencyLvl=4, evictSyncTimeout=10000, evictFilter=null, evictMaxOverflowRatio=10.0, eagerTtl=true, dfltLockTimeout=0, startSize=1500000, nearCfg=null, writeSync=null, storeFactory=javax.cache.configuration.FactoryBuilder$SingletonFactory@7f485fda, loadPrevVal=false, aff=null, cacheMode=PARTITIONED, atomicityMode=ATOMIC, atomicWriteOrderMode=null, backups=1, invalidate=false, tmLookupClsName=null, rebalanceMode=ASYNC, rebalanceOrder=0, rebalanceBatchSize=524288, offHeapMaxMem=-1, swapEnabled=false, maxConcurrentAsyncOps=500, writeBehindEnabled=false, writeBehindFlushSize=10240, writeBehindFlushFreq=5000, writeBehindFlushThreadCnt=1, writeBehindBatchSize=512, memMode=ONHEAP_TIERED, affMapper=null, rebalanceDelay=0, rebalanceThrottle=0, interceptor=null, longQryWarnTimeout=3000, readFromBackup=true, nodeFilter=null, sqlEscapeAll=false, sqlOnheapRowCacheSize=10240, cpOnRead=true, topValidator=null]
	at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal(JdkMarshaller.java:78)
	at org.apache.ignite.marshaller.AbstractMarshaller.marshal(AbstractMarshaller.java:51)
	at org.apache.ignite.internal.processors.cache.GridCacheProcessor.checkSerializable(GridCacheProcessor.java:2898)
	... 14 more
Caused by: java.io.NotSerializableException: org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal(JdkMarshaller.java:73)
	... 16 more
[10:31:06] Ignite node stopped OK [uptime=00:00:05:106]
class org.apache.ignite.IgniteException: Failed to start processor: GridProcessorAdapter []
	at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:660)
	at org.apache.ignite.Ignition.start(Ignition.java:335)
	at org.apache.ignite.startup.cmdline.CommandLineStartup.main(CommandLineStartup.java:288)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to start processor: GridProcessorAdapter []
	at org.apache.ignite.internal.IgniteKernal.startProcessor(IgniteKernal.java:1386)
	at org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:769)
	at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:1599)
	at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1467)
	at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:993)
	at org.apache.ignite.internal.IgnitionEx.startConfigurations(IgnitionEx.java:920)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:833)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:737)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:691)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:531)
	at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:501)
	at org.apache.ignite.Ignition.start(Ignition.java:332)
	... 1 more
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to validate cache configuration (make sure all objects in cache configuration are serializable): default
	at org.apache.ignite.internal.processors.cache.GridCacheProcessor.checkSerializable(GridCacheProcessor.java:2901)
	at org.apache.ignite.internal.processors.cache.GridCacheProcessor.start(GridCacheProcessor.java:576)
	at org.apache.ignite.internal.IgniteKernal.startProcessor(IgniteKernal.java:1383)
	... 12 more
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to serialize object: CacheConfiguration [name=null, rebalancePoolSize=2, rebalanceTimeout=10000, evictPlc=null, evictSync=false, evictKeyBufSize=1024, evictSyncConcurrencyLvl=4, evictSyncTimeout=10000, evictFilter=null, evictMaxOverflowRatio=10.0, eagerTtl=true, dfltLockTimeout=0, startSize=1500000, nearCfg=null, writeSync=null, storeFactory=javax.cache.configuration.FactoryBuilder$SingletonFactory@7f485fda, loadPrevVal=false, aff=null, cacheMode=PARTITIONED, atomicityMode=ATOMIC, atomicWriteOrderMode=null, backups=1, invalidate=false, tmLookupClsName=null, rebalanceMode=ASYNC, rebalanceOrder=0, rebalanceBatchSize=524288, offHeapMaxMem=-1, swapEnabled=false, maxConcurrentAsyncOps=500, writeBehindEnabled=false, writeBehindFlushSize=10240, writeBehindFlushFreq=5000, writeBehindFlushThreadCnt=1, writeBehindBatchSize=512, memMode=ONHEAP_TIERED, affMapper=null, rebalanceDelay=0, rebalanceThrottle=0, interceptor=null, longQryWarnTimeout=3000, readFromBackup=true, nodeFilter=null, sqlEscapeAll=false, sqlOnheapRowCacheSize=10240, cpOnRead=true, topValidator=null]
	at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal(JdkMarshaller.java:78)
	at org.apache.ignite.marshaller.AbstractMarshaller.marshal(AbstractMarshaller.java:51)
	at org.apache.ignite.internal.processors.cache.GridCacheProcessor.checkSerializable(GridCacheProcessor.java:2898)
	... 14 more
Caused by: java.io.NotSerializableException: org.apache.ignite.cache.store.jdbc.CacheJdbcBlobStore
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
	at org.apache.ignite.marshaller.jdk.JdkMarshaller.marshal(JdkMarshaller.java:73)
	... 16 more
Failed to start grid: Failed to start processor: GridProcessorAdapter []

I notice the presence of the JdkMarshaller even though I set the OptimizedMarshaller. Further, the documentation for the OptimizedMarshaller indicates it will be the default if no other marshaller is explicitly configured (see https://ignite.incubator.apache.org/releases/1.0.0/javadoc/org/apache/ignite/marshaller/optimized/OptimizedMarshaller.html).

So a few questions:

  1. Shouldn't I be seeing the use of the OptimizedMarshaller rather than the JdkMarshaller?
  2. How can I use the CacheJdbcBlobStore?
ivasilinets ivasilinets
Reply | Threaded
Open this post in threaded view
|

Re: How to use CacheJdbcBlobStore? Getting NotSerializableException

Hi!

1. Jdk marshaller is used only to check configuration.

2. Cache store factory should be serializable in cache configuration. FactoryBuilder$SingletonFactory save the instance of the underlying object, so you can use only serializable stores with it. CacheJdbcBlobStore is not serializable. You need to implement your own factory to use CacheJdbcBlobStore.

To implement your own factory please override method Factory.create()
 @Override public CacheJdbcBlobStore create() {
        CacheJdbcBlobStore store = new CacheJdbcBlobStore();

       //Please set only parameters that you need. To use default configuration, write only return new CacheJdbcBlobStore();

        store.setInitSchema(initSchema);
        store.setConnectionUrl(connUrl);
        store.setCreateTableQuery(createTblQry);
        store.setLoadQuery(loadQry);
        store.setUpdateQuery(updateQry);
        store.setInsertQuery(insertQry);
        store.setDeleteQuery(delQry);
        store.setUser(user);
        store.setPassword(passwd);
        store.setDataSource(dataSource);

        return store;
}

I hope my answer helps you.