Hazelcast 3.8-EA警告:收到的数据格式无效问题

时间:2017-01-04 12:35:32

标签: java hazelcast

使用MapLoader从外部数据源加载Map时Hazelcast群集(多播发现)会出现错误

    WARNING: [<IP>]:5702 [<cluster_name>] [3.8-EA] Received data format is invalid. (An old version of Hazelcast may be running here.)
com.hazelcast.nio.serialization.HazelcastSerializationException: Problem while reading DataSerializable, namespace: 0, id: 0, class: 'com.hazelcast.cluster.impl.JoinRequest', exception: com.hazelcast.cluster.impl.JoinRequest
    at com.hazelcast.internal.serialization.impl.DataSerializableSerializer.rethrowReadException(DataSerializableSerializer.java:178)
    ...
Caused by: java.lang.ClassNotFoundException: com.hazelcast.cluster.impl.JoinRequest
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

我在hazelast 3.5.4版本上测试了这个..它工作正常。 我们可以忽略这个警告,但不确定它的影响是什么。它也淹没了日志。

2 个答案:

答案 0 :(得分:1)

由于内部协议发生变化,新旧版本的Hazelcast在多播发现方面不兼容。也就是说,新的Hazelcast版本无法识别旧版本的发现数据包。

请根据http://docs.hazelcast.org/docs/3.8-EA/manual/html-single/index.html#multicast-element

下的文档更改多播组

答案 1 :(得分:-1)

对于那些可能在OSGi环境中遇到此问题的人来说,你可能会看到com.hazelcast.util.ServiceLoader.findHighestReachableClassLoader()方法的细微差别,有时在Hazelcast初始化期间选择错误的类加载器(如它不会总是选择你在配置上设置的类加载器。以下显示了一种利用Java的上下文类加载器解决该问题的方法:

private HazelcastInstance createHazelcastInstance() {  

    // Use the following if you're only using the Hazelcast data serializers   
    final ClassLoader classLoader = Hazelcast.class.getClassLoader();

    // Use the following if you have custom data serializers that you need
    // final ClassLoader classLoader = this.getClass().getClassLoader();

    final com.hazelcast.config.Config config = new com.hazelcast.config.Config();
    config.setClassLoader(classLoader);
    final ClassLoader previousContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        return Hazelcast.newHazelcastInstance(config);
    } finally {
        if(previousContextClassLoader != null) {
            Thread.currentThread().setContextClassLoader(previousContextClassLoader);
        }
    }
}