GiraphV1.2源码阅读记录

1.关于Worker和分区号的对应关系

和Hama中不同,Giraph中一个Worker对应多个分区,而worker的ID和任务号并不像Hama中存在一一对应关系,而是通过MAp保存;


BspServiceWorker中包含workerContext对象,其中含有一个AllWorkersInfo对象,用于存放taskId<->worker映射。



2. 为了确认在计算中,顶点容器中的顶点信息是被实时修改的,在ComputeCallable类的computePartition函数中测试如下代码:

	 if( ((IntWritable)vertex.getId()).get() == 666791) {
    		 PartitionOwner owner = serviceWorker.getVertexPartitionOwner((I)new IntWritable(666791)) ;
    		 ConcurrentMap> part = ((SimplePartitionStore)serviceWorker.getPartitionStore()).getPartitions() ;
    		 Partition p = part.get(owner.getPartitionId()) ;
    		 Vertex v = ((SimplePartition)p).getVertex(new IntWritable(666791)) ;
    		 LOG.info("Vertex Class: " + vertex.getClass().toString() + " partition: " + p.toString() + " Worker:" +
    				 serviceWorker.getWorkerContext().getWorkerForVertex(vertex.getId()) 
    				 +" PartitionStore:" + v.toString() + " real: " + vertex.toString()) ; 
    	 }



打印结果:

INFO org.apache.giraph.graph.ComputeCallable: Vertex Class: class org.apache.giraph.graph.DefaultVertex partition: (id=7,V=70921) Worker:3

 PartitionStore:org.apache.giraph.graph.DefaultVertex@21fefd80 Vertex(id=666791,value=666791.0,#edges=4) 

 real                : org.apache.giraph.graph.DefaultVertex@21fefd80 Vertex(id=666791,value=666791.0,#edges=4)


这里对DefaultVertex中toString方法稍作修改:

  @Override
  public String toString() {
	  String str = super.toString() + " Vertex(id=" + getId() + ",value=" + getValue() +
		        ",#edges=" + getNumEdges() + ")" ;
    return str ;
//    return "Vertex(id=" + getId() + ",value=" + getValue() +
//    		        ",#edges=" + getNumEdges() + ")" ;
  }

附: Java中无法获取真实内存地址,因此判断两个对象是否同一个可以通过Object中的toString方法,即打印hashCOde来测试,即super.toString()

结论: 顶点容器中的顶点信息是被实时修改的。

你可能感兴趣的:(GiraphV1.2源码阅读记录)