You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@giraph.apache.org by Benjamin Heitmann <be...@deri.org> on 2012/03/02 20:51:40 UTC

Error in instantiating custom Vertex class via InternalVertexRunner.run

Hello, 

in the last week I started working with Apache Giraph. My goal is to implement a version of the 
spreading activation algorithm (as described on Wikipedia [1] and in this article [2] ). 
Using Giraph will hopefully allow scaling for Linked Data/RDF from DBPedia.

I used the ConnectedComponentsVertex Example (and its UnitTest) as the 
starting point for my own Vertex, TextInputFormat, TextOutputFormat and UnitTest (and a class for VertexData/State). 
In addition, I ensured that the ConnectedComponentsVertexTest runs successfully, both from the giraph source tree
and from my own project. 

My Vertex class is called SpreadingActivationVertex, and it directly extends BasicVertex, and it has the following <I, V, E, M> signature: 
public abstract class SpreadingActivationVertex extends
BasicVertex<IntWritable, SpreadingActivationStateWritable, NullWritable, DoubleWritable>
As you can see, I need to maintain more then one variable for the state of the vertex, 
and I need to pass doubles as messages. 

When I execute my UnitTest, I get the following error: 

59820 [Thread-4] WARN  org.apache.hadoop.mapred.LocalJobRunner  - job_local_0001
java.lang.RuntimeException: java.lang.InstantiationException
	at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
	at org.apache.giraph.graph.BspUtils.createVertex(BspUtils.java:365)
	at ie.deri.uimr.ld_sa.prototyping.giraph.SpreadingActivationTextInputFormat$SpreadingActivationVertexReader.getCurrentVertex(SpreadingActivationTextInputFormat.java:53)
	at org.apache.giraph.graph.BspServiceWorker.readVerticesFromInputSplit(BspServiceWorker.java:440)
	at org.apache.giraph.graph.BspServiceWorker.loadVerticesFromInputSplit(BspServiceWorker.java:371)
	at org.apache.giraph.graph.BspServiceWorker.loadVertices(BspServiceWorker.java:305)
	at org.apache.giraph.graph.BspServiceWorker.setup(BspServiceWorker.java:583)
	at org.apache.giraph.graph.GraphMapper.setup(GraphMapper.java:474)
	at org.apache.giraph.graph.GraphMapper.run(GraphMapper.java:646)
	at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:763)
	at org.apache.hadoop.mapred.MapTask.run(MapTask.java:369)
	at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:210)
Caused by: java.lang.InstantiationException
	at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:113)
	... 11 more


Using the eclipse debugger, I traced it to these lines of code in Hadoop: 

org.apache.hadoop.util.ReflectionUtils, line 113 in newInstance():

    try {
      Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass);
      if (meth == null) {
        meth = theClass.getDeclaredConstructor(EMPTY_ARRAY);
        meth.setAccessible(true);
        CONSTRUCTOR_CACHE.put(theClass, meth);
      }
      result = meth.newInstance();    // <<<------------ this is the line causing the error
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

The constructor cache does not contain my vertex class, however the next lines successfully find the right constructor and put it into "meth". 
However, the invocation of meth.newInstance() fails with the above error. 


Did somebody have this error before ? 
What did I miss ? 
The class itself is successfully found, so it is not an issue of setting some paths.
However getting a newInstance seems to fail for some reason. 

Would it be helpful if I provide the code for my 5 classes somewhere ? If yes, in which way would that be convenient for this mailing list ? 



[1] https://en.wikipedia.org/wiki/Spreading_activation
[2] http://linkinghub.elsevier.com/retrieve/pii/0306457387900173


Re: Error in instantiating custom Vertex class via InternalVertexRunner.run

Posted by Avery Ching <ac...@apache.org>.
Inline responses.  We look forward to hearing about your work Benjamin!

On 3/5/12 9:12 AM, Benjamin Heitmann wrote:
> On 2 Mar 2012, at 23:15, Avery Ching wrote:
>
>> If I'm reading this right, you're using a public abstract class for the vertex.  The vertex class must be instantiable and cannot be abstract.
>>
>> Hope that helps,
>
> Thanks, that was the right issue to point out. I removed the "abstract" keyword, which solved the issue.
> (Of course, then I found lots of other bugs in my code... ;)
>
Glad to hear it.

