You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by "rishireddy.bokka" <ri...@gmail.com> on 2016/12/16 02:06:14 UTC

Issue while using Affinity function for mapping keys with nodes

Hi, 
I am using affinity function to map the keys with the nodes. I have 2 nodes
and trying to distribute the person objects among those two nodes. Below is
my code :

public class TestingIgnite 
{
private static final String CACHE_NAME =
TestingIgnite.class.getSimpleName();
public static void main(String[] args) throws IgniteException {
		Ignition.setClientMode(true);
		try (Ignite ignite = Ignition.start(
			
"/usr/local/ignite/apache-ignite-fabric-1.7.0-bin/examples/config/example-cache.xml"))
{
			
			try (IgniteCache<Integer, Person> cache =
ignite.getOrCreateCache(CACHE_NAME)) {
				
		    Person p1 = new Person("1", "Rishiiii", "Bokka");
	            Person p2 = new Person("2", "Gang", "Valla");
	            Person p3 = new Person("3", "Person3", "P3");
	            Person p4 = new Person("4", "Person4", "P4");
	            personList.add(p1);
	            personList.add(p2);
	            personList.add(p3);
	            personList.add(p4);
	          
	            cache.put(Integer.parseInt(p1.getId()), p1);
	            cache.put(Integer.parseInt(p2.getId()), p2);
	            cache.put(Integer.parseInt(p3.getId()), p3);
	            cache.put(Integer.parseInt(p4.getId()), p4);

	            visitUsingMapKeysToNodes()
			}

		}
	}
	 private static void visitUsingMapKeysToNodes() {
		 final Ignite ignite = Ignition.ignite();
		 Collection<Integer> keys = new ArrayList<>(personList.size()+1);
		 for (int i = 1; i < personList.size()+1; i++)
			 keys.add(i);
		 for(Integer i : keys)
			 System.out.println("keyss :"+ i);
		 // Map all keys to nodes.
		 Map<ClusterNode, Collection&lt;Integer>> mappings =   
ignite.Integer>affinity(CACHE_NAME).mapKeysToNodes(keys);
		 for (Map.Entry<ClusterNode, Collection&lt;Integer>> mapping :
mappings.entrySet()) {
			 System.out.println("Nodes :"+ mapping.getKey());
			 System.out.println("valuessss : "+ mapping.getValue());
		 }
		 for (Map.Entry<ClusterNode, Collection&lt;Integer>> mapping :
mappings.entrySet()) {
			 ClusterNode node = mapping.getKey();

			 System.out.println("Node name :"+ node.addresses());
			 final Collection<Integer> mappedKeys = mapping.getValue();
			 System.out.println("valuess : "+ mapping.getValue());
			 if (node != null) {
				 // Bring computations to the nodes where the data resides (i.e.
collocation).
				 ignite.compute(ignite.cluster().forNode(node)).run(new IgniteRunnable()
{
					 @Override public void run() {
						 System.out.println("hii");
						 IgniteCache<Integer, Person> cache = ignite.cache(CACHE_NAME);

						 for (Integer key : mappedKeys)
							 System.out.println(key= " + key +
									 ", value=" + cache.get(key));
					 }
				 });
			 }
		 }
	 }
}


But I am getting below exception. :

