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