Coverage Report - org.apache.giraph.partition.SimpleLongRangePartitionerFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleLongRangePartitionerFactory
0%
0/10
0%
0/2
1.5
 
 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.partition;
 20  
 
 21  
 import org.apache.giraph.conf.GiraphConstants;
 22  
 import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
 23  
 import org.apache.hadoop.io.LongWritable;
 24  
 import org.apache.hadoop.io.Writable;
 25  
 
 26  
 /**
 27  
  * Factory for simple range-based partitioners based on long vertex ids.
 28  
  * Workers are assigned equal-sized ranges of partitions,
 29  
  * and partitions are assigned equal-sized ranges of vertices.
 30  
  *
 31  
  * @param <V> Vertex value type
 32  
  * @param <E> Edge value type
 33  
  */
 34  0
 public class SimpleLongRangePartitionerFactory<V extends Writable,
 35  
   E extends Writable> extends GraphPartitionerFactory<LongWritable, V, E> {
 36  
 
 37  
   /** Vertex key space size. */
 38  
   private long keySpaceSize;
 39  
 
 40  
   @Override
 41  
   public int getPartition(LongWritable id, int partitionCount,
 42  
     int workerCount) {
 43  0
     return getPartition(id, partitionCount);
 44  
   }
 45  
 
 46  
   /**
 47  
    * Calculates in which partition current vertex belongs to,
 48  
    * from interval [0, partitionCount).
 49  
    *
 50  
    * @param id Vertex id
 51  
    * @param partitionCount Number of partitions
 52  
    * @return partition
 53  
    */
 54  
   protected int getPartition(LongWritable id, int partitionCount) {
 55  0
     return getPartitionInRange(id.get(), keySpaceSize, partitionCount);
 56  
   }
 57  
 
 58  
   @Override
 59  
   public int getWorker(int partition, int partitionCount, int workerCount) {
 60  0
     return getPartitionInRange(partition, partitionCount, workerCount);
 61  
   }
 62  
 
 63  
   @Override
 64  
   public void setConf(ImmutableClassesGiraphConfiguration conf) {
 65  0
     super.setConf(conf);
 66  0
     keySpaceSize =
 67  0
           conf.getLong(GiraphConstants.PARTITION_VERTEX_KEY_SPACE_SIZE, -1);
 68  0
     if (keySpaceSize == -1) {
 69  0
       throw new IllegalStateException("Need to specify " +
 70  
           GiraphConstants.PARTITION_VERTEX_KEY_SPACE_SIZE +
 71  
           " when using SimpleLongRangePartitionerFactory");
 72  
     }
 73  0
   }
 74  
 }