> After adding the abstract keyword, I ran into some problems in overriding "package private methods" of BasicVertex.
> Almost all of the abstract methods in BasicVertex are declared as public, e.g.   public abstract Iterable<M>  getMessages();
>
> However, there are two methods which do not have the public keyword:
> abstract void putMessages(Iterable<M>  messages);
> abstract void releaseResources();
>
> I am guessing that this inconsistency is just on oversight.

Actually, it is not.  =)  So the issue is that if we do make these 
methods not package-private (i.e. protected/public), then when a user 
subclasses a vertex, they will be able to shoot themselves in the foot 
by calling these methods which are only meant for internal use.  Any 
other suggestions are welcome.

> However, if I understood everything correctly, then this provides problems for developers who want to implement BasicVertex
> *outside* of the Giraph source tree. As the public keyword is missing, it is not possible to override these two method signatures
> from another package. The result, is that if I do not need IntIntNullIntVertex, but instead IntMyStateNullIntVertex which implements BasicVertex,
> then I will need to either copy BasicVe
>
> Is that the right reasoning, or is there some other pattern for using BasicVertex which I missed ?
>
> Should I file a bug report somewhere ?
>
>
> cheers, Benjamin.
>
>


Re: Error in instantiating custom Vertex class via InternalVertexRunner.run

Posted by Benjamin Heitmann <be...@deri.org>.
On 2 Mar 2012, at 23:15, Avery Ching wrote:

> If I'm reading this right, you're using a public abstract class for the vertex.  The vertex class must be instantiable and cannot be abstract.
> 
> Hope that helps,


Thanks, that was the right issue to point out. I removed the "abstract" keyword, which solved the issue. 
(Of course, then I found lots of other bugs in my code... ;) 


After adding the abstract keyword, I ran into some problems in overriding "package private methods" of BasicVertex. 
Almost all of the abstract methods in BasicVertex are declared as public, e.g.   public abstract Iterable<M> getMessages();

However, there are two methods which do not have the public keyword: 
abstract void putMessages(Iterable<M> messages);
abstract void releaseResources();

I am guessing that this inconsistency is just on oversight. 

However, if I understood everything correctly, then this provides problems for developers who want to implement BasicVertex 
*outside* of the Giraph source tree. As the public keyword is missing, it is not possible to override these two method signatures
from another package. The result, is that if I do not need IntIntNullIntVertex, but instead IntMyStateNullIntVertex which implements BasicVertex, 
then I will need to either copy BasicVertex to my own project, or I need to copy IntMyStateNullIntVertex to my local Giraph source tree. 


Is that the right reasoning, or is there some other pattern for using BasicVertex which I missed ? 

Should I file a bug report somewhere ? 


cheers, Benjamin. 



Re: Error in instantiating custom Vertex class via InternalVertexRunner.run

Posted by Avery Ching <ac...@apache.org>.
If I'm reading this right, you're using a public abstract class for the 
vertex.  The vertex class must be instantiable and cannot be abstract.

Hope that helps,

Avery

