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 java.util.Collection;
22
23 import org.apache.hadoop.io.Writable;
24 import org.apache.hadoop.io.WritableComparable;
25 import org.apache.giraph.worker.WorkerInfo;
26
27 /**
28 * Determines how to divide the graph into partitions, how to manipulate
29 * partitions and then how to assign those partitions to workers.
30 *
31 * @param <I> Vertex index value
32 * @param <V> Vertex value
33 * @param <E> Edge value
34 */
35 @SuppressWarnings("rawtypes")
36 public interface MasterGraphPartitioner<I extends WritableComparable,
37 V extends Writable, E extends Writable> {
38 /**
39 * Set some initial partition owners for the graph. Guaranteed to be called
40 * prior to the graph being loaded (initial or restart).
41 *
42 * @param availableWorkerInfos Workers available for partition assignment
43 * @param maxWorkers Maximum number of workers
44 * @return Collection of generated partition owners.
45 */
46 Collection<PartitionOwner> createInitialPartitionOwners(
47 Collection<WorkerInfo> availableWorkerInfos, int maxWorkers);
48
49 /**
50 * Sets partition owners for the graph.
51 * Used then loading from checkpoint.
52 * @param partitionOwners assigned partition owners.
53 */
54 void setPartitionOwners(Collection<PartitionOwner> partitionOwners);
55
56 /**
57 * After the worker stats have been merged to a single list, the master can
58 * use this information to send commands to the workers for any
59 * {@link Partition} changes. This protocol is specific to the
60 * {@link MasterGraphPartitioner} implementation.
61 *
62 * @param allPartitionStatsList All partition stats from all workers.
63 * @param availableWorkers Workers available for partition assignment
64 * @param maxWorkers Maximum number of workers
65 * @param superstep Partition owners will be set for this superstep
66 * @return Collection of {@link PartitionOwner} objects that changed from
67 * the previous superstep, empty list if no change.
68 */
69 Collection<PartitionOwner> generateChangedPartitionOwners(
70 Collection<PartitionStats> allPartitionStatsList,
71 Collection<WorkerInfo> availableWorkers,
72 int maxWorkers,
73 long superstep);
74
75 /**
76 * Get current partition owners at this time.
77 *
78 * @return Collection of current {@link PartitionOwner} objects
79 */
80 Collection<PartitionOwner> getCurrentPartitionOwners();
81
82 /**
83 * Instantiate the {@link PartitionStats} implementation used to read the
84 * worker stats
85 *
86 * @return Instantiated {@link PartitionStats} object
87 */
88 PartitionStats createPartitionStats();
89 }