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
019package org.apache.hadoop.hbase.master;
020
021import static org.apache.hadoop.hbase.master.MetricsMaster.convertToProcedureMetrics;
022
023import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
024import org.apache.hadoop.hbase.procedure2.ProcedureMetrics;
025import org.apache.yetus.audience.InterfaceAudience;
026
027@InterfaceAudience.Private
028public class MetricsAssignmentManager {
029  private final MetricsAssignmentManagerSource assignmentManagerSource;
030
031  private final ProcedureMetrics assignProcMetrics;
032  private final ProcedureMetrics unassignProcMetrics;
033  private final ProcedureMetrics moveProcMetrics;
034  private final ProcedureMetrics reopenProcMetrics;
035  private final ProcedureMetrics openProcMetrics;
036  private final ProcedureMetrics closeProcMetrics;
037  private final ProcedureMetrics splitProcMetrics;
038  private final ProcedureMetrics mergeProcMetrics;
039
040  public MetricsAssignmentManager() {
041    assignmentManagerSource = CompatibilitySingletonFactory.getInstance(
042        MetricsAssignmentManagerSource.class);
043
044    assignProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getAssignMetrics());
045    unassignProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getUnassignMetrics());
046    moveProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getMoveMetrics());
047    reopenProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getReopenMetrics());
048    openProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getOpenMetrics());
049    closeProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getCloseMetrics());
050    splitProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getSplitMetrics());
051    mergeProcMetrics = convertToProcedureMetrics(assignmentManagerSource.getMergeMetrics());
052  }
053
054  public MetricsAssignmentManagerSource getMetricsProcSource() {
055    return assignmentManagerSource;
056  }
057
058  /**
059   * set new value for number of regions in transition.
060   * @param ritCount
061   */
062  public void updateRITCount(final int ritCount) {
063    assignmentManagerSource.setRIT(ritCount);
064  }
065
066  /**
067   * update RIT count that are in this state for more than the threshold
068   * as defined by the property rit.metrics.threshold.time.
069   * @param ritCountOverThreshold
070   */
071  public void updateRITCountOverThreshold(final int ritCountOverThreshold) {
072    assignmentManagerSource.setRITCountOverThreshold(ritCountOverThreshold);
073  }
074
075  /**
076   * update the timestamp for oldest region in transition metrics.
077   * @param timestamp
078   */
079  public void updateRITOldestAge(final long timestamp) {
080    assignmentManagerSource.setRITOldestAge(timestamp);
081  }
082
083  /**
084   * update the duration metrics of region is transition
085   * @param duration
086   */
087  public void updateRitDuration(long duration) {
088    assignmentManagerSource.updateRitDuration(duration);
089  }
090
091  /*
092   * TODO: Remove. This may not be required as assign and unassign operations are tracked separately
093   * Increment the count of assignment operation (assign/unassign).
094   */
095  public void incrementOperationCounter() {
096    assignmentManagerSource.incrementOperationCounter();
097  }
098
099  public void updateDeadServerOpenRegions(int deadRegions) {
100    assignmentManagerSource.updateDeadServerOpenRegions(deadRegions);
101  }
102
103  public void updateUnknownServerOpenRegions(int unknownRegions) {
104    assignmentManagerSource.updateUnknownServerOpenRegions(unknownRegions);
105  }
106
107  /**
108   * @return Set of common metrics for assign procedure
109   */
110  public ProcedureMetrics getAssignProcMetrics() {
111    return assignProcMetrics;
112  }
113
114  /**
115   * @return Set of common metrics for unassign procedure
116   */
117  public ProcedureMetrics getUnassignProcMetrics() {
118    return unassignProcMetrics;
119  }
120
121  /**
122   * @return Set of common metrics for move procedure
123   */
124  public ProcedureMetrics getMoveProcMetrics() {
125    return moveProcMetrics;
126  }
127
128  /**
129   * @return Set of common metrics for reopen procedure
130   */
131  public ProcedureMetrics getReopenProcMetrics() {
132    return reopenProcMetrics;
133  }
134
135  /**
136   * @return Set of common metrics for OpenRegionProcedure
137   */
138  public ProcedureMetrics getOpenProcMetrics() {
139    return openProcMetrics;
140  }
141
142  /**
143   * @return Set of common metrics for CloseRegionProcedure
144   */
145  public ProcedureMetrics getCloseProcMetrics() {
146    return closeProcMetrics;
147  }
148
149  /**
150   * @return Set of common metrics for split procedure
151   */
152  public ProcedureMetrics getSplitProcMetrics() {
153    return splitProcMetrics;
154  }
155
156  /**
157   * @return Set of common metrics for merge procedure
158   */
159  public ProcedureMetrics getMergeProcMetrics() {
160    return mergeProcMetrics;
161  }
162}