This project has retired. For details please refer to its Attic page.
StorePartitionIOCommand 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.ooc.command;
20  
21  import org.apache.giraph.bsp.BspService;
22  import org.apache.giraph.comm.messages.MessageStore;
23  import org.apache.giraph.ooc.data.DiskBackedEdgeStore;
24  import org.apache.giraph.ooc.data.DiskBackedMessageStore;
25  import org.apache.giraph.ooc.data.DiskBackedPartitionStore;
26  import org.apache.giraph.ooc.OutOfCoreEngine;
27  
28  import java.io.IOException;
29  
30  /**
31   * IOCommand to store partition data, edge data (if in INPUT_SUPERSTEP), and
32   * message data (if in compute supersteps).
33   */
34  public class StorePartitionIOCommand extends IOCommand {
35    /**
36     * Constructor
37     *
38     * @param oocEngine out-of-core engine
39     * @param partitionId id of the partition to store its data
40     */
41    public StorePartitionIOCommand(OutOfCoreEngine oocEngine,
42                                   int partitionId) {
43      super(oocEngine, partitionId);
44    }
45  
46    @Override
47    public boolean execute() throws IOException {
48      boolean executed = false;
49      if (oocEngine.getMetaPartitionManager()
50          .startOffloadingPartition(partitionId)) {
51        DiskBackedPartitionStore partitionStore =
52            (DiskBackedPartitionStore)
53                oocEngine.getServerData().getPartitionStore();
54        numBytesTransferred +=
55            partitionStore.offloadPartitionData(partitionId);
56        if (oocEngine.getSuperstep() != BspService.INPUT_SUPERSTEP) {
57          MessageStore messageStore =
58              oocEngine.getServerData().getCurrentMessageStore();
59          if (messageStore != null) {
60            numBytesTransferred += ((DiskBackedMessageStore) messageStore)
61                .offloadPartitionData(partitionId);
62          }
63        } else {
64          DiskBackedEdgeStore edgeStore =
65              (DiskBackedEdgeStore)
66                  oocEngine.getServerData().getEdgeStore();
67          numBytesTransferred +=
68              edgeStore.offloadPartitionData(partitionId);
69        }
70        oocEngine.getMetaPartitionManager().doneOffloadingPartition(partitionId);
71        executed = true;
72      }
73      return executed;
74    }
75  
76    @Override
77    public IOCommandType getType() {
78      return IOCommandType.STORE_PARTITION;
79    }
80  
81    @Override
82    public String toString() {
83      return "StorePartitionIOCommand: (partitionId = " + partitionId + ")";
84    }
85  }