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;
021
022import org.apache.hadoop.hdfs.server.datanode.fsdataset.ReplicaOutputStreams;
023import org.apache.hadoop.util.DataChecksum;
024
025/** 
026 * This defines the interface of a replica in Pipeline that's being written to
027 */
028public interface ReplicaInPipelineInterface extends Replica {
029  /**
030   * Set the number of bytes received
031   * @param bytesReceived number of bytes received
032   */
033  void setNumBytes(long bytesReceived);
034  
035  /**
036   * Get the number of bytes acked
037   * @return the number of bytes acked
038   */
039  long getBytesAcked();
040  
041  /**
042   * Set the number bytes that have acked
043   * @param bytesAcked number bytes acked
044   */
045  void setBytesAcked(long bytesAcked);
046  
047  /**
048   * Release any disk space reserved for this replica.
049   */
050  public void releaseAllBytesReserved();
051
052  /**
053   * store the checksum for the last chunk along with the data length
054   * @param dataLength number of bytes on disk
055   * @param lastChecksum - checksum bytes for the last chunk
056   */
057  public void setLastChecksumAndDataLen(long dataLength, byte[] lastChecksum);
058  
059  /**
060   * gets the last chunk checksum and the length of the block corresponding
061   * to that checksum
062   */
063  public ChunkChecksum getLastChecksumAndDataLen();
064  
065  /**
066   * Create output streams for writing to this replica, 
067   * one for block file and one for CRC file
068   * 
069   * @param isCreate if it is for creation
070   * @param requestedChecksum the checksum the writer would prefer to use
071   * @return output streams for writing
072   * @throws IOException if any error occurs
073   */
074  public ReplicaOutputStreams createStreams(boolean isCreate,
075      DataChecksum requestedChecksum) throws IOException;
076}