On 3/2/12 11:51 AM, Benjamin Heitmann wrote:
> Hello,
>
> in the last week I started working with Apache Giraph. My goal is to implement a version of the
> spreading activation algorithm (as described on Wikipedia [1] and in this article [2] ).
> Using Giraph will hopefully allow scaling for Linked Data/RDF from DBPedia.
>
> I used the ConnectedComponentsVertex Example (and its UnitTest) as the
> starting point for my own Vertex, TextInputFormat, TextOutputFormat and UnitTest (and a class for VertexData/State).
> In addition, I ensured that the ConnectedComponentsVertexTest runs successfully, both from the giraph source tree
> and from my own project.
>
> My Vertex class is called SpreadingActivationVertex, and it directly extends BasicVertex, and it has the following<I, V, E, M>  signature:
> public abstract class SpreadingActivationVertex extends
> BasicVertex<IntWritable, SpreadingActivationStateWritable, NullWritable, DoubleWritable>
> As you can see, I need to maintain more then one variable for the state of the vertex,
> and I need to pass doubles as messages.
>
> When I execute my UnitTest, I get the following error:
>
> 59820 [Thread-4] WARN  org.apache.hadoop.mapred.LocalJobRunner  - job_local_0001
> java.lang.RuntimeException: java.lang.InstantiationException
> 	at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
> 	at org.apache.giraph.graph.BspUtils.createVertex(BspUtils.java:365)
> 	at ie.deri.uimr.ld_sa.prototyping.giraph.SpreadingActivationTextInputFormat$SpreadingActivationVertexReader.getCurrentVertex(SpreadingActivationTextInputFormat.java:53)
> 	at org.apache.giraph.graph.BspServiceWorker.readVerticesFromInputSplit(BspServiceWorker.java:440)
> 	at org.apache.giraph.graph.BspServiceWorker.loadVerticesFromInputSplit(BspServiceWorker.java:371)
> 	at org.apache.giraph.graph.BspServiceWorker.loadVertices(BspServiceWorker.java:305)
> 	at org.apache.giraph.graph.BspServiceWorker.setup(BspServiceWorker.java:583)
> 	at org.apache.giraph.graph.GraphMapper.setup(GraphMapper.java:474)
> 	at org.apache.giraph.graph.GraphMapper.run(GraphMapper.java:646)
> 	at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:763)
> 	at org.apache.hadoop.mapred.MapTask.run(MapTask.java:369)
> 	at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:210)
> Caused by: java.lang.InstantiationException
> 	at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> 	at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:113)
> 	... 11 more
>
>
> Using the eclipse debugger, I traced it to these lines of code in Hadoop:
>
> org.apache.hadoop.util.ReflectionUtils, line 113 in newInstance():
>
>      try {
>        Constructor<T>  meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass);
>        if (meth == null) {
>          meth = theClass.getDeclaredConstructor(EMPTY_ARRAY);
>          meth.setAccessible(true);
>          CONSTRUCTOR_CACHE.put(theClass, meth);
>        }
>        result = meth.newInstance();    //<<<------------ this is the line causing the error
>      } catch (Exception e) {
>        throw new RuntimeException(e);
>      }
>
> The constructor cache does not contain my vertex class, however the next lines successfully find the right constructor and put it into "meth".
> However, the invocation of meth.newInstance() fails with the above error.
>
>
> Did somebody have this error before ?
> What did I miss ?
> The class itself is successfully found, so it is not an issue of setting some paths.
> However getting a newInstance seems to fail for some reason.
>
> Would it be helpful if I provide the code for my 5 classes somewhere ? If yes, in which way would that be convenient for this mailing list ?
>
>
>
> [1] https://en.wikipedia.org/wiki/Spreading_activation
> [2] http://linkinghub.elsevier.com/retrieve/pii/0306457387900173
>


Re: Error in instantiating custom Vertex class via InternalVertexRunner.run

Posted by Claudio Martella <cl...@gmail.com>.
A part of your issues, I am looking forward to see who you are going to
attack this problem.
Please keep us posted on your progress.

