Coverage Report - org.apache.giraph.ooc.command.StoreDataBufferIOCommand
 
Classes in this File Line Coverage Branch Coverage Complexity
StoreDataBufferIOCommand
0%
0/27
0%
0/5
2
StoreDataBufferIOCommand$1
0%
0/1
N/A
2
StoreDataBufferIOCommand$DataBufferType
0%
0/1
N/A
2
 
 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.ooc.OutOfCoreEngine;
 22  
 import org.apache.giraph.ooc.data.DiskBackedEdgeStore;
 23  
 import org.apache.giraph.ooc.data.DiskBackedMessageStore;
 24  
 import org.apache.giraph.ooc.data.DiskBackedPartitionStore;
 25  
 
 26  
 import java.io.IOException;
 27  
 
 28  
 /**
 29  
  * IOCommand to store raw data buffers on disk.
 30  
  */
 31  
 public class StoreDataBufferIOCommand extends IOCommand {
 32  
   /**
 33  
    * Types of raw data buffer to offload to disk (either vertices/edges buffer
 34  
    * in INPUT_SUPERSTEP or incoming message buffer).
 35  
    */
 36  0
   public enum DataBufferType { PARTITION, MESSAGE };
 37  
   /**
 38  
    * Type of the buffer to store on disk.
 39  
    */
 40  
   private final DataBufferType type;
 41  
 
 42  
   /**
 43  
    * Constructor
 44  
    *
 45  
    * @param oocEngine out-of-core engine
 46  
    * @param partitionId id of the partition to offload its buffers
 47  
    * @param type type of the buffer to store on disk
 48  
    */
 49  
   public StoreDataBufferIOCommand(OutOfCoreEngine oocEngine,
 50  
                                   int partitionId,
 51  
                                   DataBufferType type) {
 52  0
     super(oocEngine, partitionId);
 53  0
     this.type = type;
 54  0
   }
 55  
 
 56  
   @Override
 57  
   public boolean execute() throws IOException {
 58  0
     boolean executed = false;
 59  0
     if (oocEngine.getMetaPartitionManager()
 60  0
         .startOffloadingBuffer(partitionId)) {
 61  0
       switch (type) {
 62  
       case PARTITION:
 63  0
         DiskBackedPartitionStore partitionStore =
 64  
             (DiskBackedPartitionStore)
 65  0
                 oocEngine.getServerData().getPartitionStore();
 66  0
         numBytesTransferred +=
 67  0
             partitionStore.offloadBuffers(partitionId);
 68  0
         DiskBackedEdgeStore edgeStore =
 69  0
             (DiskBackedEdgeStore) oocEngine.getServerData().getEdgeStore();
 70  0
         numBytesTransferred += edgeStore.offloadBuffers(partitionId);
 71  0
         break;
 72  
       case MESSAGE:
 73  0
         DiskBackedMessageStore messageStore =
 74  
             (DiskBackedMessageStore)
 75  0
                 oocEngine.getServerData().getIncomingMessageStore();
 76  0
         numBytesTransferred +=
 77  0
             messageStore.offloadBuffers(partitionId);
 78  0
         break;
 79  
       default:
 80  0
         throw new IllegalStateException("execute: requested data buffer type " +
 81  
             "does not exist!");
 82  
       }
 83  0
       oocEngine.getMetaPartitionManager().doneOffloadingBuffer(partitionId);
 84  0
       executed = true;
 85  
     }
 86  0
     return executed;
 87  
   }
 88  
 
 89  
   @Override
 90  
   public IOCommandType getType() {
 91  0
     return IOCommandType.STORE_BUFFER;
 92  
   }
 93  
 
 94  
   @Override
 95  
   public String toString() {
 96  0
     return "StoreDataBufferIOCommand: (partitionId = " + partitionId + ", " +
 97  0
         "type = " + type.name() + ")";
 98  
   }
 99  
 }