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