Coverage Report - org.apache.giraph.graph.partition.RangeWorkerPartitioner
 
Classes in this File Line Coverage Branch Coverage Complexity
RangeWorkerPartitioner
0%
0/10
0%
0/4
2.333
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *     http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 package org.apache.giraph.graph.partition;
 20  
 
 21  
 import java.util.Collection;
 22  
 import java.util.NavigableMap;
 23  
 import java.util.TreeMap;
 24  
 
 25  
 import org.apache.hadoop.io.Writable;
 26  
 import org.apache.hadoop.io.WritableComparable;
 27  
 
 28  
 /**
 29  
  * Range partitioning will split the vertices by a key range based on a generic
 30  
  * type.  This allows vertices that have some locality with the vertex ids
 31  
  * to reduce the amount of messages sent.  The tradeoffs are that
 32  
  * range partitioning is more susceptible to hot spots if the keys
 33  
  * are not randomly distributed.  Another negative is the user must implement
 34  
  * some of the functionality around how to split the key range.
 35  
  *
 36  
  * Note:  This implementation is incomplete, the developer must implement the
 37  
  * various methods based on their index type.
 38  
  *
 39  
  * @param <I> Vertex index value
 40  
  * @param <V> Vertex value
 41  
  * @param <E> Edge value
 42  
  * @param <M> Message value
 43  
  */
 44  
 @SuppressWarnings("rawtypes")
 45  0
 public abstract class RangeWorkerPartitioner<I extends WritableComparable,
 46  
     V extends Writable, E extends Writable, M extends Writable> implements
 47  
     WorkerGraphPartitioner<I, V, E, M> {
 48  
   /** Mapping of the vertex ids to the {@link PartitionOwner} */
 49  0
   protected NavigableMap<I, RangePartitionOwner<I>> vertexRangeMap =
 50  
       new TreeMap<I, RangePartitionOwner<I>>();
 51  
 
 52  
   @Override
 53  
   public PartitionOwner createPartitionOwner() {
 54  0
     return new RangePartitionOwner<I>();
 55  
   }
 56  
 
 57  
   @Override
 58  
   public PartitionOwner getPartitionOwner(I vertexId) {
 59  
     // Find the partition owner based on the maximum partition id.
 60  
     // If the vertex id exceeds any of the maximum partition ids, give
 61  
     // it to the last one
 62  0
     if (vertexId == null) {
 63  0
       throw new IllegalArgumentException(
 64  
           "getPartitionOwner: Illegal null vertex id");
 65  
     }
 66  0
     I maxVertexIndex = vertexRangeMap.ceilingKey(vertexId);
 67  0
     if (maxVertexIndex == null) {
 68  0
       return vertexRangeMap.lastEntry().getValue();
 69  
     } else {
 70  0
       return vertexRangeMap.get(vertexId);
 71  
     }
 72  
   }
 73  
 
 74  
   @Override
 75  
   public Collection<? extends PartitionOwner> getPartitionOwners() {
 76  0
     return vertexRangeMap.values();
 77  
   }
 78  
 }