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.File; 021 022import org.apache.hadoop.hdfs.protocol.Block; 023import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState; 024import org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi; 025 026/** This class represents replicas being written. 027 * Those are the replicas that 028 * are created in a pipeline initiated by a dfs client. 029 */ 030public class ReplicaBeingWritten extends ReplicaInPipeline { 031 /** 032 * Constructor for a zero length replica 033 * @param blockId block id 034 * @param genStamp replica generation stamp 035 * @param vol volume where replica is located 036 * @param dir directory path where block and meta files are located 037 * @param bytesToReserve disk space to reserve for this replica, based on 038 * the estimated maximum block length. 039 */ 040 public ReplicaBeingWritten(long blockId, long genStamp, 041 FsVolumeSpi vol, File dir, long bytesToReserve) { 042 super(blockId, genStamp, vol, dir, bytesToReserve); 043 } 044 045 /** 046 * Constructor 047 * @param block a block 048 * @param vol volume where replica is located 049 * @param dir directory path where block and meta files are located 050 * @param writer a thread that is writing to this replica 051 */ 052 public ReplicaBeingWritten(Block block, 053 FsVolumeSpi vol, File dir, Thread writer) { 054 super( block, vol, dir, writer); 055 } 056 057 /** 058 * Constructor 059 * @param blockId block id 060 * @param len replica length 061 * @param genStamp replica generation stamp 062 * @param vol volume where replica is located 063 * @param dir directory path where block and meta files are located 064 * @param writer a thread that is writing to this replica 065 * @param bytesToReserve disk space to reserve for this replica, based on 066 * the estimated maximum block length. 067 */ 068 public ReplicaBeingWritten(long blockId, long len, long genStamp, 069 FsVolumeSpi vol, File dir, Thread writer, long bytesToReserve) { 070 super(blockId, len, genStamp, vol, dir, writer, bytesToReserve); 071 } 072 073 /** 074 * Copy constructor. 075 * @param from where to copy from 076 */ 077 public ReplicaBeingWritten(ReplicaBeingWritten from) { 078 super(from); 079 } 080 081 @Override 082 public long getVisibleLength() { 083 return getBytesAcked(); // all acked bytes are visible 084 } 085 086 @Override //ReplicaInfo 087 public ReplicaState getState() { 088 return ReplicaState.RBW; 089 } 090 091 @Override // Object 092 public boolean equals(Object o) { 093 return super.equals(o); 094 } 095 096 @Override // Object 097 public int hashCode() { 098 return super.hashCode(); 099 } 100}