Dec 15, 2016 8:51:48 PM org.apache.ignite.logger.java.JavaLogger error
SEVERE: Failed to obtain remote job result policy for result from
ComputeTask.result(..) method (will fail the whole task): GridJobResultImpl
[job=C4V2 [r=o.a.i.ignite_core.TestingIgnite$1@41e350f1],
sib=GridJobSiblingImpl
[sesId=458f3550951-31951fae-4c34-42bb-b8eb-5106f6b2a647,
jobId=858f3550951-31951fae-4c34-42bb-b8eb-5106f6b2a647,
nodeId=4c54daa5-68f1-43c8-892b-8057fc18be7b, isJobDone=false],
jobCtx=GridJobContextImpl
[jobId=858f3550951-31951fae-4c34-42bb-b8eb-5106f6b2a647, timeoutObj=null,
attrs={}], node=TcpDiscoveryNode [id=4c54daa5-68f1-43c8-892b-8057fc18be7b,
addrs=[0:0:0:0:0:0:0:1%lo, 10.1.1.148, 127.0.0.1,
2001:470:8865:11:20c:29ff:fee0:b672%ens192],
sockAddrs=[aapvm03/10.1.1.148:47500,
/2001:470:8865:11:20c:29ff:fee0:b672%ens192:47500,
/0:0:0:0:0:0:0:1%lo:47500, /127.0.0.1:47500], discPort=47500, order=1,
intOrder=1, lastExchangeTime=1481853108069, loc=false,
ver=1.7.0#20160801-sha1:383273e3, isClient=false], ex=class
o.a.i.binary.BinaryInvalidTypeException: o.a.i.ignite_core.Person,
hasRes=true, isCancelled=false, isOccupied=true]
class org.apache.ignite.IgniteException: Remote job threw user exception
(override or implement ComputeTask.result(..) method if you would like to
have automatic failover for this exception).
	at
org.apache.ignite.compute.ComputeTaskAdapter.result(ComputeTaskAdapter.java:101)
	at
org.apache.ignite.internal.processors.task.GridTaskWorker$4.apply(GridTaskWorker.java:946)
	at
org.apache.ignite.internal.processors.task.GridTaskWorker$4.apply(GridTaskWorker.java:939)
	at
org.apache.ignite.internal.util.IgniteUtils.wrapThreadLoader(IgniteUtils.java:6553)
	at
org.apache.ignite.internal.processors.task.GridTaskWorker.result(GridTaskWorker.java:939)
	at
org.apache.ignite.internal.processors.task.GridTaskWorker.onResponse(GridTaskWorker.java:810)
	at
org.apache.ignite.internal.processors.task.GridTaskProcessor.processJobExecuteResponse(GridTaskProcessor.java:995)
	at
org.apache.ignite.internal.processors.task.GridTaskProcessor$JobMessageListener.onMessage(GridTaskProcessor.java:1220)
	at
org.apache.ignite.internal.managers.communication.GridIoManager.invokeListener(GridIoManager.java:1238)
	at
org.apache.ignite.internal.managers.communication.GridIoManager.processRegularMessage0(GridIoManager.java:866)
	at
org.apache.ignite.internal.managers.communication.GridIoManager.access$1700(GridIoManager.java:106)
	at
org.apache.ignite.internal.managers.communication.GridIoManager$5.run(GridIoManager.java:829)
	at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: class org.apache.ignite.binary.BinaryInvalidTypeException:
org.apache.ignite.ignite_core.Person
	at
org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:671)
	at
org.apache.ignite.internal.binary.BinaryReaderExImpl.deserialize(BinaryReaderExImpl.java:1474)
	at
org.apache.ignite.internal.binary.BinaryObjectImpl.deserializeValue(BinaryObjectImpl.java:585)
	at
org.apache.ignite.internal.binary.BinaryObjectImpl.value(BinaryObjectImpl.java:142)
	at
org.apache.ignite.internal.processors.cache.CacheObjectContext.unwrapBinary(CacheObjectContext.java:272)
	at
org.apache.ignite.internal.processors.cache.CacheObjectContext.unwrapBinaryIfNeeded(CacheObjectContext.java:160)
	at
org.apache.ignite.internal.processors.cache.GridCacheContext.unwrapBinaryIfNeeded(GridCacheContext.java:1764)
	at
org.apache.ignite.internal.processors.cache.GridCacheAdapter.localPeek(GridCacheAdapter.java:842)
	at
org.apache.ignite.internal.processors.cache.GridCacheProxyImpl.localPeek(GridCacheProxyImpl.java:1000)
	at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.localPeek(IgniteCacheProxy.java:793)
	at org.apache.ignite.ignite_core.TestingIgnite$1.run(TestingIgnite.java:79)
	at
org.apache.ignite.internal.processors.closure.GridClosureProcessor$C4V2.execute(GridClosureProcessor.java:2184)
	at
org.apache.ignite.internal.processors.job.GridJobWorker$2.call(GridJobWorker.java:509)
	at
org.apache.ignite.internal.util.IgniteUtils.wrapThreadLoader(IgniteUtils.java:6521)
	at
