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.blockmanagement; 019 020/** 021 * A immutable object that stores the number of live replicas and 022 * the number of decommissioned Replicas. 023 */ 024public class NumberReplicas { 025 private int liveReplicas; 026 027 // Tracks only the decommissioning replicas 028 private int decommissioning; 029 // Tracks only the decommissioned replicas 030 private int decommissioned; 031 private int corruptReplicas; 032 private int excessReplicas; 033 private int replicasOnStaleNodes; 034 035 NumberReplicas() { 036 initialize(0, 0, 0, 0, 0, 0); 037 } 038 039 NumberReplicas(int live, int decommissioned, int decommissioning, int corrupt, 040 int excess, int stale) { 041 initialize(live, decommissioned, decommissioning, corrupt, excess, stale); 042 } 043 044 void initialize(int live, int decommissioned, int decommissioning, 045 int corrupt, int excess, int stale) { 046 liveReplicas = live; 047 this.decommissioning = decommissioning; 048 this.decommissioned = decommissioned; 049 corruptReplicas = corrupt; 050 excessReplicas = excess; 051 replicasOnStaleNodes = stale; 052 } 053 054 public int liveReplicas() { 055 return liveReplicas; 056 } 057 058 /** 059 * 060 * @return decommissioned replicas + decommissioning replicas 061 * It is deprecated by decommissionedAndDecommissioning 062 * due to its misleading name. 063 */ 064 @Deprecated 065 public int decommissionedReplicas() { 066 return decommissionedAndDecommissioning(); 067 } 068 069 /** 070 * 071 * @return decommissioned and decommissioning replicas 072 */ 073 public int decommissionedAndDecommissioning() { 074 return decommissioned + decommissioning; 075 } 076 077 /** 078 * 079 * @return decommissioned replicas only 080 */ 081 public int decommissioned() { 082 return decommissioned; 083 } 084 085 /** 086 * 087 * @return decommissioning replicas only 088 */ 089 public int decommissioning() { 090 return decommissioning; 091 } 092 093 public int corruptReplicas() { 094 return corruptReplicas; 095 } 096 097 public int excessReplicas() { 098 return excessReplicas; 099 } 100 101 /** 102 * @return the number of replicas which are on stale nodes. 103 * This is not mutually exclusive with the other counts -- ie a 104 * replica may count as both "live" and "stale". 105 */ 106 public int replicasOnStaleNodes() { 107 return replicasOnStaleNodes; 108 } 109}