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 */
018 package org.apache.hadoop.hdfs.server.datanode;
019
020 import java.io.File;
021
022 import org.apache.hadoop.hdfs.protocol.Block;
023 import org.apache.hadoop.hdfs.server.common.HdfsServerConstants.ReplicaState;
024 import 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 */
030 public 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 */
038 public ReplicaBeingWritten(long blockId, long genStamp,
039 FsVolumeSpi vol, File dir) {
040 super( blockId, genStamp, vol, dir);
041 }
042
043 /**
044 * Constructor
045 * @param block a block
046 * @param vol volume where replica is located
047 * @param dir directory path where block and meta files are located
048 * @param writer a thread that is writing to this replica
049 */
050 public ReplicaBeingWritten(Block block,
051 FsVolumeSpi vol, File dir, Thread writer) {
052 super( block, vol, dir, writer);
053 }
054
055 /**
056 * Constructor
057 * @param blockId block id
058 * @param len replica length
059 * @param genStamp replica generation stamp
060 * @param vol volume where replica is located
061 * @param dir directory path where block and meta files are located
062 * @param writer a thread that is writing to this replica
063 */
064 public ReplicaBeingWritten(long blockId, long len, long genStamp,
065 FsVolumeSpi vol, File dir, Thread writer ) {
066 super( blockId, len, genStamp, vol, dir, writer);
067 }
068
069 /**
070 * Copy constructor.
071 * @param from
072 */
073 public ReplicaBeingWritten(ReplicaBeingWritten from) {
074 super(from);
075 }
076
077 @Override
078 public long getVisibleLength() {
079 return getBytesAcked(); // all acked bytes are visible
080 }
081
082 @Override //ReplicaInfo
083 public ReplicaState getState() {
084 return ReplicaState.RBW;
085 }
086
087 @Override // Object
088 public boolean equals(Object o) {
089 return super.equals(o);
090 }
091
092 @Override // Object
093 public int hashCode() {
094 return super.hashCode();
095 }
096 }