org.apache.ignite.internal.processors.job.GridJobWorker.execute0(GridJobWorker.java:503)
	at
org.apache.ignite.internal.processors.job.GridJobWorker.body(GridJobWorker.java:456)
	at
org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
	at
org.apache.ignite.internal.processors.job.GridJobProcessor.processJobExecuteRequest(GridJobProcessor.java:1161)
	at
org.apache.ignite.internal.processors.job.GridJobProcessor$JobExecutionListener.onMessage(GridJobProcessor.java:1766)
	... 7 more
Caused by: java.lang.ClassNotFoundException:
org.apache.ignite.ignite_core.Person
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at
org.apache.ignite.internal.util.IgniteUtils.forName(IgniteUtils.java:8350)
	at
org.apache.ignite.internal.MarshallerContextAdapter.getClass(MarshallerContextAdapter.java:185)
	at
org.apache.ignite.internal.binary.BinaryContext.descriptorForTypeId(BinaryContext.java:662)
	... 25 more


Could you please let me know where I am doing wrong.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Issue-while-using-Affinity-function-for-mapping-keys-with-nodes-tp9580.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Issue while using Affinity function for mapping keys with nodes

Posted by vkulichenko <va...@gmail.com>.
Hi Rishi,

You job is executed on a server node, which doesn't have Person class on
classpath. To deploy your code on server side simply create a JAR with
required classes and put it into IGNITE_HOME/libs folder before starting the
nodes.

Another way to overcome the issue is utilize BinaryObject API [1]. To do
this, use withKeepBinary() flag on the cache:

// Note that now BinaryObject is used as a value instead of Person.
IgniteCache<Integer, BinaryObject> cache =
ignite.cache(CACHE_NAME).withKeepBinary();
// get() will return instance of BinaryObject which is a binary
representation of the value.
BinaryObject value = cache.get();

BinaryObject allows you to read values of individual fields without
deserialization into Person instance. As long as deserialization is not
happening, class is not needed.

[1] https://apacheignite.readme.io/docs/binary-marshaller

-Val



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Issue-while-using-Affinity-function-for-mapping-keys-with-nodes-tp9580p9609.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Issue while using Affinity function for mapping keys with nodes

Posted by "rishireddy.bokka" <ri...@gmail.com>.
Below is my configuration file :

<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="cacheConfiguration">
            <list>
                
                <bean
class="org.apache.ignite.configuration.CacheConfiguration">
                    <property name="atomicityMode" value="ATOMIC"/>
		    <property name="atomicWriteOrderMode" value="PRIMARY"/>
		    <property name="cacheMode" value="PARTITIONED"/>
                    <property name="backups" value="1"/>
                </bean>
            </list>
        </property>

	<property name="peerClassLoadingLocalClassPathExclude">
        <list>
            <value>org.apache.ignite.ignite_core.Person</value>
        </list>
    </property>

	 <property name="peerClassLoadingEnabled" value="true"/>

        
        <property name="discoverySpi">
            <bean
class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="ipFinder">
                    
                    
                    
                    <bean
class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
                        <property name="addresses">
                            <list>
                                
				<value>0.0.0.0</value>				
                                <value>0.0.0.0</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>
</beans>


could you please tell whats wrong in it?



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Issue-while-using-Affinity-function-for-mapping-keys-with-nodes-tp9580p9604.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Issue while using Affinity function for mapping keys with nodes

Posted by "rishireddy.bokka" <ri...@gmail.com>.
Thanks for the reply Nikolai. I am new to Ignite, So could you please tell me
how to deploy classes on all nodes and about  IgniteCache.withKeepBinary.

Thanks,
Rishi



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Issue-while-using-Affinity-function-for-mapping-keys-with-nodes-tp9580p9603.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: Issue while using Affinity function for mapping keys with nodes

Posted by Nikolai Tikhonov <nt...@apache.org>.
Hi!

In your case key and value classes are not deployed on server nodes. You
need to deploy classes on all nodes or to use IgniteCache.withKeepBinary.
Also you don't need to implement visitUsingMapKeysToNodes methods. You can
use IgniteCompute#affinityRun or IgniteCompute#affinityCall methods. They
work with custom affinity function correctly.