On Saturday, March 3, 2012, Sebastian Schelter <ss...@apache.org> wrote:
> Hi Benjamin,
>
> Does your vertex class have a publicly accessible no-arg constructor?
> That's implicitly required because each Vertex class implements Writable.
>
> If you want to use to have a look at your code, you could maybe put it
> on github?
>
> Best,
> Sebastian
>
> On 02.03.2012 20:51, Benjamin Heitmann wrote:
>> Hello,
>>
>> in the last week I started working with Apache Giraph. My goal is to
implement a version of the
>> spreading activation algorithm (as described on Wikipedia [1] and in
this article [2] ).
>> Using Giraph will hopefully allow scaling for Linked Data/RDF from
DBPedia.
>>
>> I used the ConnectedComponentsVertex Example (and its UnitTest) as the
>> starting point for my own Vertex, TextInputFormat, TextOutputFormat and
UnitTest (and a class for VertexData/State).
>> In addition, I ensured that the ConnectedComponentsVertexTest runs
successfully, both from the giraph source tree
>> and from my own project.
>>
>> My Vertex class is called SpreadingActivationVertex, and it directly
extends BasicVertex, and it has the following <I, V, E, M> signature:
>> public abstract class SpreadingActivationVertex extends
>> BasicVertex<IntWritable, SpreadingActivationStateWritable, NullWritable,
DoubleWritable>
>> As you can see, I need to maintain more then one variable for the state
of the vertex,
>> and I need to pass doubles as messages.
>>
>> When I execute my UnitTest, I get the following error:
>>
>> 59820 [Thread-4] WARN  org.apache.hadoop.mapred.LocalJobRunner  -
job_local_0001
>> java.lang.RuntimeException: java.lang.InstantiationException
>>       at
org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
>>       at org.apache.giraph.graph.BspUtils.createVertex(BspUtils.java:365)
>>       at
ie.deri.uimr.ld_sa.prototyping.giraph.SpreadingActivationTextInputFormat$SpreadingActivationVertexReader.getCurrentVertex(SpreadingActivationTextInputFormat.java:53)
>>       at
org.apache.giraph.graph.BspServiceWorker.readVerticesFromInputSplit(BspServiceWorker.java:440)
>>       at
org.apache.giraph.graph.BspServiceWorker.loadVerticesFromInputSplit(BspServiceWorker.java:371)
>>       at
org.apache.giraph.graph.BspServiceWorker.loadVertices(BspServiceWorker.java:305)
>>       at
org.apache.giraph.graph.BspServiceWorker.setup(BspServiceWorker.java:583)
>>       at org.apache.giraph.graph.GraphMapper.setup(GraphMapper.java:474)
>>       at org.apache.giraph.graph.GraphMapper.run(GraphMapper.java:646)
>>       at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:763)
>>       at org.apache.hadoop.mapred.MapTask.run(MapTask.java:369)
>>       at
org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:210)
>> Caused by: java.lang.InstantiationException
>>       at
sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
>>       at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>       at
org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:113)
>>       ... 11 more
>>
>>
>> Using the eclipse debugger, I traced it to these lines of code in Hadoop:
>>
>> org.apache.hadoop.util.ReflectionUtils, line 113 in newInstance():
>>
>>     try {
>>       Constructor<T> meth = (Constructor<T>)
CONSTRUCTOR_CACHE.get(theClass);
>>       if (meth == null) {
>>         meth = theClass.getDeclaredConstructor(EMPTY_ARRAY);
>>         meth.setAccessible(true);
>>         CONSTRUCTOR_CACHE.put(theClass, meth);
>>       }
>>       result = meth.newInstance();    // <<<------------ this is the
line causing the error
>>     } catch (Exception e) {
>>       throw new RuntimeException(e);
>>     }
>>
>> The constructor cache does not contain my vertex class, however the next
lines successfully find the right constructor and put it into "meth".
>> However, the invocation of meth.newInstance() fails with the above error.
>>
>>
>> Did somebody have this error before ?
>> What did I miss ?
>> The class itself is successfully found, so it is not an issue of setting
some paths.
>> How

-- 
   Claudio Martella
   claudio.martella@gmail.com

Re: Error in instantiating custom Vertex class via InternalVertexRunner.run

Posted by Benjamin Heitmann <be...@deri.org>.
On 3 Mar 2012, at 13:49, Sebastian Schelter wrote:

> Hi Benjamin,
> 
> Does your vertex class have a publicly accessible no-arg constructor?
> That's implicitly required because each Vertex class implements Writable.

Thanks for the hint, I ran into that problem a little bit later. I had to add a no-arg constructor for my Vertex State class.

> If you want to use to have a look at your code, you could maybe put it
> on github?

After debugging some other issues, I successfully got my code to run. 
Now I just need to make it actually run the algorithm properly ;) 
But I will check if I can put my code on github. 


cheers, Benjamin. 

Re: Error in instantiating custom Vertex class via InternalVertexRunner.run

Posted by Sebastian Schelter <ss...@apache.org>.
Hi Benjamin,

Does your vertex class have a publicly accessible no-arg constructor?
That's implicitly required because each Vertex class implements Writable.

