This project has retired. For details please refer to its Attic page.
WorkerGraphPartitioner xref
View Javadoc

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.worker.WorkerInfo;
22  import org.apache.hadoop.io.Writable;
23  import org.apache.hadoop.io.WritableComparable;
24  
25  import java.util.Collection;
26  
27  /**
28   * Stores the {@link PartitionOwner} objects from the master and provides the
29   * mapping of vertex to {@link PartitionOwner}. Also generates the partition
30   * owner implementation.
31   *
32   * @param <I> Vertex id
33   * @param <V> Vertex value
34   * @param <E> Edge value
35   */
36  @SuppressWarnings("rawtypes")
37  public interface WorkerGraphPartitioner<I extends WritableComparable,
38      V extends Writable, E extends Writable> {
39    /**
40     * Instantiate the {@link PartitionOwner} implementation used to read the
41     * master assignments.
42     *
43     * @return Instantiated {@link PartitionOwner} object
44     */
45    PartitionOwner createPartitionOwner();
46  
47    /**
48     * Figure out the owner of a vertex
49     *
50     * @param vertexId Vertex id to get the partition for
51     * @return Correct partition owner
52     */
53    PartitionOwner getPartitionOwner(I vertexId);
54  
55    /**
56     * At the end of a superstep, workers have {@link PartitionStats} generated
57     * for each of their partitions.  This method will allow the user to
58     * modify or create their own {@link PartitionStats} interfaces to send to
59     * the master.
60     *
61     * @param workerPartitionStats Stats generated by the infrastructure during
62     *        the superstep
63     * @param partitionStore Partition store for this worker
64     *        (could be used to provide more useful stat information)
65     * @return Final partition stats
66     */
67    Collection<PartitionStats> finalizePartitionStats(
68        Collection<PartitionStats> workerPartitionStats,
69        PartitionStore<I, V, E> partitionStore);
70  
71    /**
72     * Get the partitions owners and update locally.  Returns the partitions
73     * to send to other workers and other dependencies.
74     *
75     * @param myWorkerInfo Worker info.
76     * @param masterSetPartitionOwners Master set partition owners, received
77     *        prior to beginning the superstep
78     * @return Information for the partition exchange.
79     */
80    PartitionExchange updatePartitionOwners(
81        WorkerInfo myWorkerInfo,
82        Collection<? extends PartitionOwner> masterSetPartitionOwners);
83  
84    /**
85     * Get a collection of the {@link PartitionOwner} objects.
86     *
87     * @return Collection of owners for every partition.
88     */
89    Collection<? extends PartitionOwner> getPartitionOwners();
90  }