1. 程式人生 > 實用技巧 >ignite官方文件學習的坑點

ignite官方文件學習的坑點

ignite有其中文文件供學習,但是你可能在照著官方文件走的時候遇到過這樣的問題。

在執行以下程式碼的時候,會報錯。

程式碼:

public class IgniteHelloWorld {
    public static void main(String[] args) throws IgniteException {
        // Preparing IgniteConfiguration using Java APIs
        IgniteConfiguration cfg = new IgniteConfiguration();

        // The node will be started as a client node.
cfg.setClientMode(true); // Classes of custom Java logic will be transferred over the wire from this app. cfg.setPeerClassLoadingEnabled(true); // Setting up an IP Finder to ensure the client can locate the servers. TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder(); ipFinder.setAddresses(Collections.singletonList(
"127.0.0.1:47500..47509")); cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder)); // Starting the node Ignite ignite = Ignition.start(cfg); // Create an IgniteCache and put some values in it. IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCache"); cache.put(
1, "Hello"); cache.put(2, "World!"); System.out.println(">> Created the cache and add the values."); // Executing custom Java compute task on server nodes. ignite.compute(ignite.cluster().forServers()).broadcast(new RemoteTask()); System.out.println(">> Compute task is executed, check for output on the server nodes."); // Disconnect from the cluster. ignite.close(); } /** * A compute tasks that prints out a node ID and some details about its OS and JRE. * Plus, the code shows how to access data stored in a cache from the compute task. */ private static class RemoteTask implements IgniteRunnable { @IgniteInstanceResource Ignite ignite; @Override public void run() { System.out.println(">> Executing the compute task"); System.out.println( " Node ID: " + ignite.cluster().localNode().id() + "\n" + " OS: " + System.getProperty("os.name") + " JRE: " + System.getProperty("java.runtime.name")); IgniteCache<Integer, String> cache = ignite.cache("myCache"); System.out.println(">> " + cache.get(1) + " " + cache.get(2)); } } }

錯誤:

[15:34:36,630][SEVERE][main][IgniteKernal] Failed to start manager: GridManagerAdapter [enabled=true, name=o.a.i.i.managers.discovery.GridDiscoveryManager]
class org.apache.ignite.IgniteCheckedException: Remote node has peer class loading enabled flag different from local [locId8=e9ebbdbb, locPeerClassLoading=true, rmtId8=a224fbe6, rmtPeerClassLoading=false, rmtAddrs=[10.1.81.221/0:0:0:0:0:0:0:1, /10.1.81.221, /127.0.0.1], rmtNode=ClusterNode [id=a224fbe6-2636-45f9-b1ce-5ce5f22103a9, order=1, addr=[0:0:0:0:0:0:0:1, 10.1.81.221, 127.0.0.1], daemon=false]]
    at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.checkAttributes(GridDiscoveryManager.java:1198)
    at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.start(GridDiscoveryManager.java:967)
    at org.apache.ignite.internal.IgniteKernal.startManager(IgniteKernal.java:1960)
    at org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:1276)
    at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:2045)
    at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1703)
    at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1117)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:637)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:563)
    at org.apache.ignite.Ignition.start(Ignition.java:321)
    at com.example.demo.IgniteHelloWorld.main(IgniteHelloWorld.java:33)
[15:34:36,630][SEVERE][main][IgniteKernal] Got exception while starting (will rollback startup routine).
class org.apache.ignite.IgniteCheckedException: Failed to start manager: GridManagerAdapter [enabled=true, name=org.apache.ignite.internal.managers.discovery.GridDiscoveryManager]
    at org.apache.ignite.internal.IgniteKernal.startManager(IgniteKernal.java:1965)
    at org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:1276)
    at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:2045)
    at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1703)
    at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1117)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:637)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:563)
    at org.apache.ignite.Ignition.start(Ignition.java:321)
    at com.example.demo.IgniteHelloWorld.main(IgniteHelloWorld.java:33)
Caused by: class org.apache.ignite.IgniteCheckedException: Remote node has peer class loading enabled flag different from local [locId8=e9ebbdbb, locPeerClassLoading=true, rmtId8=a224fbe6, rmtPeerClassLoading=false, rmtAddrs=[10.1.81.221/0:0:0:0:0:0:0:1, /10.1.81.221, /127.0.0.1], rmtNode=ClusterNode [id=a224fbe6-2636-45f9-b1ce-5ce5f22103a9, order=1, addr=[0:0:0:0:0:0:0:1, 10.1.81.221, 127.0.0.1], daemon=false]]
    at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.checkAttributes(GridDiscoveryManager.java:1198)
    at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.start(GridDiscoveryManager.java:967)
    at org.apache.ignite.internal.IgniteKernal.startManager(IgniteKernal.java:1960)
    ... 8 more
[15:34:36] Ignite node stopped OK [uptime=00:00:02.858]
Exception in thread "main" class org.apache.ignite.IgniteException: Failed to start manager: GridManagerAdapter [enabled=true, name=org.apache.ignite.internal.managers.discovery.GridDiscoveryManager]
    at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:1067)
    at org.apache.ignite.Ignition.start(Ignition.java:324)
    at com.example.demo.IgniteHelloWorld.main(IgniteHelloWorld.java:33)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to start manager: GridManagerAdapter [enabled=true, name=org.apache.ignite.internal.managers.discovery.GridDiscoveryManager]
    at org.apache.ignite.internal.IgniteKernal.startManager(IgniteKernal.java:1965)
    at org.apache.ignite.internal.IgniteKernal.start(IgniteKernal.java:1276)
    at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start0(IgnitionEx.java:2045)
    at org.apache.ignite.internal.IgnitionEx$IgniteNamedInstance.start(IgnitionEx.java:1703)
    at org.apache.ignite.internal.IgnitionEx.start0(IgnitionEx.java:1117)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:637)
    at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:563)
    at org.apache.ignite.Ignition.start(Ignition.java:321)
    ... 1 more
Caused by: class org.apache.ignite.IgniteCheckedException: Remote node has peer class loading enabled flag different from local [locId8=e9ebbdbb, locPeerClassLoading=true, rmtId8=a224fbe6, rmtPeerClassLoading=false, rmtAddrs=[10.1.81.221/0:0:0:0:0:0:0:1, /10.1.81.221, /127.0.0.1], rmtNode=ClusterNode [id=a224fbe6-2636-45f9-b1ce-5ce5f22103a9, order=1, addr=[0:0:0:0:0:0:0:1, 10.1.81.221, 127.0.0.1], daemon=false]]
    at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.checkAttributes(GridDiscoveryManager.java:1198)
    at org.apache.ignite.internal.managers.discovery.GridDiscoveryManager.start(GridDiscoveryManager.java:967)
    at org.apache.ignite.internal.IgniteKernal.startManager(IgniteKernal.java:1960)
    ... 8 more

  這時候有兩種處理辦法有可能可以使得程式正常執行

  一種是去掉

cfg.setPeerClassLoadingEnabled(true);

  另一種則是

default-config.xml

中設定

PeerClassLoadingEnabled
<?xml version="1.0" encoding="UTF-8"?>

<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<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">
  <!--
        Alter configuration below as needed.
    -->
  <bean id="grid.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
    <property name="peerClassLoadingEnabled" value="true" />
  </bean>
</beans>