If you want to use to have a look at your code, you could maybe put it
on github?

Best,
Sebastian

On 02.03.2012 20:51, Benjamin Heitmann wrote:
> Hello, 
> 
> in the last week I started working with Apache Giraph. My goal is to implement a version of the 
> spreading activation algorithm (as described on Wikipedia [1] and in this article [2] ). 
> Using Giraph will hopefully allow scaling for Linked Data/RDF from DBPedia.
> 
> I used the ConnectedComponentsVertex Example (and its UnitTest) as the 
> starting point for my own Vertex, TextInputFormat, TextOutputFormat and UnitTest (and a class for VertexData/State). 
> In addition, I ensured that the ConnectedComponentsVertexTest runs successfully, both from the giraph source tree
> and from my own project. 
> 
> My Vertex class is called SpreadingActivationVertex, and it directly extends BasicVertex, and it has the following <I, V, E, M> signature: 
> public abstract class SpreadingActivationVertex extends
> BasicVertex<IntWritable, SpreadingActivationStateWritable, NullWritable, DoubleWritable>
> As you can see, I need to maintain more then one variable for the state of the vertex, 
> and I need to pass doubles as messages. 
> 
> When I execute my UnitTest, I get the following error: 
> 
> 59820 [Thread-4] WARN  org.apache.hadoop.mapred.LocalJobRunner  - job_local_0001
> java.lang.RuntimeException: java.lang.InstantiationException
> 	at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:115)
> 	at org.apache.giraph.graph.BspUtils.createVertex(BspUtils.java:365)
> 	at ie.deri.uimr.ld_sa.prototyping.giraph.SpreadingActivationTextInputFormat$SpreadingActivationVertexReader.getCurrentVertex(SpreadingActivationTextInputFormat.java:53)
> 	at org.apache.giraph.graph.BspServiceWorker.readVerticesFromInputSplit(BspServiceWorker.java:440)
> 	at org.apache.giraph.graph.BspServiceWorker.loadVerticesFromInputSplit(BspServiceWorker.java:371)
> 	at org.apache.giraph.graph.BspServiceWorker.loadVertices(BspServiceWorker.java:305)
> 	at org.apache.giraph.graph.BspServiceWorker.setup(BspServiceWorker.java:583)
> 	at org.apache.giraph.graph.GraphMapper.setup(GraphMapper.java:474)
> 	at org.apache.giraph.graph.GraphMapper.run(GraphMapper.java:646)
> 	at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:763)
> 	at org.apache.hadoop.mapred.MapTask.run(MapTask.java:369)
> 	at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:210)
> Caused by: java.lang.InstantiationException
> 	at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:30)
> 	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
> 	at org.apache.hadoop.util.ReflectionUtils.newInstance(ReflectionUtils.java:113)
> 	... 11 more
> 
> 
> Using the eclipse debugger, I traced it to these lines of code in Hadoop: 
> 
> org.apache.hadoop.util.ReflectionUtils, line 113 in newInstance():
> 
>     try {
>       Constructor<T> meth = (Constructor<T>) CONSTRUCTOR_CACHE.get(theClass);
>       if (meth == null) {
>         meth = theClass.getDeclaredConstructor(EMPTY_ARRAY);
>         meth.setAccessible(true);
>         CONSTRUCTOR_CACHE.put(theClass, meth);
>       }
>       result = meth.newInstance();    // <<<------------ this is the line causing the error
>     } catch (Exception e) {
>       throw new RuntimeException(e);
>     }
> 
> The constructor cache does not contain my vertex class, however the next lines successfully find the right constructor and put it into "meth". 
> However, the invocation of meth.newInstance() fails with the above error. 
> 
> 
> Did somebody have this error before ? 
> What did I miss ? 
> The class itself is successfully found, so it is not an issue of setting some paths.
> However getting a newInstance seems to fail for some reason. 
> 
> Would it be helpful if I provide the code for my 5 classes somewhere ? If yes, in which way would that be convenient for this mailing list ? 
> 
> 
> 
> [1] https://en.wikipedia.org/wiki/Spreading_activation
> [2] http://linkinghub.elsevier.com/retrieve/pii/0306457387900173
>