001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hdfs.server.datanode;
019
020import java.io.IOException;
021import java.io.OutputStream;
022
023import org.apache.hadoop.hdfs.server.datanode.fsdataset.ReplicaOutputStreams;
024import org.apache.hadoop.util.DataChecksum;
025
026/** 
027 * This defines the interface of a replica in Pipeline that's being written to
028 */
029public interface ReplicaInPipelineInterface extends Replica {
030  /**
031   * Set the number of bytes received
032   * @param bytesReceived number of bytes received
033   */
034  void setNumBytes(long bytesReceived);
035  
036  /**
037   * Get the number of bytes acked
038   * @return the number of bytes acked
039   */
040  long getBytesAcked();
041  
042  /**
043   * Set the number bytes that have acked
044   * @param bytesAcked number bytes acked
045   */
046  void setBytesAcked(long bytesAcked);
047  
048  /**
049   * Release any disk space reserved for this replica.
050   */
051  public void releaseAllBytesReserved();
052
053  /**
054   * store the checksum for the last chunk along with the data length
055   * @param dataLength number of bytes on disk
056   * @param lastChecksum - checksum bytes for the last chunk
057   */
058  public void setLastChecksumAndDataLen(long dataLength, byte[] lastChecksum);
059  
060  /**
061   * gets the last chunk checksum and the length of the block corresponding
062   * to that checksum
063   */
064  public ChunkChecksum getLastChecksumAndDataLen();
065  
066  /**
067   * Create output streams for writing to this replica, 
068   * one for block file and one for CRC file
069   * 
070   * @param isCreate if it is for creation
071   * @param requestedChecksum the checksum the writer would prefer to use
072   * @return output streams for writing
073   * @throws IOException if any error occurs
074   */
075  public ReplicaOutputStreams createStreams(boolean isCreate,
076      DataChecksum requestedChecksum) throws IOException;
077
078  /**
079   * Create an output stream to write restart metadata in case of datanode
080   * shutting down for quick restart.
081   *
082   * @return output stream for writing.
083   * @throws IOException if any error occurs
084   */
085  public OutputStream createRestartMetaStream() throws IOException;
086}