CacheJdbcStoreExample中的ClassNotFoundException在集群上运行

时间:2017-09-11 04:00:23

标签: ignite

我有一个包含2个节点的集群。然后我尝试在apache-ignite-fabric-2.1.0-bin / examples中运行CacheJdbcStoreExample。但我得到以下异常:

visor> [06:51:41,113][SEVERE][tcp-disco-msg-worker-#13%null%][TcpDiscoverySpi] Failed to unmarshal discovery custom message.
class org.apache.ignite.IgniteCheckedException: Failed to find class with given class loader for unmarshalling (make sure same versions of all classes are available on all nodes or enable pee
r-class-loading) [clsLdr=sun.misc.Launcher$AppClassLoader@4aa4ceeb, cls=org.apache.ignite.examples.datagrid.store.jdbc.CacheJdbcStoreExample$1] at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:124)
    at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:94)
    at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:143)
    at org.apache.ignite.marshaller.AbstractNodeNameAwareMarshaller.unmarshal(AbstractNodeNameAwareMarshaller.java:82)
    at org.apache.ignite.internal.util.IgniteUtils.unmarshal(IgniteUtils.java:9733)
    at org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage.message(TcpDiscoveryCustomEventMessage.java:81)
    at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.notifyDiscoveryListener(ServerImpl.java:5436)
    at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processCustomMessage(ServerImpl.java:5321)
    at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processMessage(ServerImpl.java:2629)
    at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.processMessage(ServerImpl.java:2420)
    at org.apache.ignite.spi.discovery.tcp.ServerImpl$MessageWorkerAdapter.body(ServerImpl.java:6576)
    at org.apache.ignite.spi.discovery.tcp.ServerImpl$RingMessageWorker.body(ServerImpl.java:2506)
    at org.apache.ignite.spi.IgniteSpiThread.run(IgniteSpiThread.java:62)
Caused by: java.lang.ClassNotFoundException: org.apache.ignite.examples.datagrid.store.jdbc.CacheJdbcStoreExample$1
    at java.net.URLClassLoader$1.run(URLClassLoader.java:359)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:348)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:347)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:278)
    at org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:8465)
    at org.apache.ignite.marshaller.jdk.JdkMarshallerObjectInputStream.resolveClass(JdkMarshallerObjectInputStream.java:54)
    at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1817)
    at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1711)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1982)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
    at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1917)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1527)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2227)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2151)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2227)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2151)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:420)
    at java.util.ArrayList.readObject(ArrayList.java:771)
    at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1058)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2118)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2227)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2151)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2227)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2151)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2009)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1533)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:420)
    at org.apache.ignite.marshaller.jdk.JdkMarshaller.unmarshal0(JdkMarshaller.java:121)
    ... 12 more

我反编译了CacheJdbcStoreExample $ 1.class并得到以下代码:

CacheJdbcStoreExample $ 1

package org.apache.ignite.examples.datagrid.store.jdbc;

import javax.cache.configuration.Factory;
import org.apache.ignite.cache.store.CacheStoreSessionListener;
import org.apache.ignite.cache.store.jdbc.CacheJdbcStoreSessionListener;
import org.h2.jdbcx.JdbcConnectionPool;

class CacheJdbcStoreExample$1
  implements Factory<CacheStoreSessionListener>
{
  public CacheStoreSessionListener create()
  {
    CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();

    lsnr.setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", ""));

    return lsnr;
  }
}

所以我认为 CacheJdbcStoreExample 源代码第90行出了问题:

// Configure JDBC session listener.
cacheCfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>() {
    @Override public CacheStoreSessionListener create() {
        CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();

        lsnr.setDataSource(JdbcConnectionPool.create("jdbc:h2:tcp://localhost/mem:ExampleDb", "sa", ""));

        return lsnr;
    }
});

如果我只在一个节点而不是群集上运行该示例,则表示确定。

我该怎么办才能修复它?

1 个答案:

答案 0 :(得分:1)

问题是您使用CacheStoreSessionListener - s的工厂配置了缓存,但是这个工厂在其他节点上是看不到的,因为他们没有在类路径中拥有它。

您应该从示例模块启动具有org.apache.ignite.examples.ExampleNodeStartup类的其他远程节点,或者将示例模块添加到其他节点的类路径中。