Bug in LongDoubleFloatDoubleVertex.sendMsgToAllEdges()
------------------------------------------------------

                 Key: GIRAPH-125
                 URL: https://issues.apache.org/jira/browse/GIRAPH-125
             Project: Giraph
          Issue Type: Bug
          Components: graph
    Affects Versions: 0.1.0
            Reporter: Yuanyuan Tian


I just found a bug in the sendMsgToAllEdges() function of the 
LongDoubleFloatDoubleVertex class. The segment of the code that contains the 
bug is:

        final LongWritable destVertex = new LongWritable();
        final MutableVertex<LongWritable, DoubleWritable, FloatWritable,
            DoubleWritable> vertex = this;
        verticesWithEdgeValues.forEachKey(new LongProcedure() {
            @Override
            public boolean apply(long destVertexId) {
                destVertex.set(destVertexId);
                vertex.sendMsg(destVertex, msg);
                return true;
            }
        });

Here destVertex is a final object, but this single object is reused in the 
forEachKey function many times. Each time its actual value is changed but the 
same object is put to the underlying message list (a hashmap) through 
vertex.sendMsg. Because the single destVertex object has been put into the 
underlying hashmap again and again, destVertex.set(destVertexId) will change 
the existing keys in the hashmap. Eventually, every keys added to the hash map 
will have the same value as the last key. 

A simple fix is as follows:

        final MutableVertex<LongWritable, DoubleWritable, FloatWritable,
            DoubleWritable> vertex = this;
        verticesWithEdgeValues.forEachKey(new LongProcedure() {
            @Override
            public boolean apply(long destVertexId) {
                vertex.sendMsg(new LongWritable(destVertexId), msg);
                return true;
            }
        });

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to