1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * 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 and16 * limitations under the License.17 */1819package org.apache.giraph.ooc.command;
2021import org.apache.giraph.bsp.BspService;
22import org.apache.giraph.comm.messages.MessageStore;
23import org.apache.giraph.ooc.data.DiskBackedEdgeStore;
24import org.apache.giraph.ooc.data.DiskBackedMessageStore;
25import org.apache.giraph.ooc.data.DiskBackedPartitionStore;
26import org.apache.giraph.ooc.OutOfCoreEngine;
2728import java.io.IOException;
2930/**31 * IOCommand to store partition data, edge data (if in INPUT_SUPERSTEP), and32 * message data (if in compute supersteps).33 */34publicclassStorePartitionIOCommandextendsIOCommand {
35/**36 * Constructor37 *38 * @param oocEngine out-of-core engine39 * @param partitionId id of the partition to store its data40 */41publicStorePartitionIOCommand(OutOfCoreEngine oocEngine,
42int partitionId) {
43super(oocEngine, partitionId);
44 }
4546 @Override
47publicboolean execute() throws IOException {
48boolean executed = false;
49if (oocEngine.getMetaPartitionManager()
50 .startOffloadingPartition(partitionId)) {
51DiskBackedPartitionStore partitionStore =
52 (DiskBackedPartitionStore)
53 oocEngine.getServerData().getPartitionStore();
54 numBytesTransferred +=
55 partitionStore.offloadPartitionData(partitionId);
56if (oocEngine.getSuperstep() != BspService.INPUT_SUPERSTEP) {
57MessageStore messageStore =
58 oocEngine.getServerData().getCurrentMessageStore();
59if (messageStore != null) {
60 numBytesTransferred += ((DiskBackedMessageStore) messageStore)
61 .offloadPartitionData(partitionId);
62 }
63 } else {
64DiskBackedEdgeStore edgeStore =
65 (DiskBackedEdgeStore)
66 oocEngine.getServerData().getEdgeStore();
67 numBytesTransferred +=
68 edgeStore.offloadPartitionData(partitionId);
69 }
70 oocEngine.getMetaPartitionManager().doneOffloadingPartition(partitionId);
71 executed = true;
72 }
73return executed;
74 }
7576 @Override
77publicIOCommandType getType() {
78return IOCommandType.STORE_PARTITION;
79 }
8081 @Override
82public String toString() {
83return"StorePartitionIOCommand: (partitionId = " + partitionId + ")";
84 }
85 }