我正在实现 CacheStore 以在数据库中异步写入数据。 在应用程序内部作为“服务器”运行 Ignite 时,代码工作正常,并且数据保存在数据库中。
有问题的场景: 将远程节点作为服务器运行,将应用程序作为“客户端”运行, 在启动客户端节点时,已经启动的服务器节点会抛出 ClassNotFoundException。
以下是我的配置:
服务器
<bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="metricsLogFrequency" value="0"/>
<property name="peerClassLoadingEnabled" value="true"/>
<property name="marshaller">
<bean class="org.apache.ignite.marshaller.optimized.OptimizedMarshaller">
<!-- Set to false to allow non-serializable objects in examples, default is true. -->
<property name="requireSerializable" value="false"/>
</bean>
</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.zk.TcpDiscoveryZookeeperIpFinder">
<property name="zkConnectionString" value="localhost:2181"/>
</bean>
</property>
</bean>
</property>
</bean>
客户:
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName(name);
cacheConfiguration.setBackups(backup);
cacheConfiguration.setRebalanceMode(CacheRebalanceMode.SYNC);
cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
LruEvictionPolicy evictionPolicy = new LruEvictionPolicy();
evictionPolicy.setMaxSize(maxEntries);
cacheConfiguration.setEvictionPolicy(evictionPolicy);
cacheConfiguration.setEvictSynchronized(true);
cacheConfiguration.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(duration));
cacheConfiguration.setStartSize(100*1024*1024);
cacheConfiguration.setReadThrough(true);
cacheConfiguration.setWriteThrough(true);
cacheConfiguration.setWriteBehindEnabled(true);
cacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cacheConfiguration.setCacheStoreFactory(new FactoryBuilder.SingletonFactory<CacheStore>(cacheStore));
IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setPeerClassLoadingEnabled(true);
TcpDiscoverySpi tcpDiscoverySpi = new TcpDiscoverySpi();
TcpDiscoveryZookeeperIpFinder ipFinder = new TcpDiscoveryZookeeperIpFinder();
ipFinder.setZkConnectionString(zookeeperConString);
tcpDiscoverySpi.setIpFinder(ipFinder);
OptimizedMarshaller marshaller = new OptimizedMarshaller();
marshaller.setRequireSerializable(false);
igniteConfiguration.
setCacheConfiguration(cacheConfiguration).
setClientMode(isClient);
igniteConfiguration.setDiscoverySpi(tcpDiscoverySpi);
igniteConfiguration.setMarshaller(marshaller).
setGridName(gridName).
setMetricsLogFrequency(0);
SpringCacheManager springCacheManager = new SpringCacheManager();
springCacheManager.setConfiguration(igniteConfiguration);
现在,我不想在服务器节点上部署 CacheStore,因此我启用了对等类加载。但抛出了同样的异常,所以我在互联网上检查并将其原子性模式更改为事务,以便每次都会使用客户端的 CacheStore。 但仍然面临同样的问题。
最佳答案
CacheConfiguration 中存在的所有类应该在所有节点上可用。 P2P 类加载不适用于 CacheStore。您需要手动部署类。
关于java - Ignite CacheStore 实现在服务器端抛出 ClassNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41280470/