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/** 027 * This class represents a replica that is waiting to be recovered. 028 * After a datanode restart, any replica in "rbw" directory is loaded 029 * as a replica waiting to be recovered. 030 * A replica waiting to be recovered does not provision read nor 031 * participates in any pipeline recovery. It will become outdated if its 032 * client continues to write or be recovered as a result of 033 * lease recovery. 034 */ 035public class ReplicaWaitingToBeRecovered extends ReplicaInfo { 036 private boolean unlinked; // copy-on-write done for block 037 038 /** 039 * Constructor 040 * @param blockId block id 041 * @param len replica length 042 * @param genStamp replica generation stamp 043 * @param vol volume where replica is located 044 * @param dir directory path where block and meta files are located 045 */ 046 public ReplicaWaitingToBeRecovered(long blockId, long len, long genStamp, 047 FsVolumeSpi vol, File dir) { 048 super(blockId, len, genStamp, vol, dir); 049 } 050 051 /** 052 * Constructor 053 * @param block a block 054 * @param vol volume where replica is located 055 * @param dir directory path where block and meta files are located 056 */ 057 public ReplicaWaitingToBeRecovered(Block block, FsVolumeSpi vol, File dir) { 058 super(block, vol, dir); 059 } 060 061 /** 062 * Copy constructor. 063 * @param from 064 */ 065 public ReplicaWaitingToBeRecovered(ReplicaWaitingToBeRecovered from) { 066 super(from); 067 this.unlinked = from.isUnlinked(); 068 } 069 070 @Override //ReplicaInfo 071 public ReplicaState getState() { 072 return ReplicaState.RWR; 073 } 074 075 @Override //ReplicaInfo 076 public boolean isUnlinked() { 077 return unlinked; 078 } 079 080 @Override //ReplicaInfo 081 public void setUnlinked() { 082 unlinked = true; 083 } 084 085 @Override //ReplicaInfo 086 public long getVisibleLength() { 087 return -1; //no bytes are visible 088 } 089 090 @Override 091 public long getBytesOnDisk() { 092 return getNumBytes(); 093 } 094 095 @Override // Object 096 public boolean equals(Object o) { 097 return super.equals(o); 098 } 099 100 @Override // Object 101 public int hashCode() { 102 return super.hashCode(); 103 } 104 105 @Override 106 public String toString() { 107 return super.toString() 108 + "\n unlinked=" + unlinked; 109 } 110}