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 /**
027 * This class describes a replica that has been finalized.
028 */
029 public class FinalizedReplica extends ReplicaInfo {
030 private boolean unlinked; // copy-on-write done for block
031
032 /**
033 * Constructor
034 * @param blockId block id
035 * @param len replica length
036 * @param genStamp replica generation stamp
037 * @param vol volume where replica is located
038 * @param dir directory path where block and meta files are located
039 */
040 public FinalizedReplica(long blockId, long len, long genStamp,
041 FsVolumeSpi vol, File dir) {
042 super(blockId, len, genStamp, vol, dir);
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 */
051 public FinalizedReplica(Block block, FsVolumeSpi vol, File dir) {
052 super(block, vol, dir);
053 }
054
055 /**
056 * Copy constructor.
057 * @param from where to copy construct from
058 */
059 public FinalizedReplica(FinalizedReplica from) {
060 super(from);
061 this.unlinked = from.isUnlinked();
062 }
063
064 @Override // ReplicaInfo
065 public ReplicaState getState() {
066 return ReplicaState.FINALIZED;
067 }
068
069 @Override // ReplicaInfo
070 public boolean isUnlinked() {
071 return unlinked;
072 }
073
074 @Override // ReplicaInfo
075 public void setUnlinked() {
076 unlinked = true;
077 }
078
079 @Override
080 public long getVisibleLength() {
081 return getNumBytes(); // all bytes are visible
082 }
083
084 @Override
085 public long getBytesOnDisk() {
086 return getNumBytes();
087 }
088
089 @Override // Object
090 public boolean equals(Object o) {
091 return super.equals(o);
092 }
093
094 @Override // Object
095 public int hashCode() {
096 return super.hashCode();
097 }
098
099 @Override
100 public String toString() {
101 return super.toString()
102 + "\n unlinked =" + unlinked;
103 }
104 }