1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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.IntWritable;
24 import org.apache.hadoop.io.Writable;
25
26
27
28
29
30
31
32
33
34 public class SimpleIntRangePartitionerFactory<V extends Writable,
35 E extends Writable> extends GraphPartitionerFactory<IntWritable, V, E> {
36
37
38 private int keySpaceSize;
39
40 @Override
41 public int getPartition(IntWritable id, int partitionCount,
42 int workerCount) {
43 return getPartition(id, partitionCount);
44 }
45
46
47
48
49
50
51
52
53
54 protected int getPartition(IntWritable id, int partitionCount) {
55 return getPartitionInRange(id.get(), keySpaceSize, partitionCount);
56 }
57
58 @Override
59 public int getWorker(int partition, int partitionCount, int workerCount) {
60 return getPartitionInRange(partition, partitionCount, workerCount);
61 }
62
63 @Override
64 public void setConf(ImmutableClassesGiraphConfiguration conf) {
65 super.setConf(conf);
66 keySpaceSize =
67 conf.getInt(GiraphConstants.PARTITION_VERTEX_KEY_SPACE_SIZE, -1);
68 if (keySpaceSize == -1) {
69 throw new IllegalStateException("Need to specify " +
70 GiraphConstants.PARTITION_VERTEX_KEY_SPACE_SIZE +
71 " when using SimpleIntRangePartitionerFactory");
72 }
73 }
74 }